Search in sources :

Example 1 with OpenWithMenu

use of org.eclipse.ui.actions.OpenWithMenu in project eclipse.platform.text by eclipse.

the class NewTextSearchActionGroup method addOpenWithMenu.

private void addOpenWithMenu(IMenuManager menu, IStructuredSelection selection) {
    if (selection == null)
        return;
    fOpenAction.selectionChanged(selection);
    if (fOpenAction.isEnabled()) {
        menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fOpenAction);
    }
    if (selection.size() != 1) {
        return;
    }
    Object o = selection.getFirstElement();
    if (!(o instanceof IAdaptable))
        return;
    // Create menu
    IMenuManager submenu = new MenuManager(SearchMessages.OpenWithMenu_label);
    submenu.add(new OpenWithMenu(fPage, (IAdaptable) o));
    // Add the submenu.
    menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu);
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) OpenWithMenu(org.eclipse.ui.actions.OpenWithMenu) IMenuManager(org.eclipse.jface.action.IMenuManager)

Example 2 with OpenWithMenu

use of org.eclipse.ui.actions.OpenWithMenu 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 3 with OpenWithMenu

use of org.eclipse.ui.actions.OpenWithMenu in project titan.EclipsePlug-ins by eclipse.

the class LogFileActionProvider method addOpenWithMenu.

private void addOpenWithMenu(final IMenuManager aMenu) {
    final IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
    if (selection == null || selection.size() != 1 || !(selection.getFirstElement() instanceof IFile)) {
        return;
    }
    final IFile file = (IFile) selection.getFirstElement();
    IMenuManager submenu = new MenuManager("Open with", ICommonMenuConstants.GROUP_OPEN_WITH);
    submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_TOP));
    submenu.add(new OpenWithMenu(viewSite.getPage(), file));
    submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_ADDITIONS));
    if (submenu.getItems().length > 2 && submenu.isEnabled()) {
        aMenu.appendToGroup(ICommonMenuConstants.GROUP_OPEN_WITH, submenu);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IMenuManager(org.eclipse.jface.action.IMenuManager) MenuManager(org.eclipse.jface.action.MenuManager) OpenWithMenu(org.eclipse.ui.actions.OpenWithMenu) GroupMarker(org.eclipse.jface.action.GroupMarker) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IMenuManager(org.eclipse.jface.action.IMenuManager)

Example 4 with OpenWithMenu

use of org.eclipse.ui.actions.OpenWithMenu in project webtools.sourceediting by eclipse.

the class ExtendedStorageEditorInputView method createPartControl.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
public void createPartControl(Composite parent) {
    fInputList = new TableViewer(parent, SWT.FULL_SELECTION | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    fInputList.setContentProvider(new ArrayContentProvider());
    fInputList.setLabelProvider(new EditorInputLabelProvider());
    fInputList.addDoubleClickListener(new DoubleClickListener());
    fInputList.getTable().setHeaderVisible(true);
    fInputList.getTable().setLinesVisible(true);
    String[] columns = new String[] { "Path", "Type" };
    fInputList.setLabelProvider(new EditorInputLabelProvider());
    TableLayout tlayout = new TableLayout();
    CellEditor[] cellEditors = new CellEditor[5];
    for (int i = 0; i < columns.length; i++) {
        tlayout.addColumnData(new ColumnWeightData(1));
        TableColumn tc = new TableColumn(fInputList.getTable(), SWT.NONE);
        tc.setText(columns[i]);
        tc.setResizable(true);
        tc.setWidth(Display.getCurrent().getBounds().width / 14);
    }
    fInputList.setCellEditors(cellEditors);
    fInputList.setColumnProperties(columns);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    fInputList.getTable().setLayoutData(gd);
    // $NON-NLS-1$
    MenuManager menuManager = new MenuManager("#popup");
    menuManager.setRemoveAllWhenShown(false);
    menuManager.add(new InputOpenAction());
    menuManager.add(new Separator());
    menuManager.add(new InputMoveAction());
    menuManager.add(new InputChangeDirtyStateAction());
    menuManager.add(new InputDeleteAction());
    menuManager.add(new InputReplaceContentsAction());
    menuManager.add(new Separator());
    menuManager.add(new RemoveInputAction());
    Menu menu = menuManager.createContextMenu(fInputList.getControl());
    fInputList.getControl().setMenu(menu);
    SSETestsPlugin.getDefault().getPluginPreferences().setDefault(getInputsPreferenceName(), "");
    String[] paths = StringUtils.unpack(SSETestsPlugin.getDefault().getPluginPreferences().getString(getInputsPreferenceName()));
    for (int i = 0; i < paths.length; i++) {
        if (paths[i].startsWith("S!")) {
            fInputs.add(new FileBasedStorageEditorInput(new File(paths[i].substring(2))));
            menuManager.add(new OpenWithMenu(getSite().getPage(), null));
        } else if (paths[i].startsWith("F!")) {
            IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(paths[i].substring(2)));
            fInputs.add(new FileEditorInput(file));
            menuManager.add(new OpenWithMenu(getSite().getPage(), file));
        }
    }
    fInputList.setInput(fInputs);
    fInputList.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = ((IStructuredSelection) event.getSelection());
            fSelectedElement = sel.getFirstElement();
        }
    });
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) IFile(org.eclipse.core.resources.IFile) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) CellEditor(org.eclipse.jface.viewers.CellEditor) OpenWithMenu(org.eclipse.ui.actions.OpenWithMenu) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) OpenWithMenu(org.eclipse.ui.actions.OpenWithMenu) Menu(org.eclipse.swt.widgets.Menu) TableLayout(org.eclipse.jface.viewers.TableLayout) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TableColumn(org.eclipse.swt.widgets.TableColumn) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) MenuManager(org.eclipse.jface.action.MenuManager) TableViewer(org.eclipse.jface.viewers.TableViewer) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Separator(org.eclipse.jface.action.Separator)

