Skip to content

Commit 48d7314

Browse files
SougandhSlaeubi
authored andcommitted
Improved Expression Copy
This commit improves Copy Expression by excluding eclipse ui values such as pending, error and disabled
1 parent 7c2d8b8 commit 48d7314

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/expressions/CopyExpressionsToClipboardActionDelegate.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017 Bachmann electronic GmbH and others.
2+
* Copyright (c) 2017, 2025 Bachmann electronic GmbH and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,15 +10,17 @@
1010
*
1111
* Contributors:
1212
* Bachmann electronic GmbH - initial API and implementation
13+
* IBM Corporation - Exclude Expression UI values while copying
1314
*******************************************************************************/
1415
package org.eclipse.debug.internal.ui.actions.expressions;
1516

17+
import org.eclipse.debug.internal.core.WatchExpression;
18+
import org.eclipse.debug.internal.ui.DebugUIMessages;
1619
import org.eclipse.debug.internal.ui.viewers.model.VirtualCopyToClipboardActionDelegate;
1720

1821
public class CopyExpressionsToClipboardActionDelegate extends VirtualCopyToClipboardActionDelegate {
1922

2023
private static final String QUOTE = "\""; //$NON-NLS-1$
21-
2224
@Override
2325
protected String trimLabel(String rawLabel) {
2426
String label = super.trimLabel(rawLabel);
@@ -34,5 +36,31 @@ protected String trimLabel(String rawLabel) {
3436
return label;
3537
}
3638

39+
@Override
40+
protected String exludeLabels(Object itemData, String label) {
41+
if (itemData instanceof WatchExpression watchExp) {
42+
if (watchExp.isPending() || watchExp.hasErrors()) {
43+
if (label.equals(DebugUIMessages.DefaultLabelProvider_12)
44+
|| label.contains(DebugUIMessages.DefaultLabelProvider_13)) {
45+
return null;
46+
}
47+
}
48+
if (!watchExp.isEnabled()) {
49+
if (label.equals(DebugUIMessages.DefaultLabelProvider_15)) {
50+
return null;
51+
}
52+
if (label.contains(DebugUIMessages.DefaultLabelProvider_15)) {
53+
int index = label.lastIndexOf(DebugUIMessages.DefaultLabelProvider_15);
54+
if (index != -1) {
55+
label = label.substring(0, index)
56+
+ label.substring(index + DebugUIMessages.DefaultLabelProvider_15.length());
57+
}
58+
}
59+
}
60+
return label;
61+
}
62+
return label;
63+
}
64+
3765

3866
}

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/VirtualCopyToClipboardActionDelegate.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2013 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
@@ -146,7 +146,8 @@ protected void append(VirtualItem item, StringBuilder buffer, int indent) {
146146
String[] labels = (String[]) item.getData(VirtualItem.LABEL_KEY);
147147
if(labels != null && labels.length > 0) {
148148
for (String label : labels) {
149-
String text = trimLabel(label);
149+
String text = exludeLabels(item.getData(), label);
150+
text = trimLabel(text);
150151
if (text != null && !text.equals(IInternalDebugCoreConstants.EMPTY_STRING)) {
151152
buffer.append(text);
152153
}
@@ -171,6 +172,19 @@ protected String trimLabel(String label) {
171172
return label.trim();
172173
}
173174

175+
/**
176+
* Excludes unwanted labels from the selected item
177+
*
178+
* @param itemData Selected object
179+
* @param label Current label
180+
* @return filtered label or null if label or item is null
181+
*/
182+
protected String exludeLabels(Object itemData, String label) {
183+
if (itemData == null || label == null) {
184+
return null;
185+
}
186+
return label;
187+
}
174188
private static class ItemsToCopyVirtualItemValidator implements IVirtualItemValidator {
175189

176190
Set<VirtualItem> fItemsToCopy = Collections.EMPTY_SET;
@@ -367,4 +381,5 @@ protected boolean getEnableStateForSelection(IStructuredSelection selection) {
367381
public void runWithEvent(IAction action, Event event) {
368382
run(action);
369383
}
384+
370385
}

0 commit comments

Comments
 (0)