Skip to content

Commit ea7fa2a

Browse files
SougandhSjukzi
authored andcommitted
Breakpoint Enable All feature + Code review changes
1 parent cfe87a1 commit ea7fa2a

File tree

8 files changed

+244
-1
lines changed

8 files changed

+244
-1
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+
EnableAllBreakpointsAction.label=Ena&ble All
8687
EnableBreakpointsAction.label=&Enable
8788
ExpandAll.label=Expand All
8889
ExpandAll.tooltip=Expand All

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,14 @@
15571557
enablesFor="+"
15581558
id="org.eclipse.debug.ui.actions.DisableBreakpoint">
15591559
</action>
1560+
<action
1561+
label="%EnableAllBreakpointsAction.label"
1562+
icon="$nl$/icons/full/elcl16/enabled_co.png"
1563+
helpContextId="disable_breakpoint_action_context"
1564+
class="org.eclipse.debug.internal.ui.actions.breakpoints.EnableAllBreakpointsAction"
1565+
menubarPath="breakpointGroup"
1566+
id="org.eclipse.debug.ui.actions.EnableAllBreakpoint">
1567+
</action>
15601568
<action
15611569
label="%EnableBreakpointsAction.label"
15621570
icon="$nl$/icons/full/elcl16/enabled_co.png"

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/DebugUIPreferenceInitializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public void initializeDefaultPreferences() {
5555
prefs.setDefault(IDebugPreferenceConstants.PREF_PROMPT_REMOVE_BREAKPOINTS_FROM_CONTAINER, true);
5656
prefs.setDefault(IDebugPreferenceConstants.PREF_PROMPT_REMOVE_ALL_EXPRESSIONS, true);
5757
prefs.setDefault(IDebugPreferenceConstants.PREF_PROMPT_DISABLE_ALL_BREAKPOINTS, true);
58+
prefs.setDefault(IDebugPreferenceConstants.PREF_PROMPT_ENABLE_ALL_BREAKPOINTS, true);
5859

5960
/**
6061
* Context launching preferences. Appear on the the Launching preference page
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 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;
15+
16+
import org.eclipse.jface.action.IAction;
17+
import org.eclipse.jface.viewers.ISelection;
18+
import org.eclipse.swt.widgets.Event;
19+
import org.eclipse.ui.IActionDelegate2;
20+
import org.eclipse.ui.IViewActionDelegate;
21+
import org.eclipse.ui.IViewPart;
22+
import org.eclipse.ui.IWorkbenchWindow;
23+
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
24+
25+
public abstract class AbstractEnableAllActionDelegate
26+
implements IViewActionDelegate, IActionDelegate2, IWorkbenchWindowActionDelegate {
27+
28+
private IAction fAction;
29+
30+
/**
31+
* Needed for reflective creation
32+
*/
33+
34+
@Override
35+
public void dispose() {
36+
fAction = null;
37+
}
38+
39+
@Override
40+
public void init(IAction action) {
41+
fAction = action;
42+
}
43+
44+
/**
45+
* Returns this delegate's action.
46+
*
47+
* @return the underlying <code>IAction</code>
48+
*/
49+
protected IAction getAction() {
50+
return fAction;
51+
}
52+
53+
@Override
54+
public void runWithEvent(IAction action, Event event) {
55+
run(action);
56+
}
57+
58+
@Override
59+
public void init(IViewPart view) {
60+
initialize();
61+
update();
62+
}
63+
64+
@Override
65+
public void init(IWorkbenchWindow window) {
66+
initialize();
67+
update();
68+
}
69+
70+
/**
71+
* Initializes any listeners, etc.
72+
*/
73+
protected abstract void initialize();
74+
75+
/**
76+
* Update enablement.
77+
*/
78+
protected void update() {
79+
IAction action = getAction();
80+
if (action != null) {
81+
action.setEnabled(isEnabled());
82+
}
83+
}
84+
85+
@Override
86+
public void selectionChanged(IAction action, ISelection s) {
87+
// do nothing
88+
}
89+
90+
@Override
91+
public void run(IAction action) {
92+
93+
}
94+
95+
protected abstract boolean isEnabled();
96+
97+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
public class ActionMessages extends NLS {
2020
private static final String BUNDLE_NAME = "org.eclipse.debug.internal.ui.actions.ActionMessages";//$NON-NLS-1$
21-
2221
public static String AbstractLaunchHistoryAction_0;
2322
public static String AbstractLaunchHistoryAction_1;
2423
public static String AbstractLaunchHistoryAction_2;
@@ -250,4 +249,7 @@ public class ActionMessages extends NLS {
250249

251250
public static String ToggleBreakpointsTargetManager_defaultToggleTarget_name;
252251
public static String ToggleBreakpointsTargetManager_defaultToggleTarget_description;
252+
public static String EnableAllBreakpointsAction_0;
253+
public static String EnableAllBreakpointsAction_1;
254+
public static String EnableAllBreakpointsAction_3;
253255
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ OpenBreakpointMarkerAction_Go_to_File_for_Breakpoint_2=Go to File for Breakpoint
4646
RelaunchActionDelegate_An_exception_occurred_while_launching_2=An exception occurred while launching
4747
RelaunchActionDelegate_Launch_Failed_1=Launch Failed
4848

49+
EnableAllBreakpointsAction_0=Enable All Breakpoints
50+
EnableAllBreakpointsAction_1=Enable All Breakpoints?
51+
EnableAllBreakpointsAction_3=&Do not ask me again.
52+
4953
RemoveAllBreakpointsAction_0=Remove All Breakpoints
5054
RemoveAllBreakpointsAction_1=Remove all breakpoints?
5155
RemoveAllBreakpointsAction_2=Remove Breakpoints
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 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 org.eclipse.core.resources.IMarkerDelta;
17+
import org.eclipse.core.runtime.CoreException;
18+
import org.eclipse.core.runtime.IProgressMonitor;
19+
import org.eclipse.core.runtime.IStatus;
20+
import org.eclipse.core.runtime.Status;
21+
import org.eclipse.core.runtime.jobs.Job;
22+
import org.eclipse.debug.core.DebugPlugin;
23+
import org.eclipse.debug.core.IBreakpointManager;
24+
import org.eclipse.debug.core.IBreakpointsListener;
25+
import org.eclipse.debug.core.model.IBreakpoint;
26+
import org.eclipse.debug.internal.ui.DebugUIPlugin;
27+
import org.eclipse.debug.internal.ui.actions.AbstractEnableAllActionDelegate;
28+
import org.eclipse.debug.internal.ui.actions.ActionMessages;
29+
import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants;
30+
import org.eclipse.jface.action.IAction;
31+
import org.eclipse.jface.dialogs.IDialogConstants;
32+
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
33+
import org.eclipse.jface.preference.IPreferenceStore;
34+
import org.eclipse.ui.IWorkbenchWindow;
35+
36+
public class EnableAllBreakpointsAction extends AbstractEnableAllActionDelegate implements IBreakpointsListener {
37+
38+
@Override
39+
protected boolean isEnabled() {
40+
boolean allEnabled = true;
41+
IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
42+
IBreakpoint[] breakpoints = breakpointManager.getBreakpoints();
43+
44+
for (IBreakpoint bp : breakpoints) {
45+
try {
46+
if (!bp.isEnabled()) {
47+
allEnabled = false;
48+
break;
49+
}
50+
} catch (CoreException e) {
51+
DebugUIPlugin.log(e);
52+
}
53+
}
54+
if (breakpoints.length > 0 && allEnabled) {
55+
return false;
56+
}
57+
return true;
58+
}
59+
60+
@Override
61+
public void breakpointsAdded(IBreakpoint[] breakpoints) {
62+
update();
63+
}
64+
65+
@Override
66+
public void breakpointsChanged(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) {
67+
update();
68+
}
69+
70+
@Override
71+
public void breakpointsRemoved(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) {
72+
if (getAction() != null) {
73+
update();
74+
}
75+
}
76+
77+
@Override
78+
protected void initialize() {
79+
DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this);
80+
}
81+
82+
@Override
83+
public void dispose() {
84+
DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(this);
85+
super.dispose();
86+
}
87+
88+
@Override
89+
public void run(IAction action) {
90+
IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
91+
IBreakpoint[] breakpoints = breakpointManager.getBreakpoints();
92+
if (breakpoints.length < 1) {
93+
return;
94+
}
95+
IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow();
96+
if (window == null) {
97+
return;
98+
}
99+
IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
100+
boolean prompt = store.getBoolean(IDebugPreferenceConstants.PREF_PROMPT_ENABLE_ALL_BREAKPOINTS);
101+
boolean proceed = true;
102+
if (prompt) {
103+
MessageDialogWithToggle mdwt = MessageDialogWithToggle.openYesNoQuestion(window.getShell(),
104+
ActionMessages.EnableAllBreakpointsAction_0, ActionMessages.EnableAllBreakpointsAction_1,
105+
ActionMessages.EnableAllBreakpointsAction_3, !prompt, null, null);
106+
if (mdwt.getReturnCode() != IDialogConstants.YES_ID) {
107+
proceed = false;
108+
} else {
109+
store.setValue(IDebugPreferenceConstants.PREF_PROMPT_ENABLE_ALL_BREAKPOINTS, !mdwt.getToggleState());
110+
}
111+
}
112+
if (proceed) {
113+
new Job(ActionMessages.EnableAllBreakpointsAction_1) {
114+
@Override
115+
protected IStatus run(IProgressMonitor monitor) {
116+
try {
117+
for (IBreakpoint breakpoint : breakpoints) {
118+
breakpoint.setEnabled(true);
119+
}
120+
} catch (CoreException e) {
121+
DebugUIPlugin.log(e);
122+
return Status.CANCEL_STATUS;
123+
}
124+
return Status.OK_STATUS;
125+
}
126+
}.schedule();
127+
}
128+
}
129+
}

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/preferences/IDebugPreferenceConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ public interface IDebugPreferenceConstants {
187187
*
188188
* @since 3.15
189189
*/
190+
String PREF_PROMPT_ENABLE_ALL_BREAKPOINTS = IDebugUIConstants.PLUGIN_ID + ".enable_all_breakpoints_prompt"; //$NON-NLS-1$
190191
String PREF_PROMPT_DISABLE_ALL_BREAKPOINTS = IDebugUIConstants.PLUGIN_ID + ".disable_all_breakpoints_prompt"; //$NON-NLS-1$
191192

192193
/**

0 commit comments

Comments
 (0)