Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Require-Bundle: org.eclipse.cdt.core;resolution:=optional,
org.eclipse.terminal.view.ui;bundle-version="[1.0.0,2.0.0)",
org.eclipse.terminal.view.core;bundle-version="[1.0.0,2.0.0)",
org.eclipse.terminal.connector.process;bundle-version="[1.0.0,2.0.0)",
org.eclipse.terminal.control;bundle-version="[1.0.0,2.0.0)"
org.eclipse.terminal.control;bundle-version="[1.0.0,2.0.0)",
com.google.gson

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if this is already a pre-requisite plugin during the update site?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Kondal, we are already using com.google.gson and have it in the update site dependencies

Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
Expand Down
4 changes: 2 additions & 2 deletions bundles/com.espressif.idf.terminal.connector/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<!-- uses process connector -->
<extension point="org.eclipse.terminal.control.connectors">
<connector
class="org.eclipse.terminal.connector.process.ProcessConnector"
class="com.espressif.idf.terminal.connector.launcher.IDFTerminalProcessConnector"
hidden="true"
id="com.espressif.idf.terminal.connector.espidfConnector"
name="%TerminalConnector.local"/>
Expand All @@ -21,4 +21,4 @@
</delegate>
</extension>

</plugin>
</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,65 @@
*******************************************************************************/
package com.espressif.idf.terminal.connector.controls;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.terminal.view.core.ITerminalsConnectorConstants;
import org.eclipse.terminal.view.ui.launcher.AbstractExtendedConfigurationPanel;
import org.eclipse.terminal.view.ui.launcher.IConfigurationPanelContainer;
import org.eclipse.ui.WorkbenchEncoding;
import org.eclipse.ui.preferences.ScopedPreferenceStore;

import com.espressif.idf.core.IDFProjectNature;
import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.terminal.connector.controls.themes.EspressifDarkTheme;
import com.espressif.idf.terminal.connector.controls.themes.EspressifLightTheme;
import com.espressif.idf.terminal.connector.controls.themes.ITerminalTheme;
import com.espressif.idf.terminal.connector.controls.themes.PowerShellTheme;
import com.espressif.idf.terminal.connector.controls.themes.ResetTheme;
import com.espressif.idf.ui.EclipseUtil;

