Search in sources :

Example 71 with MenuManager

use of org.eclipse.jface.action.MenuManager in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method createPartControl.

/**
 * The <code>AbstractTextEditor</code> implementation of this
 * <code>IWorkbenchPart</code> method creates the vertical ruler and
 * source viewer.
 * <p>
 * Subclasses may extend this method. Besides extending this method, the
 * behavior of <code>createPartControl</code> may be customized by
 * calling, extending or replacing the following methods: <br>
 * Subclasses may supply customized implementations for some members using
 * the following methods before <code>createPartControl</code> is invoked:
 * <ul>
 * <li>
 * {@linkplain #setSourceViewerConfiguration(SourceViewerConfiguration) setSourceViewerConfiguration}
 * to supply a custom source viewer configuration,</li>
 * <li>{@linkplain #setRangeIndicator(Annotation) setRangeIndicator} to
 * provide a range indicator,</li>
 * <li>{@linkplain #setHelpContextId(String) setHelpContextId} to provide a
 * help context id,</li>
 * <li>{@linkplain #setEditorContextMenuId(String) setEditorContextMenuId}
 * to set a custom context menu id,</li>
 * <li>{@linkplain #setRulerContextMenuId(String) setRulerContextMenuId} to
 * set a custom ruler context menu id.</li>
 * </ul>
 * <br>
 * Subclasses may replace the following methods called from within
 * <code>createPartControl</code>:
 * <ul>
 * <li>{@linkplain #createVerticalRuler() createVerticalRuler} to supply a
 * custom vertical ruler,</li>
 * <li>{@linkplain #createSourceViewer(Composite, IVerticalRuler, int) createSourceViewer}
 * to supply a custom source viewer,</li>
 * <li>{@linkplain #getSelectionProvider() getSelectionProvider} to supply
 * a custom selection provider.</li>
 * </ul>
 * <br>
 * Subclasses may extend the following methods called from within
 * <code>createPartControl</code>:
 * <ul>
 * <li>
 * {@linkplain #initializeViewerColors(ISourceViewer) initializeViewerColors}
 * to customize the viewer color scheme (may also be replaced),</li>
 * <li>
 * {@linkplain #initializeDragAndDrop(ISourceViewer) initializeDragAndDrop}
 * to customize drag and drop (may also be replaced),</li>
 * <li>{@linkplain #createNavigationActions() createNavigationActions} to
 * add navigation actions,</li>
 * <li>{@linkplain #createActions() createActions} to add text editor
 * actions.</li>
 * </ul>
 * </p>
 *
 * @param parent the parent composite
 */
