diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionMessages.properties index 39ff2f61bf1..80978415d00 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionMessages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionMessages.properties @@ -122,3 +122,7 @@ DeleteResConfigsAction.1=Delete resource configurations ExcludeFromBuildAction.0=Exclude object(s) from build in the following configurations ExcludeFromBuildAction.1=Exclude from build + +BuildActiveConfigMenuAction_defaultTooltip=Build the active configurations of selected projects +BuildActiveConfigMenuAction_buildConfigTooltip =Build ''{0}'' for project ''{1}'' + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/BuildActiveConfigMenuAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/BuildActiveConfigMenuAction.java index 7df97dc3345..48849ce5dc1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/BuildActiveConfigMenuAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/BuildActiveConfigMenuAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 Nokia and others. + * Copyright (c) 2007, 2008 Nokia 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 @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.cdt.ui.actions; +import java.util.Iterator; + +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IncrementalProjectBuilder; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; @@ -22,6 +25,14 @@ import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowPulldownDelegate2; import org.eclipse.ui.actions.BuildAction; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.settings.model.CProjectDescriptionEvent; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescriptionListener; +import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager; + +import org.eclipse.cdt.internal.ui.actions.ActionMessages; + /** * Implements a toolbar button that builds the active configuration * of selected projects. Also includes a menu that builds any of the @@ -29,9 +40,10 @@ import org.eclipse.ui.actions.BuildAction; * */ public class BuildActiveConfigMenuAction extends ChangeBuildConfigActionBase - implements IWorkbenchWindowPulldownDelegate2 { + implements IWorkbenchWindowPulldownDelegate2, ICProjectDescriptionListener { private BuildAction buildaction; + private IAction actionMenuCache; // cache the menu action so we can update the tool tip when the configuration changes /** * @see org.eclipse.ui.IWorkbenchWindowPulldownDelegate2#getMenu(org.eclipse.swt.widgets.Menu) @@ -55,14 +67,17 @@ public class BuildActiveConfigMenuAction extends ChangeBuildConfigActionBase * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() */ public void dispose() { - // do nothing + ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); + mngr.removeCProjectDescriptionListener(this); } /** * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) */ public void init(IWorkbenchWindow window) { - buildaction = new BuildAction(window.getShell(), IncrementalProjectBuilder.INCREMENTAL_BUILD); + buildaction = new BuildAction(window, IncrementalProjectBuilder.INCREMENTAL_BUILD); + ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager(); + mngr.addCProjectDescriptionListener(this, CProjectDescriptionEvent.DATA_APPLIED); } /** @@ -77,11 +92,15 @@ public class BuildActiveConfigMenuAction extends ChangeBuildConfigActionBase * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) */ public void selectionChanged(IAction action, ISelection selection) { + if (actionMenuCache == null){ + actionMenuCache = action; + } onSelectionChanged(action, selection); + updateBuildConfigMenuToolTip(action); } /** - * Adds a listener to the given menu to repopulate it each time is is shown + * Adds a listener to the given menu to re-populate it each time is is shown * @param menu The menu to add listener to */ private void addMenuListener(Menu menu) { @@ -95,5 +114,32 @@ public class BuildActiveConfigMenuAction extends ChangeBuildConfigActionBase protected IAction makeAction(String sName, StringBuffer builder, int accel) { return new BuildConfigAction(fProjects, sName, builder.toString(), accel + 1, buildaction); } + + /** + * Update the tool tip based on the currently selected project and active configuration. + * @param action - The build configuration menu to change the tool tip on + */ + public void updateBuildConfigMenuToolTip(IAction action){ + String toolTipText = ActionMessages.getString("BuildActiveConfigMenuAction_defaultTooltip"); //$NON-NLS-1$ + if (fProjects.size() == 1) { + Iterator projIter = fProjects.iterator(); + IProject prj = (IProject)projIter.next(); + if (prj != null){ + ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(prj, false); + if (prjd != null) { + toolTipText = ActionMessages.getFormattedString( + "BuildActiveConfigMenuAction_buildConfigTooltip", //$NON-NLS-1$ + new Object[] { prjd.getActiveConfiguration().getName(), prj.getName() }); + } + } + } + action.setToolTipText(toolTipText); + } + + public void handleEvent(CProjectDescriptionEvent event) { + if (actionMenuCache != null){ + updateBuildConfigMenuToolTip(actionMenuCache); + } + } }