#P org.eclipse.ui.workbench
Index: Eclipse UI/org/eclipse/ui/contexts/IContextService.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/contexts/IContextService.java,v
retrieving revision 1.23
diff -u -r1.23 IContextService.java
--- Eclipse UI/org/eclipse/ui/contexts/IContextService.java 7 Nov 2008 17:46:46 -0000 1.23
+++ Eclipse UI/org/eclipse/ui/contexts/IContextService.java 2 Nov 2010 08:05:55 -0000
@@ -11,7 +11,6 @@
package org.eclipse.ui.contexts;
import java.util.Collection;
-
import org.eclipse.core.commands.contexts.Context;
import org.eclipse.core.commands.contexts.IContextManagerListener;
import org.eclipse.core.expressions.Expression;
@@ -40,6 +39,14 @@
public interface IContextService extends IServiceWithSources {
/**
+ * The identifier for the context that is active when a workbench is active.
+ *
+ * @since 3.7
+ *
+ */
+ public static final String CONTEXT_ID_WORKBENCH = "org.eclipse.ui.contexts.workbench"; //$NON-NLS-1$
+
+ /**
* The identifier for the context that is active when a shell registered as
* a dialog.
*/
Index: Eclipse UI/org/eclipse/ui/internal/ApplicationMenuManager.java
===================================================================
RCS file: Eclipse UI/org/eclipse/ui/internal/ApplicationMenuManager.java
diff -N Eclipse UI/org/eclipse/ui/internal/ApplicationMenuManager.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Eclipse UI/org/eclipse/ui/internal/ApplicationMenuManager.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.ui.internal;
+
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.swt.widgets.Decorations;
+import org.eclipse.swt.widgets.Item;
+import org.eclipse.swt.widgets.Menu;
+
+/**
+ * @since 3.7
+ *
+ */
+class ApplicationMenuManager extends MenuManager{
+
+ private final Menu appMenu;
+ private boolean disposing;
+
+ public ApplicationMenuManager(Menu appMenu) {
+ this.appMenu = appMenu;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.MenuManager#createMenuBar(org.eclipse.swt.widgets.Decorations)
+ */
+ public Menu createMenuBar(Decorations parent) {
+ return appMenu;
+ }
+
+ protected boolean menuExist() {
+ // our menu always exist,
+ // except disposing - if not dispose will be called on this menu
+ return !disposing;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.MenuManager#getMenuItemCount()
+ */
+ protected int getMenuItemCount() {
+ return appMenu.getItemCount();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.MenuManager#getMenuItem(int)
+ */
+ protected Item getMenuItem(int index) {
+ return appMenu.getItem(index);
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.MenuManager#getMenuItems()
+ */
+ protected Item[] getMenuItems() {
+ return appMenu.getItems();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.MenuManager#doItemFill(org.eclipse.jface.action.IContributionItem, int)
+ */
+ protected void doItemFill(IContributionItem ci, int index) {
+ ci.fill(appMenu, index);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.MenuManager#dispose()
+ */
+ public void dispose() {
+ disposing = true;
+ super.dispose();
+ disposing = false;
+ }
+}
+
Index: Eclipse UI/org/eclipse/ui/internal/Workbench.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java,v
retrieving revision 1.483
diff -u -r1.483 Workbench.java
--- Eclipse UI/org/eclipse/ui/internal/Workbench.java 18 May 2010 16:50:11 -0000 1.483
+++ Eclipse UI/org/eclipse/ui/internal/Workbench.java 2 Nov 2010 08:05:59 -0000
@@ -95,6 +95,7 @@
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TaskBar;
import org.eclipse.swt.widgets.TaskItem;
@@ -131,6 +132,7 @@
import org.eclipse.ui.commands.ICommandImageService;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.commands.IWorkbenchCommandSupport;
+import org.eclipse.ui.contexts.IContextActivation;
import org.eclipse.ui.contexts.IContextService;
import org.eclipse.ui.contexts.IWorkbenchContextSupport;
import org.eclipse.ui.handlers.IHandlerService;
@@ -188,6 +190,7 @@
import org.eclipse.ui.intro.IIntroManager;
import org.eclipse.ui.keys.IBindingService;
import org.eclipse.ui.menus.IMenuService;
+import org.eclipse.ui.menus.MenuUtil;
import org.eclipse.ui.model.IContributionService;
import org.eclipse.ui.operations.IWorkbenchOperationSupport;
import org.eclipse.ui.progress.IProgressService;
@@ -1553,6 +1556,29 @@
}
});
+ StartupThreading.runWithoutExceptions(new StartupRunnable() {
+
+ public void runWithException() {
+
+ activateWorkbenchContext();
+
+ }
+ });
+
+ StartupThreading.runWithoutExceptions(new StartupRunnable() {
+
+ public void runWithException() {
+
+ Menu appMenu = getAppMenu();
+ if (appMenu == null)
+ return;
+
+ createApplicationMenu(appMenu);
+ }
+ });
+
+
+
// attempt to restore a previous workbench state
try {
UIStats.start(UIStats.RESTORE_WORKBENCH, "Workbench"); //$NON-NLS-1$
@@ -2121,8 +2147,8 @@
super.handleException(e);
}
});
- // ensure at least one window was opened
- if (result[0].isOK() && windowManager.getWindows().length == 0) {
+ // ensure at least one window was opened, only when appMenu isn't there
+ if (shouldReturnNoWindowError(result[0])) {
String msg = WorkbenchMessages.Workbench_noWindowsRestored;
result[0] = new Status(IStatus.ERROR, WorkbenchPlugin.PI_WORKBENCH,
IWorkbenchConfigurer.RESTORE_CODE_RESET, msg, null);
@@ -2130,6 +2156,23 @@
return result[0];
}
+ private boolean shouldReturnNoWindowError(final IStatus result) {
+
+ final boolean[] shouldReturn = new boolean[1];
+ // first check for the result & no of windows
+ shouldReturn[0] = result.isOK() && windowManager.getWindows().length == 0;
+ if (shouldReturn[0]) {
+ // if result is ok and there is no window, check for appMenu
+ display.syncExec(new Runnable() {
+ public void run() {
+ // return error if there is no appMenu
+ shouldReturn[0] = display.getAppMenuBar() == null;
+ }
+ });
+ }
+ return shouldReturn[0];
+ }
+
/*
* (non-Javadoc) Method declared on IWorkbench.
*/
@@ -2977,6 +3020,10 @@
((GrabFocus) Tweaklets.get(GrabFocus.KEY)).dispose();
+ deactivateWorkbenchContext();
+
+ applicationMenuMgr.dispose();
+
// Bring down all of the services.
serviceLocator.dispose();
@@ -2998,6 +3045,7 @@
}
}
+
/**
* Cancels the early startup job, if it's still running.
*/
@@ -3700,6 +3748,9 @@
*/
private MenuSourceProvider menuSourceProvider;
+ private IContextActivation workbenchContext;
+
+ private ApplicationMenuManager applicationMenuMgr;
/**
@@ -3807,4 +3858,30 @@
};
}
+ private void createApplicationMenu(Menu appMenu) {
+
+ applicationMenuMgr = new ApplicationMenuManager(appMenu);
+ IMenuService menuService = (IMenuService) serviceLocator.getService(IMenuService.class);
+ menuService.populateContributionManager(applicationMenuMgr, MenuUtil.APPLICATION_MENU);
+ applicationMenuMgr.update(true);
+ }
+
+ private void activateWorkbenchContext() {
+ IContextService contextService = (IContextService) serviceLocator
+ .getService(IContextService.class);
+ workbenchContext = contextService.activateContext(IContextService.CONTEXT_ID_WORKBENCH);
+ }
+
+ private void deactivateWorkbenchContext() {
+ if(workbenchContext == null)
+ return;
+ workbenchContext.getContextService().deactivateContext(workbenchContext);
+ }
+
+
+ private Menu getAppMenu() {
+ IWorkbench workbench = getWorkbenchConfigurer().getWorkbench();
+ return workbench.getDisplay().getAppMenuBar();
+ }
+
}
Index: Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java,v
retrieving revision 1.419
diff -u -r1.419 WorkbenchWindow.java
--- Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java 30 Sep 2010 07:56:23 -0000 1.419
+++ Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java 2 Nov 2010 08:06:00 -0000
@@ -722,17 +722,8 @@
updateDisabled = true;
try {
- // Only do the check if it is OK to close if we are not closing
- // via the workbench as the workbench will check this itself.
Workbench workbench = getWorkbenchImpl();
- int count = workbench.getWorkbenchWindowCount();
- // also check for starting - if the first window dies on startup
- // then we'll need to open a default window.
- if (!workbench.isStarting()
- && !workbench.isClosing()
- && count <= 1
- && workbench.getWorkbenchConfigurer()
- .getExitOnLastWindowClose()) {
+ if (shouldCloseWorkbench(workbench)) {
windowClosed = workbench.close();
} else {
if (okToClose()) {
@@ -755,6 +746,38 @@
}
/**
+ *
+ * Checks and returns whether we should close the workbench when closing
+ * this window
+ *
+ * @param workbench
+ * @return true
, if the workbench needs to be closed,
+ * false
otherwise
+ */
+ private boolean shouldCloseWorkbench(Workbench workbench) {
+
+ // also check for starting - if the first window dies on startup
+ // then we'll need to open a default window.
+
+ if (workbench.isStarting())
+ return false;
+
+ // Only do the check if it is OK to close if we are not closing
+ // via the workbench as the workbench will check this itself.
+ if (workbench.isClosing())
+ return false;
+
+ int count = workbench.getWorkbenchWindowCount();
+
+ // we have more windows apart from this. Dont' close workbench
+ if(count >1 )
+ return false;
+
+ // now do whatever the workbenchconfigurer says ...
+ return workbench.getWorkbenchConfigurer().getExitOnLastWindowClose();
+ }
+
+ /**
* Opens a new page. Assumes that busy cursor is active.
*
* Note: Since release 2.0, a window is limited to contain at most
Index: Eclipse UI/org/eclipse/ui/menus/MenuUtil.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/menus/MenuUtil.java,v
retrieving revision 1.9
diff -u -r1.9 MenuUtil.java
--- Eclipse UI/org/eclipse/ui/menus/MenuUtil.java 1 Jun 2010 19:22:34 -0000 1.9
+++ Eclipse UI/org/eclipse/ui/menus/MenuUtil.java 2 Nov 2010 08:06:00 -0000
@@ -19,6 +19,14 @@
* @noinstantiate This class is not intended to be instantiated by clients.
*/
public class MenuUtil {
+ /**
+ *
+ * Application Menu
+ *
+ * @since 3.7
+ *
+ * */
+ public final static String APPLICATION_MENU = "menu:org.eclipse.ui.application.menu"; //$NON-NLS-1$
/** Main Menu */
public final static String MAIN_MENU = "menu:org.eclipse.ui.main.menu"; //$NON-NLS-1$
/** Main ToolBar (CoolBar) */