Skip to content

Commit 344bb51

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 344bb51

File tree

12 files changed

+238
-11
lines changed

12 files changed

+238
-11
lines changed

debug/org.eclipse.debug.core/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.debug.core; singleton:=true
5-
Bundle-Version: 3.23.0.qualifier
5+
Bundle-Version: 3.24.0.qualifier
66
Bundle-Activator: org.eclipse.debug.core.DebugPlugin
77
Bundle-Vendor: %providerName
88
Bundle-Localization: plugin

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

Lines changed: 20 additions & 2 deletions
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,23 @@ public String toString() {
384383
return builder.toString();
385384
}
386385

386+
/**
387+
* Returns associated label associated with the breakpoint.
388+
*
389+
* @since 3.24
390+
*/
391+
public String getBreakpointLabel() {
392+
return getMarker().getAttribute(LABEL, ""); //$NON-NLS-1$
393+
}
394+
395+
/**
396+
* Sets a new label for the breakpoint.
397+
*
398+
* @param label provide by the user
399+
* @since 3.24
400+
*/
401+
public void setBreakpointLabel(String label) throws CoreException {
402+
setAttribute(LABEL, label);
403+
}
404+
387405
}

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,21 @@ public interface IBreakpoint extends IAdaptable {
120120
String PERSISTED= "org.eclipse.debug.core.persisted"; //$NON-NLS-1$
121121

122122
/**
123-
* Deletes this breakpoint's underlying marker, and removes
124-
* this breakpoint from the breakpoint manager.
123+
* Label breakpoint marker attribute (value
124+
* <code>"org.eclipse.debug.core.label"</code>). The attribute is a
125+
* <code>String</code> corresponding to a custom label of a breakpoint.
125126
*
126-
* @exception CoreException if unable to delete this breakpoint's
127-
* underlying marker
127+
* @see org.eclipse.core.resources.IMarker#getAttribute(String, String)
128+
* @since 3.24
129+
*/
130+
String LABEL = "org.eclipse.debug.core.label"; //$NON-NLS-1$
131+
132+
/**
133+
* Deletes this breakpoint's underlying marker, and removes this breakpoint
134+
* from the breakpoint manager.
135+
*
136+
* @exception CoreException if unable to delete this breakpoint's underlying
137+
* marker
128138
*/
129139
void delete() throws CoreException;
130140

@@ -220,6 +230,7 @@ public interface IBreakpoint extends IAdaptable {
220230
*/
221231
void setPersisted(boolean registered) throws CoreException;
222232

233+
223234
}
224235

225236

402 Bytes
Loading
1.16 KB
Loading

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,5 @@ 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
422+
breakpointLabel.tooltip=Provide a custom label to quickly identify breakpoint

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

Lines changed: 9 additions & 0 deletions
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+
tooltip="%breakpointLabel.tooltip"
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

Lines changed: 3 additions & 1 deletion
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,6 @@ 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 BreakpointLabelDialog;
256+
255257
}

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

