Skip to content

Commit c20b1c8

Browse files
committed
Add option to disable all breakpoints except selected ones
This commit introduces a new menu option that allows users to select multiple enabled breakpoints and disable all other breakpoints except the ones selected. This provides more flexibility and control over breakpoint management.
1 parent 0fc54b8 commit c20b1c8

File tree

4 files changed

+120
-2
lines changed

4 files changed

+120
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ DetailPaneFontDefinition.description=The detail pane text font is used in the de
8383
DetailPaneFactoriesExtension.name=Detail Pane Factories
8484
DisableBreakpointsAction.label=&Disable
8585
DisableAllBreakpointsAction.label=Disa&ble All
86+
DisableOtherBreakpointsAction.label=Disa&ble Others
8687
EnableAllBreakpointsAction.label=Ena&ble All
8788
EnableBreakpointsAction.label=&Enable
8889
ExpandAll.label=Expand All

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

Lines changed: 10 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, 2021 IBM Corporation and others.
4+
Copyright (c) 2005, 2025 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
@@ -1548,6 +1548,15 @@
15481548
menubarPath="breakpointGroup"
15491549
id="org.eclipse.debug.ui.actions.DisableAllBreakpoint">
15501550
</action>
1551+
<action
1552+
label="%DisableOtherBreakpointsAction.label"
1553+
icon="$nl$/icons/full/elcl16/disabled_co.png"
1554+
helpContextId="disable_breakpoint_action_context"
1555+
class="org.eclipse.debug.internal.ui.actions.breakpoints.DisableAllOtherBreakpointsAction"
1556+
menubarPath="breakpointGroup"
1557+
enablesFor="+"
1558+
id="org.eclipse.debug.ui.actions.DisableAllOtherBreakpoint">
1559+
</action>
15511560
<action
15521561
label="%DisableBreakpointsAction.label"
15531562
icon="$nl$/icons/full/elcl16/disabled_co.png"
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 IBM Corporation and others.
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 Corporation - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.debug.internal.ui.actions.breakpoints;
15+
16+
import java.util.HashSet;
17+
import java.util.List;
18+
import java.util.Set;
19+
20+
import org.eclipse.core.resources.IWorkspaceRunnable;
21+
import org.eclipse.core.resources.ResourcesPlugin;
22+
import org.eclipse.core.runtime.CoreException;
23+
import org.eclipse.core.runtime.MultiStatus;
24+
import org.eclipse.core.runtime.NullProgressMonitor;
25+
import org.eclipse.debug.core.DebugException;
26+
import org.eclipse.debug.core.DebugPlugin;
27+
import org.eclipse.debug.core.model.IBreakpoint;
28+
import org.eclipse.debug.internal.ui.DebugUIPlugin;
29+
import org.eclipse.debug.internal.ui.actions.ActionMessages;
30+
import org.eclipse.debug.internal.ui.breakpoints.provisional.IBreakpointContainer;
31+
import org.eclipse.jface.action.IAction;
32+
import org.eclipse.jface.viewers.IStructuredSelection;
33+
import org.eclipse.ui.IWorkbenchWindow;
34+
35+
public class DisableAllOtherBreakpointsAction extends EnableBreakpointsAction {
36+
37+
@Override
38+
protected boolean isEnableAction() {
39+
int enabledCount = 0;
40+
for (IBreakpoint brkPoint : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints()) {
41+
if (enabledCount > 1) {
42+
return false;
43+
}
44+
try {
45+
if (brkPoint.isEnabled()) {
46+
enabledCount++;
47+
}
48+
} catch (CoreException e) {
49+
DebugUIPlugin.log(e);
50+
return true;
51+
}
52+
}
53+
return true;
54+
}
55+
56+
@Override
57+
public void run(IAction action) {
58+
IStructuredSelection selection = getSelection();
59+
if (selection.isEmpty()) {
60+
return;
61+
}
62+
final List<Object> selectedBreakpoints = selection.toList();
63+
final MultiStatus ms = new MultiStatus(DebugUIPlugin.getUniqueIdentifier(), DebugException.REQUEST_FAILED,
64+
ActionMessages.EnableBreakpointAction_Enable_breakpoint_s__failed_2, null);
65+
IWorkspaceRunnable runnable = monitor -> {
66+
try {
67+
Set<IBreakpoint> excludedBreakpoints = new HashSet<>();
68+
for (Object selectedObj : selectedBreakpoints) {
69+
if (selectedObj instanceof IBreakpoint breakPoint && breakPoint.isEnabled()) {
70+
excludedBreakpoints.add(breakPoint);
71+
}
72+
if (selectedObj instanceof IBreakpointContainer breakPointContainer) {
73+
for (IBreakpoint bp : breakPointContainer.getBreakpoints()) {
74+
if (bp.isEnabled()) {
75+
excludedBreakpoints.add(bp);
76+
}
77+
}
78+
}
79+
}
80+
for (IBreakpoint brk : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints()) {
81+
if (!excludedBreakpoints.contains(brk)) {
82+
brk.setEnabled(false);
83+
}
84+
}
85+
86+
} catch (CoreException e) {
87+
ms.merge(e.getStatus());
88+
}
89+
};
90+
91+
try {
92+
ResourcesPlugin.getWorkspace().run(runnable, null, 0, new NullProgressMonitor());
93+
} catch (CoreException e) {
94+
// handled by runnable
95+
}
96+
97+
if (!ms.isOK()) {
98+
IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow();
99+
if (window != null) {
100+
DebugUIPlugin.errorDialog(window.getShell(),
101+
ActionMessages.EnableBreakpointAction_Enabling_breakpoints_3,
102+
ActionMessages.EnableBreakpointAction_Exceptions_occurred_enabling_the_breakpoint_s___4, ms); //
103+
} else {
104+
DebugUIPlugin.log(ms);
105+
}
106+
}
107+
}
108+
}

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/EnableBreakpointsAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void setEnabled(IBreakpoint[] breakpoints) throws CoreException {
134134
}
135135
}
136136

137-
private IStructuredSelection getSelection() {
137+
protected IStructuredSelection getSelection() {
138138
return (IStructuredSelection)getView().getViewSite().getSelectionProvider().getSelection();
139139
}
140140

0 commit comments

Comments
 (0)