Skip to content

Commit

Permalink
Breakpoint Enable All feature + Code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SougandhS authored and jukzi committed Sep 12, 2024
1 parent cfe87a1 commit ea7fa2a
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 1 deletion.
1 change: 1 addition & 0 deletions debug/org.eclipse.debug.ui/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ DetailPaneFontDefinition.description=The detail pane text font is used in the de
DetailPaneFactoriesExtension.name=Detail Pane Factories
DisableBreakpointsAction.label=&Disable
DisableAllBreakpointsAction.label=Disa&ble All
EnableAllBreakpointsAction.label=Ena&ble All
EnableBreakpointsAction.label=&Enable
ExpandAll.label=Expand All
ExpandAll.tooltip=Expand All
Expand Down
8 changes: 8 additions & 0 deletions debug/org.eclipse.debug.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,14 @@
enablesFor="+"
id="org.eclipse.debug.ui.actions.DisableBreakpoint">
</action>
<action
label="%EnableAllBreakpointsAction.label"
icon="$nl$/icons/full/elcl16/enabled_co.png"
helpContextId="disable_breakpoint_action_context"
class="org.eclipse.debug.internal.ui.actions.breakpoints.EnableAllBreakpointsAction"
menubarPath="breakpointGroup"
id="org.eclipse.debug.ui.actions.EnableAllBreakpoint">
</action>
<action
label="%EnableBreakpointsAction.label"
icon="$nl$/icons/full/elcl16/enabled_co.png"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void initializeDefaultPreferences() {
prefs.setDefault(IDebugPreferenceConstants.PREF_PROMPT_REMOVE_BREAKPOINTS_FROM_CONTAINER, true);
prefs.setDefault(IDebugPreferenceConstants.PREF_PROMPT_REMOVE_ALL_EXPRESSIONS, true);
prefs.setDefault(IDebugPreferenceConstants.PREF_PROMPT_DISABLE_ALL_BREAKPOINTS, true);
prefs.setDefault(IDebugPreferenceConstants.PREF_PROMPT_ENABLE_ALL_BREAKPOINTS, true);

/**
* Context launching preferences. Appear on the the Launching preference page
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.debug.internal.ui.actions;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Event;
import org.eclipse.ui.IActionDelegate2;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;

public abstract class AbstractEnableAllActionDelegate
implements IViewActionDelegate, IActionDelegate2, IWorkbenchWindowActionDelegate {

private IAction fAction;

/**
* Needed for reflective creation
*/

@Override
public void dispose() {
fAction = null;
}

@Override
public void init(IAction action) {
fAction = action;
}

/**
* Returns this delegate's action.
*
* @return the underlying <code>IAction</code>
*/
protected IAction getAction() {
return fAction;
}

@Override
public void runWithEvent(IAction action, Event event) {
run(action);
}

@Override
public void init(IViewPart view) {
initialize();
update();
}

@Override
public void init(IWorkbenchWindow window) {
initialize();
update();
}

/**
* Initializes any listeners, etc.
*/
protected abstract void initialize();

/**
* Update enablement.
*/
protected void update() {
IAction action = getAction();
if (action != null) {
action.setEnabled(isEnabled());
}
}

@Override
public void selectionChanged(IAction action, ISelection s) {
// do nothing
}

@Override
public void run(IAction action) {

}

protected abstract boolean isEnabled();

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

public class ActionMessages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.debug.internal.ui.actions.ActionMessages";//$NON-NLS-1$

public static String AbstractLaunchHistoryAction_0;
public static String AbstractLaunchHistoryAction_1;
public static String AbstractLaunchHistoryAction_2;
Expand Down Expand Up @@ -250,4 +249,7 @@ public class ActionMessages extends NLS {

public static String ToggleBreakpointsTargetManager_defaultToggleTarget_name;
public static String ToggleBreakpointsTargetManager_defaultToggleTarget_description;
public static String EnableAllBreakpointsAction_0;
public static String EnableAllBreakpointsAction_1;
public static String EnableAllBreakpointsAction_3;
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ OpenBreakpointMarkerAction_Go_to_File_for_Breakpoint_2=Go to File for Breakpoint
RelaunchActionDelegate_An_exception_occurred_while_launching_2=An exception occurred while launching
RelaunchActionDelegate_Launch_Failed_1=Launch Failed

EnableAllBreakpointsAction_0=Enable All Breakpoints
EnableAllBreakpointsAction_1=Enable All Breakpoints?
EnableAllBreakpointsAction_3=&Do not ask me again.

RemoveAllBreakpointsAction_0=Remove All Breakpoints
RemoveAllBreakpointsAction_1=Remove all breakpoints?
RemoveAllBreakpointsAction_2=Remove Breakpoints
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.debug.internal.ui.actions.breakpoints;

import org.eclipse.core.resources.IMarkerDelta;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.IBreakpointManager;
import org.eclipse.debug.core.IBreakpointsListener;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.actions.AbstractEnableAllActionDelegate;
import org.eclipse.debug.internal.ui.actions.ActionMessages;
import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.IWorkbenchWindow;

public class EnableAllBreakpointsAction extends AbstractEnableAllActionDelegate implements IBreakpointsListener {

@Override
protected boolean isEnabled() {
boolean allEnabled = true;
IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
IBreakpoint[] breakpoints = breakpointManager.getBreakpoints();

for (IBreakpoint bp : breakpoints) {
try {
if (!bp.isEnabled()) {
allEnabled = false;
break;
}
} catch (CoreException e) {
DebugUIPlugin.log(e);
}
}
if (breakpoints.length > 0 && allEnabled) {
return false;
}
return true;
}

@Override
public void breakpointsAdded(IBreakpoint[] breakpoints) {
update();
}

@Override
public void breakpointsChanged(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) {
update();
}

@Override
public void breakpointsRemoved(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) {
if (getAction() != null) {
update();
}
}

@Override
protected void initialize() {
DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this);
}

@Override
public void dispose() {
DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(this);
super.dispose();
}

@Override
public void run(IAction action) {
IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
IBreakpoint[] breakpoints = breakpointManager.getBreakpoints();
if (breakpoints.length < 1) {
return;
}
IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow();
if (window == null) {
return;
}
IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
boolean prompt = store.getBoolean(IDebugPreferenceConstants.PREF_PROMPT_ENABLE_ALL_BREAKPOINTS);
boolean proceed = true;
if (prompt) {
MessageDialogWithToggle mdwt = MessageDialogWithToggle.openYesNoQuestion(window.getShell(),
ActionMessages.EnableAllBreakpointsAction_0, ActionMessages.EnableAllBreakpointsAction_1,
ActionMessages.EnableAllBreakpointsAction_3, !prompt, null, null);
if (mdwt.getReturnCode() != IDialogConstants.YES_ID) {
proceed = false;
} else {
store.setValue(IDebugPreferenceConstants.PREF_PROMPT_ENABLE_ALL_BREAKPOINTS, !mdwt.getToggleState());
}
}
if (proceed) {
new Job(ActionMessages.EnableAllBreakpointsAction_1) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
for (IBreakpoint breakpoint : breakpoints) {
breakpoint.setEnabled(true);
}
} catch (CoreException e) {
DebugUIPlugin.log(e);
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
}.schedule();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public interface IDebugPreferenceConstants {
*
* @since 3.15
*/
String PREF_PROMPT_ENABLE_ALL_BREAKPOINTS = IDebugUIConstants.PLUGIN_ID + ".enable_all_breakpoints_prompt"; //$NON-NLS-1$
String PREF_PROMPT_DISABLE_ALL_BREAKPOINTS = IDebugUIConstants.PLUGIN_ID + ".disable_all_breakpoints_prompt"; //$NON-NLS-1$

/**
Expand Down

0 comments on commit ea7fa2a

Please sign in to comment.