1 /******************************************************************************* 2 * Copyright (c) 2000, 2010 IBM Corporation and others. 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Eclipse Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/epl-v10.html 7 * 8 * Contributors: 9 * IBM Corporation - initial API and implementation 10 * Andreas Buchen <andreas.buchen@sap.com> - Bug 206584 11 *******************************************************************************/ 12 package org.wesnoth.product; 13 14 import org.eclipse.core.commands.Command; 15 import org.eclipse.core.resources.IProject; 16 import org.eclipse.core.resources.IResourceChangeEvent; 17 import org.eclipse.core.resources.IResourceChangeListener; 18 import org.eclipse.core.resources.IResourceDelta; 19 import org.eclipse.core.resources.IWorkspace; 20 import org.eclipse.core.resources.IncrementalProjectBuilder; 21 import org.eclipse.core.resources.ResourcesPlugin; 22 import org.eclipse.core.runtime.Platform; 23 import org.eclipse.core.runtime.Preferences; 24 import org.eclipse.jface.action.ActionContributionItem; 25 import org.eclipse.jface.action.GroupMarker; 26 import org.eclipse.jface.action.IAction; 27 import org.eclipse.jface.action.IContributionItem; 28 import org.eclipse.jface.action.ICoolBarManager; 29 import org.eclipse.jface.action.IMenuManager; 30 import org.eclipse.jface.action.IStatusLineManager; 31 import org.eclipse.jface.action.IToolBarManager; 32 import org.eclipse.jface.action.MenuManager; 33 import org.eclipse.jface.action.Separator; 34 import org.eclipse.jface.action.StatusLineContributionItem; 35 import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem; 36 import org.eclipse.jface.preference.IPreferenceStore; 37 import org.eclipse.jface.util.IPropertyChangeListener; 38 import org.eclipse.jface.util.PropertyChangeEvent; 39 import org.eclipse.jface.util.Util; 40 import org.eclipse.swt.widgets.Shell; 41 import org.eclipse.ui.IPageListener; 42 import org.eclipse.ui.ISharedImages; 43 import org.eclipse.ui.IWorkbenchActionConstants; 44 import org.eclipse.ui.IWorkbenchCommandConstants; 45 import org.eclipse.ui.IWorkbenchPage; 46 import org.eclipse.ui.IWorkbenchWindow; 47 import org.eclipse.ui.actions.ActionFactory; 48 import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction; 49 import org.eclipse.ui.actions.BuildAction; 50 import org.eclipse.ui.actions.ContributionItemFactory; 51 import org.eclipse.ui.actions.NewWizardMenu; 52 import org.eclipse.ui.application.ActionBarAdvisor; 53 import org.eclipse.ui.application.IActionBarConfigurer; 54 import org.eclipse.ui.commands.ICommandService; 55 import org.eclipse.ui.handlers.IHandlerService; 56 import org.eclipse.ui.ide.IDEActionFactory; 57 import org.eclipse.ui.ide.IIDEActionConstants; 58 import org.eclipse.ui.internal.IPreferenceConstants; 59 import org.eclipse.ui.internal.IWorkbenchHelpContextIds; 60 import org.eclipse.ui.internal.WorkbenchMessages; 61 import org.eclipse.ui.internal.WorkbenchPlugin; 62 import org.eclipse.ui.internal.handlers.IActionCommandMappingService; 63 import org.eclipse.ui.internal.ide.AboutInfo; 64 import org.eclipse.ui.internal.ide.IDEInternalWorkbenchImages; 65 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; 66 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 67 import org.eclipse.ui.internal.ide.actions.BuildSetMenu; 68 import org.eclipse.ui.internal.ide.actions.BuildUtilities; 69 import org.eclipse.ui.internal.ide.actions.QuickMenuAction; 70 import org.eclipse.ui.internal.ide.actions.RetargetActionWithDefault; 71 import org.eclipse.ui.internal.provisional.application.IActionBarConfigurer2; 72 import org.eclipse.ui.menus.CommandContributionItem; 73 import org.eclipse.ui.menus.CommandContributionItemParameter; 74 import org.eclipse.ui.menus.IMenuService; 75 76 /** 77 * Adds actions to a workbench window. 78 */ 79 @SuppressWarnings( "all" ) 80 public class WorkbenchActionBuilder extends ActionBarAdvisor 81 { 82 private final IWorkbenchWindow window; 83 84 // generic actions 85 private IWorkbenchAction closeAction; 86 87 private IWorkbenchAction closeAllAction; 88 89 private IWorkbenchAction closeOthersAction; 90 91 private IWorkbenchAction closeAllSavedAction; 92 93 private IWorkbenchAction saveAction; 94 95 private IWorkbenchAction saveAllAction; 96 97 private IWorkbenchAction newWindowAction; 98 99 private IWorkbenchAction newEditorAction; 100 101 private IWorkbenchAction helpContentsAction; 102 103 private IWorkbenchAction helpSearchAction; 104 105 private IWorkbenchAction dynamicHelpAction; 106 107 private IWorkbenchAction aboutAction; 108 109 private IWorkbenchAction openPreferencesAction; 110 111 private IWorkbenchAction saveAsAction; 112 113 private IWorkbenchAction hideShowEditorAction; 114 115 private IWorkbenchAction savePerspectiveAction; 116 117 private IWorkbenchAction resetPerspectiveAction; 118 119 private IWorkbenchAction editActionSetAction; 120 121 private IWorkbenchAction closePerspAction; 122 123 private IWorkbenchAction lockToolBarAction; 124 125 private IWorkbenchAction closeAllPerspsAction; 126 127 private IWorkbenchAction showViewMenuAction; 128 129 private IWorkbenchAction showPartPaneMenuAction; 130 131 private IWorkbenchAction nextPartAction; 132 133 private IWorkbenchAction prevPartAction; 134 135 private IWorkbenchAction nextEditorAction; 136 137 private IWorkbenchAction prevEditorAction; 138 139 private IWorkbenchAction nextPerspectiveAction; 140 141 private IWorkbenchAction prevPerspectiveAction; 142 143 private IWorkbenchAction activateEditorAction; 144 145 private IWorkbenchAction maximizePartAction; 146 147 private IWorkbenchAction minimizePartAction; 148 149 private IWorkbenchAction switchToEditorAction; 150 151 private IWorkbenchAction workbookEditorsAction; 152 153 private IWorkbenchAction quickAccessAction; 154 155 private IWorkbenchAction backwardHistoryAction; 156 157 private IWorkbenchAction forwardHistoryAction; 158 159 // generic retarget actions 160 private IWorkbenchAction undoAction; 161 162 private IWorkbenchAction redoAction; 163 164 private IWorkbenchAction quitAction; 165 166 private IWorkbenchAction goIntoAction; 167 168 private IWorkbenchAction backAction; 169 170 private IWorkbenchAction forwardAction; 171 172 private IWorkbenchAction upAction; 173 174 private IWorkbenchAction nextAction; 175 176 private IWorkbenchAction previousAction; 177 178 // IDE-specific actions 179 private IWorkbenchAction openWorkspaceAction; 180 181 private IWorkbenchAction projectPropertyDialogAction; 182 183 private IWorkbenchAction newWizardAction; 184 185 private IWorkbenchAction newWizardDropDownAction; 186 187 private IWorkbenchAction importResourcesAction; 188 189 private IWorkbenchAction exportResourcesAction; 190 191 IWorkbenchAction buildAllAction; // Incremental 192 // workspace 193 // build 194 195 private IWorkbenchAction cleanAction; 196 197 private IWorkbenchAction toggleAutoBuildAction; 198 199 MenuManager buildWorkingSetMenu; 200 201 private IWorkbenchAction quickStartAction; 202 203 private IWorkbenchAction tipsAndTricksAction; 204 205 private QuickMenuAction showInQuickMenu; 206 207 private QuickMenuAction newQuickMenu; 208 209 private IWorkbenchAction introAction; 210 211 // IDE-specific retarget actions 212 IWorkbenchAction buildProjectAction; 213 214 // contribution items 215 // @issue should obtain from ContributionItemFactory 216 private NewWizardMenu newWizardMenu; 217 218 // @issue class is workbench internal 219 private StatusLineContributionItem statusLineItem; 220 221 private Preferences.IPropertyChangeListener prefListener; 222 223 // listener for the "close editors automatically" 224 // preference change 225 private IPropertyChangeListener propPrefListener; 226 227 private IPageListener pageListener; 228 229 private IResourceChangeListener resourceListener; 230 231 /** 232 * Indicates if the action builder has been disposed 233 */ 234 private boolean isDisposed = false; 235 236 /** 237 * The coolbar context menu manager. 238 * 239 * @since 3.3 240 */ 241 private MenuManager coolbarPopupMenuManager; 242 243 /** 244 * Constructs a new action builder which contributes actions 245 * to the given window. 246 * 247 * @param configurer 248 * the action bar configurer for the window 249 */ WorkbenchActionBuilder( IActionBarConfigurer configurer )250 public WorkbenchActionBuilder( IActionBarConfigurer configurer ) 251 { 252 super( configurer ); 253 window = configurer.getWindowConfigurer( ).getWindow( ); 254 } 255 256 /** 257 * Returns the window to which this action builder is contributing. 258 */ getWindow( )259 private IWorkbenchWindow getWindow( ) 260 { 261 return window; 262 } 263 264 /** 265 * Hooks listeners on the preference store and the window's page, 266 * perspective and selection services. 267 */ hookListeners( )268 private void hookListeners( ) 269 { 270 271 pageListener = new IPageListener( ) { 272 public void pageActivated( IWorkbenchPage page ) 273 { 274 // do nothing 275 } 276 277 public void pageClosed( IWorkbenchPage page ) 278 { 279 // do nothing 280 } 281 282 public void pageOpened( IWorkbenchPage page ) 283 { 284 // set default build handler -- can't be done until the shell is 285 // available 286 IAction buildHandler = new BuildAction( 287 page.getWorkbenchWindow( ), 288 IncrementalProjectBuilder.INCREMENTAL_BUILD ); 289 ( ( RetargetActionWithDefault ) buildProjectAction ) 290 .setDefaultHandler( buildHandler ); 291 } 292 }; 293 getWindow( ).addPageListener( pageListener ); 294 295 prefListener = new Preferences.IPropertyChangeListener( ) { 296 public void propertyChange( Preferences.PropertyChangeEvent event ) 297 { 298 if( event.getProperty( ).equals( 299 ResourcesPlugin.PREF_AUTO_BUILDING ) ) { 300 updateBuildActions( false ); 301 } 302 } 303 }; 304 ResourcesPlugin.getPlugin( ).getPluginPreferences( ) 305 .addPropertyChangeListener( prefListener ); 306 307 // listener for the "close editors automatically" 308 // preference change 309 propPrefListener = new IPropertyChangeListener( ) { 310 public void propertyChange( PropertyChangeEvent event ) 311 { 312 if( event.getProperty( ).equals( 313 IPreferenceConstants.REUSE_EDITORS_BOOLEAN ) ) { 314 if( window.getShell( ) != null 315 && ! window.getShell( ).isDisposed( ) ) { 316 // this property change notification could be from a 317 // non-ui thread 318 window.getShell( ).getDisplay( ) 319 .syncExec( new Runnable( ) { 320 public void run( ) 321 { 322 updatePinActionToolbar( ); 323 } 324 } ); 325 } 326 } 327 } 328 }; 329 /* 330 * In order to ensure that the pin action toolbar sets its size 331 * correctly, the pin action should set its visiblity before we call 332 * updatePinActionToolbar(). 333 * 334 * In other words we always want the PinActionContributionItem to be 335 * notified before the 336 * WorkbenchActionBuilder. 337 */ 338 WorkbenchPlugin.getDefault( ).getPreferenceStore( ) 339 .addPropertyChangeListener( propPrefListener ); 340 // listen for project description changes, which can affect enablement 341 // of build actions 342 resourceListener = new IResourceChangeListener( ) { 343 public void resourceChanged( IResourceChangeEvent event ) 344 { 345 IResourceDelta delta = event.getDelta( ); 346 if( delta == null ) { 347 return; 348 } 349 IResourceDelta[] projectDeltas = delta.getAffectedChildren( ); 350 for( int i = 0; i < projectDeltas.length; i++ ) { 351 int kind = projectDeltas[i].getKind( ); 352 // affected by projects being opened/closed or description 353 // changes 354 boolean changed = ( projectDeltas[i].getFlags( ) & ( IResourceDelta.DESCRIPTION | IResourceDelta.OPEN ) ) != 0; 355 if( kind != IResourceDelta.CHANGED || changed ) { 356 updateBuildActions( false ); 357 return; 358 } 359 } 360 } 361 }; 362 ResourcesPlugin.getWorkspace( ).addResourceChangeListener( 363 resourceListener, IResourceChangeEvent.POST_CHANGE ); 364 } 365 366 @Override fillActionBars( int flags )367 public void fillActionBars( int flags ) 368 { 369 super.fillActionBars( flags ); 370 updateBuildActions( true ); 371 if( ( flags & FILL_PROXY ) == 0 ) { 372 hookListeners( ); 373 } 374 } 375 376 /** 377 * Fills the coolbar with the workbench actions. 378 */ 379 @Override fillCoolBar( ICoolBarManager coolBar )380 protected void fillCoolBar( ICoolBarManager coolBar ) 381 { 382 383 IActionBarConfigurer2 actionBarConfigurer = ( IActionBarConfigurer2 ) getActionBarConfigurer( ); 384 { // Set up the context Menu 385 coolbarPopupMenuManager = new MenuManager( ); 386 coolbarPopupMenuManager.add( new ActionContributionItem( 387 lockToolBarAction ) ); 388 coolbarPopupMenuManager.add( new ActionContributionItem( 389 editActionSetAction ) ); 390 coolBar.setContextMenuManager( coolbarPopupMenuManager ); 391 IMenuService menuService = ( IMenuService ) window 392 .getService( IMenuService.class ); 393 menuService.populateContributionManager( coolbarPopupMenuManager, "popup:windowCoolbarContextMenu" ); //$NON-NLS-1$ 394 } 395 coolBar.add( new GroupMarker( IIDEActionConstants.GROUP_FILE ) ); 396 { // File Group 397 IToolBarManager fileToolBar = actionBarConfigurer 398 .createToolBarManager( ); 399 fileToolBar 400 .add( new Separator( IWorkbenchActionConstants.NEW_GROUP ) ); 401 fileToolBar.add( newWizardDropDownAction ); 402 fileToolBar 403 .add( new GroupMarker( IWorkbenchActionConstants.NEW_EXT ) ); 404 fileToolBar.add( new GroupMarker( 405 IWorkbenchActionConstants.SAVE_GROUP ) ); 406 fileToolBar.add( saveAction ); 407 fileToolBar.add( saveAllAction ); 408 fileToolBar.add( new GroupMarker( 409 IWorkbenchActionConstants.SAVE_EXT ) ); 410 fileToolBar.add( getPrintItem( ) ); 411 fileToolBar.add( new GroupMarker( 412 IWorkbenchActionConstants.PRINT_EXT ) ); 413 414 fileToolBar.add( new Separator( 415 IWorkbenchActionConstants.BUILD_GROUP ) ); 416 fileToolBar.add( new GroupMarker( 417 IWorkbenchActionConstants.BUILD_EXT ) ); 418 fileToolBar.add( new Separator( 419 IWorkbenchActionConstants.MB_ADDITIONS ) ); 420 421 // Add to the cool bar manager 422 coolBar.add( actionBarConfigurer.createToolBarContributionItem( 423 fileToolBar, IWorkbenchActionConstants.TOOLBAR_FILE ) ); 424 } 425 426 coolBar.add( new GroupMarker( IWorkbenchActionConstants.MB_ADDITIONS ) ); 427 428 coolBar.add( new GroupMarker( IIDEActionConstants.GROUP_NAV ) ); 429 { // Navigate group 430 IToolBarManager navToolBar = actionBarConfigurer 431 .createToolBarManager( ); 432 navToolBar.add( new Separator( 433 IWorkbenchActionConstants.HISTORY_GROUP ) ); 434 navToolBar.add( new GroupMarker( 435 IWorkbenchActionConstants.GROUP_APP ) ); 436 navToolBar.add( backwardHistoryAction ); 437 navToolBar.add( forwardHistoryAction ); 438 navToolBar 439 .add( new Separator( IWorkbenchActionConstants.PIN_GROUP ) ); 440 navToolBar.add( getPinEditorItem( ) ); 441 442 // Add to the cool bar manager 443 coolBar.add( actionBarConfigurer.createToolBarContributionItem( 444 navToolBar, IWorkbenchActionConstants.TOOLBAR_NAVIGATE ) ); 445 } 446 447 coolBar.add( new GroupMarker( IWorkbenchActionConstants.GROUP_EDITOR ) ); 448 449 coolBar.add( new GroupMarker( IWorkbenchActionConstants.GROUP_HELP ) ); 450 451 { // Help group 452 IToolBarManager helpToolBar = actionBarConfigurer 453 .createToolBarManager( ); 454 helpToolBar.add( new Separator( 455 IWorkbenchActionConstants.GROUP_HELP ) ); 456 // helpToolBar.add(searchComboItem); 457 // Add the group for applications to contribute 458 helpToolBar.add( new GroupMarker( 459 IWorkbenchActionConstants.GROUP_APP ) ); 460 // Add to the cool bar manager 461 coolBar.add( actionBarConfigurer.createToolBarContributionItem( 462 helpToolBar, IWorkbenchActionConstants.TOOLBAR_HELP ) ); 463 } 464 465 } 466 467 /** 468 * Fills the menu bar with the workbench actions. 469 */ 470 @Override fillMenuBar( IMenuManager menuBar )471 protected void fillMenuBar( IMenuManager menuBar ) 472 { 473 menuBar.add( createFileMenu( ) ); 474 menuBar.add( createEditMenu( ) ); 475 menuBar.add( createNavigateMenu( ) ); 476 menuBar.add( createProjectMenu( ) ); 477 menuBar.add( new GroupMarker( IWorkbenchActionConstants.MB_ADDITIONS ) ); 478 menuBar.add( createWindowMenu( ) ); 479 menuBar.add( createHelpMenu( ) ); 480 } 481 482 /** 483 * Creates and returns the File menu. 484 */ createFileMenu( )485 private MenuManager createFileMenu( ) 486 { 487 MenuManager menu = new MenuManager( 488 IDEWorkbenchMessages.Workbench_file, 489 IWorkbenchActionConstants.M_FILE ); 490 menu.add( new GroupMarker( IWorkbenchActionConstants.FILE_START ) ); 491 { 492 // create the New submenu, using the same id for it as the New 493 // action 494 String newText = IDEWorkbenchMessages.Workbench_new; 495 String newId = ActionFactory.NEW.getId( ); 496 MenuManager newMenu = new MenuManager( newText, newId ); 497 newMenu.setActionDefinitionId( "org.eclipse.ui.file.newQuickMenu" ); //$NON-NLS-1$ 498 newMenu.add( new Separator( newId ) ); 499 this.newWizardMenu = new NewWizardMenu( getWindow( ) ); 500 newMenu.add( this.newWizardMenu ); 501 newMenu 502 .add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) ); 503 menu.add( newMenu ); 504 } 505 506 menu.add( new GroupMarker( IWorkbenchActionConstants.NEW_EXT ) ); 507 menu.add( new Separator( ) ); 508 509 menu.add( closeAction ); 510 menu.add( closeAllAction ); 511 // menu.add(closeAllSavedAction); 512 menu.add( new GroupMarker( IWorkbenchActionConstants.CLOSE_EXT ) ); 513 menu.add( new Separator( ) ); 514 menu.add( saveAction ); 515 menu.add( saveAsAction ); 516 menu.add( saveAllAction ); 517 menu.add( getRevertItem( ) ); 518 menu.add( new Separator( ) ); 519 menu.add( getMoveItem( ) ); 520 menu.add( getRenameItem( ) ); 521 menu.add( getRefreshItem( ) ); 522 523 menu.add( new GroupMarker( IWorkbenchActionConstants.SAVE_EXT ) ); 524 menu.add( new Separator( ) ); 525 menu.add( getPrintItem( ) ); 526 menu.add( new GroupMarker( IWorkbenchActionConstants.PRINT_EXT ) ); 527 menu.add( new Separator( ) ); 528 menu.add( openWorkspaceAction ); 529 menu.add( new GroupMarker( IWorkbenchActionConstants.OPEN_EXT ) ); 530 menu.add( new Separator( ) ); 531 menu.add( importResourcesAction ); 532 menu.add( exportResourcesAction ); 533 menu.add( new GroupMarker( IWorkbenchActionConstants.IMPORT_EXT ) ); 534 menu.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) ); 535 536 menu.add( new Separator( ) ); 537 menu.add( getPropertiesItem( ) ); 538 539 menu.add( ContributionItemFactory.REOPEN_EDITORS.create( getWindow( ) ) ); 540 menu.add( new GroupMarker( IWorkbenchActionConstants.MRU ) ); 541 menu.add( new Separator( ) ); 542 543 // If we're on OS X we shouldn't show this command in the File menu. It 544 // should be invisible to the user. However, we should not remove it - 545 // the carbon UI code will do a search through our menu structure 546 // looking for it when Cmd-Q is invoked (or Quit is chosen from the 547 // application menu. 548 ActionContributionItem quitItem = new ActionContributionItem( 549 quitAction ); 550 quitItem.setVisible( ! Util.isMac( ) ); 551 menu.add( quitItem ); 552 menu.add( new GroupMarker( IWorkbenchActionConstants.FILE_END ) ); 553 return menu; 554 } 555 556 /** 557 * Creates and returns the Edit menu. 558 */ createEditMenu( )559 private MenuManager createEditMenu( ) 560 { 561 MenuManager menu = new MenuManager( 562 IDEWorkbenchMessages.Workbench_edit, 563 IWorkbenchActionConstants.M_EDIT ); 564 menu.add( new GroupMarker( IWorkbenchActionConstants.EDIT_START ) ); 565 566 menu.add( undoAction ); 567 menu.add( redoAction ); 568 menu.add( new GroupMarker( IWorkbenchActionConstants.UNDO_EXT ) ); 569 menu.add( new Separator( ) ); 570 571 menu.add( getCutItem( ) ); 572 menu.add( getCopyItem( ) ); 573 menu.add( getPasteItem( ) ); 574 menu.add( new GroupMarker( IWorkbenchActionConstants.CUT_EXT ) ); 575 menu.add( new Separator( ) ); 576 577 menu.add( getDeleteItem( ) ); 578 menu.add( getSelectAllItem( ) ); 579 menu.add( new Separator( ) ); 580 581 menu.add( getFindItem( ) ); 582 menu.add( new GroupMarker( IWorkbenchActionConstants.FIND_EXT ) ); 583 menu.add( new Separator( ) ); 584 585 menu.add( getBookmarkItem( ) ); 586 menu.add( getTaskItem( ) ); 587 menu.add( new GroupMarker( IWorkbenchActionConstants.ADD_EXT ) ); 588 589 menu.add( new GroupMarker( IWorkbenchActionConstants.EDIT_END ) ); 590 menu.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) ); 591 return menu; 592 } 593 594 /** 595 * Creates and returns the Navigate menu. 596 */ createNavigateMenu( )597 private MenuManager createNavigateMenu( ) 598 { 599 MenuManager menu = new MenuManager( 600 IDEWorkbenchMessages.Workbench_navigate, 601 IWorkbenchActionConstants.M_NAVIGATE ); 602 menu.add( new GroupMarker( IWorkbenchActionConstants.NAV_START ) ); 603 menu.add( goIntoAction ); 604 605 MenuManager goToSubMenu = new MenuManager( 606 IDEWorkbenchMessages.Workbench_goTo, 607 IWorkbenchActionConstants.GO_TO ); 608 menu.add( goToSubMenu ); 609 goToSubMenu.add( backAction ); 610 goToSubMenu.add( forwardAction ); 611 goToSubMenu.add( upAction ); 612 goToSubMenu 613 .add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) ); 614 615 menu.add( new Separator( IWorkbenchActionConstants.OPEN_EXT ) ); 616 for( int i = 2; i < 5; ++i ) { 617 menu.add( new Separator( IWorkbenchActionConstants.OPEN_EXT + i ) ); 618 } 619 menu.add( new Separator( IWorkbenchActionConstants.SHOW_EXT ) ); 620 { 621 MenuManager showInSubMenu = new MenuManager( 622 IDEWorkbenchMessages.Workbench_showIn, "showIn" ); //$NON-NLS-1$ 623 showInSubMenu.setActionDefinitionId( showInQuickMenu 624 .getActionDefinitionId( ) ); 625 showInSubMenu.add( ContributionItemFactory.VIEWS_SHOW_IN 626 .create( getWindow( ) ) ); 627 menu.add( showInSubMenu ); 628 } 629 for( int i = 2; i < 5; ++i ) { 630 menu.add( new Separator( IWorkbenchActionConstants.SHOW_EXT + i ) ); 631 } 632 menu.add( new Separator( ) ); 633 menu.add( nextAction ); 634 menu.add( previousAction ); 635 menu.add( new Separator( IWorkbenchActionConstants.MB_ADDITIONS ) ); 636 menu.add( new GroupMarker( IWorkbenchActionConstants.NAV_END ) ); 637 638 // TBD: Location of this actions 639 menu.add( new Separator( ) ); 640 menu.add( backwardHistoryAction ); 641 menu.add( forwardHistoryAction ); 642 return menu; 643 } 644 645 /** 646 * Creates and returns the Project menu. 647 */ createProjectMenu( )648 private MenuManager createProjectMenu( ) 649 { 650 MenuManager menu = new MenuManager( 651 IDEWorkbenchMessages.Workbench_project, 652 IWorkbenchActionConstants.M_PROJECT ); 653 menu.add( new Separator( IWorkbenchActionConstants.PROJ_START ) ); 654 655 menu.add( getOpenProjectItem( ) ); 656 menu.add( getCloseProjectItem( ) ); 657 menu.add( new GroupMarker( IWorkbenchActionConstants.OPEN_EXT ) ); 658 menu.add( new Separator( ) ); 659 menu.add( buildAllAction ); 660 menu.add( buildProjectAction ); 661 addWorkingSetBuildActions( menu ); 662 menu.add( cleanAction ); 663 menu.add( toggleAutoBuildAction ); 664 menu.add( new GroupMarker( IWorkbenchActionConstants.BUILD_EXT ) ); 665 menu.add( new Separator( ) ); 666 667 menu.add( new GroupMarker( IWorkbenchActionConstants.MB_ADDITIONS ) ); 668 menu.add( new GroupMarker( IWorkbenchActionConstants.PROJ_END ) ); 669 menu.add( new Separator( ) ); 670 menu.add( projectPropertyDialogAction ); 671 return menu; 672 } 673 674 /** 675 * Creates and returns the Window menu. 676 */ createWindowMenu( )677 private MenuManager createWindowMenu( ) 678 { 679 MenuManager menu = new MenuManager( 680 IDEWorkbenchMessages.Workbench_window, 681 IWorkbenchActionConstants.M_WINDOW ); 682 683 menu.add( newWindowAction ); 684 menu.add( newEditorAction ); 685 686 menu.add( new Separator( ) ); 687 addPerspectiveActions( menu ); 688 menu.add( new Separator( ) ); 689 addKeyboardShortcuts( menu ); 690 Separator sep = new Separator( IWorkbenchActionConstants.MB_ADDITIONS ); 691 sep.setVisible( ! Util.isMac( ) ); 692 menu.add( sep ); 693 694 // See the comment for quit in createFileMenu 695 ActionContributionItem openPreferencesItem = new ActionContributionItem( 696 openPreferencesAction ); 697 openPreferencesItem.setVisible( ! Util.isMac( ) ); 698 menu.add( openPreferencesItem ); 699 700 menu.add( ContributionItemFactory.OPEN_WINDOWS.create( getWindow( ) ) ); 701 return menu; 702 } 703 704 /** 705 * Adds the perspective actions to the specified menu. 706 */ addPerspectiveActions( MenuManager menu )707 private void addPerspectiveActions( MenuManager menu ) 708 { 709 { 710 String openText = IDEWorkbenchMessages.Workbench_openPerspective; 711 MenuManager changePerspMenuMgr = new MenuManager( openText, "openPerspective" ); //$NON-NLS-1$ 712 IContributionItem changePerspMenuItem = ContributionItemFactory.PERSPECTIVES_SHORTLIST 713 .create( getWindow( ) ); 714 changePerspMenuMgr.add( changePerspMenuItem ); 715 menu.add( changePerspMenuMgr ); 716 } 717 { 718 MenuManager showViewMenuMgr = new MenuManager( 719 IDEWorkbenchMessages.Workbench_showView, "showView" ); //$NON-NLS-1$ 720 IContributionItem showViewMenu = ContributionItemFactory.VIEWS_SHORTLIST 721 .create( getWindow( ) ); 722 showViewMenuMgr.add( showViewMenu ); 723 menu.add( showViewMenuMgr ); 724 } 725 menu.add( new Separator( ) ); 726 menu.add( editActionSetAction ); 727 menu.add( savePerspectiveAction ); 728 menu.add( resetPerspectiveAction ); 729 menu.add( closePerspAction ); 730 menu.add( closeAllPerspsAction ); 731 } 732 733 /** 734 * Adds the keyboard navigation submenu to the specified menu. 735 */ addWorkingSetBuildActions( MenuManager menu )736 private void addWorkingSetBuildActions( MenuManager menu ) 737 { 738 buildWorkingSetMenu = new MenuManager( 739 IDEWorkbenchMessages.Workbench_buildSet ); 740 IContributionItem workingSetBuilds = new BuildSetMenu( window, 741 getActionBarConfigurer( ) ); 742 buildWorkingSetMenu.add( workingSetBuilds ); 743 menu.add( buildWorkingSetMenu ); 744 } 745 746 /** 747 * Adds the keyboard navigation submenu to the specified menu. 748 */ addKeyboardShortcuts( MenuManager menu )749 private void addKeyboardShortcuts( MenuManager menu ) 750 { 751 MenuManager subMenu = new MenuManager( 752 IDEWorkbenchMessages.Workbench_shortcuts, "shortcuts" ); //$NON-NLS-1$ 753 menu.add( subMenu ); 754 subMenu.add( showPartPaneMenuAction ); 755 subMenu.add( showViewMenuAction ); 756 subMenu.add( quickAccessAction ); 757 subMenu.add( new Separator( ) ); 758 subMenu.add( maximizePartAction ); 759 subMenu.add( minimizePartAction ); 760 subMenu.add( new Separator( ) ); 761 subMenu.add( activateEditorAction ); 762 subMenu.add( nextEditorAction ); 763 subMenu.add( prevEditorAction ); 764 subMenu.add( switchToEditorAction ); 765 subMenu.add( new Separator( ) ); 766 subMenu.add( nextPartAction ); 767 subMenu.add( prevPartAction ); 768 subMenu.add( new Separator( ) ); 769 subMenu.add( nextPerspectiveAction ); 770 subMenu.add( prevPerspectiveAction ); 771 } 772 773 /** 774 * Creates and returns the Help menu. 775 */ createHelpMenu( )776 private MenuManager createHelpMenu( ) 777 { 778 MenuManager menu = new MenuManager( 779 IDEWorkbenchMessages.Workbench_help, 780 IWorkbenchActionConstants.M_HELP ); 781 addSeparatorOrGroupMarker( menu, "group.intro" ); //$NON-NLS-1$ 782 // See if a welcome or intro page is specified 783 if( introAction != null ) { 784 menu.add( introAction ); 785 } 786 else if( quickStartAction != null ) { 787 menu.add( quickStartAction ); 788 } 789 menu.add( new GroupMarker( "group.intro.ext" ) ); //$NON-NLS-1$ 790 addSeparatorOrGroupMarker( menu, "group.main" ); //$NON-NLS-1$ 791 menu.add( helpContentsAction ); 792 menu.add( helpSearchAction ); 793 menu.add( dynamicHelpAction ); 794 addSeparatorOrGroupMarker( menu, "group.assist" ); //$NON-NLS-1$ 795 // See if a tips and tricks page is specified 796 if( tipsAndTricksAction != null ) { 797 menu.add( tipsAndTricksAction ); 798 } 799 // HELP_START should really be the first item, but it was after 800 // quickStartAction and tipsAndTricksAction in 2.1. 801 menu.add( new GroupMarker( IWorkbenchActionConstants.HELP_START ) ); 802 menu.add( new GroupMarker( "group.main.ext" ) ); //$NON-NLS-1$ 803 addSeparatorOrGroupMarker( menu, "group.tutorials" ); //$NON-NLS-1$ 804 addSeparatorOrGroupMarker( menu, "group.tools" ); //$NON-NLS-1$ 805 addSeparatorOrGroupMarker( menu, "group.updates" ); //$NON-NLS-1$ 806 menu.add( new GroupMarker( IWorkbenchActionConstants.HELP_END ) ); 807 addSeparatorOrGroupMarker( menu, IWorkbenchActionConstants.MB_ADDITIONS ); 808 // about should always be at the bottom 809 menu.add( new Separator( "group.about" ) ); //$NON-NLS-1$ 810 811 ActionContributionItem aboutItem = new ActionContributionItem( 812 aboutAction ); 813 aboutItem.setVisible( ! Util.isMac( ) ); 814 menu.add( aboutItem ); 815 menu.add( new GroupMarker( "group.about.ext" ) ); //$NON-NLS-1$ 816 return menu; 817 } 818 819 /** 820 * Adds a <code>GroupMarker</code> or <code>Separator</code> to a menu. 821 * The test for whether a separator should be added is done by checking for 822 * the existence of a preference matching the string 823 * useSeparator.MENUID.GROUPID that is set to <code>true</code>. 824 * 825 * @param menu 826 * the menu to add to 827 * @param groupId 828 * the group id for the added separator or group marker 829 */ addSeparatorOrGroupMarker( MenuManager menu, String groupId )830 private void addSeparatorOrGroupMarker( MenuManager menu, String groupId ) 831 { 832 String prefId = "useSeparator." + menu.getId( ) + "." + groupId; //$NON-NLS-1$ //$NON-NLS-2$ 833 boolean addExtraSeparators = IDEWorkbenchPlugin.getDefault( ) 834 .getPreferenceStore( ).getBoolean( prefId ); 835 if( addExtraSeparators ) { 836 menu.add( new Separator( groupId ) ); 837 } 838 else { 839 menu.add( new GroupMarker( groupId ) ); 840 } 841 } 842 843 /** 844 * Disposes any resources and unhooks any listeners that are no longer 845 * needed. 846 * Called when the window is closed. 847 */ 848 @Override dispose( )849 public void dispose( ) 850 { 851 if( isDisposed ) { 852 return; 853 } 854 isDisposed = true; 855 IMenuService menuService = ( IMenuService ) window 856 .getService( IMenuService.class ); 857 menuService.releaseContributions( coolbarPopupMenuManager ); 858 coolbarPopupMenuManager.dispose( ); 859 860 getActionBarConfigurer( ).getStatusLineManager( ).remove( 861 statusLineItem ); 862 if( pageListener != null ) { 863 window.removePageListener( pageListener ); 864 pageListener = null; 865 } 866 if( prefListener != null ) { 867 ResourcesPlugin.getPlugin( ).getPluginPreferences( ) 868 .removePropertyChangeListener( prefListener ); 869 prefListener = null; 870 } 871 if( propPrefListener != null ) { 872 WorkbenchPlugin.getDefault( ).getPreferenceStore( ) 873 .removePropertyChangeListener( propPrefListener ); 874 propPrefListener = null; 875 } 876 if( resourceListener != null ) { 877 ResourcesPlugin.getWorkspace( ).removeResourceChangeListener( 878 resourceListener ); 879 resourceListener = null; 880 } 881 882 showInQuickMenu.dispose( ); 883 newQuickMenu.dispose( ); 884 885 // null out actions to make leak debugging easier 886 closeAction = null; 887 closeAllAction = null; 888 closeAllSavedAction = null; 889 closeOthersAction = null; 890 saveAction = null; 891 saveAllAction = null; 892 newWindowAction = null; 893 newEditorAction = null; 894 helpContentsAction = null; 895 helpSearchAction = null; 896 dynamicHelpAction = null; 897 aboutAction = null; 898 openPreferencesAction = null; 899 saveAsAction = null; 900 hideShowEditorAction = null; 901 savePerspectiveAction = null; 902 resetPerspectiveAction = null; 903 editActionSetAction = null; 904 closePerspAction = null; 905 lockToolBarAction = null; 906 closeAllPerspsAction = null; 907 showViewMenuAction = null; 908 showPartPaneMenuAction = null; 909 nextPartAction = null; 910 prevPartAction = null; 911 nextEditorAction = null; 912 prevEditorAction = null; 913 nextPerspectiveAction = null; 914 prevPerspectiveAction = null; 915 activateEditorAction = null; 916 maximizePartAction = null; 917 minimizePartAction = null; 918 switchToEditorAction = null; 919 quickAccessAction.dispose( ); 920 quickAccessAction = null; 921 backwardHistoryAction = null; 922 forwardHistoryAction = null; 923 undoAction = null; 924 redoAction = null; 925 quitAction = null; 926 goIntoAction = null; 927 backAction = null; 928 forwardAction = null; 929 upAction = null; 930 nextAction = null; 931 previousAction = null; 932 openWorkspaceAction = null; 933 projectPropertyDialogAction = null; 934 newWizardAction = null; 935 newWizardDropDownAction = null; 936 importResourcesAction = null; 937 exportResourcesAction = null; 938 buildAllAction = null; 939 cleanAction = null; 940 toggleAutoBuildAction = null; 941 buildWorkingSetMenu = null; 942 quickStartAction = null; 943 tipsAndTricksAction = null; 944 showInQuickMenu = null; 945 newQuickMenu = null; 946 buildProjectAction = null; 947 newWizardMenu = null; 948 statusLineItem = null; 949 prefListener = null; 950 propPrefListener = null; 951 introAction = null; 952 953 super.dispose( ); 954 } 955 updateModeLine( final String text )956 void updateModeLine( final String text ) 957 { 958 statusLineItem.setText( text ); 959 } 960 961 /** 962 * Returns true if the menu with the given ID should 963 * be considered as an OLE container menu. Container menus 964 * are preserved in OLE menu merging. 965 */ 966 @Override isApplicationMenu( String menuId )967 public boolean isApplicationMenu( String menuId ) 968 { 969 if( menuId.equals( IWorkbenchActionConstants.M_FILE ) ) { 970 return true; 971 } 972 if( menuId.equals( IWorkbenchActionConstants.M_WINDOW ) ) { 973 return true; 974 } 975 return false; 976 } 977 978 /** 979 * Return whether or not given id matches the id of the coolitems that 980 * the workbench creates. 981 */ isWorkbenchCoolItemId( String id )982 public boolean isWorkbenchCoolItemId( String id ) 983 { 984 if( IWorkbenchActionConstants.TOOLBAR_FILE.equalsIgnoreCase( id ) ) { 985 return true; 986 } 987 if( IWorkbenchActionConstants.TOOLBAR_NAVIGATE.equalsIgnoreCase( id ) ) { 988 return true; 989 } 990 return false; 991 } 992 993 /** 994 * Fills the status line with the workbench contribution items. 995 */ 996 @Override fillStatusLine( IStatusLineManager statusLine )997 protected void fillStatusLine( IStatusLineManager statusLine ) 998 { 999 statusLine.add( statusLineItem ); 1000 } 1001 1002 /** 1003 * Creates actions (and contribution items) for the menu bar, toolbar and 1004 * status line. 1005 */ 1006 @Override makeActions( final IWorkbenchWindow window )1007 protected void makeActions( final IWorkbenchWindow window ) 1008 { 1009 // @issue should obtain from ConfigurationItemFactory 1010 statusLineItem = new StatusLineContributionItem( "ModeContributionItem" ); //$NON-NLS-1$ 1011 1012 newWizardAction = ActionFactory.NEW.create( window ); 1013 register( newWizardAction ); 1014 1015 newWizardDropDownAction = IDEActionFactory.NEW_WIZARD_DROP_DOWN 1016 .create( window ); 1017 register( newWizardDropDownAction ); 1018 1019 importResourcesAction = ActionFactory.IMPORT.create( window ); 1020 register( importResourcesAction ); 1021 1022 exportResourcesAction = ActionFactory.EXPORT.create( window ); 1023 register( exportResourcesAction ); 1024 1025 buildAllAction = IDEActionFactory.BUILD.create( window ); 1026 register( buildAllAction ); 1027 1028 cleanAction = IDEActionFactory.BUILD_CLEAN.create( window ); 1029 register( cleanAction ); 1030 1031 toggleAutoBuildAction = IDEActionFactory.BUILD_AUTOMATICALLY 1032 .create( window ); 1033 register( toggleAutoBuildAction ); 1034 1035 saveAction = ActionFactory.SAVE.create( window ); 1036 register( saveAction ); 1037 1038 saveAsAction = ActionFactory.SAVE_AS.create( window ); 1039 register( saveAsAction ); 1040 1041 saveAllAction = ActionFactory.SAVE_ALL.create( window ); 1042 register( saveAllAction ); 1043 1044 newWindowAction = ActionFactory.OPEN_NEW_WINDOW.create( getWindow( ) ); 1045 newWindowAction.setText( IDEWorkbenchMessages.Workbench_openNewWindow ); 1046 register( newWindowAction ); 1047 1048 newEditorAction = ActionFactory.NEW_EDITOR.create( window ); 1049 register( newEditorAction ); 1050 1051 undoAction = ActionFactory.UNDO.create( window ); 1052 register( undoAction ); 1053 1054 redoAction = ActionFactory.REDO.create( window ); 1055 register( redoAction ); 1056 1057 1058 1059 1060 1061 1062 closeAction = ActionFactory.CLOSE.create( window ); 1063 register( closeAction ); 1064 1065 closeAllAction = ActionFactory.CLOSE_ALL.create( window ); 1066 register( closeAllAction ); 1067 1068 closeOthersAction = ActionFactory.CLOSE_OTHERS.create( window ); 1069 register( closeOthersAction ); 1070 1071 closeAllSavedAction = ActionFactory.CLOSE_ALL_SAVED.create( window ); 1072 register( closeAllSavedAction ); 1073 1074 helpContentsAction = ActionFactory.HELP_CONTENTS.create( window ); 1075 register( helpContentsAction ); 1076 1077 helpSearchAction = ActionFactory.HELP_SEARCH.create( window ); 1078 register( helpSearchAction ); 1079 1080 dynamicHelpAction = ActionFactory.DYNAMIC_HELP.create( window ); 1081 register( dynamicHelpAction ); 1082 1083 aboutAction = ActionFactory.ABOUT.create( window ); 1084 aboutAction 1085 .setImageDescriptor( IDEInternalWorkbenchImages 1086 .getImageDescriptor( IDEInternalWorkbenchImages.IMG_OBJS_DEFAULT_PROD ) ); 1087 register( aboutAction ); 1088 1089 openPreferencesAction = ActionFactory.PREFERENCES.create( window ); 1090 register( openPreferencesAction ); 1091 1092 1093 1094 1095 1096 makeFeatureDependentActions( window ); 1097 1098 // Actions for invisible accelerators 1099 showViewMenuAction = ActionFactory.SHOW_VIEW_MENU.create( window ); 1100 register( showViewMenuAction ); 1101 1102 showPartPaneMenuAction = ActionFactory.SHOW_PART_PANE_MENU 1103 .create( window ); 1104 register( showPartPaneMenuAction ); 1105 1106 nextEditorAction = ActionFactory.NEXT_EDITOR.create( window ); 1107 register( nextEditorAction ); 1108 prevEditorAction = ActionFactory.PREVIOUS_EDITOR.create( window ); 1109 register( prevEditorAction ); 1110 ActionFactory.linkCycleActionPair( nextEditorAction, prevEditorAction ); 1111 1112 nextPartAction = ActionFactory.NEXT_PART.create( window ); 1113 register( nextPartAction ); 1114 prevPartAction = ActionFactory.PREVIOUS_PART.create( window ); 1115 register( prevPartAction ); 1116 ActionFactory.linkCycleActionPair( nextPartAction, prevPartAction ); 1117 1118 nextPerspectiveAction = ActionFactory.NEXT_PERSPECTIVE.create( window ); 1119 register( nextPerspectiveAction ); 1120 prevPerspectiveAction = ActionFactory.PREVIOUS_PERSPECTIVE 1121 .create( window ); 1122 register( prevPerspectiveAction ); 1123 ActionFactory.linkCycleActionPair( nextPerspectiveAction, 1124 prevPerspectiveAction ); 1125 1126 activateEditorAction = ActionFactory.ACTIVATE_EDITOR.create( window ); 1127 register( activateEditorAction ); 1128 1129 maximizePartAction = ActionFactory.MAXIMIZE.create( window ); 1130 register( maximizePartAction ); 1131 1132 minimizePartAction = ActionFactory.MINIMIZE.create( window ); 1133 register( minimizePartAction ); 1134 1135 switchToEditorAction = ActionFactory.SHOW_OPEN_EDITORS.create( window ); 1136 register( switchToEditorAction ); 1137 1138 workbookEditorsAction = ActionFactory.SHOW_WORKBOOK_EDITORS 1139 .create( window ); 1140 register( workbookEditorsAction ); 1141 1142 quickAccessAction = ActionFactory.SHOW_QUICK_ACCESS.create( window ); 1143 1144 hideShowEditorAction = ActionFactory.SHOW_EDITOR.create( window ); 1145 register( hideShowEditorAction ); 1146 savePerspectiveAction = ActionFactory.SAVE_PERSPECTIVE.create( window ); 1147 register( savePerspectiveAction ); 1148 editActionSetAction = ActionFactory.EDIT_ACTION_SETS.create( window ); 1149 register( editActionSetAction ); 1150 lockToolBarAction = ActionFactory.LOCK_TOOL_BAR.create( window ); 1151 register( lockToolBarAction ); 1152 resetPerspectiveAction = ActionFactory.RESET_PERSPECTIVE 1153 .create( window ); 1154 register( resetPerspectiveAction ); 1155 closePerspAction = ActionFactory.CLOSE_PERSPECTIVE.create( window ); 1156 register( closePerspAction ); 1157 closeAllPerspsAction = ActionFactory.CLOSE_ALL_PERSPECTIVES 1158 .create( window ); 1159 register( closeAllPerspsAction ); 1160 1161 forwardHistoryAction = ActionFactory.FORWARD_HISTORY.create( window ); 1162 register( forwardHistoryAction ); 1163 1164 backwardHistoryAction = ActionFactory.BACKWARD_HISTORY.create( window ); 1165 register( backwardHistoryAction ); 1166 1167 1168 1169 1170 quitAction = ActionFactory.QUIT.create( window ); 1171 register( quitAction ); 1172 1173 1174 1175 goIntoAction = ActionFactory.GO_INTO.create( window ); 1176 register( goIntoAction ); 1177 1178 backAction = ActionFactory.BACK.create( window ); 1179 register( backAction ); 1180 1181 forwardAction = ActionFactory.FORWARD.create( window ); 1182 register( forwardAction ); 1183 1184 upAction = ActionFactory.UP.create( window ); 1185 register( upAction ); 1186 1187 nextAction = ActionFactory.NEXT.create( window ); 1188 nextAction 1189 .setImageDescriptor( IDEInternalWorkbenchImages 1190 .getImageDescriptor( IDEInternalWorkbenchImages.IMG_ETOOL_NEXT_NAV ) ); 1191 register( nextAction ); 1192 1193 previousAction = ActionFactory.PREVIOUS.create( window ); 1194 previousAction 1195 .setImageDescriptor( IDEInternalWorkbenchImages 1196 .getImageDescriptor( IDEInternalWorkbenchImages.IMG_ETOOL_PREVIOUS_NAV ) ); 1197 register( previousAction ); 1198 1199 buildProjectAction = IDEActionFactory.BUILD_PROJECT.create( window ); 1200 register( buildProjectAction ); 1201 1202 openWorkspaceAction = IDEActionFactory.OPEN_WORKSPACE.create( window ); 1203 register( openWorkspaceAction ); 1204 1205 projectPropertyDialogAction = IDEActionFactory.OPEN_PROJECT_PROPERTIES 1206 .create( window ); 1207 register( projectPropertyDialogAction ); 1208 1209 if( window.getWorkbench( ).getIntroManager( ).hasIntro( ) ) { 1210 introAction = ActionFactory.INTRO.create( window ); 1211 register( introAction ); 1212 } 1213 1214 String showInQuickMenuId = IWorkbenchCommandConstants.NAVIGATE_SHOW_IN_QUICK_MENU; 1215 showInQuickMenu = new QuickMenuAction( showInQuickMenuId ) { 1216 @Override 1217 protected void fillMenu( IMenuManager menu ) 1218 { 1219 menu.add( ContributionItemFactory.VIEWS_SHOW_IN.create( window ) ); 1220 } 1221 }; 1222 register( showInQuickMenu ); 1223 1224 final String newQuickMenuId = "org.eclipse.ui.file.newQuickMenu"; //$NON-NLS-1$ 1225 newQuickMenu = new QuickMenuAction( newQuickMenuId ) { 1226 @Override 1227 protected void fillMenu( IMenuManager menu ) 1228 { 1229 menu.add( new NewWizardMenu( window ) ); 1230 } 1231 }; 1232 register( newQuickMenu ); 1233 1234 } 1235 1236 /** 1237 * Creates the feature-dependent actions for the menu bar. 1238 */ makeFeatureDependentActions( IWorkbenchWindow window )1239 private void makeFeatureDependentActions( IWorkbenchWindow window ) 1240 { 1241 AboutInfo[] infos = null; 1242 1243 IPreferenceStore prefs = IDEWorkbenchPlugin.getDefault( ) 1244 .getPreferenceStore( ); 1245 1246 // Optimization: avoid obtaining the about infos if the platform state 1247 // is 1248 // unchanged from last time. See bug 75130 for details. 1249 String stateKey = "platformState"; //$NON-NLS-1$ 1250 String prevState = prefs.getString( stateKey ); 1251 String currentState = String.valueOf( Platform.getStateStamp( ) ); 1252 boolean sameState = currentState.equals( prevState ); 1253 if( ! sameState ) { 1254 prefs.putValue( stateKey, currentState ); 1255 } 1256 1257 // See if a welcome page is specified. 1258 // Optimization: if welcome pages were found on a previous run, then 1259 // just add the action. 1260 String quickStartKey = IDEActionFactory.QUICK_START.getId( ); 1261 String showQuickStart = prefs.getString( quickStartKey ); 1262 if( sameState && "true".equals( showQuickStart ) ) { //$NON-NLS-1$ 1263 quickStartAction = IDEActionFactory.QUICK_START.create( window ); 1264 register( quickStartAction ); 1265 } 1266 else if( sameState && "false".equals( showQuickStart ) ) { //$NON-NLS-1$ 1267 // do nothing 1268 } 1269 else { 1270 // do the work 1271 infos = IDEWorkbenchPlugin.getDefault( ).getFeatureInfos( ); 1272 boolean found = hasWelcomePage( infos ); 1273 prefs.setValue( quickStartKey, String.valueOf( found ) ); 1274 if( found ) { 1275 quickStartAction = IDEActionFactory.QUICK_START.create( window ); 1276 register( quickStartAction ); 1277 } 1278 } 1279 1280 // See if a tips and tricks page is specified. 1281 // Optimization: if tips and tricks were found on a previous run, then 1282 // just add the action. 1283 String tipsAndTricksKey = IDEActionFactory.TIPS_AND_TRICKS.getId( ); 1284 String showTipsAndTricks = prefs.getString( tipsAndTricksKey ); 1285 if( sameState && "true".equals( showTipsAndTricks ) ) { //$NON-NLS-1$ 1286 tipsAndTricksAction = IDEActionFactory.TIPS_AND_TRICKS 1287 .create( window ); 1288 register( tipsAndTricksAction ); 1289 } 1290 else if( sameState && "false".equals( showTipsAndTricks ) ) { //$NON-NLS-1$ 1291 // do nothing 1292 } 1293 else { 1294 // do the work 1295 if( infos == null ) { 1296 infos = IDEWorkbenchPlugin.getDefault( ).getFeatureInfos( ); 1297 } 1298 boolean found = hasTipsAndTricks( infos ); 1299 prefs.setValue( tipsAndTricksKey, String.valueOf( found ) ); 1300 if( found ) { 1301 tipsAndTricksAction = IDEActionFactory.TIPS_AND_TRICKS 1302 .create( window ); 1303 register( tipsAndTricksAction ); 1304 } 1305 } 1306 } 1307 1308 /** 1309 * Returns whether any of the given infos have a welcome page. 1310 * 1311 * @param infos 1312 * the infos 1313 * @return <code>true</code> if a welcome page was found, <code>false</code> 1314 * if not 1315 */ hasWelcomePage( AboutInfo[] infos )1316 private boolean hasWelcomePage( AboutInfo[] infos ) 1317 { 1318 for( int i = 0; i < infos.length; i++ ) { 1319 if( infos[i].getWelcomePageURL( ) != null ) { 1320 return true; 1321 } 1322 } 1323 return false; 1324 } 1325 1326 /** 1327 * Returns whether any of the given infos have tips and tricks. 1328 * 1329 * @param infos 1330 * the infos 1331 * @return <code>true</code> if tips and tricks were found, 1332 * <code>false</code> if not 1333 */ hasTipsAndTricks( AboutInfo[] infos )1334 private boolean hasTipsAndTricks( AboutInfo[] infos ) 1335 { 1336 for( int i = 0; i < infos.length; i++ ) { 1337 if( infos[i].getTipsAndTricksHref( ) != null ) { 1338 return true; 1339 } 1340 } 1341 return false; 1342 } 1343 1344 /** 1345 * Update the build actions on the toolbar and menu bar based on the current 1346 * state of autobuild. This method can be called from any thread. 1347 * 1348 * @param immediately 1349 * <code>true</code> to update the actions immediately, 1350 * <code>false</code> to queue the update to be run in the 1351 * event loop 1352 */ updateBuildActions( boolean immediately )1353 void updateBuildActions( boolean immediately ) 1354 { 1355 // this can be triggered by property or resource change notifications 1356 Runnable update = new Runnable( ) { 1357 public void run( ) 1358 { 1359 if( isDisposed ) { 1360 return; 1361 } 1362 IWorkspace workspace = ResourcesPlugin.getWorkspace( ); 1363 IProject[] projects = workspace.getRoot( ).getProjects( ); 1364 boolean enabled = BuildUtilities.isEnabled( projects, 1365 IncrementalProjectBuilder.INCREMENTAL_BUILD ); 1366 // update menu bar actions in project menu 1367 updateCommandEnablement( buildAllAction.getActionDefinitionId( ) ); 1368 buildProjectAction.setEnabled( enabled ); 1369 toggleAutoBuildAction.setChecked( workspace.isAutoBuilding( ) ); 1370 cleanAction.setEnabled( BuildUtilities.isEnabled( projects, 1371 IncrementalProjectBuilder.CLEAN_BUILD ) ); 1372 1373 // update the cool bar build button 1374 ICoolBarManager coolBarManager = getActionBarConfigurer( ) 1375 .getCoolBarManager( ); 1376 IContributionItem cbItem = coolBarManager 1377 .find( IWorkbenchActionConstants.TOOLBAR_FILE ); 1378 if( ! ( cbItem instanceof IToolBarContributionItem ) ) { 1379 // This should not happen 1380 IDEWorkbenchPlugin 1381 .log( "File toolbar contribution item is missing" ); //$NON-NLS-1$ 1382 return; 1383 } 1384 IToolBarContributionItem toolBarItem = ( IToolBarContributionItem ) cbItem; 1385 IToolBarManager toolBarManager = toolBarItem 1386 .getToolBarManager( ); 1387 if( toolBarManager == null ) { 1388 // error if this happens, file toolbar assumed to always 1389 // exist 1390 IDEWorkbenchPlugin.log( "File toolbar is missing" ); //$NON-NLS-1$ 1391 return; 1392 } 1393 // add the build button if build actions are enabled, and remove 1394 // it otherwise 1395 boolean found = toolBarManager.find( buildAllAction.getId( ) ) != null; 1396 if( enabled && ! found ) { 1397 toolBarManager.appendToGroup( 1398 IWorkbenchActionConstants.BUILD_GROUP, 1399 buildAllAction ); 1400 toolBarManager.update( false ); 1401 toolBarItem.update( ICoolBarManager.SIZE ); 1402 } 1403 else if( buildAllAction != null && found && ! enabled ) { 1404 toolBarManager.remove( buildAllAction.getId( ) ); 1405 toolBarManager.update( false ); 1406 toolBarItem.update( ICoolBarManager.SIZE ); 1407 } 1408 } 1409 1410 private void updateCommandEnablement( String commandId ) 1411 { 1412 IHandlerService handlerService = ( IHandlerService ) window 1413 .getService( IHandlerService.class ); 1414 ICommandService commandService = ( ICommandService ) window 1415 .getService( ICommandService.class ); 1416 if( handlerService != null && commandService != null ) { 1417 Command buildAllCmd = commandService.getCommand( commandId ); 1418 buildAllCmd.setEnabled( handlerService.getCurrentState( ) ); 1419 } 1420 } 1421 }; 1422 if( immediately ) { 1423 update.run( ); 1424 } 1425 else { 1426 // Dispatch the update to be run later in the UI thread. 1427 // This helps to reduce flicker if autobuild is being temporarily 1428 // disabled programmatically. 1429 Shell shell = window.getShell( ); 1430 if( shell != null && ! shell.isDisposed( ) ) { 1431 shell.getDisplay( ).asyncExec( update ); 1432 } 1433 } 1434 } 1435 1436 /** 1437 * Update the pin action's tool bar 1438 */ updatePinActionToolbar( )1439 void updatePinActionToolbar( ) 1440 { 1441 1442 ICoolBarManager coolBarManager = getActionBarConfigurer( ) 1443 .getCoolBarManager( ); 1444 IContributionItem cbItem = coolBarManager 1445 .find( IWorkbenchActionConstants.TOOLBAR_NAVIGATE ); 1446 if( ! ( cbItem instanceof IToolBarContributionItem ) ) { 1447 // This should not happen 1448 IDEWorkbenchPlugin 1449 .log( "Navigation toolbar contribution item is missing" ); //$NON-NLS-1$ 1450 return; 1451 } 1452 IToolBarContributionItem toolBarItem = ( IToolBarContributionItem ) cbItem; 1453 IToolBarManager toolBarManager = toolBarItem.getToolBarManager( ); 1454 if( toolBarManager == null ) { 1455 // error if this happens, navigation toolbar assumed to always exist 1456 IDEWorkbenchPlugin.log( "Navigate toolbar is missing" ); //$NON-NLS-1$ 1457 return; 1458 } 1459 1460 toolBarManager.update( false ); 1461 toolBarItem.update( ICoolBarManager.SIZE ); 1462 } 1463 getPinEditorItem( )1464 private IContributionItem getPinEditorItem( ) 1465 { 1466 return ContributionItemFactory.PIN_EDITOR.create( window ); 1467 } 1468 getCutItem( )1469 private IContributionItem getCutItem( ) 1470 { 1471 return getItem( ActionFactory.CUT.getId( ), 1472 ActionFactory.CUT.getCommandId( ), ISharedImages.IMG_TOOL_CUT, 1473 ISharedImages.IMG_TOOL_CUT_DISABLED, 1474 WorkbenchMessages.Workbench_cut, 1475 WorkbenchMessages.Workbench_cutToolTip, null ); 1476 } 1477 getCopyItem( )1478 private IContributionItem getCopyItem( ) 1479 { 1480 return getItem( ActionFactory.COPY.getId( ), 1481 ActionFactory.COPY.getCommandId( ), 1482 ISharedImages.IMG_TOOL_COPY, 1483 ISharedImages.IMG_TOOL_COPY_DISABLED, 1484 WorkbenchMessages.Workbench_copy, 1485 WorkbenchMessages.Workbench_copyToolTip, null ); 1486 } 1487 getPasteItem( )1488 private IContributionItem getPasteItem( ) 1489 { 1490 return getItem( ActionFactory.PASTE.getId( ), 1491 ActionFactory.PASTE.getCommandId( ), 1492 ISharedImages.IMG_TOOL_PASTE, 1493 ISharedImages.IMG_TOOL_PASTE_DISABLED, 1494 WorkbenchMessages.Workbench_paste, 1495 WorkbenchMessages.Workbench_pasteToolTip, null ); 1496 } 1497 getPrintItem( )1498 private IContributionItem getPrintItem( ) 1499 { 1500 return getItem( ActionFactory.PRINT.getId( ), 1501 ActionFactory.PRINT.getCommandId( ), 1502 ISharedImages.IMG_ETOOL_PRINT_EDIT, 1503 ISharedImages.IMG_ETOOL_PRINT_EDIT_DISABLED, 1504 WorkbenchMessages.Workbench_print, 1505 WorkbenchMessages.Workbench_printToolTip, null ); 1506 } 1507 getSelectAllItem( )1508 private IContributionItem getSelectAllItem( ) 1509 { 1510 return getItem( ActionFactory.SELECT_ALL.getId( ), 1511 ActionFactory.SELECT_ALL.getCommandId( ), null, null, 1512 WorkbenchMessages.Workbench_selectAll, 1513 WorkbenchMessages.Workbench_selectAllToolTip, null ); 1514 } 1515 getFindItem( )1516 private IContributionItem getFindItem( ) 1517 { 1518 return getItem( ActionFactory.FIND.getId( ), 1519 ActionFactory.FIND.getCommandId( ), null, null, 1520 WorkbenchMessages.Workbench_findReplace, 1521 WorkbenchMessages.Workbench_findReplaceToolTip, null ); 1522 } 1523 getBookmarkItem( )1524 private IContributionItem getBookmarkItem( ) 1525 { 1526 return getItem( IDEActionFactory.BOOKMARK.getId( ), 1527 IDEActionFactory.BOOKMARK.getCommandId( ), null, null, 1528 IDEWorkbenchMessages.Workbench_addBookmark, 1529 IDEWorkbenchMessages.Workbench_addBookmarkToolTip, null ); 1530 } 1531 getTaskItem( )1532 private IContributionItem getTaskItem( ) 1533 { 1534 return getItem( IDEActionFactory.ADD_TASK.getId( ), 1535 IDEActionFactory.ADD_TASK.getCommandId( ), null, null, 1536 IDEWorkbenchMessages.Workbench_addTask, 1537 IDEWorkbenchMessages.Workbench_addTaskToolTip, null ); 1538 } 1539 getDeleteItem( )1540 private IContributionItem getDeleteItem( ) 1541 { 1542 return getItem( ActionFactory.DELETE.getId( ), 1543 ActionFactory.DELETE.getCommandId( ), 1544 ISharedImages.IMG_TOOL_DELETE, 1545 ISharedImages.IMG_TOOL_DELETE_DISABLED, 1546 WorkbenchMessages.Workbench_delete, 1547 WorkbenchMessages.Workbench_deleteToolTip, 1548 IWorkbenchHelpContextIds.DELETE_RETARGET_ACTION ); 1549 } 1550 getRevertItem( )1551 private IContributionItem getRevertItem( ) 1552 { 1553 return getItem( ActionFactory.REVERT.getId( ), 1554 ActionFactory.REVERT.getCommandId( ), null, null, 1555 WorkbenchMessages.Workbench_revert, 1556 WorkbenchMessages.Workbench_revertToolTip, null ); 1557 } 1558 getRefreshItem( )1559 private IContributionItem getRefreshItem( ) 1560 { 1561 return getItem( ActionFactory.REFRESH.getId( ), 1562 ActionFactory.REFRESH.getCommandId( ), null, null, 1563 WorkbenchMessages.Workbench_refresh, 1564 WorkbenchMessages.Workbench_refreshToolTip, null ); 1565 } 1566 getPropertiesItem( )1567 private IContributionItem getPropertiesItem( ) 1568 { 1569 return getItem( ActionFactory.PROPERTIES.getId( ), 1570 ActionFactory.PROPERTIES.getCommandId( ), null, null, 1571 WorkbenchMessages.Workbench_properties, 1572 WorkbenchMessages.Workbench_propertiesToolTip, null ); 1573 } 1574 getMoveItem( )1575 private IContributionItem getMoveItem( ) 1576 { 1577 return getItem( ActionFactory.MOVE.getId( ), 1578 ActionFactory.MOVE.getCommandId( ), null, null, 1579 WorkbenchMessages.Workbench_move, 1580 WorkbenchMessages.Workbench_moveToolTip, null ); 1581 } 1582 getRenameItem( )1583 private IContributionItem getRenameItem( ) 1584 { 1585 return getItem( ActionFactory.RENAME.getId( ), 1586 ActionFactory.RENAME.getCommandId( ), null, null, 1587 WorkbenchMessages.Workbench_rename, 1588 WorkbenchMessages.Workbench_renameToolTip, null ); 1589 } 1590 getOpenProjectItem( )1591 private IContributionItem getOpenProjectItem( ) 1592 { 1593 return getItem( IDEActionFactory.OPEN_PROJECT.getId( ), 1594 IDEActionFactory.OPEN_PROJECT.getCommandId( ), null, null, 1595 IDEWorkbenchMessages.OpenResourceAction_text, 1596 IDEWorkbenchMessages.OpenResourceAction_toolTip, null ); 1597 } 1598 getCloseProjectItem( )1599 private IContributionItem getCloseProjectItem( ) 1600 { 1601 return getItem( IDEActionFactory.CLOSE_PROJECT.getId( ), 1602 IDEActionFactory.CLOSE_PROJECT.getCommandId( ), null, null, 1603 IDEWorkbenchMessages.CloseResourceAction_text, 1604 IDEWorkbenchMessages.CloseResourceAction_text, null ); 1605 } 1606 getItem( String actionId, String commandId, String image, String disabledImage, String label, String tooltip, String helpContextId )1607 private IContributionItem getItem( String actionId, String commandId, 1608 String image, String disabledImage, String label, String tooltip, 1609 String helpContextId ) 1610 { 1611 ISharedImages sharedImages = getWindow( ).getWorkbench( ) 1612 .getSharedImages( ); 1613 1614 IActionCommandMappingService acms = ( IActionCommandMappingService ) getWindow( ) 1615 .getService( IActionCommandMappingService.class ); 1616 acms.map( actionId, commandId ); 1617 1618 CommandContributionItemParameter commandParm = new CommandContributionItemParameter( 1619 getWindow( ), actionId, commandId, null, 1620 sharedImages.getImageDescriptor( image ), 1621 sharedImages.getImageDescriptor( disabledImage ), null, label, 1622 null, tooltip, CommandContributionItem.STYLE_PUSH, null, false ); 1623 return new CommandContributionItem( commandParm ); 1624 } 1625 } 1626