use of org.eclipse.jface.action.IAction 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.jface.action.IAction in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method createNavigationActions.
/**
* Creates action entries for all SWT StyledText actions as defined in
* <code>org.eclipse.swt.custom.ST</code>. Overwrites and
* extends the list of these actions afterwards.
* <p>
* Subclasses may extend.
* </p>
* @since 2.0
*/
protected void createNavigationActions() {
IAction action;
StyledText textWidget = fSourceViewer.getTextWidget();
for (int i = 0; i < ACTION_MAP.length; i++) {
IdMapEntry entry = ACTION_MAP[i];
action = new TextNavigationAction(textWidget, entry.getAction());
action.setActionDefinitionId(entry.getActionId());
setAction(entry.getActionId(), action);
}
// $NON-NLS-1$
action = new ToggleOverwriteModeAction(EditorMessages.getBundleForConstructedKeys(), "Editor.ToggleOverwriteMode.");
action.setActionDefinitionId(ITextEditorActionDefinitionIds.TOGGLE_OVERWRITE);
setAction(ITextEditorActionDefinitionIds.TOGGLE_OVERWRITE, action);
textWidget.setKeyBinding(SWT.INSERT, SWT.NULL);
action = new ScrollLinesAction(-1);
action.setActionDefinitionId(ITextEditorActionDefinitionIds.SCROLL_LINE_UP);
setAction(ITextEditorActionDefinitionIds.SCROLL_LINE_UP, action);
action = new ScrollLinesAction(1);
action.setActionDefinitionId(ITextEditorActionDefinitionIds.SCROLL_LINE_DOWN);
setAction(ITextEditorActionDefinitionIds.SCROLL_LINE_DOWN, action);
action = new LineEndAction(textWidget, false);
action.setActionDefinitionId(ITextEditorActionDefinitionIds.LINE_END);
setAction(ITextEditorActionDefinitionIds.LINE_END, action);
action = new LineStartAction(textWidget, false);
action.setActionDefinitionId(ITextEditorActionDefinitionIds.LINE_START);
setAction(ITextEditorActionDefinitionIds.LINE_START, action);
action = new LineEndAction(textWidget, true);
action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_LINE_END);
setAction(ITextEditorActionDefinitionIds.SELECT_LINE_END, action);
action = new LineStartAction(textWidget, true);
action.setActionDefinitionId(ITextEditorActionDefinitionIds.SELECT_LINE_START);
setAction(ITextEditorActionDefinitionIds.SELECT_LINE_START, action);
// to accommodate https://bugs.eclipse.org/bugs/show_bug.cgi?id=51516
// nullify handling of DELETE key by StyledText
textWidget.setKeyBinding(SWT.DEL, SWT.NULL);
}
use of org.eclipse.jface.action.IAction in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method createAccessibilityActions.
/**
* Creates this editor's accessibility actions.
* @since 2.0
*/
private void createAccessibilityActions() {
IAction action = new ShowRulerContextMenuAction();
action.setActionDefinitionId(ITextEditorActionDefinitionIds.SHOW_RULER_CONTEXT_MENU);
setAction(ITextEditorActionDefinitionIds.SHOW_RULER_CONTEXT_MENU, action);
}
use of org.eclipse.jface.action.IAction in project eclipse.platform.text by eclipse.
the class AbstractDecoratedTextEditor method editorContextMenuAboutToShow.
@Override
protected void editorContextMenuAboutToShow(IMenuManager menu) {
super.editorContextMenuAboutToShow(menu);
IAction preferencesAction = getAction(ITextEditorActionConstants.CONTEXT_PREFERENCES);
menu.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, new Separator(ITextEditorActionConstants.GROUP_SETTINGS));
menu.appendToGroup(ITextEditorActionConstants.GROUP_SETTINGS, preferencesAction);
menu.appendToGroup(ITextEditorActionConstants.GROUP_SAVE, new Separator(ITextEditorActionConstants.GROUP_OPEN));
IEditorInput editorInput = getEditorInput();
if ((editorInput.getAdapter(IResource.class)) instanceof IFile) {
MenuManager openWithSubMenu = new MenuManager(TextEditorMessages.AbstractDecoratedTextEditor_openWith_menu);
final IWorkbenchPage page = getEditorSite().getPage();
// XXX: Internal reference will get fixed during 3.7, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=307026
openWithSubMenu.add(new OpenWithMenu(page, editorInput) {
@Override
protected void openEditor(IEditorDescriptor editorDescriptor, boolean openUsingDescriptor) {
super.openEditor(editorDescriptor, openUsingDescriptor);
ISelection selection = getSelectionProvider().getSelection();
if (selection instanceof ITextSelection) {
revealInEditor(page.getActiveEditor(), ((ITextSelection) selection).getOffset(), ((ITextSelection) selection).getLength());
}
}
});
menu.appendToGroup(ITextEditorActionConstants.GROUP_OPEN, openWithSubMenu);
}
MenuManager showInSubMenu = new MenuManager(getShowInMenuLabel());
showInSubMenu.add(ContributionItemFactory.VIEWS_SHOW_IN.create(getEditorSite().getWorkbenchWindow()));
menu.appendToGroup(ITextEditorActionConstants.GROUP_OPEN, showInSubMenu);
}
use of org.eclipse.jface.action.IAction in project eclipse.platform.text by eclipse.
the class AbstractDecoratedTextEditor method rulerContextMenuAboutToShow.
@Override
protected void rulerContextMenuAboutToShow(IMenuManager menu) {
/*
* XXX: workaround for reliable menu item ordering.
* This can be changed once the action contribution story converges,
* see http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/platform-ui-home/R3_1/dynamic_teams/dynamic_teams.html#actionContributions
*/
// pre-install menus for contributions and call super
// $NON-NLS-1$
menu.add(new Separator("debug"));
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
menu.add(new GroupMarker(ITextEditorActionConstants.GROUP_RESTORE));
// $NON-NLS-1$
menu.add(new Separator("add"));
menu.add(new Separator(ITextEditorActionConstants.GROUP_RULERS));
menu.add(new Separator(ITextEditorActionConstants.GROUP_REST));
super.rulerContextMenuAboutToShow(menu);
addRulerContributionActions(menu);
/* quick diff */
if (isEditorInputModifiable()) {
IAction quickdiffAction = getAction(ITextEditorActionConstants.QUICKDIFF_TOGGLE);
quickdiffAction.setChecked(isChangeInformationShowing());
menu.appendToGroup(ITextEditorActionConstants.GROUP_RULERS, quickdiffAction);
if (isChangeInformationShowing()) {
TextEditorAction revertLine = new RevertLineAction(this, true);
TextEditorAction revertSelection = new RevertSelectionAction(this, true);
TextEditorAction revertBlock = new RevertBlockAction(this, true);
TextEditorAction revertDeletion = new RestoreAction(this, true);
revertSelection.update();
revertBlock.update();
revertLine.update();
revertDeletion.update();
// only add block action if selection action is not enabled
if (revertSelection.isEnabled())
menu.appendToGroup(ITextEditorActionConstants.GROUP_RESTORE, revertSelection);
else if (revertBlock.isEnabled())
menu.appendToGroup(ITextEditorActionConstants.GROUP_RESTORE, revertBlock);
if (revertLine.isEnabled())
menu.appendToGroup(ITextEditorActionConstants.GROUP_RESTORE, revertLine);
if (revertDeletion.isEnabled())
menu.appendToGroup(ITextEditorActionConstants.GROUP_RESTORE, revertDeletion);
}
}
// revision info
if (fLineColumn != null && fLineColumn.isShowingRevisionInformation()) {
IMenuManager revisionMenu = new MenuManager(TextEditorMessages.AbstractDecoratedTextEditor_revisions_menu);
menu.appendToGroup(ITextEditorActionConstants.GROUP_RULERS, revisionMenu);
IAction hideRevisionInfoAction = getAction(ITextEditorActionConstants.REVISION_HIDE_INFO);
revisionMenu.add(hideRevisionInfoAction);
revisionMenu.add(new Separator());
String[] labels = { TextEditorMessages.AbstractDecoratedTextEditor_revision_colors_option_by_date, TextEditorMessages.AbstractDecoratedTextEditor_revision_colors_option_by_author, TextEditorMessages.AbstractDecoratedTextEditor_revision_colors_option_by_author_and_date };
final RenderingMode[] modes = { IRevisionRulerColumnExtension.AGE, IRevisionRulerColumnExtension.AUTHOR, IRevisionRulerColumnExtension.AUTHOR_SHADED_BY_AGE };
final IPreferenceStore uiStore = EditorsUI.getPreferenceStore();
String current = uiStore.getString(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_RENDERING_MODE);
for (int i = 0; i < modes.length; i++) {
final String mode = modes[i].name();
IAction action = new Action(labels[i], IAction.AS_RADIO_BUTTON) {
@Override
public void run() {
// set preference globally, LineNumberColumn reacts on preference change
uiStore.setValue(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_RENDERING_MODE, mode);
}
};
action.setChecked(mode.equals(current));
revisionMenu.add(action);
}
revisionMenu.add(new Separator());
IAction action = getAction(ITextEditorActionConstants.REVISION_SHOW_AUTHOR_TOGGLE);
if (action instanceof IUpdate)
((IUpdate) action).update();
revisionMenu.add(action);
action = getAction(ITextEditorActionConstants.REVISION_SHOW_ID_TOGGLE);
if (action instanceof IUpdate)
((IUpdate) action).update();
revisionMenu.add(action);
}
IAction lineNumberAction = getAction(ITextEditorActionConstants.LINENUMBERS_TOGGLE);
lineNumberAction.setChecked(fLineColumn != null && fLineColumn.isShowingLineNumbers());
menu.appendToGroup(ITextEditorActionConstants.GROUP_RULERS, lineNumberAction);
IAction preferencesAction = getAction(ITextEditorActionConstants.RULER_PREFERENCES);
menu.appendToGroup(ITextEditorActionConstants.GROUP_RULERS, new Separator(ITextEditorActionConstants.GROUP_SETTINGS));
menu.appendToGroup(ITextEditorActionConstants.GROUP_SETTINGS, preferencesAction);
}
Aggregations