Skip to content

Commit afa36d2

Browse files
committed
Clear all conditions in breakpoints #549
Provides additional right click menu option for disabling all the conditions set in breakpoints. Will be useful for disabling every conditions in breakpoints by keeping the condition in the text editor itself. Enhancement #549
1 parent c73de59 commit afa36d2

File tree

8 files changed

+151
-7
lines changed

8 files changed

+151
-7
lines changed
284 Bytes
Loading

org.eclipse.jdt.debug.ui/plugin.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,5 +335,6 @@ OpenFromClipboardAction.label = Open from Clipboar&d
335335
OpenFromClipboardAction.tooltip = Opens a Java element or Java Stack Trace from Clipboard
336336
OpenFromClipboardAction.description = Opens a Java element or a Java stack trace from clipboard
337337
OpenFromClipboardAction.name = Open from Clipboard
338-
339338
VariablesView.name = Variables
339+
340+
DisableAllConditions.label = Disable All Conditions

org.eclipse.jdt.debug.ui/plugin.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<?eclipse version="3.0"?>
33
<!--
4-
Copyright (c) 2005, 2022 IBM Corporation and others.
4+
Copyright (c) 2005, 2024 IBM Corporation and others.
55
66
This program and the accompanying materials
77
are made available under the terms of the Eclipse Public License 2.0
@@ -3865,6 +3865,21 @@ M4 = Platform-specific fourth key
38653865
type="org.eclipse.swt.widgets.Composite"
38663866
description="%descriptionSWTComposite"/>
38673867
</extension>
3868+
<extension
3869+
point="org.eclipse.ui.popupMenus">
3870+
<viewerContribution
3871+
targetID="org.eclipse.debug.ui.BreakpointView"
3872+
id="org.eclipse.jdt.debug.ui.removeAllConditions">
3873+
<action
3874+
label="%DisableAllConditions.label"
3875+
helpContextId="remove_all_breakpoints_action_context"
3876+
icon="$nl$/icons/full/elcl16/removeAllConditions.png"
3877+
class="org.eclipse.jdt.internal.debug.ui.actions.RemoveAllCondtionalBreakpoints"
3878+
menubarPath="breakpointGroupJava"
3879+
id="org.eclipse.jdt.internal.debug.ui.RemoveAction">
3880+
</action>
3881+
</viewerContribution>
3882+
</extension>
38683883
<extension
38693884
point="org.eclipse.ui.handlers">
38703885
<handler

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/debug/ui/IJavaDebugUIConstants.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2008 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -117,4 +117,9 @@ public interface IJavaDebugUIConstants {
117117
*/
118118
public static final String PREF_ALLREFERENCES_MAX_COUNT = PLUGIN_ID + ".all_references_max_count"; //$NON-NLS-1$
119119

120+
/**
121+
* @since 3.13
122+
*/
123+
public static final String PREF_PROMPT_REMOVE_ALL_CONDITIONAL_BREAKPOINTS = PLUGIN_ID + ".remove_all_conditions_in_breakpoints_prompt"; //$NON-NLS-1$
124+
120125
}

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/JDIDebugUIPreferenceInitializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2004, 2020 IBM Corporation and others.
2+
* Copyright (c) 2004, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -64,6 +64,7 @@ public void initializeDefaultPreferences() {
6464
store.setDefault(IJDIPreferencesConstants.PREF_OPEN_INSPECT_POPUP_ON_EXCEPTION, false);
6565
store.setDefault(IJavaDebugUIConstants.PREF_ALLINSTANCES_MAX_COUNT, 100);
6666
store.setDefault(IJavaDebugUIConstants.PREF_ALLREFERENCES_MAX_COUNT, 100);
67+
store.setDefault(IJavaDebugUIConstants.PREF_PROMPT_REMOVE_ALL_CONDITIONAL_BREAKPOINTS, true);
6768
}
6869

