Skip to content

Commit ba449de

Browse files
committed
Expand editor and launcher settings
1 parent 6708f27 commit ba449de

7 files changed

Lines changed: 363 additions & 50 deletions

File tree

editor/src/main/java/com/jvn/editor/EditorApp.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,25 @@ private Window dialogOwner() {
264264
}
265265

266266
private void setEditorTheme(EditorTheme.Theme theme) {
267+
setEditorTheme(theme, true);
268+
}
269+
270+
private void setEditorTheme(EditorTheme.Theme theme, boolean persist) {
267271
EditorTheme.Theme target = theme == null ? EditorTheme.Theme.DARK : theme;
268-
if (target == EditorTheme.theme()) return;
269-
EditorTheme.setTheme(target);
270-
applyThemeToOpenWindows();
272+
boolean changed = target != EditorTheme.theme();
273+
if (changed) {
274+
EditorTheme.setTheme(target);
275+
applyThemeToOpenWindows();
276+
}
277+
if (persist && editorPreferences != null) {
278+
editorPreferences.setEditorTheme(target == EditorTheme.Theme.LIGHT
279+
? EditorPreferences.LAUNCHER_THEME_LIGHT
280+
: EditorPreferences.LAUNCHER_THEME_DARK);
281+
persistEditorPreferences();
282+
if (editorSettingsView != null) {
283+
editorSettingsView.loadIntoForm(editorPreferences);
284+
}
285+
}
271286
if (status != null) {
272287
status.setText("Theme: " + (target == EditorTheme.Theme.LIGHT ? "Light" : "Dark"));
273288
}
@@ -313,7 +328,9 @@ private void doRunProject(Stage stage) {
313328

314329
private void doRunProject(File root) {
315330
if (root == null) return;
316-
if (!saveDirtyEditorsBeforeRun()) return;
331+
if (editorPreferences == null || editorPreferences.isAutoSaveBeforeRun()) {
332+
if (!saveDirtyEditorsBeforeRun()) return;
333+
}
317334
Properties mf = loadManifest(root);
318335
if (mf == null) { status.setText("jvn.project not found"); return; }
319336
String type = mf.getProperty("type", "gradle").trim();
@@ -504,7 +521,9 @@ private void runVnProjectInRuntime(File root, Properties mf) {
504521
if (!runtimeAudio.isBlank()) runtimeArgs.append(" --audio ").append(quoteCliArg(runtimeAudio));
505522
String runtimeLocale = mf.getProperty("runtime.locale", "").trim();
506523
if (!runtimeLocale.isBlank()) runtimeArgs.append(" --locale ").append(quoteCliArg(runtimeLocale));
507-
runtimeArgs.append(" --perf-hud");
524+
if (editorPreferences == null || editorPreferences.isEditorRuntimePerfHud()) {
525+
runtimeArgs.append(" --perf-hud");
526+
}
508527

509528
runGradle(workspaceRoot, ":runtime:run", new String[] { "--args=" + runtimeArgs }, "JVN Runtime");
510529
status.setText("Launching runtime: " + root.getName());
@@ -2922,6 +2941,10 @@ private void applyEditorPreferences(EditorPreferences preferences) {
29222941
targetFps = maxFps;
29232942
minFrameIntervalNs = (long) (1_000_000_000.0 / targetFps);
29242943
}
2944+
setEditorTheme(EditorPreferences.LAUNCHER_THEME_LIGHT.equals(editorPreferences.getEditorTheme())
2945+
? EditorTheme.Theme.LIGHT
2946+
: EditorTheme.Theme.DARK,
2947+
false);
29252948
applyCodeEditorFontSizePreference();
29262949
applyWelcomeTabPreference();
29272950
applyDefaultSidebarPreferences();

editor/src/main/java/com/jvn/editor/JvnLauncherApp.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,17 @@ private void runSelectedProject() {
689689
EditorDialogs.info(primaryStage, "Run Project", "Select a project first.");
690690
return;
691691
}
692+
if (editorPreferences != null
693+
&& editorPreferences.isLauncherConfirmRunProject()
694+
&& !EditorDialogs.confirm(
695+
primaryStage,
696+
"Run Project",
697+
"Run " + displayProjectName(currentProject) + " from the launcher?",
698+
"Run",
699+
false)) {
700+
statusLabel.setText("Run cancelled");
701+
return;
702+
}
692703

693704
Properties manifest = loadManifest(currentProject);
694705
if (manifest == null) {
@@ -801,7 +812,9 @@ private void runVnProjectInRuntime(File root, Properties manifest) {
801812
if (!runtimeAudio.isBlank()) runtimeArgs.append(" --audio ").append(quoteCliArg(runtimeAudio));
802813
String runtimeLocale = manifest.getProperty("runtime.locale", "").trim();
803814
if (!runtimeLocale.isBlank()) runtimeArgs.append(" --locale ").append(quoteCliArg(runtimeLocale));
804-
runtimeArgs.append(" --perf-hud");
815+
if (editorPreferences == null || editorPreferences.isLauncherRuntimePerfHud()) {
816+
runtimeArgs.append(" --perf-hud");
817+
}
805818

806819
runGradle(workspace, ":runtime:run", new String[] {"--args=" + runtimeArgs}, "JVN Runtime");
807820
}
@@ -817,7 +830,10 @@ private void launchEditor(File projectDir, File startupFile) {
817830
command.addAll(resolveForwardedJvmArgs());
818831
command.add("-cp");
819832
command.add(System.getProperty("java.class.path", ""));
820-
command.add("-Djvn.editor.theme=" + (EditorTheme.theme() == EditorTheme.Theme.LIGHT ? "light" : "dark"));
833+
String editorTheme = editorPreferences == null
834+
? EditorPreferences.LAUNCHER_THEME_DARK
835+
: EditorPreferences.normalizeEditorTheme(editorPreferences.getEditorTheme());
836+
command.add("-Djvn.editor.theme=" + editorTheme);
821837
if (projectDir != null && projectDir.isDirectory()) {
822838
command.add("-D" + EDITOR_OPEN_PROJECT_PROPERTY + "=" + projectDir.getAbsolutePath());
823839
}
@@ -842,9 +858,11 @@ private void launchEditor(File projectDir, File startupFile) {
842858
: "Editor launched for " + projectDir.getName());
843859
}
844860

845-
primaryStage.hide();
846-
editorProcess.onExit().thenRunAsync(
847-
() -> Platform.runLater(() -> primaryStage.show()));
861+
if (editorPreferences == null || !editorPreferences.isLauncherKeepOpenAfterEditorLaunch()) {
862+
primaryStage.hide();
863+
editorProcess.onExit().thenRunAsync(
864+
() -> Platform.runLater(() -> primaryStage.show()));
865+
}
848866
} catch (Exception ex) {
849867
EditorDialogs.error(primaryStage, "Open Editor", "Failed to launch editor: " + ex.getMessage());
850868
}

editor/src/main/java/com/jvn/editor/ui/EditorPreferences.java

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ public final class EditorPreferences {
1818

1919
private int codeEditorFontSize;
2020
private int editorMaxFps = DEFAULT_EDITOR_MAX_FPS;
21+
private String editorTheme;
2122
private boolean showWelcomeOnStartup;
2223
private boolean loadSidebarExtensionsOnDemand;
24+
private boolean autoSaveBeforeRun;
25+
private boolean editorRuntimePerfHud;
2326
private String defaultTextEditor;
2427
private String customTextEditorCommand;
2528
private String launcherTheme;
2629
private boolean launcherRestoreLastProject;
2730
private String launcherLastProjectPath;
31+
private boolean launcherKeepOpenAfterEditorLaunch;
32+
private boolean launcherConfirmRunProject;
33+
private boolean launcherRuntimePerfHud;
2834
private final EnumMap<EditorSidebarPanel, EditorPanelPlacement> panelPlacements =
2935
new EnumMap<>(EditorSidebarPanel.class);
3036
private final EnumMap<EditorSidebarPanel, Boolean> chooserVisibility =
@@ -33,37 +39,55 @@ public final class EditorPreferences {
3339
public EditorPreferences() {
3440
this(
3541
DEFAULT_CODE_EDITOR_FONT_SIZE,
42+
LAUNCHER_THEME_DARK,
43+
true,
44+
true,
3645
true,
3746
true,
3847
TEXT_EDITOR_JVN,
3948
"",
4049
LAUNCHER_THEME_DARK,
4150
true,
4251
"",
52+
false,
53+
false,
54+
true,
4355
EditorSidebarPanel.defaultPlacements(),
4456
EditorSidebarPanel.defaultChooserVisibility());
4557
}
4658

4759
public EditorPreferences(
4860
int codeEditorFontSize,
61+
String editorTheme,
4962
boolean showWelcomeOnStartup,
5063
boolean loadSidebarExtensionsOnDemand,
64+
boolean autoSaveBeforeRun,
65+
boolean editorRuntimePerfHud,
5166
String defaultTextEditor,
5267
String customTextEditorCommand,
5368
String launcherTheme,
5469
boolean launcherRestoreLastProject,
5570
String launcherLastProjectPath,
71+
boolean launcherKeepOpenAfterEditorLaunch,
72+
boolean launcherConfirmRunProject,
73+
boolean launcherRuntimePerfHud,
5674
Map<EditorSidebarPanel, EditorPanelPlacement> placements,
5775
Map<EditorSidebarPanel, Boolean> chooserVisibility) {
5876
this.codeEditorFontSize =
5977
clampCodeEditorFontSize(codeEditorFontSize);
78+
this.editorTheme = normalizeTheme(editorTheme);
6079
this.showWelcomeOnStartup = showWelcomeOnStartup;
6180
this.loadSidebarExtensionsOnDemand = loadSidebarExtensionsOnDemand;
81+
this.autoSaveBeforeRun = autoSaveBeforeRun;
82+
this.editorRuntimePerfHud = editorRuntimePerfHud;
6283
this.defaultTextEditor = normalizeTextEditor(defaultTextEditor);
6384
this.customTextEditorCommand = cleanText(customTextEditorCommand);
6485
this.launcherTheme = normalizeLauncherTheme(launcherTheme);
6586
this.launcherRestoreLastProject = launcherRestoreLastProject;
6687
this.launcherLastProjectPath = cleanText(launcherLastProjectPath);
88+
this.launcherKeepOpenAfterEditorLaunch = launcherKeepOpenAfterEditorLaunch;
89+
this.launcherConfirmRunProject = launcherConfirmRunProject;
90+
this.launcherRuntimePerfHud = launcherRuntimePerfHud;
6791
panelPlacements.putAll(EditorSidebarPanel.defaultPlacements());
6892
this.chooserVisibility.putAll(EditorSidebarPanel.defaultChooserVisibility());
6993
if (placements != null) {
@@ -105,6 +129,14 @@ public void setEditorMaxFps(int editorMaxFps) {
105129
}
106130
}
107131

132+
public String getEditorTheme() {
133+
return editorTheme;
134+
}
135+
136+
public void setEditorTheme(String editorTheme) {
137+
this.editorTheme = normalizeTheme(editorTheme);
138+
}
139+
108140
public boolean isShowWelcomeOnStartup() {
109141
return showWelcomeOnStartup;
110142
}
@@ -121,6 +153,22 @@ public void setLoadSidebarExtensionsOnDemand(boolean loadSidebarExtensionsOnDema
121153
this.loadSidebarExtensionsOnDemand = loadSidebarExtensionsOnDemand;
122154
}
123155

156+
public boolean isAutoSaveBeforeRun() {
157+
return autoSaveBeforeRun;
158+
}
159+
160+
public void setAutoSaveBeforeRun(boolean autoSaveBeforeRun) {
161+
this.autoSaveBeforeRun = autoSaveBeforeRun;
162+
}
163+
164+
public boolean isEditorRuntimePerfHud() {
165+
return editorRuntimePerfHud;
166+
}
167+
168+
public void setEditorRuntimePerfHud(boolean editorRuntimePerfHud) {
169+
this.editorRuntimePerfHud = editorRuntimePerfHud;
170+
}
171+
124172
public String getDefaultTextEditor() {
125173
return defaultTextEditor;
126174
}
@@ -161,6 +209,30 @@ public void setLauncherLastProjectPath(String launcherLastProjectPath) {
161209
this.launcherLastProjectPath = cleanText(launcherLastProjectPath);
162210
}
163211

212+
public boolean isLauncherKeepOpenAfterEditorLaunch() {
213+
return launcherKeepOpenAfterEditorLaunch;
214+
}
215+
216+
public void setLauncherKeepOpenAfterEditorLaunch(boolean launcherKeepOpenAfterEditorLaunch) {
217+
this.launcherKeepOpenAfterEditorLaunch = launcherKeepOpenAfterEditorLaunch;
218+
}
219+
220+
public boolean isLauncherConfirmRunProject() {
221+
return launcherConfirmRunProject;
222+
}
223+
224+
public void setLauncherConfirmRunProject(boolean launcherConfirmRunProject) {
225+
this.launcherConfirmRunProject = launcherConfirmRunProject;
226+
}
227+
228+
public boolean isLauncherRuntimePerfHud() {
229+
return launcherRuntimePerfHud;
230+
}
231+
232+
public void setLauncherRuntimePerfHud(boolean launcherRuntimePerfHud) {
233+
this.launcherRuntimePerfHud = launcherRuntimePerfHud;
234+
}
235+
164236
public EditorPanelPlacement getPlacement(EditorSidebarPanel panel) {
165237
if (panel == null) return EditorPanelPlacement.HIDDEN;
166238
return panelPlacements.getOrDefault(panel, panel.defaultPlacement());
@@ -192,13 +264,19 @@ public EnumMap<EditorSidebarPanel, Boolean> copyChooserVisibility() {
192264
public EditorPreferences copy() {
193265
EditorPreferences c = new EditorPreferences(
194266
codeEditorFontSize,
267+
editorTheme,
195268
showWelcomeOnStartup,
196269
loadSidebarExtensionsOnDemand,
270+
autoSaveBeforeRun,
271+
editorRuntimePerfHud,
197272
defaultTextEditor,
198273
customTextEditorCommand,
199274
launcherTheme,
200275
launcherRestoreLastProject,
201276
launcherLastProjectPath,
277+
launcherKeepOpenAfterEditorLaunch,
278+
launcherConfirmRunProject,
279+
launcherRuntimePerfHud,
202280
panelPlacements,
203281
chooserVisibility);
204282
c.editorMaxFps = this.editorMaxFps;
@@ -217,6 +295,14 @@ public static String normalizeTextEditor(String value) {
217295
}
218296

219297
public static String normalizeLauncherTheme(String value) {
298+
return normalizeTheme(value);
299+
}
300+
301+
public static String normalizeEditorTheme(String value) {
302+
return normalizeTheme(value);
303+
}
304+
305+
private static String normalizeTheme(String value) {
220306
String normalized = cleanText(value).toLowerCase();
221307
return LAUNCHER_THEME_LIGHT.equals(normalized) ? LAUNCHER_THEME_LIGHT : LAUNCHER_THEME_DARK;
222308
}

editor/src/main/java/com/jvn/editor/ui/EditorPreferencesStore.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@
1010
public final class EditorPreferencesStore {
1111
static final String KEY_CODE_EDITOR_FONT_SIZE = "codeEditorFontSize";
1212
static final String KEY_EDITOR_MAX_FPS = "editorMaxFps";
13+
static final String KEY_EDITOR_THEME = "editor.theme";
1314
static final String KEY_SHOW_WELCOME_ON_STARTUP = "showWelcomeOnStartup";
1415
static final String KEY_LOAD_SIDEBAR_EXTENSIONS_ON_DEMAND = "loadSidebarExtensionsOnDemand";
16+
static final String KEY_AUTO_SAVE_BEFORE_RUN = "autoSaveBeforeRun";
17+
static final String KEY_EDITOR_RUNTIME_PERF_HUD = "editor.runtimePerfHud";
1518
static final String KEY_DEFAULT_TEXT_EDITOR = "defaultTextEditor";
1619
static final String KEY_CUSTOM_TEXT_EDITOR_COMMAND = "customTextEditorCommand";
1720
static final String KEY_LAUNCHER_THEME = "launcher.theme";
1821
static final String KEY_LAUNCHER_RESTORE_LAST_PROJECT = "launcher.restoreLastProject";
1922
static final String KEY_LAUNCHER_LAST_PROJECT_PATH = "launcher.lastProjectPath";
23+
static final String KEY_LAUNCHER_KEEP_OPEN_AFTER_EDITOR_LAUNCH =
24+
"launcher.keepOpenAfterEditorLaunch";
25+
static final String KEY_LAUNCHER_CONFIRM_RUN_PROJECT = "launcher.confirmRunProject";
26+
static final String KEY_LAUNCHER_RUNTIME_PERF_HUD = "launcher.runtimePerfHud";
2027
static final String KEY_PANEL_PREFIX = "panel.";
2128
static final String KEY_PANEL_SUFFIX = ".placement";
2229
static final String KEY_CHOOSER_SUFFIX = ".chooserVisible";
@@ -72,12 +79,21 @@ static Properties toProperties(EditorPreferences preferences) {
7279
props.setProperty(
7380
KEY_EDITOR_MAX_FPS,
7481
Integer.toString(preferences.getEditorMaxFps()));
82+
props.setProperty(
83+
KEY_EDITOR_THEME,
84+
preferences.getEditorTheme());
7585
props.setProperty(
7686
KEY_SHOW_WELCOME_ON_STARTUP,
7787
Boolean.toString(preferences.isShowWelcomeOnStartup()));
7888
props.setProperty(
7989
KEY_LOAD_SIDEBAR_EXTENSIONS_ON_DEMAND,
8090
Boolean.toString(preferences.isLoadSidebarExtensionsOnDemand()));
91+
props.setProperty(
92+
KEY_AUTO_SAVE_BEFORE_RUN,
93+
Boolean.toString(preferences.isAutoSaveBeforeRun()));
94+
props.setProperty(
95+
KEY_EDITOR_RUNTIME_PERF_HUD,
96+
Boolean.toString(preferences.isEditorRuntimePerfHud()));
8197
props.setProperty(
8298
KEY_DEFAULT_TEXT_EDITOR,
8399
preferences.getDefaultTextEditor());
@@ -93,6 +109,15 @@ static Properties toProperties(EditorPreferences preferences) {
93109
props.setProperty(
94110
KEY_LAUNCHER_LAST_PROJECT_PATH,
95111
preferences.getLauncherLastProjectPath());
112+
props.setProperty(
113+
KEY_LAUNCHER_KEEP_OPEN_AFTER_EDITOR_LAUNCH,
114+
Boolean.toString(preferences.isLauncherKeepOpenAfterEditorLaunch()));
115+
props.setProperty(
116+
KEY_LAUNCHER_CONFIRM_RUN_PROJECT,
117+
Boolean.toString(preferences.isLauncherConfirmRunProject()));
118+
props.setProperty(
119+
KEY_LAUNCHER_RUNTIME_PERF_HUD,
120+
Boolean.toString(preferences.isLauncherRuntimePerfHud()));
96121
for (EditorSidebarPanel panel : EditorSidebarPanel.values()) {
97122
props.setProperty(
98123
KEY_PANEL_PREFIX + panel.key() + KEY_PANEL_SUFFIX,
@@ -113,10 +138,17 @@ static EditorPreferences fromProperties(Properties props) {
113138
preferences.setEditorMaxFps(parseInt(
114139
props.getProperty(KEY_EDITOR_MAX_FPS),
115140
EditorPreferences.DEFAULT_EDITOR_MAX_FPS));
141+
preferences.setEditorTheme(props.getProperty(
142+
KEY_EDITOR_THEME,
143+
EditorPreferences.LAUNCHER_THEME_DARK));
116144
preferences.setShowWelcomeOnStartup(Boolean.parseBoolean(
117145
props.getProperty(KEY_SHOW_WELCOME_ON_STARTUP, "true")));
118146
preferences.setLoadSidebarExtensionsOnDemand(parseBoolean(
119147
props.getProperty(KEY_LOAD_SIDEBAR_EXTENSIONS_ON_DEMAND), true));
148+
preferences.setAutoSaveBeforeRun(parseBoolean(
149+
props.getProperty(KEY_AUTO_SAVE_BEFORE_RUN), true));
150+
preferences.setEditorRuntimePerfHud(parseBoolean(
151+
props.getProperty(KEY_EDITOR_RUNTIME_PERF_HUD), true));
120152
preferences.setDefaultTextEditor(props.getProperty(
121153
KEY_DEFAULT_TEXT_EDITOR,
122154
EditorPreferences.TEXT_EDITOR_JVN));
@@ -131,6 +163,12 @@ static EditorPreferences fromProperties(Properties props) {
131163
preferences.setLauncherLastProjectPath(props.getProperty(
132164
KEY_LAUNCHER_LAST_PROJECT_PATH,
133165
""));
166+
preferences.setLauncherKeepOpenAfterEditorLaunch(parseBoolean(
167+
props.getProperty(KEY_LAUNCHER_KEEP_OPEN_AFTER_EDITOR_LAUNCH), false));
168+
preferences.setLauncherConfirmRunProject(parseBoolean(
169+
props.getProperty(KEY_LAUNCHER_CONFIRM_RUN_PROJECT), false));
170+
preferences.setLauncherRuntimePerfHud(parseBoolean(
171+
props.getProperty(KEY_LAUNCHER_RUNTIME_PERF_HUD), true));
134172
for (EditorSidebarPanel panel : EditorSidebarPanel.values()) {
135173
String key = KEY_PANEL_PREFIX + panel.key() + KEY_PANEL_SUFFIX;
136174
EditorPanelPlacement placement = parsePlacement(props.getProperty(key), panel.defaultPlacement());

0 commit comments

Comments
 (0)