use of org.eclipse.text.undo.IDocumentUndoListener 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);
}
use of org.eclipse.text.undo.IDocumentUndoListener 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);
}
Aggregations