Search in sources :

Example 61 with IAction

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));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) OperationHistoryActionHandler(org.eclipse.ui.operations.OperationHistoryActionHandler) IStatus(org.eclipse.core.runtime.IStatus) IAction(org.eclipse.jface.action.IAction) IVerticalRuler(org.eclipse.jface.text.source.IVerticalRuler) CompositeRuler(org.eclipse.jface.text.source.CompositeRuler) ISaveablesLifecycleListener(org.eclipse.ui.ISaveablesLifecycleListener) IUndoContext(org.eclipse.core.commands.operations.IUndoContext) CoreException(org.eclipse.core.runtime.CoreException) IEditorInput(org.eclipse.ui.IEditorInput) SaveablesLifecycleEvent(org.eclipse.ui.SaveablesLifecycleEvent)

Example 62 with IAction

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);
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) IAction(org.eclipse.jface.action.IAction) Point(org.eclipse.swt.graphics.Point)

Example 63 with IAction

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);
}
Also used : IAction(org.eclipse.jface.action.IAction)

Example 64 with IAction

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);
}
Also used : IFile(org.eclipse.core.resources.IFile) IAction(org.eclipse.jface.action.IAction) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) OpenWithMenu(org.eclipse.ui.actions.OpenWithMenu) Separator(org.eclipse.jface.action.Separator) IEditorInput(org.eclipse.ui.IEditorInput) IURIEditorInput(org.eclipse.ui.IURIEditorInput) ITextSelection(org.eclipse.jface.text.ITextSelection)

Example 65 with IAction

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);
}
Also used : RevertSelectionAction(org.eclipse.ui.internal.editors.quickdiff.RevertSelectionAction) RevertLineAction(org.eclipse.ui.internal.editors.quickdiff.RevertLineAction) RevertBlockAction(org.eclipse.ui.internal.editors.quickdiff.RevertBlockAction) BooleanPreferenceToggleAction(org.eclipse.ui.internal.texteditor.BooleanPreferenceToggleAction) RevertSelectionAction(org.eclipse.ui.internal.editors.quickdiff.RevertSelectionAction) CompositeRevertAction(org.eclipse.ui.internal.editors.quickdiff.CompositeRevertAction) RestoreAction(org.eclipse.ui.internal.editors.quickdiff.RestoreAction) IAction(org.eclipse.jface.action.IAction) RefreshEditorAction(org.eclipse.ui.internal.editors.text.RefreshEditorAction) Action(org.eclipse.jface.action.Action) IAction(org.eclipse.jface.action.IAction) RestoreAction(org.eclipse.ui.internal.editors.quickdiff.RestoreAction) RevertBlockAction(org.eclipse.ui.internal.editors.quickdiff.RevertBlockAction) Point(org.eclipse.swt.graphics.Point) RevertLineAction(org.eclipse.ui.internal.editors.quickdiff.RevertLineAction) RenderingMode(org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension.RenderingMode) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) GroupMarker(org.eclipse.jface.action.GroupMarker) IMenuManager(org.eclipse.jface.action.IMenuManager) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Separator(org.eclipse.jface.action.Separator)

Aggregations

IAction (org.eclipse.jface.action.IAction)387 Action (org.eclipse.jface.action.Action)147 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)79 IWorkbenchAction (org.eclipse.ui.actions.ActionFactory.IWorkbenchAction)57 Separator (org.eclipse.jface.action.Separator)55 WebLaunchAction (com.centurylink.mdw.plugin.actions.WebLaunchActions.WebLaunchAction)50 MenuManager (org.eclipse.jface.action.MenuManager)39 IMenuManager (org.eclipse.jface.action.IMenuManager)37 ArrayList (java.util.ArrayList)36 ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)35 IContributionItem (org.eclipse.jface.action.IContributionItem)31 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)26 WorkflowElement (com.centurylink.mdw.plugin.designer.model.WorkflowElement)22 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)18 ActionRegistry (org.eclipse.gef.ui.actions.ActionRegistry)16 IToolBarManager (org.eclipse.jface.action.IToolBarManager)16 IEditorPart (org.eclipse.ui.IEditorPart)15 Point (org.eclipse.swt.graphics.Point)14 Iterator (java.util.Iterator)13 Menu (org.eclipse.swt.widgets.Menu)13