Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ public class DebugPreferencesMessages extends NLS {
public static String SimpleVariablePreferencePage_7;
public static String SimpleVariablePreferencePage_8;
public static String SimpleVariablePreferencePage_9;
public static String SimpleVariablePreferencePage_Preview;
public static String StringVariablePreviewDialog_Title;
public static String StringVariablePreviewDialog_Name;
public static String StringVariablePreviewDialog_Value;
public static String StringVariablePreviewDialog_Description;
public static String StringVariablePreviewDialog_ReadOnly;
public static String StringVariablePreviewDialog_Contributed;
public static String StringVariablePreviewDialog_ContributedBy;
public static String StringVariablePreviewDialog_Yes;
public static String StringVariablePreviewDialog_No;
public static String StringVariablePreviewDialog_Close;
public static String SimpleVariablePreferencePage_10;
public static String SimpleVariablePreferencePage_11;
public static String SimpleVariablePreferencePage_12;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ SimpleVariablePreferencePage_6=&Create and configure string substitution variabl
SimpleVariablePreferencePage_7=&New...
SimpleVariablePreferencePage_8=&Edit...
SimpleVariablePreferencePage_9=&Remove
SimpleVariablePreferencePage_Preview=&Preview...
StringVariablePreviewDialog_Title=Variable Preview
StringVariablePreviewDialog_Name=Name
StringVariablePreviewDialog_Value=Value
StringVariablePreviewDialog_Description=Description
StringVariablePreviewDialog_ReadOnly=Read-only
StringVariablePreviewDialog_Contributed=Contributed
StringVariablePreviewDialog_ContributedBy=Contributed by
StringVariablePreviewDialog_Yes=Yes
StringVariablePreviewDialog_No=No
StringVariablePreviewDialog_Close=&Close
SimpleVariablePreferencePage_10=&Name:
SimpleVariablePreferencePage_11=&Value:
SimpleVariablePreferencePage_12=&Description:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corporation and others.
* Copyright (c) 2000, 2026 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -15,7 +15,6 @@

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.core.runtime.CoreException;
Expand Down Expand Up @@ -75,6 +74,7 @@ public class StringVariablePreferencePage extends PreferencePage implements IWor
protected Button envAddButton;
protected Button envEditButton;
protected Button envRemoveButton;
private Button envPreviewButton;

protected SimpleVariableContentProvider variableContentProvider= new SimpleVariableContentProvider();

Expand Down Expand Up @@ -247,6 +247,22 @@ public void widgetSelected(SelectionEvent event) {
}
});
envRemoveButton.setEnabled(false);
envPreviewButton = SWTFactory.createPushButton(buttonComposite, DebugPreferencesMessages.SimpleVariablePreferencePage_Preview, null);
envPreviewButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
handlePreviewButtonPressed();
}
});
envPreviewButton.setEnabled(false);
}

private void handlePreviewButtonPressed() {
IStructuredSelection selection = variableTable.getStructuredSelection();
if (selection.size() != 1) {
return;
}
new StringVariablePreviewDialog(getShell(), (VariableWrapper) selection.getFirstElement()).open();
}

