From fd34df5d7e3b18950142b391a750c3f2d6f42e5c Mon Sep 17 00:00:00 2001 From: Marco Maccaferri Date: Mon, 6 May 2024 11:14:18 +0200 Subject: [PATCH] Fixed tool dialog theme --- .../com/maccasoft/propeller/EditorTab.java | 4 +- .../propeller/ExternalToolDialog.java | 104 ++++++++++++++++++ .../com/maccasoft/propeller/SpinTools.java | 2 +- 3 files changed, 108 insertions(+), 2 deletions(-) diff --git a/modules/spin-tools/src/com/maccasoft/propeller/EditorTab.java b/modules/spin-tools/src/com/maccasoft/propeller/EditorTab.java index 1b77f06d..0f89df6e 100644 --- a/modules/spin-tools/src/com/maccasoft/propeller/EditorTab.java +++ b/modules/spin-tools/src/com/maccasoft/propeller/EditorTab.java @@ -810,7 +810,9 @@ else if (tabItemText.toLowerCase().endsWith(".c")) { } public void setFocus() { - editor.getControl().setFocus(); + if (!editor.getControl().isDisposed()) { + editor.getControl().setFocus(); + } } public void setText(String text) { diff --git a/modules/spin-tools/src/com/maccasoft/propeller/ExternalToolDialog.java b/modules/spin-tools/src/com/maccasoft/propeller/ExternalToolDialog.java index f81b003c..81585014 100644 --- a/modules/spin-tools/src/com/maccasoft/propeller/ExternalToolDialog.java +++ b/modules/spin-tools/src/com/maccasoft/propeller/ExternalToolDialog.java @@ -21,17 +21,24 @@ import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.internal.Platform; 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.Control; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Spinner; import org.eclipse.swt.widgets.Text; import com.maccasoft.propeller.Preferences.ExternalTool; +import com.maccasoft.propeller.internal.ColorRegistry; import com.maccasoft.propeller.internal.ImageRegistry; public class ExternalToolDialog extends Dialog { @@ -75,6 +82,103 @@ protected void configureShell(Shell newShell) { newShell.setText("External Tool"); } + @Override + protected Control createContents(Composite parent) { + Control contents = super.createContents(parent); + Preferences preferences = Preferences.getInstance(); + if ("win32".equals(Platform.PLATFORM) || preferences.getTheme() != null) { + applyTheme(parent, preferences.getTheme()); + } + return contents; + } + + Color widgetForeground; + Color widgetBackground; + Color listForeground; + Color listBackground; + Color labelForeground; + Color buttonBackground; + + void applyTheme(Control control, String id) { + widgetForeground = null; + widgetBackground = null; + listForeground = null; + listBackground = null; + labelForeground = null; + buttonBackground = null; + + if ("win32".equals(Platform.PLATFORM) && id == null) { + if (Display.isSystemDarkTheme()) { + id = "dark"; + } + } + + if (id == null) { + listBackground = ColorRegistry.getColor(ColorRegistry.LIST_BACKGROUND); + listForeground = ColorRegistry.getColor(ColorRegistry.LIST_FOREGROUND); + widgetBackground = ColorRegistry.getColor(ColorRegistry.WIDGET_BACKGROUND); + widgetForeground = ColorRegistry.getColor(ColorRegistry.WIDGET_FOREGROUND); + } + else if ("dark".equals(id)) { + widgetForeground = new Color(0xF0, 0xF0, 0xF0); + widgetBackground = new Color(0x50, 0x55, 0x57); + listForeground = new Color(0xA7, 0xA7, 0xA7); + listBackground = new Color(0x2B, 0x2B, 0x2B); + labelForeground = new Color(0xD7, 0xD7, 0xD7); + buttonBackground = new Color(0x50, 0x55, 0x57); + } + else if ("light".equals(id)) { + widgetForeground = new Color(0x00, 0x00, 0x00); + if ("win32".equals(Platform.PLATFORM)) { + widgetBackground = new Color(0xF0, 0xF0, 0xF0); + } + else { + widgetBackground = new Color(0xFA, 0xFA, 0xFA); + } + listForeground = new Color(0x00, 0x00, 0x00); + listBackground = new Color(0xFE, 0xFE, 0xFE); + labelForeground = new Color(0x00, 0x00, 0x00); + buttonBackground = new Color(0xFA, 0xFA, 0xFA); + } + + applyTheme(control); + } + + void applyTheme(Control control) { + if (control instanceof List) { + control.setForeground(listForeground); + control.setBackground(listBackground); + } + else if (control instanceof Button) { + if (control != getShell().getDefaultButton()) { + control.setForeground(widgetForeground); + control.setBackground(buttonBackground); + } + } + else if (control instanceof Text) { + control.setForeground(listForeground); + control.setBackground(listBackground); + } + else if (control instanceof Spinner) { + control.setForeground(listForeground); + control.setBackground(listBackground); + } + else if (control instanceof Combo) { + control.setForeground(listForeground); + control.setBackground(listBackground); + } + else if (control instanceof Label) { + control.setForeground(widgetForeground); + } + else if (control instanceof Composite) { + control.setBackground(widgetBackground); + Control[] children = ((Composite) control).getChildren(); + for (int i = 0; i < children.length; i++) { + applyTheme(children[i]); + } + } + } + @Override protected Control createDialogArea(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); diff --git a/modules/spin-tools/src/com/maccasoft/propeller/SpinTools.java b/modules/spin-tools/src/com/maccasoft/propeller/SpinTools.java index c5c75e4a..a4723483 100644 --- a/modules/spin-tools/src/com/maccasoft/propeller/SpinTools.java +++ b/modules/spin-tools/src/com/maccasoft/propeller/SpinTools.java @@ -2534,7 +2534,7 @@ void populateRunMenu() { MenuItem item = new MenuItem(runMenu, SWT.PUSH); if (i < 9) { - item.setText(name + "\tAlt+" + ('1' + i)); + item.setText(name + "\tAlt+" + (char) ('1' + i)); item.setAccelerator(SWT.MOD3 + '1' + i); } else {