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 453d38d..1714719 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
@@ -294,6 +294,23 @@
 	}
 	
 	/**
+	 * Returns the most recent launch for the given group taking launch configuration
+	 * filters into account, or <code>null</code> if none.
+	 * 
+	 * @param groupId launch group
+	 * @return the most recent, un-filtered launch
+	 */
+	public ILaunchConfiguration getFilteredLastLaunch(String groupId) {
+		LaunchHistory history = getLaunchHistory(groupId);if (history != null) {
+			ILaunchConfiguration[] filterConfigs = filterConfigs(history.getHistory());
+			if (filterConfigs.length > 0) {
+				return filterConfigs[0];
+			}
+		}
+		return null;
+	}
+	
+	/**
 	 * Add the specified listener to the list of listeners that will be notified when the
 	 * launch history changes.
 	 */
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchHistory.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchHistory.java
index b155d66..5a8f348 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchHistory.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchHistory.java
@@ -78,7 +78,7 @@
 	}
 	
 	/**
-	 * Adds the given configuration to this hisotry
+	 * Adds the given configuration to this history
 	 * 
 	 * @param configuration
 	 * @param prepend whether the configuration should be added to the beginning of
@@ -382,7 +382,7 @@
 	}
 	
 	/**
-	 * Revmoves the given config from the favorites list, if needed.
+	 * Removes the given config from the favorites list, if needed.
 	 * 
 	 * @param configuration
 	 */
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 bc2fff0..b7214cd 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
@@ -45,7 +45,7 @@
  * </p>
  * @since 2.1
  */
-public abstract class AbstractLaunchHistoryAction implements IWorkbenchWindowPulldownDelegate2, ILaunchHistoryChangedListener, IResourceChangeListener {
+public abstract class AbstractLaunchHistoryAction implements IWorkbenchWindowPulldownDelegate2, ILaunchHistoryChangedListener {
 	
 	/**
 	 * The menu created by this action
@@ -77,6 +77,19 @@
 	public AbstractLaunchHistoryAction(String launchGroupIdentifier) {
 		fLaunchGroupIdentifier = launchGroupIdentifier;
 	}
+	
+	/**
+	 * Resource change listener to update tooltip
+	 */
+	private IResourceChangeListener fListener = new IResourceChangeListener() {
+		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();
+			}
+		}
+	};
 
 	/**
 	 * Sets the action used to render this delegate.
@@ -125,7 +138,7 @@
 	 */
 	private void initialize(IAction action) {
 		getLaunchConfigurationManager().addLaunchHistoryListener(this);
-		ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
+		ResourcesPlugin.getWorkspace().addResourceChangeListener(fListener);
 		setAction(action);
 		updateTooltip();	
 		action.setEnabled(existsConfigTypesForMode());	
@@ -157,31 +170,19 @@
 		if (lastLaunched == null) {
 			tooltip = DebugUIPlugin.removeAccelerators(getLaunchHistory().getLaunchGroup().getLabel());
 		} else {
-			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}); 
+			tooltip = getToolTip(lastLaunched); 
 		}
 		getAction().setToolTipText(tooltip);
 	}
 	
 	/**
-	 * This method is used to set the tooltip for the luanch history action
-	 * @param lastLaunched the last launched <code>ILauncConfiguration</code>
+	 * Returns the tooltip specific to a configuration.
+	 * 
+	 * @param configuration a <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();
+	protected String getToolTip(ILaunchConfiguration configuration) {
+		String launchName= configuration.getName();
 		String mode= getMode();
 		String label;
 		if (mode.equals(ILaunchManager.RUN_MODE)) {
@@ -210,14 +211,17 @@
 	public void dispose() {
 		setMenu(null);
 		getLaunchConfigurationManager().removeLaunchHistoryListener(this);
-		ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
+		ResourcesPlugin.getWorkspace().removeResourceChangeListener(fListener);
 	}
 	
 	/**
-	 * Return the last launch in this action's launch history
+	 * Return the last launch in this action's launch history.
+	 * 
+	 * @return the most recent configuration that was launched from this
+	 *  action's launch history that is not filtered from the menu
 	 */
 	protected ILaunchConfiguration getLastLaunch() {
-		return getLaunchConfigurationManager().getLastLaunch(getLaunchGroupIdentifier());
+		return getLaunchConfigurationManager().getFilteredLastLaunch(getLaunchGroupIdentifier());
 	}
 
 	/**
@@ -373,14 +377,4 @@
 		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();
-		}
-	}
 }