/**
* IDF console wizard configuration panel implementation.
*/
public class IDFConsoleWizardConfigurationPanel extends AbstractExtendedConfigurationPanel {

private static final String PREF_THEME_SELECTION = "IDF_CONSOLE_THEME_SELECTION"; //$NON-NLS-1$
private static final String TERMINAL_PREF_NODE = "org.eclipse.terminal.control"; //$NON-NLS-1$

private Combo projectCombo;
private final List<ITerminalTheme> themes = new ArrayList<>();
private final List<Button> themeButtons = new ArrayList<>();

/**
* Constructor.
*
* @param container The configuration panel container or <code>null</code>.
*/
public IDFConsoleWizardConfigurationPanel(IConfigurationPanelContainer container) {
super(container);

themes.add(new ResetTheme());
themes.add(new EspressifLightTheme());
themes.add(new EspressifDarkTheme());
themes.add(new PowerShellTheme());
}

@Override
Expand All @@ -58,11 +80,10 @@ public void setupPanel(Composite parent) {
panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

createProjectCombo(panel);
// Create the encoding selection combo
createEncodingUI(panel, false);
createThemeUI(panel);

// Set the default encoding:
// Default UTF-8 on Mac or Windows for Local, Preferences:Platform encoding otherwise
// Set the default encoding based on OS
if (Platform.OS_MACOSX.equals(Platform.getOS()) || Platform.OS_WIN32.equals(Platform.getOS())) {
setEncoding("UTF-8"); //$NON-NLS-1$
} else {
Expand All @@ -71,8 +92,7 @@ public void setupPanel(Composite parent) {
setEncoding(encoding);
}

// Fill the rest of the panel with a label to be able to
// set a height and width hint for the dialog
// Fill the rest of the panel with a spacer
Label label = new Label(panel, SWT.HORIZONTAL);
GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
layoutData.widthHint = 300;
Expand All @@ -82,8 +102,126 @@ public void setupPanel(Composite parent) {
setControl(panel);
}

private void createProjectCombo(Composite parent) {
/**
* Dynamically creates radio buttons for each loaded ITerminalTheme strategy.
*/
private void createThemeUI(Composite parent) {
Group group = new Group(parent, SWT.NONE);
group.setText(Messages.IDFConsoleWizardConfigurationPanel_TerminalColorPresetsLbl);
group.setLayout(new GridLayout(1, false));
group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

themeButtons.clear();

for (ITerminalTheme theme : themes) {
Button btn = new Button(group, SWT.RADIO);
btn.setText(theme.getLabel());
btn.setData(theme);
themeButtons.add(btn);
}

Label noteLabel = new Label(group, SWT.WRAP);
noteLabel.setText(Messages.IDFConsoleWizardConfigurationPanel_TerminalColorPresetsNote);
noteLabel.setFont(JFaceResources.getFontRegistry().getItalic(JFaceResources.DIALOG_FONT));
GridData noteData = new GridData(SWT.FILL, SWT.CENTER, true, false);
noteData.verticalIndent = 5;
noteLabel.setLayoutData(noteData);
}

@Override
public void extractData(Map<String, Object> data) {
data.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID,
"com.espressif.idf.terminal.connector.espidfConnector"); //$NON-NLS-1$

data.put(ITerminalsConnectorConstants.PROP_ENCODING, getEncoding());

if (projectCombo != null && !projectCombo.isDisposed() && !projectCombo.getText().isEmpty()) {
IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(projectCombo.getText());
if (p != null && p.exists() && p.getLocation() != null) {
data.put(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR, p.getLocation().toOSString());
data.put(ITerminalsConnectorConstants.PROP_TITLE, p.getName());
}
}

for (Button btn : themeButtons) {
if (btn != null && !btn.isDisposed() && btn.getSelection()) {
ITerminalTheme strategy = (ITerminalTheme) btn.getData();
if (strategy != null) {
applyThemeStrategy(strategy);
}
break;
}
}
}

/**
* Instantiates the Preference Store and delegates the coloring logic
* to the selected strategy.
*/
private void applyThemeStrategy(ITerminalTheme theme) {
IPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, TERMINAL_PREF_NODE);

theme.apply(store);

if (store instanceof ScopedPreferenceStore preferenceStore) {
try {
preferenceStore.save();
} catch (Exception ex) {
Logger.log(ex);
}
}
}

@Override
public void doSaveWidgetValues(IDialogSettings settings, String idPrefix) {
// Save encoding settings
doSaveEncodingsWidgetValues(settings, idPrefix);

// Save selected theme ID
if (settings != null) {
for (Button btn : themeButtons) {
if (btn.getSelection()) {
ITerminalTheme theme = (ITerminalTheme) btn.getData();
settings.put(PREF_THEME_SELECTION, theme.getId());
break;
}
}
Comment thread
sigmaaa marked this conversation as resolved.
}
}

@Override
public void doRestoreWidgetValues(IDialogSettings settings, String idPrefix) {
doRestoreEncodingsWidgetValues(settings, idPrefix);

// Restore theme selection
if (settings != null) {
String savedId = settings.get(PREF_THEME_SELECTION);

boolean found = false;
// Iterate over buttons to find the one matching the saved ID
for (Button btn : themeButtons) {
ITerminalTheme theme = (ITerminalTheme) btn.getData();
if (theme.getId().equals(savedId)) {
btn.setSelection(true);
found = true;
} else {
btn.setSelection(false);
}
}
Comment thread
sigmaaa marked this conversation as resolved.

// Fallback: If no setting saved (or ID not found), select the first one (Restore Defaults)
if (!found && !themeButtons.isEmpty()) {
themeButtons.get(0).setSelection(true);
}
} else {
// No settings at all? Default to the first option
if (!themeButtons.isEmpty()) {
themeButtons.get(0).setSelection(true);
}
}
}

private void createProjectCombo(Composite parent) {
Composite panel = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
layout.marginHeight = 0;
Expand Down Expand Up @@ -119,29 +257,11 @@ private void createProjectCombo(Composite parent) {
public void setupData(Map<String, Object> data) {
if (data == null)
return;

String value = (String) data.get(ITerminalsConnectorConstants.PROP_ENCODING);
if (value != null)
setEncoding(value);
}

@Override
public void extractData(Map<String, Object> data) {

data.put(ITerminalsConnectorConstants.PROP_TERMINAL_CONNECTOR_ID,
"com.espressif.idf.terminal.connector.espidfConnector"); //$NON-NLS-1$

data.put(ITerminalsConnectorConstants.PROP_ENCODING, getEncoding());

if (projectCombo != null && !projectCombo.isDisposed() && !projectCombo.getText().isEmpty()) {
IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(projectCombo.getText());
if (p != null && p.exists() && p.getLocation() != null) {
data.put(ITerminalsConnectorConstants.PROP_PROCESS_WORKING_DIR, p.getLocation().toOSString());
data.put(ITerminalsConnectorConstants.PROP_TITLE, p.getName());
}
}
}

@Override
protected void fillSettingsForHost(String host) {
}
Expand All @@ -155,18 +275,6 @@ public boolean isValid() {
return true;
}

@Override
public void doSaveWidgetValues(IDialogSettings settings, String idPrefix) {
// Save the encodings widget values
doSaveEncodingsWidgetValues(settings, idPrefix);
}

@Override
public void doRestoreWidgetValues(IDialogSettings settings, String idPrefix) {
// Restore the encodings widget values
doRestoreEncodingsWidgetValues(settings, idPrefix);
}

@Override
protected String getHostFromSettings() {
return null;
Expand All @@ -176,4 +284,4 @@ protected String getHostFromSettings() {
public boolean isWithHostList() {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ private Messages() {

public static String IDFConsoleWizardConfigurationPanel_MissingProjectErrorMsg;
public static String IDFConsoleWizardConfigurationPanel_IDFConsoleWizardConfigurationPanel_ProjectLabel;
public static String IDFConsoleWizardConfigurationPanel_TerminalColorPresetsLbl;
public static String IDFConsoleWizardConfigurationPanel_TerminalColorPresetsNote;
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
IDFConsoleWizardConfigurationPanel_MissingProjectErrorMsg=Please create and select an ESP-IDF Project first.
IDFConsoleWizardConfigurationPanel_IDFConsoleWizardConfigurationPanel_ProjectLabel=Project name:
IDFConsoleWizardConfigurationPanel_IDFConsoleWizardConfigurationPanel_ProjectLabel=Project name:
IDFConsoleWizardConfigurationPanel_TerminalColorPresetsLbl=Terminal Color Presets
IDFConsoleWizardConfigurationPanel_TerminalColorPresetsNote=Note: This setting applies globally to all Terminal views in the workspace.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.espressif.idf.terminal.connector.controls.themes;

import java.util.EnumMap;
import java.util.Map;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.terminal.model.TerminalColor;

/**
* Base class for defining a terminal theme using a Map.
*/
public class CustomTheme implements ITerminalTheme {

private final String id;
private final String label;
protected final Map<TerminalColor, String> colorMap = new EnumMap<>(TerminalColor.class);

public CustomTheme(String id, String label) {
this.id = id;
this.label = label;
loadDefaults();
configure();
}

/**
* Subclasses should override this to set their specific colors.
*/
protected void configure() {
// Default implementation does nothing
}

@Override
public String getId() {
return id;
}

@Override
public String getLabel() {
return label;
}

/**
* Helper to set a color.
*/
protected void set(TerminalColor color, int r, int g, int b) {
colorMap.put(color, r + "," + g + "," + b); //$NON-NLS-1$ //$NON-NLS-2$
}

@Override
public void apply(IPreferenceStore store) {
for (Map.Entry<TerminalColor, String> entry : colorMap.entrySet()) {
store.setValue(entry.getKey().name(), entry.getValue());
}
}

private void loadDefaults() {
set(TerminalColor.BLACK, 0, 0, 0);
set(TerminalColor.RED, 205, 0, 0);
set(TerminalColor.GREEN, 0, 205, 0);
set(TerminalColor.YELLOW, 205, 205, 0);
set(TerminalColor.BLUE, 0, 0, 238);
set(TerminalColor.MAGENTA, 205, 0, 205);
set(TerminalColor.CYAN, 0, 205, 205);
set(TerminalColor.WHITE, 229, 229, 229);

set(TerminalColor.BRIGHT_BLACK, 0, 0, 0);
set(TerminalColor.BRIGHT_RED, 255, 0, 0);
set(TerminalColor.BRIGHT_GREEN, 0, 255, 0);
set(TerminalColor.BRIGHT_YELLOW, 255, 255, 0);
set(TerminalColor.BRIGHT_BLUE, 92, 92, 255);
set(TerminalColor.BRIGHT_MAGENTA, 255, 0, 255);
set(TerminalColor.BRIGHT_CYAN, 0, 255, 255);
set(TerminalColor.BRIGHT_WHITE, 255, 255, 255);
}
}
Loading
Loading