Search in sources :

Example 1 with IContextReplacingOperation

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);
}
Also used : IContextReplacingOperation(org.eclipse.core.commands.operations.IContextReplacingOperation) IUndoContext(org.eclipse.core.commands.operations.IUndoContext) IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) IUndoableOperation(org.eclipse.core.commands.operations.IUndoableOperation)

Aggregations

IContextReplacingOperation (org.eclipse.core.commands.operations.IContextReplacingOperation)1 IUndoContext (org.eclipse.core.commands.operations.IUndoContext)1 IUndoableOperation (org.eclipse.core.commands.operations.IUndoableOperation)1 IDocumentExtension4 (org.eclipse.jface.text.IDocumentExtension4)1