From 80ee40d03524fd0342ce4765ab531ccf6755f2e0 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Thu, 8 Jul 2021 06:25:22 -0400 Subject: [PATCH] working on how to debug theme.txt changes --- app/src/processing/app/ui/Theme.java | 28 +++++++++------ .../src/processing/app/tools/ThemeEngine.java | 34 +++++++++++++++---- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/app/src/processing/app/ui/Theme.java b/app/src/processing/app/ui/Theme.java index 4f1bd214d..21546c790 100644 --- a/app/src/processing/app/ui/Theme.java +++ b/app/src/processing/app/ui/Theme.java @@ -42,10 +42,6 @@ public class Theme { static Settings theme; static public void init() { - load(); - } - - static public void load() { try { File inputFile = Platform.getContentFile("lib/theme.txt"); if (inputFile == null) { @@ -54,6 +50,8 @@ public class Theme { // First load the default theme data for the whole PDE. theme = new Settings(inputFile); + // A spot-check of Modes shows that theme.txt is not being overridden, + // so removing this (questionable, warned against) capability for 4.0a6. /* // The mode-specific theme.txt file should only contain additions, // and in extremely rare cases, it might override entries from the @@ -66,22 +64,30 @@ public class Theme { } */ - // https://github.com/processing/processing/issues/5445 - File sketchbookTheme = getSketchbookFile(); -// new File(Base.getSketchbookFolder(), "theme.txt"); - if (sketchbookTheme.exists()) { - theme.load(sketchbookTheme); - } - // other things that have to be set explicitly for the defaults theme.setColor("run.window.bgcolor", SystemColor.control); + // pull in the version from the user's sketchbook folder + load(); + } catch (IOException e) { Messages.showError("Problem loading theme.txt", "Could not load theme.txt, please re-install Processing", e); } } + + /** + * Load theme.txt from the user's sketchbook folder. + */ + static public void load() { + File sketchbookTheme = getSketchbookFile(); + if (sketchbookTheme.exists()) { + theme.load(sketchbookTheme); + } + } + + static public void save() { theme.save(getSketchbookFile()); } diff --git a/build/shared/tools/ThemeEngine/src/processing/app/tools/ThemeEngine.java b/build/shared/tools/ThemeEngine/src/processing/app/tools/ThemeEngine.java index f2e1d0a9c..5c27874fe 100644 --- a/build/shared/tools/ThemeEngine/src/processing/app/tools/ThemeEngine.java +++ b/build/shared/tools/ThemeEngine/src/processing/app/tools/ThemeEngine.java @@ -2,6 +2,9 @@ package processing.app.tools; import processing.app.Base; import processing.app.ui.Editor; +import processing.app.ui.Theme; + +import java.io.File; public class ThemeEngine implements Tool { @@ -19,13 +22,32 @@ public class ThemeEngine implements Tool { public void run() { - //setVisible(true); - //Preferences.init(); + Editor activeEditor = base.getActiveEditor(); - for (Editor editor : base.getEditors()) { - System.out.println("Updating theme for " + editor.getSketch().getName()); - //editor.applyPreferences(); - editor.updateTheme(); + File sketchbookFile = Theme.getSketchbookFile(); + if (!sketchbookFile.exists()) { + // When first called, just create the theme.txt file + Theme.save(); + + if (activeEditor != null) { + activeEditor.statusNotice("Saved theme.txt to " + sketchbookFile); + } + + } else { + // Normally, just reset the theme by loading theme.txt + //setVisible(true); + //Preferences.init(); + Theme.load(); + + for (Editor editor : base.getEditors()) { + System.out.println("Updating theme for " + editor.getSketch().getName()); + //editor.applyPreferences(); + editor.updateTheme(); + } + + if (activeEditor != null) { + activeEditor.statusNotice("Finished updating theme."); + } } } }