Skip to content

Commit

Permalink
Clear all conditions in breakpoints eclipse-jdt#549
Browse files Browse the repository at this point in the history
Provides additional right click menu option for removing all the
conditions set in breakpoints. Will be useful for clearing all the
conditions in breakpoints at once.

Enhancement eclipse-jdt#549
  • Loading branch information
SougandhS committed Oct 29, 2024
1 parent b47a6d2 commit d5623bc
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 6 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions org.eclipse.jdt.debug.ui/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,5 @@ OpenFromClipboardAction.description = Opens a Java element or a Java stack trace
OpenFromClipboardAction.name = Open from Clipboard

VariablesView.name = Variables

RemoveAllConditions.label = Remove All Conditions
17 changes: 16 additions & 1 deletion org.eclipse.jdt.debug.ui/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<!--
Copyright (c) 2005, 2022 IBM Corporation and others.
Copyright (c) 2005, 2024 IBM Corporation and others.
This program and the accompanying materials
are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -3865,6 +3865,21 @@ M4 = Platform-specific fourth key
type="org.eclipse.swt.widgets.Composite"
description="%descriptionSWTComposite"/>
</extension>
<extension
point="org.eclipse.ui.popupMenus">
<viewerContribution
targetID="org.eclipse.debug.ui.BreakpointView"
id="org.eclipse.jdt.debug.ui.removeAllConditions">
<action
label="%RemoveAllConditions.label"
helpContextId="remove_all_breakpoints_action_context"
icon="$nl$/icons/full/elcl16/removeAllConditions.png"
class="org.eclipse.jdt.internal.debug.ui.actions.RemoveAllCondtionalBreakpoints"
menubarPath="breakpointGroupJava"
id="org.eclipse.jdt.internal.debug.ui.RemoveAction">
</action>
</viewerContribution>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2008 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -117,4 +117,9 @@ public interface IJavaDebugUIConstants {
*/
public static final String PREF_ALLREFERENCES_MAX_COUNT = PLUGIN_ID + ".all_references_max_count"; //$NON-NLS-1$

/**
* @since 3.13
*/
public static final String PREF_PROMPT_REMOVE_ALL_CONDITIONAL_BREAKPOINTS = PLUGIN_ID + ".remove_all_conditional_breakpoints_prompt"; //$NON-NLS-1$

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2020 IBM Corporation and others.
* Copyright (c) 2004, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -64,6 +64,7 @@ public void initializeDefaultPreferences() {
store.setDefault(IJDIPreferencesConstants.PREF_OPEN_INSPECT_POPUP_ON_EXCEPTION, false);
store.setDefault(IJavaDebugUIConstants.PREF_ALLINSTANCES_MAX_COUNT, 100);
store.setDefault(IJavaDebugUIConstants.PREF_ALLREFERENCES_MAX_COUNT, 100);
store.setDefault(IJavaDebugUIConstants.PREF_PROMPT_REMOVE_ALL_CONDITIONAL_BREAKPOINTS, true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2022 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -176,6 +176,10 @@ public class ActionMessages extends NLS {
public static String Override_Dependencies_label1;
public static String Override_Dependencies_label2;

public static String RemoveAllCondtionalBreakpointsAction_0;
public static String RemoveAllCondtionalBreakpointsAction_1;
public static String RemoveAllCondtionalBreakpointsAction_2;

static {
// load message values from bundle file
NLS.initializeMessages(BUNDLE_NAME, ActionMessages.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2000, 2022 IBM Corporation and others.
# Copyright (c) 2000, 2024 IBM Corporation and others.
#
# This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -154,4 +154,7 @@ Override_Dependencies_title=Override Dependencies
Override_Dependencies_button=&Override
Override_Dependencies_button1=&Override Dependencies...
Override_Dependencies_label1=Dependencies derived from the Java Build Path:
Override_Dependencies_label2=Dependencies for launching:
Override_Dependencies_label2=Dependencies for launching:
RemoveAllCondtionalBreakpointsAction_0=Clear All Conditions
RemoveAllCondtionalBreakpointsAction_1=Clear all conditions ?
RemoveAllCondtionalBreakpointsAction_2=&Do not ask me again.
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation.
*
* 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 - Initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.debug.ui.actions;

import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
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.model.IBreakpoint;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.internal.ui.actions.breakpoints.RemoveAllTriggerPointsAction;
import org.eclipse.jdt.debug.ui.IJavaDebugUIConstants;
import org.eclipse.jdt.internal.debug.core.breakpoints.JavaLineBreakpoint;
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
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 RemoveAllCondtionalBreakpoints extends RemoveAllTriggerPointsAction {
public RemoveAllCondtionalBreakpoints() {
super();
}
@Override
protected boolean isEnabled() {
for (IBreakpoint breakpoint : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints()) {
if (breakpoint instanceof JavaLineBreakpoint javaBreakpoint) {
try {
if (javaBreakpoint.isConditionEnabled()) {
return true;
}
} catch (CoreException e) {
DebugUIPlugin.log(e);
}
}
}
return false;
}

@Override
public void run(IAction action) {
IWorkbenchWindow window = JDIDebugUIPlugin.getActiveWorkbenchWindow();
if (window == null) {
return;
}
IPreferenceStore store = JDIDebugUIPlugin.getDefault().getPreferenceStore();
boolean prompt = store.getBoolean(IJavaDebugUIConstants.PREF_PROMPT_REMOVE_ALL_CONDITIONAL_BREAKPOINTS);
boolean proceed = true;
if (prompt) {
MessageDialogWithToggle mdwt = MessageDialogWithToggle.openYesNoQuestion(window.getShell(), ActionMessages.RemoveAllCondtionalBreakpointsAction_0, ActionMessages.RemoveAllCondtionalBreakpointsAction_1, ActionMessages.RemoveAllCondtionalBreakpointsAction_2, !prompt, null, null);
if (mdwt.getReturnCode() != IDialogConstants.YES_ID) {
proceed = false;
} else {
store.setValue(IJavaDebugUIConstants.PREF_PROMPT_REMOVE_ALL_CONDITIONAL_BREAKPOINTS, !mdwt.getToggleState());
}
}
if (proceed) {
new Job(ActionMessages.RemoveAllCondtionalBreakpointsAction_1) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
for (IBreakpoint breakpoint : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints()) {
if (breakpoint instanceof JavaLineBreakpoint javaBp) {
if (javaBp.isConditionEnabled()) {
javaBp.setConditionEnabled(false);
}
}
}
refreshAllBreakpoints();
} catch (Exception e) {
DebugUIPlugin.log(e);
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
}.schedule();
}
}

private void refreshAllBreakpoints() {
IWorkspaceRunnable runnable = monitor -> {
for (IBreakpoint breakpoint : DebugPlugin.getDefault().getBreakpointManager().getBreakpoints()) {
try {
breakpoint.getMarker().setAttribute(IBreakpoint.ENABLED, breakpoint.isEnabled());
} catch (CoreException e) {
DebugPlugin.log(e);
}
}
};
try {
ResourcesPlugin.getWorkspace().run(runnable, null, IWorkspace.AVOID_UPDATE, null);
} catch (CoreException e) {
DebugPlugin.log(e);
}
}

}

0 comments on commit d5623bc

Please sign in to comment.