@Override
public void createPartControl(Composite parent) {
    fVerticalRuler = createVerticalRuler();
    int styles = SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION;
    fSourceViewer = createSourceViewer(parent, fVerticalRuler, styles);
    if (fConfiguration == null)
        fConfiguration = new SourceViewerConfiguration();
    fSourceViewer.configure(fConfiguration);
    if (fSourceViewer instanceof ISourceViewerExtension4)
        fKeyBindingSupportForContentAssistant = new KeyBindingSupportForAssistant(((ISourceViewerExtension4) fSourceViewer));
    if (fSourceViewer instanceof ISourceViewerExtension3) {
        IQuickAssistAssistant assistant = ((ISourceViewerExtension3) fSourceViewer).getQuickAssistAssistant();
        if (assistant != null)
            fKeyBindingSupportForQuickAssistant = new KeyBindingSupportForAssistant(assistant);
    }
    if (fRangeIndicator != null)
        fSourceViewer.setRangeIndicator(fRangeIndicator);
    fSourceViewer.addTextListener(fTextListener);
    fSourceViewer.addTextInputListener(fTextListener);
    getSelectionProvider().addSelectionChangedListener(getSelectionChangedListener());
    initializeViewerFont(fSourceViewer);
    initializeViewerColors(fSourceViewer);
    initializeFindScopeColor(fSourceViewer);
    initializeDragAndDrop(fSourceViewer);
    StyledText styledText = fSourceViewer.getTextWidget();
    styledText.addMouseListener(getCursorListener());
    styledText.addKeyListener(getCursorListener());
    // Disable orientation switching until we fully support it.
    styledText.addListener(SWT.OrientationChange, new Listener() {

        @Override
        public void handleEvent(Event event) {
            event.doit = false;
        }
    });
    if (getHelpContextId() != null)
        PlatformUI.getWorkbench().getHelpSystem().setHelp(styledText, getHelpContextId());
    String id = fEditorContextMenuId != null ? fEditorContextMenuId : DEFAULT_EDITOR_CONTEXT_MENU_ID;
    MenuManager manager = new MenuManager(id, id);
    manager.setRemoveAllWhenShown(true);
    manager.addMenuListener(getContextMenuListener());
    fTextContextMenu = manager.createContextMenu(styledText);
    styledText.setMenu(fTextContextMenu);
    if (fEditorContextMenuId != null)
        getEditorSite().registerContextMenu(fEditorContextMenuId, manager, getSelectionProvider(), isEditorInputIncludedInContextMenu());
    else if (fCompatibilityMode)
        getEditorSite().registerContextMenu(DEFAULT_EDITOR_CONTEXT_MENU_ID, manager, getSelectionProvider(), isEditorInputIncludedInContextMenu());
    if ((fEditorContextMenuId != null && fCompatibilityMode) || fEditorContextMenuId == null) {
        String partId = getEditorSite().getId();
        if (partId != null)
            // $NON-NLS-1$
            getEditorSite().registerContextMenu(partId + ".EditorContext", manager, getSelectionProvider(), isEditorInputIncludedInContextMenu());
    }
    getEditorSite().registerContextMenu(COMMON_EDITOR_CONTEXT_MENU_ID, manager, getSelectionProvider(), false);
    if (fEditorContextMenuId == null)
        fEditorContextMenuId = DEFAULT_EDITOR_CONTEXT_MENU_ID;
    id = fRulerContextMenuId != null ? fRulerContextMenuId : DEFAULT_RULER_CONTEXT_MENU_ID;
    manager = new MenuManager(id, id);
    manager.setRemoveAllWhenShown(true);
    manager.addMenuListener(getContextMenuListener());
    Control rulerControl = fVerticalRuler.getControl();
    fRulerContextMenu = manager.createContextMenu(rulerControl);
    rulerControl.setMenu(fRulerContextMenu);
    rulerControl.addMouseListener(getRulerMouseListener());
    if (fRulerContextMenuId != null)
        getEditorSite().registerContextMenu(fRulerContextMenuId, manager, getSelectionProvider(), false);
    else if (fCompatibilityMode)
        getEditorSite().registerContextMenu(DEFAULT_RULER_CONTEXT_MENU_ID, manager, getSelectionProvider(), false);
    if ((fRulerContextMenuId != null && fCompatibilityMode) || fRulerContextMenuId == null) {
        String partId = getSite().getId();
        if (partId != null)
            // $NON-NLS-1$
            getEditorSite().registerContextMenu(partId + ".RulerContext", manager, getSelectionProvider(), false);
    }
    getEditorSite().registerContextMenu(COMMON_RULER_CONTEXT_MENU_ID, manager, getSelectionProvider(), false);
    if (fRulerContextMenuId == null)
        fRulerContextMenuId = DEFAULT_RULER_CONTEXT_MENU_ID;
    initializeZoomGestures(rulerControl, fSourceViewer);
    getSite().setSelectionProvider(getSelectionProvider());
    fSelectionListener = new SelectionListener();
    fSelectionListener.install(getSelectionProvider());
    fSelectionListener.setDocument(getDocumentProvider().getDocument(getEditorInput()));
    initializeActivationCodeTrigger();
    createNavigationActions();
    createAccessibilityActions();
    createActions();
    initializeSourceViewer(getEditorInput());
    /* since 3.2 - undo redo actions should be created after
		 * the source viewer is initialized, so that the undo manager
		 * can obtain its undo context from its document.
		 */
    createUndoRedoActions();
    JFaceResources.getFontRegistry().addListener(fFontPropertyChangeListener);
    IVerticalRuler ruler = getVerticalRuler();
    if (ruler instanceof CompositeRuler)
        updateContributedRulerColumns((CompositeRuler) ruler);
    if (isWordWrapSupported()) {
        setWordWrap(getInitialWordWrapStatus());
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ITextListener(org.eclipse.jface.text.ITextListener) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) ISaveablesLifecycleListener(org.eclipse.ui.ISaveablesLifecycleListener) IPartListener(org.eclipse.ui.IPartListener) KeyListener(org.eclipse.swt.events.KeyListener) GestureListener(org.eclipse.swt.events.GestureListener) IDocumentListener(org.eclipse.jface.text.IDocumentListener) Listener(org.eclipse.swt.widgets.Listener) ITextInputListener(org.eclipse.jface.text.ITextInputListener) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) VerifyListener(org.eclipse.swt.events.VerifyListener) MouseListener(org.eclipse.swt.events.MouseListener) IWindowListener(org.eclipse.ui.IWindowListener) IMenuListener(org.eclipse.jface.action.IMenuListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) IVerticalRuler(org.eclipse.jface.text.source.IVerticalRuler) CompositeRuler(org.eclipse.jface.text.source.CompositeRuler) ISourceViewerExtension3(org.eclipse.jface.text.source.ISourceViewerExtension3) ISourceViewerExtension4(org.eclipse.jface.text.source.ISourceViewerExtension4) Point(org.eclipse.swt.graphics.Point) SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) Control(org.eclipse.swt.widgets.Control) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) SaveablesLifecycleEvent(org.eclipse.ui.SaveablesLifecycleEvent) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) TextEvent(org.eclipse.jface.text.TextEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) GestureEvent(org.eclipse.swt.events.GestureEvent) DocumentEvent(org.eclipse.jface.text.DocumentEvent) Event(org.eclipse.swt.widgets.Event) VerifyEvent(org.eclipse.swt.events.VerifyEvent) IQuickAssistAssistant(org.eclipse.jface.text.quickassist.IQuickAssistAssistant)

