Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarin Wright2007-04-18 13:14:57 -0400
committerDarin Wright2007-04-18 13:14:57 -0400
commitf10872afc3297d9bb9c4b403a0307e8f5e89a77b (patch)
tree7e3ea0c29aa873a88081446b42779410f8018fa6
parent4540b487677928fda17803e14efa71a49bf7948f (diff)
downloadeclipse.platform.debug-f10872afc3297d9bb9c4b403a0307e8f5e89a77b.tar.gz
eclipse.platform.debug-f10872afc3297d9bb9c4b403a0307e8f5e89a77b.tar.xz
eclipse.platform.debug-f10872afc3297d9bb9c4b403a0307e8f5e89a77b.zip
Bug 180441 RetargetAction should not update upon text selection change
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.java4
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.properties2
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RetargetAction.java99
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RetargetRunToLineAction.java24
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/Messages.java31
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/Messages.properties14
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetMethodBreakpointAction.java6
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetToggleBreakpointAction.java6
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetToggleLineBreakpointAction.java6
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetWatchpointAction.java6
10 files changed, 172 insertions, 26 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.java
index ed3fa70ca..ca2166248 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.java
@@ -96,6 +96,10 @@ public class ActionMessages extends NLS {
public static String RemoveBreakpointAction_Exceptions_occurred_attempting_to_remove_a_breakpoint__5;
public static String RemoveBreakpointAction_Removing_a_breakpoint_4;
+ public static String RetargetAction_1;
+
+ public static String RetargetRunToLineAction_0;
+
public static String RunLastAction_0;
public static String RunLastAction_1;
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.properties b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.properties
index fbe08ef10..7ccc960b8 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.properties
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.properties
@@ -131,6 +131,7 @@ RunToLineActionDelegate_4=Run to &Line
RetargetAction_2=Error
RetargetAction_3=Operation failed
+RetargetAction_1=Operation Unavailable
ModifyWatchpointAction_0=Error
ModifyWatchpointAction_1=Failed to modify watchpoint
LaunchShortcutsAction_1=(none applicable)
@@ -144,6 +145,7 @@ FindDialog_3=Find
FindAction_0=&Find...
RetargetAddMemoryBlockAction_0=Add Memory Monitor Failed.
RetargetAddMemoryBlockAction_1=Unable to add memory monitor.
+RetargetRunToLineAction_0=The operation is unavailable on the current selection. Please place the cursor on valid line to run to.
AddMemoryRenderingActionDelegate_0=Add Memory Rendering Failed
AddMemoryRenderingActionDelegate_1=Unable to add the selected rendering.
AddMemoryRenderingActionDelegate_2=Add Memory Rendering
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RetargetAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RetargetAction.java
index fab62d74f..7658ba7ac 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RetargetAction.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RetargetAction.java
@@ -14,26 +14,29 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IAdapterManager;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.ui.IActionDelegate2;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IPartService;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
-import org.eclipse.ui.texteditor.IUpdate;
/**
* Global retargettable debug action.
*
* @since 3.0
*/
-public abstract class RetargetAction implements IWorkbenchWindowActionDelegate, IPartListener, IUpdate {
+public abstract class RetargetAction implements IWorkbenchWindowActionDelegate, IPartListener, IActionDelegate2 {
protected IWorkbenchWindow fWindow = null;
private IWorkbenchPart fActivePart = null;
@@ -95,7 +98,13 @@ public abstract class RetargetAction implements IWorkbenchWindowActionDelegate,
public void run(IAction action) {
if (fTargetAdapter != null) {
try {
- performAction(fTargetAdapter, getTargetSelection(), fActivePart);
+ if (isTargetEnabled()) {
+ performAction(fTargetAdapter, getTargetSelection(), fActivePart);
+ } else {
+ String message = getOperationUnavailableMessage();
+ IStatus status = new Status(IStatus.INFO, DebugUIPlugin.getUniqueIdentifier(), message);
+ DebugUIPlugin.errorDialog(DebugUIPlugin.getShell(), ActionMessages.RetargetAction_1, message, status);
+ }
} catch (CoreException e) {
DebugUIPlugin.errorDialog(fWindow.getShell(), ActionMessages.RetargetAction_2, ActionMessages.RetargetAction_3, e.getStatus()); //
}
@@ -103,6 +112,15 @@ public abstract class RetargetAction implements IWorkbenchWindowActionDelegate,
}
/**
+ * Returns a message to display when we find that the operation is not enabled
+ * when invoked in an editor (we check enabled state before running in this case,
+ * rather than updating on each selection change - see bug 180441).
+ *
+ * @return information message when unavailable
+ */
+ protected abstract String getOperationUnavailableMessage();
+
+ /**
* Performs the specific breakpoint toggling.
*
* @param selection selection in the active part
@@ -115,7 +133,6 @@ public abstract class RetargetAction implements IWorkbenchWindowActionDelegate,
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
*/
public void selectionChanged(IAction action, ISelection selection) {
- this.fAction = action;
// if the active part did not provide an adapter, see if the selection does
if (fTargetAdapter == null && selection instanceof IStructuredSelection) {
IStructuredSelection ss = (IStructuredSelection) selection;
@@ -126,7 +143,11 @@ public abstract class RetargetAction implements IWorkbenchWindowActionDelegate,
}
}
}
- update();
+ boolean enabled = fTargetAdapter != null;
+ if (selection instanceof IStructuredSelection) {
+ enabled = isTargetEnabled();
+ }
+ action.setEnabled(enabled);
}
/* (non-Javadoc)
@@ -144,7 +165,9 @@ public abstract class RetargetAction implements IWorkbenchWindowActionDelegate,
if (fTargetAdapter == null) {
fTargetAdapter = getAdapter(part);
}
- update();
+ if (fAction != null) {
+ fAction.setEnabled(fTargetAdapter != null);
+ }
}
protected Object getAdapter(IAdaptable adaptable) {
@@ -200,26 +223,19 @@ public abstract class RetargetAction implements IWorkbenchWindowActionDelegate,
*/
public void partOpened(IWorkbenchPart part) {
}
- /* (non-Javadoc)
- * @see org.eclipse.ui.texteditor.IUpdate#update()
+
+ /**
+ * Returns whether the target adapter is enabled
+ *
+ * @return whether target adapter is enabled
*/
- public void update() {
- if (fAction == null) {
- return;
- }
- final Object target = fTargetAdapter;
- if (target != null) {
- Runnable r = new Runnable() {
- public void run() {
- if (fActivePart != null) {
- fAction.setEnabled(canPerformAction(target, getTargetSelection(), fActivePart));
- }
- }
- };
- DebugUIPlugin.getStandardDisplay().asyncExec(r);
- } else {
- fAction.setEnabled(false);
+ protected boolean isTargetEnabled() {
+ if (fTargetAdapter != null) {
+ if (fActivePart != null) {
+ return canPerformAction(fTargetAdapter, getTargetSelection(), fActivePart);
+ }
}
+ return false;
}
/**
@@ -230,5 +246,38 @@ public abstract class RetargetAction implements IWorkbenchWindowActionDelegate,
* @param part the part the operation has been requested on
* @return whether the operation can be performed
*/
- protected abstract boolean canPerformAction(Object target, ISelection selection, IWorkbenchPart part);
+ protected abstract boolean canPerformAction(Object target, ISelection selection, IWorkbenchPart part);
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
+ */
+ public void init(IAction action) {
+ fAction = action;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
+ */
+ public void runWithEvent(IAction action, Event event) {
+ run(action);
+ }
+
+ /**
+ * Returns the proxy to this action delegate or <code>null</code>
+ *
+ * @return action proxy or <code>null</code>
+ */
+ protected IAction getAction() {
+ return fAction;
+ }
+
+ /**
+ * Returns whether there is currently a target adapter for this action.
+ *
+ * @return whether the action has a target adapter.
+ */
+ protected boolean hasTargetAdapter() {
+ return fTargetAdapter != null;
+ }
+
}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RetargetRunToLineAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RetargetRunToLineAction.java
index a5e87eeda..5338ceeac 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RetargetRunToLineAction.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/RetargetRunToLineAction.java
@@ -17,6 +17,7 @@ import org.eclipse.debug.ui.actions.IRunToLineTarget;
import org.eclipse.debug.ui.contexts.DebugContextEvent;
import org.eclipse.debug.ui.contexts.IDebugContextListener;
import org.eclipse.debug.ui.contexts.IDebugContextService;
+import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchPart;
@@ -45,7 +46,10 @@ public class RetargetRunToLineAction extends RetargetAction {
}
}
}
- update();
+ IAction action = getAction();
+ if (action != null) {
+ action.setEnabled(fTargetElement != null && hasTargetAdapter());
+ }
}
public void debugContextChanged(DebugContextEvent event) {
@@ -93,4 +97,22 @@ public class RetargetRunToLineAction extends RetargetAction {
protected void performAction(Object target, ISelection selection, IWorkbenchPart part) throws CoreException {
((IRunToLineTarget)target).runToLine(part, selection, fTargetElement);
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.actions.RetargetAction#getOperationUnavailableMessage()
+ */
+ protected String getOperationUnavailableMessage() {
+ return ActionMessages.RetargetRunToLineAction_0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ if (fTargetElement == null) {
+ action.setEnabled(false);
+ } else {
+ super.selectionChanged(action, selection);
+ }
+ }
}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/Messages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/Messages.java
new file mode 100644
index 000000000..ca6845893
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/Messages.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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.debug.internal.ui.actions.breakpoints;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ *
+ */
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.debug.internal.ui.actions.breakpoints.Messages"; //$NON-NLS-1$
+ public static String RetargetMethodBreakpointAction_0;
+ public static String RetargetToggleBreakpointAction_0;
+ public static String RetargetToggleLineBreakpointAction_0;
+ public static String RetargetWatchpointAction_0;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/Messages.properties b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/Messages.properties
new file mode 100644
index 000000000..4d58ef129
--- /dev/null
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/Messages.properties
@@ -0,0 +1,14 @@
+###############################################################################
+# Copyright (c) 2007 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
+###############################################################################
+RetargetMethodBreakpointAction_0=The operation is unavailable on the current selection. Please place the cursor inside a method.
+RetargetToggleBreakpointAction_0=The operation is unavailable on the current selection. Please place the cursor in a valid location for a breakpoint.
+RetargetWatchpointAction_0=The operation is unavailable on the current selection. Please select or place the cursor on a field.
+RetargetToggleLineBreakpointAction_0=The operation is unavailable on the current selection. Please place the cursor on a valid line.
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetMethodBreakpointAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetMethodBreakpointAction.java
index 331d0b62c..a3714e78b 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetMethodBreakpointAction.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetMethodBreakpointAction.java
@@ -35,4 +35,10 @@ public class RetargetMethodBreakpointAction extends RetargetBreakpointAction {
protected boolean canPerformAction(Object target, ISelection selection, IWorkbenchPart part) {
return ((IToggleBreakpointsTarget)target).canToggleMethodBreakpoints(part, selection);
}
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.actions.RetargetAction#getOperationUnavailableMessage()
+ */
+ protected String getOperationUnavailableMessage() {
+ return Messages.RetargetMethodBreakpointAction_0;
+ }
}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetToggleBreakpointAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetToggleBreakpointAction.java
index f83aec9e1..d9e8316b8 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetToggleBreakpointAction.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetToggleBreakpointAction.java
@@ -46,4 +46,10 @@ public class RetargetToggleBreakpointAction extends RetargetBreakpointAction {
return ((IToggleBreakpointsTarget)target).canToggleLineBreakpoints(part, selection);
}
}
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.actions.RetargetAction#getOperationUnavailableMessage()
+ */
+ protected String getOperationUnavailableMessage() {
+ return Messages.RetargetToggleBreakpointAction_0;
+ }
}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetToggleLineBreakpointAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetToggleLineBreakpointAction.java
index ba78a269b..b6d2fcc50 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetToggleLineBreakpointAction.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetToggleLineBreakpointAction.java
@@ -35,4 +35,10 @@ public class RetargetToggleLineBreakpointAction extends RetargetBreakpointAction
protected boolean canPerformAction(Object target, ISelection selection, IWorkbenchPart part) {
return ((IToggleBreakpointsTarget)target).canToggleLineBreakpoints(part, selection);
}
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.actions.RetargetAction#getOperationUnavailableMessage()
+ */
+ protected String getOperationUnavailableMessage() {
+ return Messages.RetargetToggleLineBreakpointAction_0;
+ }
}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetWatchpointAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetWatchpointAction.java
index e0a585dac..112b32108 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetWatchpointAction.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RetargetWatchpointAction.java
@@ -35,4 +35,10 @@ public class RetargetWatchpointAction extends RetargetBreakpointAction {
protected boolean canPerformAction(Object target, ISelection selection, IWorkbenchPart part) {
return ((IToggleBreakpointsTarget)target).canToggleWatchpoints(part, selection);
}
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.internal.ui.actions.RetargetAction#getOperationUnavailableMessage()
+ */
+ protected String getOperationUnavailableMessage() {
+ return Messages.RetargetWatchpointAction_0;
+ }
}

Back to the top