Lines changed: 3 additions & 2 deletions
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,5 @@ 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+
BreakpointLabelDialog=Provide a custom label, or blank for the default label
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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.debug.internal.ui.viewers.model.provisional.TreeModelViewer;
21+
import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointsView;
22+
import org.eclipse.debug.ui.IDebugUIConstants;
23+
import org.eclipse.jface.action.IAction;
24+
import org.eclipse.jface.viewers.ISelection;
25+
import org.eclipse.jface.viewers.IStructuredSelection;
26+
import org.eclipse.jface.viewers.TreeSelection;
27+
import org.eclipse.swt.SWT;
28+
import org.eclipse.swt.events.KeyAdapter;
29+
import org.eclipse.swt.events.KeyEvent;
30+
import org.eclipse.swt.graphics.Font;
31+
import org.eclipse.swt.graphics.GC;
32+
import org.eclipse.swt.graphics.Point;
33+
import org.eclipse.swt.graphics.Rectangle;
34+
import org.eclipse.swt.widgets.Label;
35+
import org.eclipse.swt.widgets.Text;
36+
import org.eclipse.swt.widgets.TreeItem;
37+
import org.eclipse.swt.widgets.Widget;
38+
import org.eclipse.ui.IViewActionDelegate;
39+
import org.eclipse.ui.IViewPart;
40+
import org.eclipse.ui.IWorkbenchPage;
41+
import org.eclipse.ui.PlatformUI;
42+
43+
public class BreakpointLabelAction implements IViewActionDelegate {
44+
45+
private IViewPart fView;
46+
protected IViewPart getView() {
47+
return fView;
48+
}
49+
50+
protected void setView(IViewPart view) {
51+
fView = view;
52+
}
53+
54+
@Override
55+
public void run(IAction action) {
56+
String emptyString = ""; //$NON-NLS-1$
57+
IStructuredSelection selection = getSelection();
58+
59+
if (selection instanceof TreeSelection treeSelect && selection.getFirstElement() instanceof Breakpoint breakpoint) {
60+
if (treeSelect.size() == 1) {
61+
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
62+
IViewPart viewPart = page.findView(IDebugUIConstants.ID_BREAKPOINT_VIEW);
63+
if (viewPart instanceof BreakpointsView breakpointView) {
64+
TreeModelViewer treeViewer = breakpointView.getTreeModelViewer();
65+
Widget item = treeViewer.findItem(treeSelect.getPaths()[0]);
66+
if (item instanceof TreeItem tree) {
67+
String current = tree.getText();
68+
Rectangle bounds;
69+
try {
70+
bounds = tree.getBounds();
71+
} catch (ArrayIndexOutOfBoundsException e) { // TreeItem having FontData [Breakpoints having
72+
// custom label]
73+
tree.setFont(null);
74+
GC gc = new GC(tree.getParent());
75+
Font currentFont = gc.getFont();
76+
gc.setFont(currentFont);
77+
Point textWidth = gc.textExtent(tree.getText());
78+
gc.dispose();
79+
bounds = tree.getBounds(0);
80+
bounds.x = bounds.x + 10;
81+
bounds.width = textWidth.x + 20;
82+
83+
}
84+
Label label = new Label(tree.getParent(), SWT.WRAP);
85+
label.setText(ActionMessages.BreakpointLabelDialog);
86+
label.setBounds(bounds.x, bounds.y - 20, label.computeSize(SWT.DEFAULT, SWT.DEFAULT).x,
87+
label.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
88+
89+
Text inlineEditor = new Text(tree.getParent(), SWT.BORDER);
90+
inlineEditor.setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
91+
inlineEditor.setText(current);
92+
inlineEditor.setFocus();
93+
94+
inlineEditor.addListener(SWT.FocusOut, event -> {
95+
tree.setText(current);
96+
label.dispose();
97+
inlineEditor.dispose();
98+
99+
});
100+
inlineEditor.addKeyListener(new KeyAdapter() {
101+
@Override
102+
public void keyPressed(KeyEvent e) {
103+
if (e.keyCode == SWT.ESC) {
104+
tree.setText(current);
105+
inlineEditor.dispose();
106+
label.dispose();
107+
} else if (e.keyCode == SWT.CR) {
108+
String newLabel = inlineEditor.getText();
109+
if (!newLabel.isEmpty() && !newLabel.equals(current)) {
110+
try {
111+
breakpoint.setBreakpointLabel(newLabel);
112+
} catch (CoreException e1) {
113+
DebugUIPlugin.log(e1);
114+
}
115+
} else if (newLabel.isEmpty()) {
116+
try {
117+
breakpoint.setBreakpointLabel(emptyString); // Set to default
118+
} catch (CoreException e2) {
119+
DebugUIPlugin.log(e2);
120+
}
121+
}
122+
inlineEditor.dispose();
123+
label.dispose();
124+
}
125+
}
126+
});
127+
tree.setText(emptyString);
128+
129+
}
130+
131+
}
132+
}
133+
}
134+
135+
}
136+
137+
protected IStructuredSelection getSelection() {
138+
return (IStructuredSelection) getView().getViewSite().getSelectionProvider().getSelection();
139+
}
140+
141+
@Override
142+
public void selectionChanged(IAction action, ISelection selection) {
143+
}
144+
145+
@Override
146+
public void init(IViewPart view) {
147+
setView(view);
148+
}
149+
150+
}

0 commit comments

Comments
 (0)