Bug 156516 Incorrect popuptext in debug icon
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java index 8fed20f..453d38d 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java
@@ -316,26 +316,37 @@ */ protected void fireLaunchHistoryChanged() { Iterator iterator = fLaunchHistoryChangedListeners.iterator(); + ILaunchHistoryChangedListener listener = null; while (iterator.hasNext()) { - ILaunchHistoryChangedListener listener = (ILaunchHistoryChangedListener) iterator.next(); + listener = (ILaunchHistoryChangedListener) iterator.next(); listener.launchHistoryChanged(); } } + /** + * Returns the history listing as XML + * @return the history loisting as XML + * @throws CoreException + * @throws ParserConfigurationException + * @throws TransformerException + * @throws IOException + */ protected String getHistoryAsXML() throws CoreException, ParserConfigurationException, TransformerException, IOException { Document doc = DebugUIPlugin.getDocument(); Element historyRootElement = doc.createElement(HISTORY_ROOT_NODE); doc.appendChild(historyRootElement); Iterator histories = fLaunchHistories.values().iterator(); + LaunchHistory history = null; + Element last = null; while (histories.hasNext()) { - LaunchHistory history = (LaunchHistory)histories.next(); + history = (LaunchHistory)histories.next(); createEntry(doc, historyRootElement, history.getLaunchGroup().getMode(), history.getHistory()); createEntry(doc, historyRootElement, history.getLaunchGroup().getMode(), history.getFavorites()); ILaunchConfiguration configuration = history.getRecentLaunch(); if (configuration != null) { if(configuration.exists()) { - Element last = doc.createElement(HISTORY_LAST_LAUNCH_NODE); + last = doc.createElement(HISTORY_LAST_LAUNCH_NODE); last.setAttribute(HISTORY_MEMENTO_ATT, configuration.getMemento()); last.setAttribute(HISTORY_MODE_ATT, history.getLaunchGroup().getMode()); historyRootElement.appendChild(last); @@ -346,6 +357,14 @@ return DebugUIPlugin.serializeDocument(doc); } + /** + * Creates a new launch history element and adds it to the specified <code>Document</code> + * @param doc the <code>Document</code> to add the new element to + * @param historyRootElement the root element + * @param mode the modes the history element should apply to + * @param configurations the configurations to create entries for + * @throws CoreException + */ protected void createEntry(Document doc, Element historyRootElement, String mode, ILaunchConfiguration[] configurations) throws CoreException { for (int i = 0; i < configurations.length; i++) { ILaunchConfiguration configuration = configurations[i]; @@ -358,6 +377,10 @@ } } + /** + * Returns the path to the local file for the launch history + * @return the file path for the launch history file + */ protected IPath getHistoryFilePath() { return DebugUIPlugin.getDefault().getStateLocation().append(LAUNCH_CONFIGURATION_HISTORY_FILENAME); } @@ -431,11 +454,13 @@ LaunchHistory[] histories = (LaunchHistory[])l.toArray(new LaunchHistory[l.size()]); NodeList list = rootHistoryElement.getChildNodes(); int length = list.getLength(); + Node node = null; + Element entry = null; for (int i = 0; i < length; ++i) { - Node node = list.item(i); + node = list.item(i); short type = node.getNodeType(); if (type == Node.ELEMENT_NODE) { - Element entry = (Element) node; + entry = (Element) node; if (entry.getNodeName().equalsIgnoreCase(HISTORY_LAUNCH_NODE)) { createHistoryElement(entry, histories); } else if (entry.getNodeName().equalsIgnoreCase(HISTORY_LAST_LAUNCH_NODE)) { @@ -455,8 +480,9 @@ try { ILaunchConfiguration launchConfig = DebugPlugin.getDefault().getLaunchManager().getLaunchConfiguration(memento); if (launchConfig.exists()) { + LaunchHistory history = null; for (int i = 0; i < histories.length; i++) { - LaunchHistory history = histories[i]; + history = histories[i]; if (history.accepts(launchConfig) && history.getLaunchGroup().getMode().equals(mode)) { history.addHistory(launchConfig, false); } @@ -477,8 +503,9 @@ try { ILaunchConfiguration launchConfig = DebugPlugin.getDefault().getLaunchManager().getLaunchConfiguration(memento); if (launchConfig.exists()) { + LaunchHistory history = null; for (int i = 0; i < histories.length; i++) { - LaunchHistory history = histories[i]; + history = histories[i]; if (history.accepts(launchConfig) && history.getLaunchGroup().getMode().equals(mode)) { history.setRecentLaunch(launchConfig); } @@ -503,8 +530,7 @@ // Load the configuration elements into a Map fLaunchShortcuts = new ArrayList(infos.length); for (int i = 0; i < infos.length; i++) { - LaunchShortcutExtension ext = new LaunchShortcutExtension(infos[i]); - fLaunchShortcuts.add(ext); + fLaunchShortcuts.add(new LaunchShortcutExtension(infos[i])); } Collections.sort(fLaunchShortcuts, new ShortcutComparator()); } @@ -520,8 +546,9 @@ // Load the configuration elements into a Map fLaunchGroups = new HashMap(infos.length); + LaunchGroupExtension ext = null; for (int i = 0; i < infos.length; i++) { - LaunchGroupExtension ext = new LaunchGroupExtension(infos[i]); + ext = new LaunchGroupExtension(infos[i]); fLaunchGroups.put(ext.getIdentifier(), ext); } } @@ -558,8 +585,9 @@ protected List filterShortcuts(List unfiltered, String category) { List filtered = new ArrayList(unfiltered.size()); Iterator iter = unfiltered.iterator(); + LaunchShortcutExtension extension = null; while (iter.hasNext()){ - LaunchShortcutExtension extension = (LaunchShortcutExtension)iter.next(); + extension = (LaunchShortcutExtension)iter.next(); if (category == null) { if (extension.getCategory() == null) { filtered.add(extension); @@ -583,9 +611,11 @@ if (fLaunchShortcutsByPerspective == null) { Iterator shortcuts = getLaunchShortcuts().iterator(); fLaunchShortcutsByPerspective = new HashMap(10); + LaunchShortcutExtension ext = null; + Iterator perspectives = null; while (shortcuts.hasNext()) { - LaunchShortcutExtension ext = (LaunchShortcutExtension)shortcuts.next(); - Iterator perspectives = ext.getPerspectives().iterator(); + ext = (LaunchShortcutExtension)shortcuts.next(); + perspectives = ext.getPerspectives().iterator(); while (perspectives.hasNext()) { String id = (String)perspectives.next(); List list = (List)fLaunchShortcutsByPerspective.get(id); @@ -672,8 +702,9 @@ fRestoring = true; ILaunchGroup[] groups = getLaunchGroups(); fLaunchHistories = new HashMap(groups.length); + ILaunchGroup extension = null; for (int i = 0; i < groups.length; i++) { - ILaunchGroup extension = groups[i]; + extension = groups[i]; if (extension.isPublic()) { fLaunchHistories.put(extension.getIdentifier(), new LaunchHistory(extension)); } @@ -709,8 +740,9 @@ try { String category = configuration.getCategory(); ILaunchGroup[] groups = getLaunchGroups(); + ILaunchGroup extension = null; for (int i = 0; i < groups.length; i++) { - ILaunchGroup extension = groups[i]; + extension = groups[i]; if (category == null) { if (extension.getCategory() == null && extension.getMode().equals(mode)) { return extension; @@ -740,8 +772,9 @@ String name = id + ".SHARED_INFO"; //$NON-NLS-1$ ILaunchConfiguration shared = null; ILaunchConfiguration[] configurations = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(type); + ILaunchConfiguration configuration = null; for (int i = 0; i < configurations.length; i++) { - ILaunchConfiguration configuration = configurations[i]; + configuration = configurations[i]; if (configuration.getName().equals(name)) { shared = configuration; break; @@ -762,6 +795,10 @@ } +/** + * A comparator for the ordering of launch shortcut extensions + * @since 3.3 + */ class ShortcutComparator implements Comparator { /** * @see Comparator#compare(Object, Object)
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchHistoryAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchHistoryAction.java index 1f7c832..bc2fff0 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchHistoryAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchHistoryAction.java
@@ -11,7 +11,9 @@ package org.eclipse.debug.ui.actions; -import com.ibm.icu.text.MessageFormat; +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; @@ -33,6 +35,8 @@ import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowPulldownDelegate2; +import com.ibm.icu.text.MessageFormat; + /** * Abstract implementation of an action that displays a drop-down launch * history for a specific launch group. @@ -41,7 +45,7 @@ * </p> * @since 2.1 */ -public abstract class AbstractLaunchHistoryAction implements IWorkbenchWindowPulldownDelegate2, ILaunchHistoryChangedListener { +public abstract class AbstractLaunchHistoryAction implements IWorkbenchWindowPulldownDelegate2, ILaunchHistoryChangedListener, IResourceChangeListener { /** * The menu created by this action @@ -121,6 +125,7 @@ */ private void initialize(IAction action) { getLaunchConfigurationManager().addLaunchHistoryListener(this); + ResourcesPlugin.getWorkspace().addResourceChangeListener(this); setAction(action); updateTooltip(); action.setEnabled(existsConfigTypesForMode()); @@ -136,8 +141,7 @@ private boolean existsConfigTypesForMode() { ILaunchConfigurationType[] configTypes = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationTypes(); for (int i = 0; i < configTypes.length; i++) { - ILaunchConfigurationType configType = configTypes[i]; - if (configType.supportsMode(getMode())) { + if (configTypes[i].supportsMode(getMode())) { return true; } } @@ -153,11 +157,29 @@ if (lastLaunched == null) { tooltip = DebugUIPlugin.removeAccelerators(getLaunchHistory().getLaunchGroup().getLabel()); } else { - tooltip= getToolTip(lastLaunched); + String launchName = lastLaunched.getName(); + String mode = getMode(); + String label; + if (mode.equals(ILaunchManager.RUN_MODE)) { + label= ActionMessages.AbstractLaunchHistoryAction_1; + } else if (mode.equals(ILaunchManager.DEBUG_MODE)){ + label= ActionMessages.AbstractLaunchHistoryAction_2; + } else if (mode.equals(ILaunchManager.PROFILE_MODE)){ + label= ActionMessages.AbstractLaunchHistoryAction_3; + } else { + label= ActionMessages.AbstractLaunchHistoryAction_4; + } + tooltip = MessageFormat.format(ActionMessages.AbstractLaunchHistoryAction_0, new String[] {label, launchName}); } getAction().setToolTipText(tooltip); } + /** + * This method is used to set the tooltip for the luanch history action + * @param lastLaunched the last launched <code>ILauncConfiguration</code> + * @return the string for the tool tip + * @deprecated use the method <code>updateToolTip</code> only, this is part of bug 156516 + */ protected String getToolTip(ILaunchConfiguration lastLaunched) { String launchName= lastLaunched.getName(); String mode= getMode(); @@ -188,6 +210,7 @@ public void dispose() { setMenu(null); getLaunchConfigurationManager().removeLaunchHistoryListener(this); + ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); } /** @@ -310,8 +333,7 @@ /** * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) */ - public void init(IWorkbenchWindow window){ - } + public void init(IWorkbenchWindow window){} /** * Returns the launch history associated with this action's launch group. @@ -350,5 +372,15 @@ protected String getLaunchGroupIdentifier() { return fLaunchGroupIdentifier; } - + + /** + * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent) + */ + public void resourceChanged(IResourceChangeEvent event) { + // need to update the tooltip in the event that one of the launch filters has removed the most recent entry. + // bug 156516 we only want to respond to after-the-fact updates + if(event.getType() == IResourceChangeEvent.POST_CHANGE) { + updateTooltip(); + } + } }