Fix (re)loading of preferences when calling `VDBStartup >> main:` from workspace
authorJan Vrany <jan.vrany@fit.cvut.cz>
Fri, 05 Oct 2018 11:45:46 +0100
changeset 119 be31a77e2d9c
parent 118 b5fe8d511cfa
child 120 4fae7ad78949
Fix (re)loading of preferences when calling `VDBStartup >> main:` from workspace In this case, we MUST NOT load preferences from file, otherwise all unsaved settings would be lost! On the other hand, when VDB is compiled as standalone application or run from command line (`--load jv:vdb --run VDBStartup`) we MUST load them. Unfortunately, there's no good way how to tell whether the startup has been called by means of `--run` - hence the `thisContext sender` hackery. Bleh.
VDBStartup.st
--- a/VDBStartup.st	Fri Oct 05 09:43:53 2018 +0100
+++ b/VDBStartup.st	Fri Oct 05 11:45:46 2018 +0100
@@ -90,11 +90,21 @@
 main:argv
     "Application entry point. `argv` is the array of command arguments (as Array of Strings)"
 
-    | optparser positional settingsFile settingsSuppressed gdb replay 
-      programExecutable programArgs programPid attach 
+    | standalone optparser positional settingsFile settingsSuppressed gdb replay
+      programExecutable programArgs programPid attach
       debugger debuggerApp |
 
-    settingsSuppressed := false.
+    "/ This is awkward. We HAVE TO load prefetences when VDB is compiled standalone
+    "/ application or run from a command line (`--load jv:vdb` --run VDBStarup`.
+    "/ We MUST NOT load preferences when `VDBStarup main` is run from running IDE.
+    "/ for example while developing.
+    "/
+    "/ The trick is that there's no good and easy way to check this, so we have to
+    "/ check whether this method is called from `Smalltalk >> start`. Bleh.
+    standalone := Smalltalk isStandAloneApp
+                    or:[ thisContext sender method == (Smalltalk class compiledMethodAt: #start) ].
+    settingsSuppressed := standalone not.
+
     replay := false.
     attach := false.