Example 5 with OpenWithMenu

use of org.eclipse.ui.actions.OpenWithMenu in project erlide_eclipse by erlang.

the class OpenEditorActionGroup method addOpenWithMenu.

private void addOpenWithMenu(final IMenuManager menu) {
    final ISelection selection = getContext().getSelection();
    if (selection.isEmpty() || !(selection instanceof IStructuredSelection)) {
        return;
    }
    final IStructuredSelection ss = (IStructuredSelection) selection;
    if (ss.size() != 1) {
        return;
    }
    final Object o = ss.getFirstElement();
    if (!(o instanceof IAdaptable)) {
        return;
    }
    final IAdaptable element = (IAdaptable) o;
    final Object resource = element.getAdapter(IResource.class);
    if (!(resource instanceof IFile)) {
        return;
    }
    // Create a menu.
    final IMenuManager submenu = new MenuManager(ActionMessages.OpenWithMenu_label);
    submenu.add(new OpenWithMenu(fSite.getPage(), (IFile) resource));
    // Add the submenu.
    menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu);
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) ISelection(org.eclipse.jface.viewers.ISelection) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) OpenWithMenu(org.eclipse.ui.actions.OpenWithMenu) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IMenuManager(org.eclipse.jface.action.IMenuManager)

Aggregations

MenuManager (org.eclipse.jface.action.MenuManager)6 OpenWithMenu (org.eclipse.ui.actions.OpenWithMenu)6 IFile (org.eclipse.core.resources.IFile)5 IMenuManager (org.eclipse.jface.action.IMenuManager)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 ISelection (org.eclipse.jface.viewers.ISelection)3 IAdaptable (org.eclipse.core.runtime.IAdaptable)2 Separator (org.eclipse.jface.action.Separator)2 File (java.io.File)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 GroupMarker (org.eclipse.jface.action.GroupMarker)1 IAction (org.eclipse.jface.action.IAction)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 CellEditor (org.eclipse.jface.viewers.CellEditor)1 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1