1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.workbench.internal;
14 import java.util.HashSet;
17 import org.eclipse.core.runtime.IAdaptable;
18 import org.eclipse.core.runtime.IExtension;
19 import org.eclipse.jface.action.ActionContributionItem;
20 import org.eclipse.jface.action.GroupMarker;
21 import org.eclipse.jface.action.IAction;
22 import org.eclipse.jface.action.IContributionItem;
23 import org.eclipse.jface.action.IMenuManager;
24 import org.eclipse.jface.action.IStatusLineManager;
25 import org.eclipse.jface.action.MenuManager;
26 import org.eclipse.jface.action.Separator;
27 import org.eclipse.jface.util.Util;
28 import org.eclipse.ui.IWorkbenchActionConstants;
29 import org.eclipse.ui.IWorkbenchWindow;
30 import org.eclipse.ui.actions.ActionFactory;
31 import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
32 import org.eclipse.ui.actions.ContributionItemFactory;
33 import org.eclipse.ui.actions.OpenInNewWindowAction;
34 import org.eclipse.ui.application.ActionBarAdvisor;
35 import org.eclipse.ui.application.IActionBarConfigurer;
36 import org.eclipse.ui.ide.IDEActionFactory;
37 import org.eclipse.ui.internal.Workbench;
38 import org.eclipse.ui.internal.WorkbenchPlugin;
39 import org.eclipse.ui.internal.cheatsheets.actions.CheatSheetCategoryBasedSelectionAction;
40 import org.eclipse.ui.internal.registry.ActionSetRegistry;
41 import org.eclipse.ui.internal.registry.IActionSetDescriptor;
44 * An action bar advisor is responsible for creating, adding, and disposing of
45 * the actions added to a workbench window. Each window will be populated with
48 public class SimanticsWorkbenchActionBarAdvisor extends ActionBarAdvisor {
50 //private final WorkbenchActionBuilder ideAdvisor;
52 private final IWorkbenchWindow window;
55 * Indicates if the action builder has been disposed
57 private boolean isDisposed = false;
59 // Actions - important to allocate these only in makeActions, and then use
61 // in the fill methods. This ensures that the actions aren't recreated
62 // when fillActionBars is called with FILL_PROXY.
65 private IWorkbenchAction closeAction;
67 private IWorkbenchAction closeAllAction;
69 private IWorkbenchAction closeOthersAction;
71 private IWorkbenchAction closeAllSavedAction;
73 // private IWorkbenchAction saveAction;
75 // protected IWorkbenchAction printAction;
77 protected IWorkbenchAction openWorkspaceAction;
79 private IWorkbenchAction importResourcesAction;
81 private IWorkbenchAction exportResourcesAction;
83 protected IWorkbenchAction quitAction;
86 protected IWorkbenchAction undoAction;
88 protected IWorkbenchAction redoAction;
90 protected IWorkbenchAction cutAction;
92 protected IWorkbenchAction copyAction;
94 protected IWorkbenchAction pasteAction;
96 protected IWorkbenchAction deleteAction;
98 protected IWorkbenchAction selectAllAction;
101 private IWorkbenchAction backwardHistoryAction;
103 private IWorkbenchAction forwardHistoryAction;
105 private IWorkbenchAction goIntoAction;
107 private IWorkbenchAction backAction;
109 private IWorkbenchAction forwardAction;
111 private IWorkbenchAction upAction;
113 private IWorkbenchAction nextAction;
115 private IWorkbenchAction previousAction;
118 private IWorkbenchAction newWindowAction;
120 private IWorkbenchAction newEditorAction;
122 private IWorkbenchAction savePerspectiveAction;
124 private IWorkbenchAction resetPerspectiveAction;
126 private IWorkbenchAction editActionSetAction;
128 private IWorkbenchAction closePerspAction;
130 private IWorkbenchAction closeAllPerspsAction;
132 private IWorkbenchAction openPreferencesAction;
135 private IWorkbenchAction showViewMenuAction;
137 private IWorkbenchAction showPartPaneMenuAction;
139 private IWorkbenchAction maximizePartAction;
141 private IWorkbenchAction minimizePartAction;
143 private IWorkbenchAction nextEditorAction;
145 private IWorkbenchAction prevEditorAction;
147 private IWorkbenchAction activateEditorAction;
149 private IWorkbenchAction switchToEditorAction;
151 private IWorkbenchAction openEditorDropDownAction;
153 private IWorkbenchAction nextPartAction;
155 private IWorkbenchAction prevPartAction;
157 private IWorkbenchAction nextPerspectiveAction;
159 private IWorkbenchAction prevPerspectiveAction;
162 private IWorkbenchAction introAction;
164 private IWorkbenchAction tocAction;
166 private IWorkbenchAction searchAction;
168 private IWorkbenchAction dynamicHelpAction;
170 private IAction cheatSheetsAction;
172 private IWorkbenchAction aboutAction;
176 * Constructs a new action builder which contributes actions
177 * to the given window.
179 * @param configurer the action bar configurer for the window
181 public SimanticsWorkbenchActionBarAdvisor(IActionBarConfigurer configurer) {
183 //ideAdvisor = new WorkbenchActionBuilder(configurer);
184 window = configurer.getWindowConfigurer().getWindow();
188 * Returns the window to which this action builder is contributing.
190 private IWorkbenchWindow getWindow() {
195 * Disposes any resources and unhooks any listeners that are no longer needed.
196 * Called when the window is closed.
199 public void dispose() {
206 // null out actions to make leak debugging easier
209 closeAllAction = null;
210 closeAllSavedAction = null;
211 closeOthersAction = null;
212 // saveAction = null;
213 // printAction = null;
214 openWorkspaceAction = null;
215 importResourcesAction = null;
216 exportResourcesAction = null;
226 selectAllAction = null;
229 backwardHistoryAction = null;
230 forwardHistoryAction = null;
233 forwardAction = null;
236 previousAction = null;
239 newWindowAction = null;
240 newEditorAction = null;
241 openPreferencesAction = null;
242 savePerspectiveAction = null;
243 resetPerspectiveAction = null;
244 editActionSetAction = null;
245 closePerspAction = null;
246 closeAllPerspsAction = null;
247 openPreferencesAction = null;
250 showViewMenuAction = null;
251 showPartPaneMenuAction = null;
252 maximizePartAction = null;
253 minimizePartAction = null;
254 nextPartAction = null;
255 prevPartAction = null;
256 nextPerspectiveAction = null;
257 prevPerspectiveAction = null;
259 nextEditorAction = null;
260 prevEditorAction = null;
261 activateEditorAction = null;
262 switchToEditorAction = null;
263 openEditorDropDownAction = null;
269 dynamicHelpAction = null;
270 cheatSheetsAction = null;
277 protected void makeActions(final IWorkbenchWindow window) {
278 // Creates the actions and registers them.
279 // Registering is needed to ensure that key bindings work.
280 // The corresponding commands keybindings are defined in the plugin.xml
282 // Registering also provides automatic disposal of the actions when
283 // the window is closed.
286 closeAction = ActionFactory.CLOSE.create(window);
287 register(closeAction);
288 closeAllAction = ActionFactory.CLOSE_ALL.create(window);
289 register(closeAllAction);
290 closeOthersAction = ActionFactory.CLOSE_OTHERS.create(window);
291 register(closeOthersAction);
292 closeAllSavedAction = ActionFactory.CLOSE_ALL_SAVED.create(window);
293 register(closeAllSavedAction);
294 // saveAction = ActionFactory.SAVE.create(window);
295 // register(saveAction);
296 // printAction = ActionFactory.PRINT.create(window);
297 // register(printAction);
298 openWorkspaceAction = IDEActionFactory.OPEN_WORKSPACE.create(window);
299 register(openWorkspaceAction);
300 importResourcesAction = ActionFactory.IMPORT.create(window);
301 register(importResourcesAction);
302 exportResourcesAction = ActionFactory.EXPORT.create(window);
303 register(exportResourcesAction);
304 quitAction = ActionFactory.QUIT.create(window);
305 register(quitAction);
308 // undoAction = ActionFactory.UNDO.create(window);
309 // register(undoAction);
310 // redoAction = ActionFactory.REDO.create(window);
311 // register(redoAction);
312 // cutAction = ActionFactory.CUT.create(window);
313 // register(cutAction);
314 // copyAction = ActionFactory.COPY.create(window);
315 // register(copyAction);
316 // pasteAction = ActionFactory.PASTE.create(window);
317 // register(pasteAction);
318 // deleteAction = ActionFactory.DELETE.create(window);
319 // register(deleteAction);
320 // selectAllAction = ActionFactory.SELECT_ALL.create(window);
321 // register(selectAllAction);
324 forwardHistoryAction = ActionFactory.FORWARD_HISTORY.create(window);
325 register(forwardHistoryAction);
326 backwardHistoryAction = ActionFactory.BACKWARD_HISTORY.create(window);
327 register(backwardHistoryAction);
328 goIntoAction = ActionFactory.GO_INTO.create(window);
329 register(goIntoAction);
330 backAction = ActionFactory.BACK.create(window);
331 register(backAction);
332 forwardAction = ActionFactory.FORWARD.create(window);
333 register(forwardAction);
334 upAction = ActionFactory.UP.create(window);
336 nextAction = ActionFactory.NEXT.create(window);
337 //nextAction.setImageDescriptor(IDEInternalWorkbenchImages.getImageDescriptor(IDEInternalWorkbenchImages.IMG_ETOOL_NEXT_NAV));
338 register(nextAction);
339 previousAction = ActionFactory.PREVIOUS.create(window);
340 //previousAction.setImageDescriptor(IDEInternalWorkbenchImages.getImageDescriptor(IDEInternalWorkbenchImages.IMG_ETOOL_PREVIOUS_NAV));
341 register(previousAction);
345 newWindowAction = OPEN_NEW_WINDOW.create(getWindow());
346 newWindowAction.setText("&New Window");
347 register(newWindowAction);
348 newEditorAction = ActionFactory.NEW_EDITOR.create(window);
349 register(newEditorAction);
350 editActionSetAction = ActionFactory.EDIT_ACTION_SETS.create(window);
351 register(editActionSetAction);
352 savePerspectiveAction = ActionFactory.SAVE_PERSPECTIVE.create(window);
353 register(savePerspectiveAction);
354 resetPerspectiveAction = ActionFactory.RESET_PERSPECTIVE.create(window);
355 register(resetPerspectiveAction);
356 closePerspAction = ActionFactory.CLOSE_PERSPECTIVE.create(window);
357 register(closePerspAction);
358 closeAllPerspsAction = ActionFactory.CLOSE_ALL_PERSPECTIVES.create(window);
359 register(closeAllPerspsAction);
360 openPreferencesAction = ActionFactory.PREFERENCES.create(window);
361 // preferencesAction = new OpenPreferencesAction(window);
362 // preferencesAction.setId("preferences");
363 register(openPreferencesAction);
365 // Window/Navigation: Actions for invisible accelerators
366 showViewMenuAction = ActionFactory.SHOW_VIEW_MENU.create(window);
367 register(showViewMenuAction);
368 showPartPaneMenuAction = ActionFactory.SHOW_PART_PANE_MENU.create(window);
369 register(showPartPaneMenuAction);
370 maximizePartAction = ActionFactory.MAXIMIZE.create(window);
371 register(maximizePartAction);
372 minimizePartAction = ActionFactory.MINIMIZE.create(window);
373 register(minimizePartAction);
375 nextEditorAction = ActionFactory.NEXT_EDITOR.create(window);
376 register(nextEditorAction);
377 prevEditorAction = ActionFactory.PREVIOUS_EDITOR.create(window);
378 register(prevEditorAction);
379 ActionFactory.linkCycleActionPair(nextEditorAction, prevEditorAction);
380 activateEditorAction = ActionFactory.ACTIVATE_EDITOR.create(window);
381 register(activateEditorAction);
382 switchToEditorAction = ActionFactory.SHOW_OPEN_EDITORS.create(window);
383 register(switchToEditorAction);
384 openEditorDropDownAction = ActionFactory.SHOW_WORKBOOK_EDITORS.create(window);
385 register(openEditorDropDownAction);
387 nextPartAction = ActionFactory.NEXT_PART.create(window);
388 register(nextPartAction);
389 prevPartAction = ActionFactory.PREVIOUS_PART.create(window);
390 register(prevPartAction);
391 ActionFactory.linkCycleActionPair(nextPartAction, prevPartAction);
392 nextPerspectiveAction = ActionFactory.NEXT_PERSPECTIVE.create(window);
393 register(nextPerspectiveAction);
394 prevPerspectiveAction = ActionFactory.PREVIOUS_PERSPECTIVE.create(window);
395 register(prevPerspectiveAction);
396 ActionFactory.linkCycleActionPair(nextPerspectiveAction, prevPerspectiveAction);
399 if (window.getWorkbench().getIntroManager().hasIntro()) {
400 introAction = ActionFactory.INTRO.create(window);
401 register(introAction);
403 tocAction = ActionFactory.HELP_CONTENTS.create(window);
405 searchAction = ActionFactory.HELP_SEARCH.create(window);
406 register(searchAction);
407 dynamicHelpAction = ActionFactory.DYNAMIC_HELP.create(window);
408 register(dynamicHelpAction);
409 cheatSheetsAction = new CheatSheetCategoryBasedSelectionAction("&Cheat Sheets...");
410 cheatSheetsAction.setId("org.eclipse.ui.help.cheatSheetsAction");
411 register(cheatSheetsAction);
412 aboutAction = ActionFactory.ABOUT.create(window);
413 register(aboutAction);
417 * TODO: HACK for removing Eclipse's own forced and totally unwanted actionSet extensions.
418 * Remove if a better way to achieve the same effect is found.
420 protected void hackRemoveUnwantedNavigationActions() {
421 ActionSetRegistry reg = WorkbenchPlugin.getDefault().getActionSetRegistry();
422 IActionSetDescriptor[] actionSets = reg.getActionSets();
423 String actionSetId[] = {
424 "org.eclipse.ui.edit.text.actionSet.navigation",
425 "org.eclipse.ui.edit.text.actionSet.annotationNavigation",
426 "org.eclipse.ui.NavigateActionSet"
428 Set<String> actionSetIds = new HashSet<String>();
429 for (String s : actionSetId)
432 for (int i = 0; i < actionSets.length; i++) {
433 if ((!actionSetIds.contains(actionSets[i].getId())))
435 IExtension ext = actionSets[i].getConfigurationElement().getDeclaringExtension();
436 reg.removeExtension(ext, new Object[] { actionSets[i] });
441 protected void fillMenuBar(IMenuManager menuBar) {
442 hackRemoveUnwantedNavigationActions();
444 menuBar.add(createFileMenu());
445 menuBar.add(createEditMenu());
446 menuBar.add(createNavigateMenu());
447 menuBar.add(createProjectMenu());
448 menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
449 menuBar.add(createWindowMenu());
450 menuBar.add(createHelpMenu());
454 protected void fillStatusLine(IStatusLineManager statusLine) {
455 //System.out.println("fillStatusLine: " + statusLine);
456 //statusLine.appendToGroup(StatusLineManager.BEGIN_GROUP, GlobalStatusLineContributionItem.getInstance());
457 // statusLine.add(new GraphRequestStatusContribution(window));
458 // statusLine.add(new DumpHeapContribution(window));
459 // statusLine.add(new DumpStackTracesContribution(window));
460 // statusLine.add(new FlushRequestsContribution(window));
461 // statusLine.add(new SearchContribution(window));
464 protected IContributionItem createFileMenu() {
465 //MenuManager menu = new MenuManager("&File", IWorkbenchActionConstants.M_FILE);
466 MenuManager menu = new MenuManager("&File", ISimanticsWorkbenchConstants.M_FILE);
468 menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_START));
470 // // create the New submenu, using the same id for it as the New action
471 // String newText = IDEWorkbenchMessages.Workbench_new;
472 // String newId = ActionFactory.NEW.getId();
473 // MenuManager newMenu = new MenuManager(newText, newId) {
474 // public String getMenuText() {
475 // String result = super.getMenuText();
476 // if (newQuickMenu == null) {
479 // String shortCut = newQuickMenu.getShortCutString();
480 // if (shortCut == null) {
483 // return result + "\t" + shortCut; //$NON-NLS-1$
486 // newMenu.add(new Separator(newId));
487 // this.newWizardMenu = new NewWizardMenu(getWindow());
488 // newMenu.add(this.newWizardMenu);
489 // newMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
490 // menu.add(newMenu);
493 menu.add(new GroupMarker(IWorkbenchActionConstants.NEW_EXT));
494 menu.add(new Separator());
496 menu.add(closeAction);
497 menu.add(closeAllAction);
498 //menu.add(closeAllSavedAction);
499 menu.add(new GroupMarker(IWorkbenchActionConstants.CLOSE_EXT));
500 menu.add(new Separator());
501 // menu.add(saveAction);
503 menu.add(new GroupMarker(IWorkbenchActionConstants.SAVE_EXT));
504 menu.add(new Separator());
505 // menu.add(printAction);
506 menu.add(new GroupMarker(IWorkbenchActionConstants.PRINT_EXT));
507 menu.add(new Separator());
508 menu.add(openWorkspaceAction);
509 menu.add(new GroupMarker(IWorkbenchActionConstants.OPEN_EXT));
510 menu.add(new Separator());
511 // menu.add(importResourcesAction);
512 // menu.add(exportResourcesAction);
513 menu.add(new GroupMarker(IWorkbenchActionConstants.IMPORT_EXT));
514 menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
516 menu.add(new Separator());
518 // If we're on OS X we shouldn't show this command in the File menu. It
519 // should be invisible to the user. However, we should not remove it -
520 // the carbon UI code will do a search through our menu structure
521 // looking for it when Cmd-Q is invoked (or Quit is chosen from the
523 ActionContributionItem quitItem = new ActionContributionItem(quitAction);
524 quitItem.setVisible(!Util.isMac());
526 menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_END));
531 protected IContributionItem createEditMenu() {
532 MenuManager menu = new MenuManager("&Edit", IWorkbenchActionConstants.M_EDIT);
534 // menu.add(undoAction);
535 // menu.add(redoAction);
536 // menu.add(new Separator());
537 // menu.add(cutAction);
538 // menu.add(copyAction);
539 // menu.add(pasteAction);
540 // menu.add(new Separator());
541 // menu.add(deleteAction);
542 // menu.add(selectAllAction);
543 menu.add(new GroupMarker(IWorkbenchActionConstants.EDIT_START));
544 // menu.add(new GroupMarker(IWorkbenchActionConstants.UNDO_EXT));
545 // menu.add(new GroupMarker(IWorkbenchActionConstants.CUT_EXT));
546 menu.add(new GroupMarker(IWorkbenchActionConstants.FIND_EXT));
547 menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
548 menu.add(new GroupMarker(IWorkbenchActionConstants.EDIT_END));
554 * Creates and returns the Navigate menu.
556 protected MenuManager createNavigateMenu() {
557 MenuManager menu = new MenuManager("&Navigate", IWorkbenchActionConstants.M_NAVIGATE);
558 menu.add(new GroupMarker(IWorkbenchActionConstants.NAV_START));
559 // menu.add(goIntoAction);
561 // MenuManager goToSubMenu = new MenuManager("&Go To", IWorkbenchActionConstants.GO_TO);
562 // menu.add(goToSubMenu);
563 // goToSubMenu.add(backAction);
564 // goToSubMenu.add(forwardAction);
565 // goToSubMenu.add(upAction);
566 // goToSubMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
568 menu.add(new Separator(IWorkbenchActionConstants.OPEN_EXT));
569 for (int i = 2; i < 5; ++i) {
570 menu.add(new Separator(IWorkbenchActionConstants.OPEN_EXT + i));
572 menu.add(new Separator(IWorkbenchActionConstants.SHOW_EXT));
575 // MenuManager showInSubMenu = new MenuManager("Sho&w In", "showIn") {
576 // public String getMenuText() {
577 // String result = super.getMenuText();
578 // if (showInQuickMenu == null) {
581 // String shortCut = showInQuickMenu.getShortCutString();
582 // if (shortCut == null) {
585 // return result + "\t" + shortCut; //$NON-NLS-1$
588 // showInSubMenu.add(ContributionItemFactory.VIEWS_SHOW_IN
589 // .create(getWindow()));
590 // menu.add(showInSubMenu);
592 for (int i = 2; i < 5; ++i) {
593 menu.add(new Separator(IWorkbenchActionConstants.SHOW_EXT + i));
595 menu.add(new Separator());
596 // menu.add(nextAction);
597 // menu.add(previousAction);
598 menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
599 menu.add(new GroupMarker(IWorkbenchActionConstants.NAV_END));
601 //TBD: Location of this actions
602 menu.add(new Separator());
603 // menu.add(backwardHistoryAction);
604 // menu.add(forwardHistoryAction);
609 * Creates and returns the Project menu.
611 protected MenuManager createProjectMenu() {
612 MenuManager menu = new MenuManager("&Project", ISimanticsWorkbenchConstants.M_PROJECT);
613 menu.add(new Separator(IWorkbenchActionConstants.PROJ_START));
615 // menu.add(openProjectAction);
616 // menu.add(closeProjectAction);
617 // menu.add(new GroupMarker(IWorkbenchActionConstants.OPEN_EXT));
618 // menu.add(new Separator());
619 // menu.add(buildAllAction);
620 // menu.add(buildProjectAction);
621 // addWorkingSetBuildActions(menu);
622 // menu.add(cleanAction);
623 // menu.add(toggleAutoBuildAction);
624 // menu.add(new GroupMarker(IWorkbenchActionConstants.BUILD_EXT));
625 // menu.add(new Separator());
627 menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
628 menu.add(new GroupMarker(IWorkbenchActionConstants.PROJ_END));
629 menu.add(new Separator());
630 // menu.add(projectPropertyDialogAction);
635 protected IContributionItem createWindowMenu() {
636 MenuManager menu = new MenuManager("&Window", IWorkbenchActionConstants.M_WINDOW);
638 menu.add(newWindowAction);
639 // menu.add(newEditorAction);
641 menu.add(new Separator());
642 addPerspectiveActions(menu);
643 menu.add(new Separator());
644 addKeyboardShortcuts(menu);
645 Separator sep = new Separator(IWorkbenchActionConstants.MB_ADDITIONS);
646 sep.setVisible(!Util.isMac());
648 sep = new Separator(IWorkbenchActionConstants.MB_ADDITIONS + ".end"); //$NON-NLS-1$
649 sep.setVisible(!Util.isMac());
652 // See the comment for quit in createFileMenu
653 ActionContributionItem openPreferencesItem = new ActionContributionItem(openPreferencesAction);
654 openPreferencesItem.setVisible(!Util.isMac());
655 menu.add(openPreferencesItem);
657 menu.add(ContributionItemFactory.OPEN_WINDOWS.create(getWindow()));
661 protected IContributionItem createHelpMenu() {
663 MenuManager menu = new MenuManager("&Help", IWorkbenchActionConstants.M_HELP);
665 menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_START));
666 if (introAction != null)
667 menu.add(introAction);
668 menu.add(new GroupMarker("group.intro.ext")); //$NON-NLS-1$
669 menu.add(new Separator("group.main"));
670 //addSeparatorOrGroupMarker(menu, "group.main"); //$NON-NLS-1$
672 menu.add(searchAction);
673 menu.add(dynamicHelpAction);
674 menu.add(new GroupMarker("group.intro.ext")); //$NON-NLS-1$
675 menu.add(new Separator("group.main")); //$NON-NLS-1$
676 //addSeparatorOrGroupMarker(menu, "group.main"); //$NON-NLS-1$
677 addSeparatorOrGroupMarker(menu, "group.assist"); //$NON-NLS-1$
678 menu.add(new GroupMarker("group.main.ext")); //$NON-NLS-1$
679 menu.add(cheatSheetsAction);
680 addSeparatorOrGroupMarker(menu, "group.tutorials"); //$NON-NLS-1$
681 addSeparatorOrGroupMarker(menu, "group.tools"); //$NON-NLS-1$
682 addSeparatorOrGroupMarker(menu, "group.updates"); //$NON-NLS-1$
683 menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_END));
684 //addSeparatorOrGroupMarker(menu, IWorkbenchActionConstants.MB_ADDITIONS);
685 menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
686 //menu.add(new Separator());
687 menu.add(new Separator("group.about")); //$NON-NLS-1$
689 ActionContributionItem aboutItem = new ActionContributionItem(aboutAction);
690 aboutItem.setVisible(!Util.isMac());
692 menu.add(new GroupMarker("group.about.ext")); //$NON-NLS-1$
697 * Adds the perspective actions to the specified menu.
699 private void addPerspectiveActions(MenuManager menu) {
701 MenuManager changePerspMenuMgr = new MenuManager("&Open Perspective", "openPerspective");
702 IContributionItem changePerspMenuItem = ContributionItemFactory.PERSPECTIVES_SHORTLIST.create(getWindow());
703 changePerspMenuMgr.add(changePerspMenuItem);
704 menu.add(changePerspMenuMgr);
707 MenuManager showViewMenuMgr = new MenuManager("Show &View", "showView");
708 IContributionItem showViewMenu = ContributionItemFactory.VIEWS_SHORTLIST.create(getWindow());
709 showViewMenuMgr.add(showViewMenu);
710 menu.add(showViewMenuMgr);
712 menu.add(new Separator());
713 menu.add(editActionSetAction);
714 menu.add(savePerspectiveAction);
715 menu.add(resetPerspectiveAction);
716 menu.add(closePerspAction);
717 menu.add(closeAllPerspsAction);
721 * Adds the keyboard navigation submenu to the specified menu.
723 private void addKeyboardShortcuts(MenuManager menu) {
724 MenuManager subMenu = new MenuManager("Navi&gation", "shortcuts");
727 subMenu.add(showPartPaneMenuAction);
728 subMenu.add(showViewMenuAction);
729 subMenu.add(new Separator());
730 subMenu.add(maximizePartAction);
731 subMenu.add(minimizePartAction);
732 subMenu.add(new Separator());
733 subMenu.add(activateEditorAction);
734 subMenu.add(nextEditorAction);
735 subMenu.add(prevEditorAction);
736 subMenu.add(switchToEditorAction);
737 subMenu.add(openEditorDropDownAction);
738 subMenu.add(new Separator());
739 subMenu.add(nextPartAction);
740 subMenu.add(prevPartAction);
741 subMenu.add(new Separator());
742 subMenu.add(nextPerspectiveAction);
743 subMenu.add(prevPerspectiveAction);
747 private static String[] getPreferencePageIDs() {
748 PreferenceManager mgr = PlatformUI.getWorkbench().getPreferenceManager();
749 List nodes = mgr.getElements(PreferenceManager.POST_ORDER);
750 String result[] = new String[nodes.size()];
752 for (Object o : nodes) {
753 IPreferenceNode node = (IPreferenceNode) o;
754 result[i++] = node.getId();
761 class OpenPreferencesAction extends Action implements ActionFactory.IWorkbenchAction {
762 IWorkbenchWindow workbenchWindow;
763 public OpenPreferencesAction(IWorkbenchWindow window) {
764 super(WorkbenchMessages.OpenPreferences_text);
765 workbenchWindow = window;
766 setActionDefinitionId("org.eclipse.ui.window.preferences");
767 setToolTipText(WorkbenchMessages.OpenPreferences_toolTip);
768 window.getWorkbench().getHelpSystem().setHelp(this,
769 IWorkbenchHelpContextIds.OPEN_PREFERENCES_ACTION);
771 public String[] getIDsToBeDisplayed() {
772 String nodes[] = ApplicationActionBarAdvisor.getPreferencePageIDs();
773 List<String> ids = new ArrayList<String>();
774 for (String node: nodes) {
775 if (node.startsWith("fi"))
778 return ids.toArray(new String[0]);
781 if (workbenchWindow == null)
784 String toBeDisplayed[] = getIDsToBeDisplayed();
785 PreferenceDialog dialog =
786 PreferencesUtil.createPreferenceDialogOn(null, null, toBeDisplayed, null);
789 public void dispose() {
790 workbenchWindow = null;
796 * Our own version of the "New Window" in
797 * <code>IWorkbenchAction.OPEN_NEW_WINDOW</code> action which allows
798 * setting the page input IAdaptable.
800 public static final ActionFactory OPEN_NEW_WINDOW = new ActionFactory("openNewWindow") {//$NON-NLS-1$
802 public IWorkbenchAction create(IWorkbenchWindow window) {
803 if (window == null) {
804 throw new IllegalArgumentException();
806 IWorkbenchAction action = new NewWindowAction(window);
807 action.setId(getId());
813 * This version of {@link OpenInNewWindowAction} will simply add a new
814 * unique IAdaptable page input object for each window created through it.
816 static class NewWindowAction extends OpenInNewWindowAction {
817 private IWorkbenchWindow workbenchWindow;
818 public NewWindowAction(IWorkbenchWindow window) {
820 this.workbenchWindow = window;
823 public void dispose() {
824 workbenchWindow = null;
829 IAdaptable defaultInput = ((Workbench) workbenchWindow.getWorkbench()).getDefaultPageInput();
830 setPageInput(new DelegateAdaptable(defaultInput));
835 static class DelegateAdaptable implements IAdaptable {
837 public DelegateAdaptable(IAdaptable target) {
838 this.target = target;
840 @SuppressWarnings({ "rawtypes" })
842 public Object getAdapter(Class adapter) {
843 return (target != null) ? target.getAdapter(adapter) : null;
848 * Adds a <code>GroupMarker</code> or <code>Separator</code> to a menu.
849 * The test for whether a separator should be added is done by checking for
850 * the existence of a preference matching the string
851 * useSeparator.MENUID.GROUPID that is set to <code>true</code>.
856 * the group id for the added separator or group marker
858 private void addSeparatorOrGroupMarker(MenuManager menu, String groupId) {
859 String prefId = "useSeparator." + menu.getId() + "." + groupId; //$NON-NLS-1$ //$NON-NLS-2$
860 boolean addExtraSeparators = Activator.getDefault().getPreferenceStore().getBoolean(prefId);
861 if (addExtraSeparators) {
862 menu.add(new Separator(groupId));
864 menu.add(new GroupMarker(groupId));