StandaloneStartup.st
changeset 12998 c967aa65e09a
parent 12996 8662430ec3de
child 12999 a5ab22c6470c
--- a/StandaloneStartup.st	Thu Aug 05 17:40:40 2010 +0200
+++ b/StandaloneStartup.st	Fri Aug 06 11:58:33 2010 +0200
@@ -163,24 +163,10 @@
     self subclassResponsibility
 !
 
-checkForAndExitIfAnotherApplicationInstanceIsRunning
-    "if another instance of this application is running,
-     send it an openFile command for my file-argument, and exit.
-     (i.e. to let the already running application open up another window)."
-
-    |shouldExit|
+shouldReuseRunningApplication
+    "answer true, if an already running application instance should be re-used"
 
-    self isAnotherApplicationInstanceRunning ifTrue:[
-        shouldExit := self processStartupOfASecondInstance.
-        shouldExit ifTrue:[
-            self releaseApplicationMutex.
-            Smalltalk isStandAloneApp ifTrue:[
-                Smalltalk exit.
-            ]
-        ].
-    ].
-
-    "Modified: / 03-08-2010 / 17:27:25 / cg"
+    ^ false
 ! !
 
 !StandaloneStartup class methodsFor:'multiple applications support-helpers'!
@@ -216,6 +202,26 @@
     ^ applicationEntry
 !
 
+checkForAndExitIfAnotherApplicationInstanceIsRunning
+    "if another instance of this application is running,
+     send it an openFile command for my file-argument, and exit.
+     (i.e. to let the already running application open up another window)."
+
+    |shouldExit|
+
+    self isAnotherApplicationInstanceRunning ifTrue:[
+        shouldExit := self processStartupOfASecondInstance.
+        shouldExit ifTrue:[
+            self releaseApplicationMutex.
+            Smalltalk isStandAloneApp ifTrue:[
+                Smalltalk exit.
+            ]
+        ].
+    ].
+
+    "Modified: / 03-08-2010 / 17:27:25 / cg"
+!
+
 confirmOpenNewApplicationInstance
 
     ^ Dialog confirm: ('Continue opening a new instance of %1 or exit?' bindWith:self applicationName)
@@ -287,7 +293,7 @@
 
     |currentIDStringFromRegistry currentIDFromRegistry fileArg commands aWindowId setForegroundWindowSucceeded|
 
-    commands := Smalltalk commandLineArguments.
+    commands := CommandLineArguments.
 
     currentIDStringFromRegistry := self getCurrentIDFromRegistry.
 
@@ -455,6 +461,49 @@
     "Modified: / 19-09-2006 / 16:30:58 / cg"
 !
 
+loadRemainingClassLibraries
+    "To speedup startup, we did not load all dll's (only a subset of non-GUI dll's is present).
+     Now, load all skipped libs (the ones marked with '*') from modules.stx."
+
+    |modulesFile dllDirectory dlls|
+
+    OperatingSystem isMSWINDOWSlike ifFalse:[^ self ].
+
+    self verboseInfo:'loadRemainingClassLibraries'.
+    modulesFile  := self stxModulesFilename.
+    dllDirectory := modulesFile directory.
+
+    dlls := OrderedCollection new.
+
+    modulesFile readingLinesDo:[:eachModulesLine|
+        |basename dllFile|
+
+        basename := eachModulesLine withoutSeparators.
+
+        (basename notEmpty and:[basename first == $*]) ifTrue:[
+            basename := (basename copyFrom:2) withoutSeparators, '.dll'.
+            dllFile := dllDirectory construct:basename.
+
+            dllFile exists ifTrue:[
+"/                self verboseInfo:('loading: ', basename).
+                Smalltalk showSplashMessage:('loading ', basename).
+                dlls add:dllFile.
+            ] ifFalse:[
+                self verboseInfo:( '**** cannot resolve: ', basename).
+            ].
+        ].
+    ].
+
+    dlls notEmpty ifTrue:[
+        ObjectFileLoader loadObjectFiles:dlls.
+        Display notNil ifTrue:[
+            "New view classes may have been loaded - have to update their styles"
+            self verboseInfo:'update style caches of loaded dlls'.
+            SimpleView updateAllStyleCaches.
+        ].
+    ].
+!
+
 setupSmalltalkFromArguments:argv
     "handle common command line arguments:
         --help ............... print usage and exit
@@ -601,12 +650,33 @@
         Verbose == true ifTrue:[ex suspendedContext fullPrintAllLevels:10].
         ex reject.        
     ] do:[
+        |idx|
+        self verboseInfo:('starting...').
         CommandLineArguments := (self additionalArgumentsFromRegistry) 
                                 , Smalltalk commandLineArguments.
 
-        self verboseInfo:('starting...').
         self verboseInfo:('args: ', CommandLineArguments asStringCollection asString).
 
+        "--noRemote - do not reuse an existing application instance,
+         but run in a separate process"
+        idx := CommandLineArguments indexOfAny:#('--noRemote').
+        idx == 0 ifTrue:[
+            self shouldReuseRunningApplication ifTrue:[
+                "Multiple Application support:
+                 if another expecco is running, ask it to open another window for me.
+                 If that is the case, the following function will not return, but instead exit."
+                self checkForAndExitIfAnotherApplicationInstanceIsRunning.
+            ].
+        ] ifFalse:[
+            CommandLineArguments removeAtIndex:idx.
+            Verbose := true.
+        ].
+
+        "/ Arrive here, if no other application is running.
+        "/ to speedup startup, we did not load all dll's (only a subset of non-GUI dll's is present).
+        "/ now, load all skipped libs from modules.stx.
+        self loadRemainingClassLibraries.
+
         Smalltalk isStandAloneApp ifTrue:[
             self loadPatches.
             self verboseInfo:('setup Smalltalk').
@@ -622,6 +692,20 @@
     Smalltalk startStartBlockProcess
 !
 
+stxModulesFilename
+    "answer the Filename of modules.stx"
+
+    |file|
+
+    file := 'modules.stx' asFilename.
+    file exists ifTrue:[^ file].
+
+    file := OperatingSystem pathOfSTXExecutable asFilename directory construct:'modules.stx'.
+    file exists ifTrue:[^ file].
+
+    self error:'cannot find: modules.stx'.
+!
+
 usage
     Stderr nextPutLine:'usage:'.
     Stderr nextPutLine:'  ',self applicationName,' [options...]'.
@@ -629,6 +713,9 @@
     Stderr nextPutLine:'          --help .................. output this message'.
     Stderr nextPutLine:'          --verbose ............... verbose startup'.
     Stderr nextPutLine:'          --noBanner .............. no splash screen'.
+    self shouldReuseRunningApplication ifTrue:[
+        Stderr nextPutLine:'          --noRemote .............. start as an own application process and do not reuse a running instance'.
+    ].
     self allowScriptingOption ifTrue:[
         Stderr nextPutLine:'          --scripting portNr ...... enable scripting via port (or stdin/stdOut, if 0)'.
     ].
@@ -711,11 +798,11 @@
 !StandaloneStartup class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/StandaloneStartup.st,v 1.48 2010-08-05 13:16:45 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/StandaloneStartup.st,v 1.49 2010-08-06 09:58:33 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libbasic/StandaloneStartup.st,v 1.48 2010-08-05 13:16:45 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/StandaloneStartup.st,v 1.49 2010-08-06 09:58:33 stefan Exp $'
 ! !
 
 StandaloneStartup initialize!