private void handleAddButtonPressed() {
Expand Down Expand Up @@ -290,9 +306,7 @@ private boolean addVariable(String name, String description, String value) {
return false;
}
List<VariableWrapper> editedVariables = variableContentProvider.getWorkingSetVariables();
Iterator<VariableWrapper> iter = editedVariables.iterator();
while (iter.hasNext()) {
VariableWrapper currentVariable = iter.next();
for (VariableWrapper currentVariable : editedVariables) {
if (!currentVariable.isRemoved()) {
String currentName = currentVariable.getName();
if (currentName.equals(name)) {
Expand Down Expand Up @@ -360,9 +374,7 @@ private void handleRemoveButtonPressed() {
IStructuredSelection selection = variableTable.getStructuredSelection();
List<VariableWrapper> variablesToRemove = selection.toList();
StringBuilder contributedVariablesToRemove= new StringBuilder();
Iterator<VariableWrapper> iter = variablesToRemove.iterator();
while (iter.hasNext()) {
VariableWrapper variable = iter.next();
for (VariableWrapper variable : variablesToRemove) {
if (variable.isContributed()) {
contributedVariablesToRemove.append('\t').append(variable.getName()).append('\n');
}
Expand All @@ -387,6 +399,7 @@ private void handleRemoveButtonPressed() {
protected void handleTableSelectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (event.getStructuredSelection());
VariableWrapper variable= (VariableWrapper) selection.getFirstElement();
envPreviewButton.setEnabled(selection.size() == 1);
if (variable == null || variable.isReadOnly()) {
envEditButton.setEnabled(false);
envRemoveButton.setEnabled(false);
Expand Down Expand Up @@ -503,11 +516,9 @@ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
*/
public void saveChanges() {
IStringVariableManager manager = getVariableManager();
Iterator<VariableWrapper> iterator = fWorkingSet.iterator();
List<IValueVariable> remove = new ArrayList<>();
List<IValueVariable> add = new ArrayList<>();
while (iterator.hasNext()) {
VariableWrapper variable = iterator.next();
for (VariableWrapper variable : fWorkingSet) {
if (!variable.isReadOnly()) {
IValueVariable underlyingVariable = variable.getUnderlyingVariable();
if (variable.isRemoved()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*******************************************************************************
* Copyright (c) 2026 IBM Corporation and others.
*
* 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 Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.debug.internal.ui.preferences;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.internal.ui.preferences.StringVariablePreferencePage.VariableWrapper;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;

class StringVariablePreviewDialog extends Dialog {

private final VariableWrapper fVariable;

StringVariablePreviewDialog(Shell parentShell, VariableWrapper variable) {
super(parentShell);
fVariable = variable;
setShellStyle(SWT.RESIZE | getShellStyle());
}

@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
newShell.setText(DebugPreferencesMessages.StringVariablePreviewDialog_Title);
}

@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.CANCEL_ID, DebugPreferencesMessages.StringVariablePreviewDialog_Close,
false);
}

@Override
protected Control createDialogArea(Composite parent) {
Composite comp = (Composite) super.createDialogArea(parent);

StringBuilder text = new StringBuilder();
List<StyleRange> styles = new ArrayList<>();
appendDetail(text, styles, DebugPreferencesMessages.StringVariablePreviewDialog_Name, fVariable.getName());
appendDetail(text, styles, DebugPreferencesMessages.StringVariablePreviewDialog_Value, fVariable.getValue());
appendDetail(text, styles, DebugPreferencesMessages.StringVariablePreviewDialog_Description,
fVariable.getDescription());
appendDetail(text, styles, DebugPreferencesMessages.StringVariablePreviewDialog_ReadOnly,
yesNo(fVariable.isReadOnly()));
appendDetail(text, styles, DebugPreferencesMessages.StringVariablePreviewDialog_Contributed,
yesNo(fVariable.isContributed()));
if (fVariable.isContributed()) {
appendDetail(text, styles, DebugPreferencesMessages.StringVariablePreviewDialog_ContributedBy,
VariablesPlugin.getDefault().getStringVariableManager()
.getContributingPluginId(fVariable.getUnderlyingVariable()));
}

StyledText styledText = new StyledText(comp, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL | SWT.READ_ONLY);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = convertHeightInCharsToPixels(22);
gd.widthHint = convertWidthInCharsToPixels(120);
styledText.setLayoutData(gd);
styledText.setText(text.toString());
styledText.setStyleRanges(styles.toArray(new StyleRange[0]));
return comp;
}

private static String yesNo(boolean flag) {
return flag ? DebugPreferencesMessages.StringVariablePreviewDialog_Yes
: DebugPreferencesMessages.StringVariablePreviewDialog_No;
}

/**
* Appends a bold title followed by its value on the next line; skipped if the
* value is null.
*/
private static void appendDetail(StringBuilder text, List<StyleRange> styles, String title, String value) {
if (value == null) {
return;
}
if (text.length() > 0) {
text.append("\n\n"); //$NON-NLS-1$
}
styles.add(new StyleRange(text.length(), title.length(), null, null, SWT.BOLD));
text.append(title).append('\n').append(value);
}
}
Loading