Skip to content

Commit

Permalink
Fixed tool dialog theme
Browse files Browse the repository at this point in the history
  • Loading branch information
maccasoft committed May 6, 2024
1 parent e7d8667 commit fd34df5
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
104 changes: 104 additions & 0 deletions modules/spin-tools/src/com/maccasoft/propeller/ExternalToolDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit fd34df5

Please sign in to comment.