Search in sources :

Example 1 with AbstractOperation

use of org.eclipse.core.commands.operations.AbstractOperation in project eclipse.platform.text by eclipse.

the class TextViewerUndoManagerTest method internalTestTransferNonTextOp.

// --- DocumentUndoManager only ---
public void internalTestTransferNonTextOp(final boolean isUndoable) throws Exception {
    Object context = new Object();
    DocumentUndoManager tempUndoManager = new DocumentUndoManager(new Document());
    tempUndoManager.connect(context);
    IUndoableOperation operation = new AbstractOperation("") {

        @Override
        public boolean canUndo() {
            return isUndoable;
        }

        @Override
        public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
            return Status.OK_STATUS;
        }

        @Override
        public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
            return Status.OK_STATUS;
        }

        @Override
        public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
            return Status.OK_STATUS;
        }
    };
    operation.addContext(tempUndoManager.getUndoContext());
    OperationHistoryFactory.getOperationHistory().add(operation);
    assertEquals(isUndoable, tempUndoManager.undoable());
    final DocumentUndoManager undoManager = new DocumentUndoManager(new Document());
    Object newContext = new Object();
    undoManager.connect(newContext);
    undoManager.addDocumentUndoListener(new IDocumentUndoListener() {

        @Override
        public void documentUndoNotification(DocumentUndoEvent event) {
            fail();
        }
    });
    undoManager.transferUndoHistory(tempUndoManager);
    tempUndoManager.disconnect(context);
    assertEquals(isUndoable, undoManager.undoable());
    undoManager.undo();
    assertEquals(false, undoManager.undoable());
    undoManager.disconnect(newContext);
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractOperation(org.eclipse.core.commands.operations.AbstractOperation) DocumentUndoEvent(org.eclipse.text.undo.DocumentUndoEvent) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation) IDocumentUndoListener(org.eclipse.text.undo.IDocumentUndoListener) DocumentUndoManager(org.eclipse.text.undo.DocumentUndoManager) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

AbstractOperation (org.eclipse.core.commands.operations.AbstractOperation)1 IUndoableOperation (org.eclipse.core.commands.operations.IUndoableOperation)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Document (org.eclipse.jface.text.Document)1 IDocument (org.eclipse.jface.text.IDocument)1 DocumentUndoEvent (org.eclipse.text.undo.DocumentUndoEvent)1 DocumentUndoManager (org.eclipse.text.undo.DocumentUndoManager)1 IDocumentUndoListener (org.eclipse.text.undo.IDocumentUndoListener)1