diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java
index 74f61314af0..9d549066e8c 100644
--- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java
+++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDIDebugModel.java
@@ -1358,7 +1358,6 @@ public class CDIDebugModel {
public static ICFunctionBreakpoint functionBreakpointExists(String sourceHandle, IResource resource, String function)
throws CoreException {
String modelId = getPluginIdentifier();
- String markerType = ICFunctionBreakpoint.C_FUNCTION_BREAKPOINT_MARKER;
IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
IBreakpoint[] breakpoints = manager.getBreakpoints(modelId);
for (int i = 0; i < breakpoints.length; i++) {
@@ -1366,12 +1365,10 @@ public class CDIDebugModel {
continue;
}
ICFunctionBreakpoint breakpoint = (ICFunctionBreakpoint) breakpoints[i];
- if (breakpoint.getMarker().getType().equals(markerType)) {
- if (sameSourceHandle(sourceHandle, breakpoint.getSourceHandle())) {
- if (breakpoint.getMarker().getResource().equals(resource)) {
- if (breakpoint.getFunction() != null && breakpoint.getFunction().equals(function)) {
- return breakpoint;
- }
+ if (sameSourceHandle(sourceHandle, breakpoint.getSourceHandle())) {
+ if (breakpoint.getMarker().getResource().equals(resource)) {
+ if (breakpoint.getFunction() != null && breakpoint.getFunction().equals(function)) {
+ return breakpoint;
}
}
}
diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml
index 194a8e62bcd..c2bc5288985 100644
--- a/debug/org.eclipse.cdt.debug.ui/plugin.xml
+++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml
@@ -679,7 +679,7 @@
enablesFor="1"
label="%ToggleWatchpointAction.label"
icon="icons/elcl16/watchpoint_co.gif"
- class="org.eclipse.debug.ui.actions.ToggleWatchpointActionDelegate"
+ class="org.eclipse.cdt.debug.internal.ui.actions.breakpoints.CToggleWatchpointActionDelegate"
tooltip="%ToggleWatchpointAction.tooltip"
menubarPath="additions"
id="org.eclipse.cdt.debug.ui.actions.ToggleWatchpointAction"/>
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/breakpoints/CToggleBreakpointObjectActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/breakpoints/CToggleBreakpointObjectActionDelegate.java
index 14e1e3e24be..a874f0053c4 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/breakpoints/CToggleBreakpointObjectActionDelegate.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/breakpoints/CToggleBreakpointObjectActionDelegate.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 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
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Wind River Systems - added support for IToggleBreakpointsTargetFactory
+ * Freescale - Add support for conditionally activating an action
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions.breakpoints;
@@ -71,6 +72,16 @@ public abstract class CToggleBreakpointObjectActionDelegate implements IObjectAc
protected abstract void performAction(IToggleBreakpointsTarget target, IWorkbenchPart part, ISelection selection, Event event)
throws CoreException;
+ /**
+ * Returns whether the specific operation is supported.
+ *
+ * @param target the target adapter
+ * @param selection the selection to verify the operation on
+ * @param part the part the operation has been requested on
+ * @return whether the operation can be performed
+ */
+ protected abstract boolean canPerformAction(IToggleBreakpointsTarget target, IWorkbenchPart part, ISelection selection);
+
public void selectionChanged(IAction action, ISelection selection) {
boolean enabled = false;
if (selection instanceof IStructuredSelection) {
@@ -81,7 +92,7 @@ public abstract class CToggleBreakpointObjectActionDelegate implements IObjectAc
if (fPart != null) {
IToggleBreakpointsTarget target =
DebugUITools.getToggleBreakpointsTargetManager().getToggleBreakpointsTarget(fPart, fSelection);
- enabled = target != null;
+ enabled = target != null && canPerformAction(target, fPart, fSelection);
}
}
action.setEnabled(enabled);
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/breakpoints/CToggleMethodBreakpointActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/breakpoints/CToggleMethodBreakpointActionDelegate.java
index 37aa40ad275..140ba52401a 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/breakpoints/CToggleMethodBreakpointActionDelegate.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/breakpoints/CToggleMethodBreakpointActionDelegate.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Freescale - Add support for conditionally activating an action
*******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions.breakpoints;
@@ -45,4 +46,10 @@ public class CToggleMethodBreakpointActionDelegate extends CToggleBreakpointObje
target.toggleMethodBreakpoints(part, selection);
}
}
+
+ @Override
+ protected boolean canPerformAction(IToggleBreakpointsTarget target,
+ IWorkbenchPart part, ISelection selection) {
+ return target.canToggleMethodBreakpoints(part, selection);
+ }
}
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/breakpoints/CToggleWatchpointActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/breakpoints/CToggleWatchpointActionDelegate.java
new file mode 100644
index 00000000000..968e48e634d
--- /dev/null
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/breakpoints/CToggleWatchpointActionDelegate.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2014 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
+ * Freescale - add support for conditionally activating action
+ *******************************************************************************/
+package org.eclipse.cdt.debug.internal.ui.actions.breakpoints;
+
+import org.eclipse.cdt.debug.ui.breakpoints.IToggleBreakpointsTargetCExtension;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * A toggle watchpoint action that can be contributed an object
+ * contribution. The action will toggle watchpoints on objects
+ * that provide an IToggleBreakpointsTarget
adapter.
+ *
+ * This class is based on {@link org.eclipse.debug.ui.actions.ToggleWatchpointActionDelegate } + * class. In addition to the copied functionality, it adds the handling of + * action-triggering event. + *
+ * + * @since 7.5 + */ +public class CToggleWatchpointActionDelegate extends CToggleBreakpointObjectActionDelegate { + + protected void performAction(IToggleBreakpointsTarget target, IWorkbenchPart part, ISelection selection, Event event) + throws CoreException + { + if ((event.stateMask & SWT.MOD1) != 0 && + target instanceof IToggleBreakpointsTargetCExtension && + ((IToggleBreakpointsTargetCExtension)target).canCreateWatchpointsInteractive(part, selection)) + { + ((IToggleBreakpointsTargetCExtension)target).createWatchpointsInteractive(part, selection); + } + else { + target.toggleWatchpoints(part, selection); + } + } + + @Override + protected boolean canPerformAction(IToggleBreakpointsTarget target, + IWorkbenchPart part, ISelection selection) { + return target.canToggleWatchpoints(part, selection); + } +} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/AbstractToggleBreakpointAdapter.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/AbstractToggleBreakpointAdapter.java index 3cd09acbdb9..d38d993512c 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/AbstractToggleBreakpointAdapter.java +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/ui/breakpoints/AbstractToggleBreakpointAdapter.java @@ -8,6 +8,7 @@ * Contributors: * Mentor Graphics - Initial API and implementation * Marc Khouzam (Ericsson) - Don't allow to set two bps at same line (bug 432503) + * Teodor Madan (Freescale) - Do not create multiple watchpoints /method breakpoints at same location ( 445375 ) *******************************************************************************/ package org.eclipse.cdt.debug.ui.breakpoints; @@ -184,8 +185,7 @@ abstract public class AbstractToggleBreakpointAdapter @Override public boolean canCreateWatchpointsInteractive(IWorkbenchPart part, ISelection selection) { - // Gather all input from user if needed. - return true; + return canToggleWatchpoints(part, selection) && !hasWatchpoint(part, selection); } @Override @@ -229,7 +229,7 @@ abstract public class AbstractToggleBreakpointAdapter @Override public boolean canCreateFunctionBreakpointInteractive(IWorkbenchPart part, ISelection selection) { - return true; + return canToggleMethodBreakpoints(part, selection) && !hasMethodBreakpoints(part, selection); } @Override @@ -256,6 +256,40 @@ abstract public class AbstractToggleBreakpointAdapter return false; } + private boolean hasWatchpoint(IWorkbenchPart part, ISelection selection) { + ICElement element = getCElementFromSelection( part, selection ); + if (element instanceof IVariable) { + IVariable variable = (IVariable) element; + String sourceHandle = getSourceHandle(variable ); + IResource resource = getElementResource(variable); + String expression = getVariableName(variable); + try { + return null != findWatchpoint(sourceHandle, resource, expression); + } catch (CoreException e) { + DebugPlugin.log(e); + } + } + return false; + } + + private boolean hasMethodBreakpoints(IWorkbenchPart part, ISelection selection) { + ICElement element = getCElementFromSelection( part, selection ); + if ( element instanceof IFunction || element instanceof IMethod ) { + IDeclaration declaration = (IDeclaration) element; + String sourceHandle = getSourceHandle(declaration); + IResource resource = getElementResource(declaration); + String functionName = (declaration instanceof IFunction) ? + getFunctionName((IFunction) declaration) + : getMethodName((IMethod) declaration); + try { + return null != findFunctionBreakpoint(sourceHandle, resource, functionName); + } catch (CoreException e) { + DebugPlugin.log(e); + } + } + return false; + } + /** * Updates the breakpoint for given part and selection. * Depending on the flags and on whether a breakpoint exists, this method @@ -607,7 +641,8 @@ abstract public class AbstractToggleBreakpointAdapter return null; } - protected ICWatchpointTarget getWatchpointTarget( IWorkbenchPart part, ISelection selection ) { + @SuppressWarnings("deprecation") + protected ICWatchpointTarget getWatchpointTarget( IWorkbenchPart part, ISelection selection ) { if (selection != null && selection instanceof IStructuredSelection && !selection.isEmpty()) { Object obj = ((IStructuredSelection)selection).getFirstElement(); if (obj != null) {