Example 72 with MenuManager

use of org.eclipse.jface.action.MenuManager 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 73 with MenuManager

use of org.eclipse.jface.action.MenuManager in project eclipse.platform.text by eclipse.

the class AbstractDecoratedTextEditor method createOverviewRulerContextMenu.

/**
 * Creates the context menu for the overview ruler.
 * <p>
 * Subclasses may extend or replace this method.
 * </p>
 *
 * @since 3.4
 */
protected void createOverviewRulerContextMenu() {
    if (fOverviewRulerContextMenuId == null)
        fOverviewRulerContextMenuId = DEFAULT_OVERVIEW_RULER_CONTEXT_MENU_ID;
    if (fOverviewRuler == null || fOverviewRuler.getControl() == null)
        return;
    MenuManager menuManager = new MenuManager(fOverviewRulerContextMenuId, fOverviewRulerContextMenuId);
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(getContextMenuListener());
    Menu menu = menuManager.createContextMenu(getOverviewRuler().getControl());
    getOverviewRuler().getControl().setMenu(menu);
    getEditorSite().registerContextMenu(fOverviewRulerContextMenuId, menuManager, getSelectionProvider(), false);
}
Also used : MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) OpenWithMenu(org.eclipse.ui.actions.OpenWithMenu) Menu(org.eclipse.swt.widgets.Menu)

Example 74 with MenuManager

use of org.eclipse.jface.action.MenuManager 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)

Example 75 with MenuManager

use of org.eclipse.jface.action.MenuManager in project linuxtools by eclipse.

the class PerfProfileView method hookContextMenu.

private void hookContextMenu() {
    // $NON-NLS-1$
    MenuManager menuMgr = new MenuManager("#PopupMenu");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(manager -> PerfProfileView.this.fillContextMenu(manager));
    Menu menu = menuMgr.createContextMenu(viewer.getControl());
    viewer.getControl().setMenu(menu);
    getSite().registerContextMenu(menuMgr, viewer);
}
Also used : MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu)

Aggregations

MenuManager (org.eclipse.jface.action.MenuManager)657 IMenuManager (org.eclipse.jface.action.IMenuManager)498 Menu (org.eclipse.swt.widgets.Menu)303 IMenuListener (org.eclipse.jface.action.IMenuListener)246 Separator (org.eclipse.jface.action.Separator)220 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)65 Point (org.eclipse.swt.graphics.Point)63 Action (org.eclipse.jface.action.Action)55 Composite (org.eclipse.swt.widgets.Composite)49 IAction (org.eclipse.jface.action.IAction)48 SelectionEvent (org.eclipse.swt.events.SelectionEvent)44 GridData (org.eclipse.swt.layout.GridData)44 GroupMarker (org.eclipse.jface.action.GroupMarker)43 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)43 Transfer (org.eclipse.swt.dnd.Transfer)35 GridLayout (org.eclipse.swt.layout.GridLayout)32 List (java.util.List)30 EditingDomainViewerDropAdapter (org.eclipse.emf.edit.ui.dnd.EditingDomainViewerDropAdapter)30 LocalTransfer (org.eclipse.emf.edit.ui.dnd.LocalTransfer)30 ViewerDragAdapter (org.eclipse.emf.edit.ui.dnd.ViewerDragAdapter)30