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