use of org.eclipse.ui.operations.OperationHistoryActionHandler 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);
}
}
}
use of org.eclipse.ui.operations.OperationHistoryActionHandler in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method doSetInput.
/**
* Called directly from <code>setInput</code> and from within a workspace
* runnable from <code>init</code>, this method does the actual setting
* of the editor input. Closes the editor if <code>input</code> is
* <code>null</code>. Disconnects from any previous editor input and its
* document provider and connects to the new one.
* <p>
* Subclasses may extend.
* </p>
*
* @param input the input to be set
* @exception CoreException if input cannot be connected to the document
* provider
*/
protected void doSetInput(IEditorInput input) throws CoreException {
ISaveablesLifecycleListener listener = getSite().getService(ISaveablesLifecycleListener.class);
if (listener == null)
fSavable = null;
if (input == null) {
close(isSaveOnCloseNeeded());
if (fSavable != null) {
listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_CLOSE, getSaveables(), false));
fSavable.disconnectEditor();
fSavable = null;
}
} else {
boolean mustSendLifeCycleEvent = false;
if (fSavable != null) {
listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_CLOSE, getSaveables(), false));
fSavable.disconnectEditor();
fSavable = null;
mustSendLifeCycleEvent = true;
}
IEditorInput oldInput = getEditorInput();
if (oldInput != null)
getDocumentProvider().disconnect(oldInput);
super.setInput(input);
updateDocumentProvider(input);
IDocumentProvider provider = getDocumentProvider();
if (provider == null) {
IStatus s = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, EditorMessages.Editor_error_no_provider, null);
throw new CoreException(s);
}
provider.connect(input);
initializeTitle(input);
if (fSourceViewer != null) {
initializeSourceViewer(input);
// Reset the undo context for the undo and redo action handlers
IAction undoAction = getAction(ITextEditorActionConstants.UNDO);
IAction redoAction = getAction(ITextEditorActionConstants.REDO);
boolean areOperationActionHandlersInstalled = undoAction instanceof OperationHistoryActionHandler && redoAction instanceof OperationHistoryActionHandler;
IUndoContext undoContext = getUndoContext();
if (undoContext != null && areOperationActionHandlersInstalled) {
((OperationHistoryActionHandler) undoAction).setContext(undoContext);
((OperationHistoryActionHandler) redoAction).setContext(undoContext);
} else {
createUndoRedoActions();
}
}
if (fIsOverwriting)
toggleOverwriteMode();
setInsertMode(getLegalInsertModes().get(0));
updateCaret();
updateStatusField(ITextEditorActionConstants.STATUS_CATEGORY_ELEMENT_STATE);
if (fSelectionListener != null)
fSelectionListener.setDocument(getDocumentProvider().getDocument(input));
IVerticalRuler ruler = getVerticalRuler();
if (ruler instanceof CompositeRuler)
updateContributedRulerColumns((CompositeRuler) ruler);
// Send savable life-cycle if needed.
if (mustSendLifeCycleEvent && listener != null)
listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_OPEN, getSaveables(), false));
}
}
use of org.eclipse.ui.operations.OperationHistoryActionHandler in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method registerUndoRedoAction.
/**
* Registers the given undo/redo action under the given ID and ensures that previously installed
* actions get disposed. It also takes care of re-registering the new action with the global
* action handler.
*
* @param actionId the action id under which to register the action
* @param action the action to register or <code>null</code> to dispose them
* @since 3.1
*/
private void registerUndoRedoAction(String actionId, OperationHistoryActionHandler action) {
IAction oldAction = getAction(actionId);
if (oldAction instanceof OperationHistoryActionHandler)
((OperationHistoryActionHandler) oldAction).dispose();
if (action == null)
return;
setAction(actionId, action);
IActionBars actionBars = getEditorSite().getActionBars();
if (actionBars != null)
actionBars.setGlobalActionHandler(actionId, action);
}
Aggregations