Skip to content

Commit dbfe104

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 87a5e5a commit dbfe104

File tree

4 files changed

+126
-2
lines changed

4 files changed

+126
-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=Disable 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: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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+
/**
38+
* If this action can enable breakpoints
39+
*
40+
* @return <code>false</code> if there's more than 1 enabled breakpoint else
41+
* <code>true</code>
42+
*/
43+
@Override
44+
protected boolean isEnableAction() {
45+
int enabledCount = 0;
46+
for (IBreakpoint brkPoint : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints()) {
47+
if (enabledCount > 0) {
48+
return false;
49+
}
50+
try {
51+
if (brkPoint.isEnabled()) {
52+
enabledCount++;
53+
}
54+
} catch (CoreException e) {
55+
DebugUIPlugin.log(e);
56+
return true;
57+
}
58+
}
59+
return true;
60+
}
61+
62+
@Override
63+
public void run(IAction action) {
64+
IStructuredSelection selection = getSelection();
65+
if (selection.isEmpty()) {
66+
return;
67+
}
68+
final List<Object> selectedBreakpoints = selection.toList();
69+
final MultiStatus ms = new MultiStatus(DebugUIPlugin.getUniqueIdentifier(), DebugException.REQUEST_FAILED,
70+
ActionMessages.EnableBreakpointAction_Enable_breakpoint_s__failed_2, null);
71+
IWorkspaceRunnable runnable = monitor -> {
72+
try {
73+
Set<IBreakpoint> excludedBreakpoints = new HashSet<>();
74+
for (Object selectedObj : selectedBreakpoints) {
75+
if (selectedObj instanceof IBreakpoint breakPoint && breakPoint.isEnabled()) {
76+
excludedBreakpoints.add(breakPoint);
77+
}
78+
if (selectedObj instanceof IBreakpointContainer breakPointContainer) {
79+
for (IBreakpoint bp : breakPointContainer.getBreakpoints()) {
80+
if (bp.isEnabled()) {
81+
excludedBreakpoints.add(bp);
82+
}
83+
}
84+
}
85+
}
86+
for (IBreakpoint brk : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints()) {
87+
if (!excludedBreakpoints.contains(brk)) {
88+
brk.setEnabled(false);
89+
}
90+
}
91+
92+
} catch (CoreException e) {
93+
ms.merge(e.getStatus());
94+
}
95+
};
96+
97+
try {
98+
ResourcesPlugin.getWorkspace().run(runnable, null, 0, new NullProgressMonitor());
99+
} catch (CoreException e) {
100+
DebugUIPlugin.log(e);
101+
}
102+
103+
if (!ms.isOK()) {
104+
IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow();
105+
if (window != null) {
106+
DebugUIPlugin.errorDialog(window.getShell(),
107+
ActionMessages.EnableBreakpointAction_Enabling_breakpoints_3,
108+
ActionMessages.EnableBreakpointAction_Exceptions_occurred_enabling_the_breakpoint_s___4, ms); //
109+
} else {
110+
DebugUIPlugin.log(ms);
111+
}
112+
}
113+
}
114+
}

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)