diff --git a/org.eclipse.jdt.debug.ui/icons/full/elcl16/disable_conditional_breakpoints.png b/org.eclipse.jdt.debug.ui/icons/full/elcl16/disable_conditional_breakpoints.png new file mode 100644 index 0000000000..dd38fefd5a Binary files /dev/null and b/org.eclipse.jdt.debug.ui/icons/full/elcl16/disable_conditional_breakpoints.png differ diff --git a/org.eclipse.jdt.debug.ui/plugin.properties b/org.eclipse.jdt.debug.ui/plugin.properties index 805de3ad88..a8379e5a5d 100644 --- a/org.eclipse.jdt.debug.ui/plugin.properties +++ b/org.eclipse.jdt.debug.ui/plugin.properties @@ -339,4 +339,5 @@ OpenFromClipboardAction.name = Open from Clipboard VariablesView.name = Variables CompareObjects.label=Compare -CompareObjects.tooltip=Compare selected objects \ No newline at end of file +CompareObjects.tooltip=Compare selected objects +DisableConditionalBreakpoints.label = Disable Conditional Breakpoints \ No newline at end of file diff --git a/org.eclipse.jdt.debug.ui/plugin.xml b/org.eclipse.jdt.debug.ui/plugin.xml index c68914fc4c..004e6b9bcd 100644 --- a/org.eclipse.jdt.debug.ui/plugin.xml +++ b/org.eclipse.jdt.debug.ui/plugin.xml @@ -3899,6 +3899,21 @@ M4 = Platform-specific fourth key type="org.eclipse.swt.widgets.Composite" description="%descriptionSWTComposite"/> + + + + + + IAction + */ + private IAction fAction; + + /** + * Needed for reflective creation + */ + public AbstractDisableAllActionDelegate() { + } + + @Override + public void dispose() { + fAction = null; + } + + @Override + public void init(IAction action) { + fAction = action; + } + + /** + * Returns this delegate's action. + * + * @return the underlying IAction + */ + 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()); + } + } + + /** + * Returns whether this action is enabled + * + * @return true if this action is enabled, false otherwise + */ + protected abstract boolean isEnabled(); + + @Override + public void selectionChanged(IAction action, ISelection s) { + + } + +} diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.java index 61fe1daff8..c756586007 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.java +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.java @@ -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 @@ -175,6 +175,7 @@ public class ActionMessages extends NLS { public static String Override_Dependencies_button1; public static String Override_Dependencies_label1; public static String Override_Dependencies_label2; + public static String DisableConditionalBreakpoints_1; static { // load message values from bundle file diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.properties b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.properties index d1ad471931..adc2a6aeee 100644 --- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.properties +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/ActionMessages.properties @@ -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 @@ -154,4 +154,5 @@ 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: \ No newline at end of file +Override_Dependencies_label2=Dependencies for launching: +DisableConditionalBreakpoints_1=Disable Conditional Breakpoints \ No newline at end of file diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/DisableCondtionalBreakpoints.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/DisableCondtionalBreakpoints.java new file mode 100644 index 0000000000..28791b4132 --- /dev/null +++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/actions/DisableCondtionalBreakpoints.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2025 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.IMarkerDelta; +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.IBreakpointsListener; +import org.eclipse.debug.core.model.IBreakpoint; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.jdt.internal.debug.core.breakpoints.JavaLineBreakpoint; +import org.eclipse.jface.action.IAction; + +public class DisableCondtionalBreakpoints extends AbstractDisableAllActionDelegate implements IBreakpointsListener { + public DisableCondtionalBreakpoints() { + 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) { + + new Job(ActionMessages.DisableConditionalBreakpoints_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 { + if (breakpoint instanceof JavaLineBreakpoint javaLB) { + javaLB.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); + } + } + + @Override + protected void initialize() { + DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this); + } + + @Override + public void breakpointsAdded(IBreakpoint[] breakpoints) { + update(); + } + + @Override + public void breakpointsRemoved(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) { + if (getAction() != null) { + update(); + } + } + + @Override + public void breakpointsChanged(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) { + update(); + } + + @Override + public void dispose() { + DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(this); + super.dispose(); + } + +}