Search in sources :

Example 1 with IUndoManagerExtension

use of org.eclipse.jface.text.IUndoManagerExtension in project xtext-eclipse by eclipse.

the class LinkedEditingUndoSupport method startRecording.

public void startRecording(XtextEditor editor) {
    this.editor = editor;
    ISourceViewer viewer = editor.getInternalSourceViewer();
    if (viewer instanceof ITextViewerExtension6) {
        IUndoManager undoManager = ((ITextViewerExtension6) viewer).getUndoManager();
        if (undoManager instanceof IUndoManagerExtension) {
            IUndoManagerExtension undoManagerExtension = (IUndoManagerExtension) undoManager;
            IUndoContext undoContext = undoManagerExtension.getUndoContext();
            IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
            startingUndoOperation = operationHistory.getUndoOperation(undoContext);
        }
    }
}
Also used : IUndoContext(org.eclipse.core.commands.operations.IUndoContext) IUndoManager(org.eclipse.jface.text.IUndoManager) ITextViewerExtension6(org.eclipse.jface.text.ITextViewerExtension6) IOperationHistory(org.eclipse.core.commands.operations.IOperationHistory) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IUndoManagerExtension(org.eclipse.jface.text.IUndoManagerExtension)

Example 2 with IUndoManagerExtension

use of org.eclipse.jface.text.IUndoManagerExtension in project xtext-eclipse by eclipse.

the class LinkedEditingUndoSupport method undoDocumentChanges.

public void undoDocumentChanges() {
    final ISourceViewer viewer = editor.getInternalSourceViewer();
    try {
        editor.getSite().getWorkbenchWindow().run(false, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                if (viewer instanceof ITextViewerExtension6) {
                    IUndoManager undoManager = ((ITextViewerExtension6) viewer).getUndoManager();
                    if (undoManager instanceof IUndoManagerExtension) {
                        IUndoManagerExtension undoManagerExtension = (IUndoManagerExtension) undoManager;
                        IUndoContext undoContext = undoManagerExtension.getUndoContext();
                        IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
                        while (undoManager.undoable()) {
                            if (startingUndoOperation != null && startingUndoOperation.equals(operationHistory.getUndoOperation(undoContext)))
                                return;
                            undoManager.undo();
                        }
                    }
                }
            }
        });
        syncUtil.waitForReconciler(editor);
    } catch (InterruptedException e) {
        // cancelled by user, ok
        return;
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
}
Also used : IUndoContext(org.eclipse.core.commands.operations.IUndoContext) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IUndoManager(org.eclipse.jface.text.IUndoManager) ITextViewerExtension6(org.eclipse.jface.text.ITextViewerExtension6) IOperationHistory(org.eclipse.core.commands.operations.IOperationHistory) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IUndoManagerExtension(org.eclipse.jface.text.IUndoManagerExtension)

Aggregations

IOperationHistory (org.eclipse.core.commands.operations.IOperationHistory)2 IUndoContext (org.eclipse.core.commands.operations.IUndoContext)2 ITextViewerExtension6 (org.eclipse.jface.text.ITextViewerExtension6)2 IUndoManager (org.eclipse.jface.text.IUndoManager)2 IUndoManagerExtension (org.eclipse.jface.text.IUndoManagerExtension)2 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1