Skip to content

Commit 1469e17

Browse files
committed
Add support for custom labels on breakpoints
This commit introduces the ability for users to set custom labels on breakpoints, making it easier to identify and differentiate them. Additionally, breakpoints with custom labels are visually highlighted, improving workflow and debugging efficiency.
1 parent 9e339b2 commit 1469e17

File tree

10 files changed

+200
-6
lines changed

10 files changed

+200
-6
lines changed

debug/org.eclipse.debug.core/core/org/eclipse/debug/core/model/Breakpoint.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2016 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -45,7 +45,6 @@
4545

4646
public abstract class Breakpoint extends PlatformObject implements IBreakpoint, ITriggerPoint {
4747

48-
4948
/**
5049
* Creates a breakpoint.
5150
*
@@ -384,4 +383,12 @@ public String toString() {
384383
return builder.toString();
385384
}
386385

386+
public String getBreakpointLabel() {
387+
return getMarker().getAttribute(LABEL, ""); //$NON-NLS-1$
388+
}
389+
390+
public void setBreakpointLabel(String label) throws CoreException {
391+
setAttribute(LABEL, label);
392+
}
393+
387394
}

debug/org.eclipse.debug.core/core/org/eclipse/debug/core/model/IBreakpoint.java

+10
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ public interface IBreakpoint extends IAdaptable {
119119
*/
120120
String PERSISTED= "org.eclipse.debug.core.persisted"; //$NON-NLS-1$
121121

122+
/**
123+
* Persisted breakpoint marker attribute (value
124+
* <code>"org.eclipse.debug.core.label"</code>). The attribute is a
125+
* <code>String</code> corresponding to whether a breakpoint's custom label
126+
* for easier identification
127+
*
128+
* @see org.eclipse.core.resources.IMarker#getAttribute(String, String)
129+
*/
130+
String LABEL = "org.eclipse.debug.core.label"; //$NON-NLS-1$
131+
122132
/**
123133
* Deletes this breakpoint's underlying marker, and removes
124134
* this breakpoint from the breakpoint manager.
Loading

debug/org.eclipse.debug.ui/plugin.properties

+1
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,4 @@ debug.core.component.label = Platform Debug Core
418418
GroupLaunch.description=Launch several other configurations sequentially
419419

420420
prototype.decorator.label = Prototype Decorator
421+
breakpointLabel.label=Label

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

+9
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,15 @@
15401540
enablesFor="+"
15411541
id="org.eclipse.debug.ui.breakpointsView.toolbar.remove">
15421542
</action>
1543+
<action
1544+
label="%breakpointLabel.label"
1545+
icon="$nl$/icons/full/elcl16/bp_label.png"
1546+
helpContextId="remove_breakpoint_action_context"
1547+
class="org.eclipse.debug.internal.ui.actions.breakpoints.BreakpointLabelAction"
1548+
menubarPath="breakpointGroup"
1549+
enablesFor="1"
1550+
id="org.eclipse.debug.ui.breakpointsView.breakpointLabel">
1551+
</action>
15431552
<action
15441553
label="%DisableAllBreakpointsAction.label"
15451554
icon="$nl$/icons/full/elcl16/disabled_co.png"

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2020 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -252,4 +252,9 @@ public class ActionMessages extends NLS {
252252
public static String EnableAllBreakpointsAction_0;
253253
public static String EnableAllBreakpointsAction_1;
254254
public static String EnableAllBreakpointsAction_3;
255+
public static String BreakpointLabelTitle;
256+
public static String BreakpointLabelDialog;
257+
public static String BreakpointLabelRemove;
258+
public static String BreakpointLabelValid;
259+
255260
}

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###############################################################################
2-
# Copyright (c) 2000, 2020 IBM Corporation and others.
2+
# Copyright (c) 2000, 2025 IBM Corporation and others.
33
#
44
# This program and the accompanying materials
55
# are made available under the terms of the Eclipse Public License 2.0
@@ -235,4 +235,8 @@ VirtualFindAction_0=Error
235235
VirtualFindAction_1=Unable to locate {0} in viewer
236236

237237
ToggleBreakpointsTargetManager_defaultToggleTarget_name = Default
238-
ToggleBreakpointsTargetManager_defaultToggleTarget_description = Default
238+
ToggleBreakpointsTargetManager_defaultToggleTarget_description = Default
239+
BreakpointLabelTitle=Set Breakpoint Label
240+
BreakpointLabelDialog=A custom label to make breakpoint easily distinguishable
241+
BreakpointLabelRemove=Remove
242+
BreakpointLabelValid=Label should contain valid characters
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 IBM Corporation
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.runtime.CoreException;
17+
import org.eclipse.debug.core.model.Breakpoint;
18+
import org.eclipse.debug.internal.ui.DebugUIPlugin;
19+
import org.eclipse.debug.internal.ui.actions.ActionMessages;
20+
import org.eclipse.jface.action.IAction;
21+
import org.eclipse.jface.dialogs.IDialogConstants;
22+
import org.eclipse.jface.dialogs.IInputValidator;
23+
import org.eclipse.jface.dialogs.InputDialog;
24+
import org.eclipse.jface.viewers.ISelection;
25+
import org.eclipse.jface.viewers.IStructuredSelection;
26+
import org.eclipse.jface.window.Window;
27+
import org.eclipse.swt.events.SelectionAdapter;
28+
import org.eclipse.swt.events.SelectionEvent;
29+
import org.eclipse.swt.widgets.Button;
30+
import org.eclipse.swt.widgets.Composite;
31+
import org.eclipse.swt.widgets.Shell;
32+
import org.eclipse.ui.IViewActionDelegate;
33+
import org.eclipse.ui.IViewPart;
34+
35+
public class BreakpointLabelAction implements IViewActionDelegate {
36+
37+
private IViewPart fView;
38+
39+
protected IViewPart getView() {
40+
return fView;
41+
}
42+
43+
protected void setView(IViewPart view) {
44+
fView = view;
45+
}
46+
47+
@Override
48+
public void run(IAction action) {
49+
IStructuredSelection selection = getSelection();
50+
if (selection.getFirstElement() instanceof Breakpoint bp) {
51+
String label = askForLabel(bp);
52+
if (!label.isEmpty()) {
53+
try {
54+
bp.setBreakpointLabel(label);
55+
} catch (CoreException e) {
56+
DebugUIPlugin.log(e);
57+
}
58+
}
59+
}
60+
}
61+
62+
protected IStructuredSelection getSelection() {
63+
return (IStructuredSelection) getView().getViewSite().getSelectionProvider().getSelection();
64+
}
65+
66+
@Override
67+
public void selectionChanged(IAction action, ISelection selection) {
68+
}
69+
70+
@Override
71+
public void init(IViewPart view) {
72+
setView(view);
73+
}
74+
75+
private String askForLabel(Breakpoint breakpoint) {
76+
String current = breakpoint.getBreakpointLabel();
77+
class CustomInputDialog extends InputDialog {
78+
public CustomInputDialog(Shell parentShell, String dialogTitle, String dialogMessage, String initialValue,
79+
IInputValidator validator) {
80+
super(parentShell, dialogTitle, dialogMessage, initialValue, validator);
81+
}
82+
@Override
83+
protected void createButtonsForButtonBar(Composite parent) {
84+
super.createButtonsForButtonBar(parent);
85+
Button removeButton = createButton(parent, IDialogConstants.CANCEL_ID,
86+
ActionMessages.BreakpointLabelRemove, false);
87+
boolean buttonEnable = false;
88+
if (!breakpoint.getBreakpointLabel().isEmpty()) {
89+
buttonEnable = true;
90+
}
91+
removeButton.setEnabled(buttonEnable);
92+
removeButton.addSelectionListener(new SelectionAdapter() {
93+
@Override
94+
public void widgetSelected(SelectionEvent e) {
95+
try {
96+
breakpoint.setBreakpointLabel("");//$NON-NLS-1$
97+
buttonPressed(IDialogConstants.CANCEL_ID);
98+
} catch (CoreException e1) {
99+
DebugUIPlugin.log(e1);
100+
}
101+
}
102+
});
103+
}
104+
}
105+
IInputValidator validator = value -> {
106+
if (value.isBlank() || value.isEmpty()) {
107+
return ActionMessages.BreakpointLabelValid;
108+
}
109+
return null;
110+
};
111+
CustomInputDialog dialog = new CustomInputDialog(fView.getSite().getShell(),
112+
ActionMessages.BreakpointLabelTitle, ActionMessages.BreakpointLabelDialog,
113+
current, validator);
114+
115+
if (dialog.open() != Window.OK) {
116+
return ""; //$NON-NLS-1$
117+
}
118+
String data = dialog.getValue();
119+
return data.trim();
120+
}
121+
122+
}

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/model/elements/BreakpointLabelProvider.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*****************************************************************
2-
* Copyright (c) 2009, 2010 Texas Instruments and others
2+
* Copyright (c) 2009, 2025 Texas Instruments and others
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -15,6 +15,7 @@
1515
package org.eclipse.debug.internal.ui.model.elements;
1616

1717
import org.eclipse.core.runtime.CoreException;
18+
import org.eclipse.debug.core.model.Breakpoint;
1819
import org.eclipse.debug.core.model.IBreakpoint;
1920
import org.eclipse.debug.internal.core.IInternalDebugCoreConstants;
2021
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
@@ -31,6 +32,20 @@ public class BreakpointLabelProvider extends DebugElementLabelProvider {
3132
@Override
3233
protected String getLabel(TreePath elementPath, IPresentationContext presentationContext, String columnId, int columnIndex) throws CoreException {
3334
if (columnIndex == 0) {
35+
if (elementPath.getFirstSegment() instanceof Breakpoint breakpoint) {
36+
String current = super.getLabel(elementPath, presentationContext, columnId, columnIndex);
37+
if (!breakpoint.getBreakpointLabel().isEmpty()) {
38+
String[] currentElements = current.split(" "); //$NON-NLS-1$
39+
if (current.contains("line")) { //$NON-NLS-1$
40+
return currentElements[0] + currentElements[1] + currentElements[2] + " " //$NON-NLS-1$
41+
+ breakpoint.getMarker().getAttribute(org.eclipse.debug.core.model.IBreakpoint.LABEL,
42+
""); //$NON-NLS-1$
43+
}
44+
return currentElements[0] + " " //$NON-NLS-1$
45+
+ breakpoint.getMarker().getAttribute(org.eclipse.debug.core.model.IBreakpoint.LABEL, ""); //$NON-NLS-1$
46+
}
47+
48+
}
3449
return super.getLabel(elementPath, presentationContext, columnId, columnIndex);
3550
} else {
3651
return IInternalDebugCoreConstants.EMPTY_STRING;

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementHelper.java

+21
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@
1616
import java.util.HashMap;
1717
import java.util.Map;
1818

19+
import org.eclipse.debug.core.model.Breakpoint;
1920
import org.eclipse.debug.internal.ui.DelegatingModelPresentation;
2021
import org.eclipse.debug.ui.IDebugModelPresentation;
22+
import org.eclipse.debug.ui.IDebugUIConstants;
2123
import org.eclipse.jface.resource.ImageDescriptor;
24+
import org.eclipse.jface.resource.JFaceResources;
2225
import org.eclipse.jface.viewers.IColorProvider;
2326
import org.eclipse.jface.viewers.IFontProvider;
27+
import org.eclipse.swt.SWT;
2428
import org.eclipse.swt.graphics.Color;
2529
import org.eclipse.swt.graphics.Font;
2630
import org.eclipse.swt.graphics.FontData;
2731
import org.eclipse.swt.graphics.Image;
2832
import org.eclipse.swt.graphics.RGB;
33+
import org.eclipse.swt.widgets.Display;
2934

3035
/**
3136
* Translates images, colors, and fonts into image descriptors, RGBs, and font
@@ -144,6 +149,13 @@ public static RGB getForeground(Object element, IDebugModelPresentation presenta
144149
if (color != null) {
145150
return color.getRGB();
146151
}
152+
if (element instanceof Breakpoint breakpoint) {
153+
if (!breakpoint.getBreakpointLabel().isEmpty()) {
154+
Color redColor = new Color(Display.getCurrent(), 255, 0, 0);
155+
return redColor.getRGB();
156+
}
157+
158+
}
147159
return null;
148160
}
149161

@@ -222,7 +234,16 @@ public static FontData getFont(Object element, IDebugModelPresentation presentat
222234
if (font != null) {
223235
return font.getFontData()[0];
224236
}
237+
if (element instanceof Breakpoint breakpoint) {
238+
if (!breakpoint.getBreakpointLabel().isEmpty()) {
239+
var fontNew = JFaceResources.getFontDescriptor(IDebugUIConstants.PREF_VARIABLE_TEXT_FONT)
240+
.getFontData()[0];
241+
return new FontData(fontNew.getName(), fontNew.getHeight(), fontNew.getStyle() ^ SWT.BOLD);
242+
}
243+
244+
}
225245
return null;
246+
226247
}
227248

228249
/**

0 commit comments

Comments
 (0)