Search in sources :

Example 1 with DocumentUndoManager

use of org.eclipse.text.undo.DocumentUndoManager in project eclipse.platform.text by eclipse.

the class DocumentUndoManagerTest method testDocumentStamp2.

// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=109104
public void testDocumentStamp2() throws BadLocationException, ExecutionException {
    final Document document = new Document("");
    fUndoManager = new DocumentUndoManager(document);
    fUndoManager.connect(this);
    final int stringLength = 13;
    document.replace(0, 0, createRandomString(stringLength));
    long stamp = document.getModificationStamp();
    fUndoManager.undo();
    document.replace(0, 0, createRandomString(stringLength));
    assertFalse(stamp == document.getModificationStamp());
}
Also used : DocumentUndoManager(org.eclipse.text.undo.DocumentUndoManager) IDocumentUndoManager(org.eclipse.text.undo.IDocumentUndoManager) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with DocumentUndoManager

use of org.eclipse.text.undo.DocumentUndoManager in project eclipse.platform.text by eclipse.

the class DocumentUndoManagerTest method createUndoManager.

private void createUndoManager(final IDocument document) {
    fUndoManager = new DocumentUndoManager(document);
    fUndoManager.connect(this);
    fUndoManager.setMaximalUndoLevel(MAX_UNDO_LEVEL);
}
Also used : DocumentUndoManager(org.eclipse.text.undo.DocumentUndoManager) IDocumentUndoManager(org.eclipse.text.undo.IDocumentUndoManager)

Example 3 with DocumentUndoManager

use of org.eclipse.text.undo.DocumentUndoManager in project eclipse.platform.text by eclipse.

the class DocumentUndoManagerTest method testDocumentStamp.

public void testDocumentStamp() throws ExecutionException {
    final Document document = new Document(INITIAL_DOCUMENT_CONTENT);
    fUndoManager = new DocumentUndoManager(document);
    fUndoManager.connect(this);
    long stamp = document.getModificationStamp();
    doChange(document, 1);
    fUndoManager.undo();
    assertEquals(stamp, document.getModificationStamp());
}
Also used : DocumentUndoManager(org.eclipse.text.undo.DocumentUndoManager) IDocumentUndoManager(org.eclipse.text.undo.IDocumentUndoManager) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument)

Example 4 with DocumentUndoManager

use of org.eclipse.text.undo.DocumentUndoManager 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)

Example 5 with DocumentUndoManager

use of org.eclipse.text.undo.DocumentUndoManager in project eclipse.platform.text by eclipse.

the class TextViewerUndoManagerTest method testCanUndo.

@Test
public void testCanUndo() throws Exception {
    IDocument doc = new Document();
    final DocumentUndoManager undoManager = new DocumentUndoManager(doc);
    Object context = new Object();
    undoManager.connect(context);
    undoManager.addDocumentUndoListener(new IDocumentUndoListener() {

        @Override
        public void documentUndoNotification(DocumentUndoEvent event) {
            if (event.getEventType() == DocumentUndoEvent.ABOUT_TO_UNDO)
                assertEquals(true, undoManager.undoable());
            else if (event.getEventType() == DocumentUndoEvent.UNDONE)
                assertEquals(false, undoManager.undoable());
        }
    });
    doc.set("foo");
    assertEquals(true, undoManager.undoable());
    undoManager.undo();
    assertEquals(false, undoManager.undoable());
    undoManager.disconnect(context);
}
Also used : DocumentUndoEvent(org.eclipse.text.undo.DocumentUndoEvent) IDocumentUndoListener(org.eclipse.text.undo.IDocumentUndoListener) DocumentUndoManager(org.eclipse.text.undo.DocumentUndoManager) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Aggregations

DocumentUndoManager (org.eclipse.text.undo.DocumentUndoManager)5 Document (org.eclipse.jface.text.Document)4 IDocument (org.eclipse.jface.text.IDocument)4 IDocumentUndoManager (org.eclipse.text.undo.IDocumentUndoManager)3 DocumentUndoEvent (org.eclipse.text.undo.DocumentUndoEvent)2 IDocumentUndoListener (org.eclipse.text.undo.IDocumentUndoListener)2 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 Test (org.junit.Test)1