6970
/**

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2022 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -176,6 +176,10 @@ public class ActionMessages extends NLS {
176176
public static String Override_Dependencies_label1;
177177
public static String Override_Dependencies_label2;
178178

179+
public static String ClearAllCondtionsInBreakpointsAction_0;
180+
public static String ClearAllCondtionsInBreakpointsAction_1;
181+
public static String ClearAllCondtionsInBreakpointsAction_2;
182+
179183
static {
180184
// load message values from bundle file
181185
NLS.initializeMessages(BUNDLE_NAME, ActionMessages.class);

org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.properties

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###############################################################################
2-
# Copyright (c) 2000, 2022 IBM Corporation and others.
2+
# Copyright (c) 2000, 2024 IBM Corporation and others.
33
#
44
# This program and the accompanying materials
55
# are made available under the terms of the Eclipse Public License 2.0
@@ -154,4 +154,7 @@ Override_Dependencies_title=Override Dependencies
154154
Override_Dependencies_button=&Override
155155
Override_Dependencies_button1=&Override Dependencies...
156156
Override_Dependencies_label1=Dependencies derived from the Java Build Path:
157-
Override_Dependencies_label2=Dependencies for launching:
157+
Override_Dependencies_label2=Dependencies for launching:
158+
ClearAllCondtionsInBreakpointsAction_0=Clear All Conditions
159+
ClearAllCondtionsInBreakpointsAction_1=Clear all conditions ?
160+
ClearAllCondtionsInBreakpointsAction_2=&Do not ask me again.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 IBM Corporation.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* IBM - Initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.jdt.internal.debug.ui.actions;
15+
16+
import org.eclipse.core.resources.IWorkspace;
17+
import org.eclipse.core.resources.IWorkspaceRunnable;
18+
import org.eclipse.core.resources.ResourcesPlugin;
19+
import org.eclipse.core.runtime.CoreException;
20+
import org.eclipse.core.runtime.IProgressMonitor;
21+
import org.eclipse.core.runtime.IStatus;
22+
import org.eclipse.core.runtime.Status;
23+
import org.eclipse.core.runtime.jobs.Job;
24+
import org.eclipse.debug.core.DebugPlugin;
25+
import org.eclipse.debug.core.model.IBreakpoint;
26+
import org.eclipse.debug.internal.ui.DebugUIPlugin;
27+
import org.eclipse.debug.internal.ui.actions.breakpoints.RemoveAllTriggerPointsAction;
28+
import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants;
29+
import org.eclipse.jdt.internal.debug.core.breakpoints.JavaLineBreakpoint;
30+
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
31+
import org.eclipse.jface.action.IAction;
32+
import org.eclipse.jface.dialogs.IDialogConstants;
33+
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
34+
import org.eclipse.jface.preference.IPreferenceStore;
35+
import org.eclipse.ui.IWorkbenchWindow;
36+
37+
38+
public class RemoveAllCondtionalBreakpoints extends RemoveAllTriggerPointsAction {
39+
public RemoveAllCondtionalBreakpoints() {
40+
super();
41+
}
42+
@Override
43+
protected boolean isEnabled() {
44+
for (IBreakpoint breakpoint : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints()) {
45+
if (breakpoint instanceof JavaLineBreakpoint javaBreakpoint) {
46+
try {
47+
if (javaBreakpoint.isConditionEnabled()) {
48+
return true;
49+
}
50+
} catch (CoreException e) {
51+
DebugUIPlugin.log(e);
52+
}
53+
}
54+
}
55+
return false;
56+
}
57+
58+
@Override
59+
public void run(IAction action) {
60+
IWorkbenchWindow window = JDIDebugUIPlugin.getActiveWorkbenchWindow();
61+
if (window == null) {
62+
return;
63+
}
64+
IPreferenceStore store = JDIDebugUIPlugin.getDefault().getPreferenceStore();
65+
boolean prompt = store.getBoolean(IJavaDebugUIConstants.PREF_PROMPT_REMOVE_ALL_CONDITIONAL_BREAKPOINTS);
66+
boolean proceed = true;
67+
if (prompt) {
68+
MessageDialogWithToggle mdwt = MessageDialogWithToggle.openYesNoQuestion(window.getShell(), ActionMessages.ClearAllCondtionsInBreakpointsAction_0, ActionMessages.ClearAllCondtionsInBreakpointsAction_1, ActionMessages.ClearAllCondtionsInBreakpointsAction_2, !prompt, null, null);
69+
if (mdwt.getReturnCode() != IDialogConstants.YES_ID) {
70+
proceed = false;
71+
} else {
72+
store.setValue(IJavaDebugUIConstants.PREF_PROMPT_REMOVE_ALL_CONDITIONAL_BREAKPOINTS, !mdwt.getToggleState());
73+
}
74+
}
75+
if (proceed) {
76+
new Job(ActionMessages.ClearAllCondtionsInBreakpointsAction_1) {
77+
@Override
78+
protected IStatus run(IProgressMonitor monitor) {
79+
try {
80+
for (IBreakpoint breakpoint : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints()) {
81+
if (breakpoint instanceof JavaLineBreakpoint javaBp) {
82+
if (javaBp.isConditionEnabled()) {
83+
javaBp.setConditionEnabled(false);
84+
}
85+
}
86+
}
87+
refreshAllBreakpoints();
88+
} catch (Exception e) {
89+
DebugUIPlugin.log(e);
90+
return Status.CANCEL_STATUS;
91+
}
92+
return Status.OK_STATUS;
93+
}
94+
}.schedule();
95+
}
96+
}
97+
98+
private void refreshAllBreakpoints() {
99+
IWorkspaceRunnable runnable = monitor -> {
100+
for (IBreakpoint breakpoint : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints()) {
101+
try {
102+
breakpoint.getMarker().setAttribute(IBreakpoint.ENABLED, breakpoint.isEnabled());
103+
} catch (CoreException e) {
104+
DebugPlugin.log(e);
105+
}
106+
}
107+
};
108+
try {
109+
ResourcesPlugin.getWorkspace().run(runnable, null, IWorkspace.AVOID_UPDATE, null);
110+
} catch (CoreException e) {
111+
DebugPlugin.log(e);
112+
}
113+
}
114+
115+
}

0 commit comments

Comments
 (0)