Search in sources :

Example 1 with LinearUndoViolationUserApprover

use of org.eclipse.ui.operations.LinearUndoViolationUserApprover in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method createUndoRedoActions.

/**
 * Creates this editor's undo/redo actions.
 * <p>
 * Subclasses may override or extend.</p>
 *
 * @since 3.1
 */
protected void createUndoRedoActions() {
    IUndoContext undoContext = getUndoContext();
    if (undoContext != null) {
        // Use actions provided by global undo/redo
        // Create the undo action
        OperationHistoryActionHandler undoAction = new UndoActionHandler(getEditorSite(), undoContext);
        PlatformUI.getWorkbench().getHelpSystem().setHelp(undoAction, IAbstractTextEditorHelpContextIds.UNDO_ACTION);
        undoAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_UNDO);
        registerUndoRedoAction(ITextEditorActionConstants.UNDO, undoAction);
        // Create the redo action.
        OperationHistoryActionHandler redoAction = new RedoActionHandler(getEditorSite(), undoContext);
        PlatformUI.getWorkbench().getHelpSystem().setHelp(redoAction, IAbstractTextEditorHelpContextIds.REDO_ACTION);
        redoAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_REDO);
        registerUndoRedoAction(ITextEditorActionConstants.REDO, redoAction);
        // Install operation approvers
        IOperationHistory history = OperationHistoryFactory.getOperationHistory();
        // The first approver will prompt when operations affecting outside elements are to be undone or redone.
        if (fNonLocalOperationApprover != null)
            history.removeOperationApprover(fNonLocalOperationApprover);
        fNonLocalOperationApprover = getUndoRedoOperationApprover(undoContext);
        history.addOperationApprover(fNonLocalOperationApprover);
        // and it is not the most recent operation in the editor.
        if (fLinearUndoViolationApprover != null)
            history.removeOperationApprover(fLinearUndoViolationApprover);
        fLinearUndoViolationApprover = new LinearUndoViolationUserApprover(undoContext, this);
        history.addOperationApprover(fLinearUndoViolationApprover);
    } else {
        // Use text operation actions (pre 3.1 style)
        ResourceAction action;
        if (getAction(ITextEditorActionConstants.UNDO) == null) {
            // $NON-NLS-1$
            action = new TextOperationAction(EditorMessages.getBundleForConstructedKeys(), "Editor.Undo.", this, ITextOperationTarget.UNDO);
            action.setHelpContextId(IAbstractTextEditorHelpContextIds.UNDO_ACTION);
            action.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_UNDO);
            setAction(ITextEditorActionConstants.UNDO, action);
        }
        if (getAction(ITextEditorActionConstants.REDO) == null) {
            // $NON-NLS-1$
            action = new TextOperationAction(EditorMessages.getBundleForConstructedKeys(), "Editor.Redo.", this, ITextOperationTarget.REDO);
            action.setHelpContextId(IAbstractTextEditorHelpContextIds.REDO_ACTION);
            action.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_REDO);
            setAction(ITextEditorActionConstants.REDO, action);
        }
    }
}
Also used : IUndoContext(org.eclipse.core.commands.operations.IUndoContext) OperationHistoryActionHandler(org.eclipse.ui.operations.OperationHistoryActionHandler) LinearUndoViolationUserApprover(org.eclipse.ui.operations.LinearUndoViolationUserApprover) IOperationHistory(org.eclipse.core.commands.operations.IOperationHistory) RedoActionHandler(org.eclipse.ui.operations.RedoActionHandler) UndoActionHandler(org.eclipse.ui.operations.UndoActionHandler)

Aggregations

IOperationHistory (org.eclipse.core.commands.operations.IOperationHistory)1 IUndoContext (org.eclipse.core.commands.operations.IUndoContext)1 LinearUndoViolationUserApprover (org.eclipse.ui.operations.LinearUndoViolationUserApprover)1 OperationHistoryActionHandler (org.eclipse.ui.operations.OperationHistoryActionHandler)1 RedoActionHandler (org.eclipse.ui.operations.RedoActionHandler)1 UndoActionHandler (org.eclipse.ui.operations.UndoActionHandler)1