use of org.eclipse.core.commands.operations.IContextReplacingOperation in project eclipse.platform.text by eclipse.
the class DocumentUndoManager method transferUndoHistory.
@Override
public void transferUndoHistory(IDocumentUndoManager manager) {
IUndoContext oldUndoContext = manager.getUndoContext();
// Get the history for the old undo context.
IUndoableOperation[] operations = OperationHistoryFactory.getOperationHistory().getUndoHistory(oldUndoContext);
for (IUndoableOperation operation : operations) {
// First replace the undo context
IUndoableOperation op = operation;
if (op instanceof IContextReplacingOperation) {
((IContextReplacingOperation) op).replaceContext(oldUndoContext, getUndoContext());
} else {
op.addContext(getUndoContext());
op.removeContext(oldUndoContext);
}
// Now update the manager that owns the text edit.
if (op instanceof UndoableTextChange) {
((UndoableTextChange) op).fDocumentUndoManager = this;
}
}
IUndoableOperation op = OperationHistoryFactory.getOperationHistory().getUndoOperation(getUndoContext());
if (op != null && !(op instanceof UndoableTextChange))
return;
// Record the transfer itself as an undoable change.
// If the transfer results from some open operation, recording this change will
// cause our undo context to be added to the outer operation. If there is no
// outer operation, there will be a local change to signify the transfer.
// This also serves to synchronize the modification stamps with the documents.
UndoableTextChange cmd = new UndoableTextChange(this);
cmd.fStart = cmd.fEnd = 0;
// $NON-NLS-1$
cmd.fText = cmd.fPreservedText = "";
if (fDocument instanceof IDocumentExtension4) {
cmd.fRedoModificationStamp = ((IDocumentExtension4) fDocument).getModificationStamp();
if (op != null)
cmd.fUndoModificationStamp = ((UndoableTextChange) op).fRedoModificationStamp;
}
addToOperationHistory(cmd);
}
Aggregations