author | Stefan Vogel <sv@exept.de> |
Thu, 05 Aug 2010 15:16:45 +0200 | |
changeset 12996 | 8662430ec3de |
parent 12992 | cad1bd395046 |
child 12998 | c967aa65e09a |
permissions | -rw-r--r-- |
9944 | 1 |
" |
2 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
"{ Package: 'stx:libbasic' }" |
|
13 |
||
14 |
Object subclass:#StandaloneStartup |
|
15 |
instanceVariableNames:'' |
|
10772 | 16 |
classVariableNames:'Verbose CommandLineArguments' |
9944 | 17 |
poolDictionaries:'' |
18 |
category:'System-Support' |
|
19 |
! |
|
20 |
||
11102 | 21 |
StandaloneStartup class instanceVariableNames:'MutexHandle' |
22 |
||
23 |
" |
|
24 |
No other class instance variables are inherited by this class. |
|
25 |
" |
|
26 |
! |
|
27 |
||
9944 | 28 |
!StandaloneStartup class methodsFor:'documentation'! |
29 |
||
30 |
copyright |
|
31 |
" |
|
32 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
33 |
All Rights Reserved |
|
34 |
||
35 |
This software is furnished under a license and may be used |
|
36 |
only in accordance with the terms of that license and with the |
|
37 |
inclusion of the above copyright notice. This software may not |
|
38 |
be provided or otherwise made available to, or used by, any |
|
39 |
other person. No title to or ownership of the software is |
|
40 |
hereby transferred. |
|
41 |
" |
|
42 |
! |
|
43 |
||
44 |
documentation |
|
45 |
" |
|
46 |
a subclassable template class for a standalone GUI-application's startup; |
|
47 |
For your own stand alone programs, define a subclass of this, |
|
12335 | 48 |
and redefine the #main: method there. |
9944 | 49 |
(of course, the other methods can also be redefined.) |
50 |
||
51 |
[author:] |
|
52 |
Claus Gittinger |
|
53 |
||
54 |
[start with:] |
|
55 |
<yourNamehere>Startup start |
|
10886 | 56 |
|
57 |
[see also:] |
|
58 |
Smalltalk |
|
59 |
GetOpt |
|
60 |
ReadEvalPrintLoop |
|
9944 | 61 |
" |
11102 | 62 |
! |
63 |
||
64 |
howToDealWithMultipleApplicationInstances |
|
65 |
" |
|
66 |
please read the comment in the corresponding ApplicationModel class-documentation method. |
|
67 |
" |
|
11352 | 68 |
! |
69 |
||
70 |
whichMethodsToRedefine |
|
71 |
" |
|
72 |
main:argv |
|
73 |
thats the actual program. |
|
74 |
||
75 |
suppressRCFileReading |
|
76 |
false here; redefine to return true, to disable the rc-file reading. |
|
77 |
you loose the chance of configuration, but lock the user out from any access to any smalltalk |
|
78 |
(if you have a user-phobia) |
|
79 |
||
80 |
allowDebugOption |
|
11361
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
81 |
false here; redefine to return true, to enable the --debug startup option. |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
82 |
if disabled, you loose the chance of debugging, but lock the user out from any access to any smalltalk |
11352 | 83 |
|
84 |
allowScriptingOption |
|
11361
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
85 |
false here; redefine to return true, to enable the --scripting startup option. |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
86 |
if disabled, you loose the chance of remote control, but lock the user out from any access to any smalltalk |
11352 | 87 |
|
88 |
" |
|
9944 | 89 |
! ! |
90 |
||
91 |
!StandaloneStartup class methodsFor:'initialization'! |
|
92 |
||
93 |
initialize |
|
11360 | 94 |
"/ Verbose := true. |
9944 | 95 |
Verbose := false. |
96 |
! ! |
|
97 |
||
11361
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
98 |
!StandaloneStartup class methodsFor:'defaults'! |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
99 |
|
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
100 |
allowDebugOption |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
101 |
"enable/disable the --debug startup option. |
11363 | 102 |
The default is now false, so standAlone apps are closed by default. |
103 |
Can be redefined in subclasses to enable it" |
|
11361
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
104 |
|
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
105 |
^ false |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
106 |
! |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
107 |
|
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
108 |
allowScriptingOption |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
109 |
"enable/disable the --scripting startup option. |
11363 | 110 |
The default is now false, so standAlone apps are closed by default. |
111 |
Can be redefined in subclasses to enable it" |
|
11361
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
112 |
|
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
113 |
^ false |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
114 |
! |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
115 |
|
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
116 |
suppressRCFileReading |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
117 |
"enable/disable the rc-file reading (and also the --rcFileName option). |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
118 |
If suppressed, there is no chance to interfere with the startup. |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
119 |
Can be redefined in subclasses to disable it" |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
120 |
|
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
121 |
^ false |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
122 |
! ! |
36d809458749
defaults for allowDebug and allowScripting
Michael Beyl <mb@exept.de>
parents:
11360
diff
changeset
|
123 |
|
9944 | 124 |
!StandaloneStartup class methodsFor:'helpers'! |
125 |
||
11423 | 126 |
printInfo:msg |
127 |
Transcript |
|
128 |
show:('%1 [info]: ' bindWith:(self applicationName)); |
|
129 |
showCR:msg |
|
130 |
! |
|
131 |
||
9944 | 132 |
redirectStandardStreams |
133 |
Stdout := Stderr. |
|
134 |
Transcript := Stderr. |
|
135 |
! |
|
136 |
||
137 |
verboseInfo:msg |
|
138 |
Verbose == true ifFalse:[^ self]. |
|
11423 | 139 |
self printInfo:msg |
9944 | 140 |
|
141 |
"Modified: / 19-09-2006 / 16:30:27 / cg" |
|
142 |
! ! |
|
143 |
||
11102 | 144 |
!StandaloneStartup class methodsFor:'multiple applications support'! |
145 |
||
146 |
applicationRegistryPath |
|
147 |
"the key under which this application stores its process ID in the registry |
|
148 |
as a collection of path-components. |
|
149 |
i.e. if #('foo' 'bar' 'baz') is returned here, the current applications ID will be stored |
|
150 |
in HKEY_CURRENT_USER\Software\foo\bar\baz\CurrentID. |
|
151 |
(would also be used as a relative path for a temporary lock file under unix). |
|
152 |
Used to detect if another instance of this application is already running." |
|
153 |
||
154 |
self subclassResponsibility |
|
155 |
! |
|
156 |
||
157 |
applicationUUID |
|
158 |
"answer an application-specific unique uuid. |
|
159 |
This is used as the name of some exclusive OS-resource, which is used to find out, |
|
160 |
if another instance of this application is already running. |
|
161 |
Under win32, a mutex is used; under unix, an exclusive file in the tempDir could be used." |
|
162 |
||
163 |
self subclassResponsibility |
|
164 |
! |
|
165 |
||
166 |
checkForAndExitIfAnotherApplicationInstanceIsRunning |
|
167 |
"if another instance of this application is running, |
|
168 |
send it an openFile command for my file-argument, and exit. |
|
169 |
(i.e. to let the already running application open up another window)." |
|
170 |
||
171 |
|shouldExit| |
|
172 |
||
173 |
self isAnotherApplicationInstanceRunning ifTrue:[ |
|
174 |
shouldExit := self processStartupOfASecondInstance. |
|
175 |
shouldExit ifTrue:[ |
|
176 |
self releaseApplicationMutex. |
|
177 |
Smalltalk isStandAloneApp ifTrue:[ |
|
178 |
Smalltalk exit. |
|
179 |
] |
|
180 |
]. |
|
181 |
]. |
|
12985
4ee69c6dacde
changed: #checkForAndExitIfAnotherApplicationInstanceIsRunning
Claus Gittinger <cg@exept.de>
parents:
12935
diff
changeset
|
182 |
|
12988
6a502f44c515
changed: #checkForAndExitIfAnotherApplicationInstanceIsRunning
Claus Gittinger <cg@exept.de>
parents:
12985
diff
changeset
|
183 |
"Modified: / 03-08-2010 / 17:27:25 / cg" |
11102 | 184 |
! ! |
185 |
||
186 |
!StandaloneStartup class methodsFor:'multiple applications support-helpers'! |
|
187 |
||
188 |
applicationRegistryEntry |
|
189 |
"retrieve the registry entry in which (if present), any currently running application |
|
190 |
has left its process ID" |
|
191 |
||
192 |
|path relPathName applicationEntry softwareEntry| |
|
193 |
||
194 |
path := self applicationRegistryPath. |
|
195 |
relPathName := path asStringWith:$\. |
|
196 |
applicationEntry := Win32OperatingSystem registryEntry key:'HKEY_CURRENT_USER\Software\',relPathName. |
|
197 |
applicationEntry isNil ifTrue:[ |
|
198 |
softwareEntry := Win32OperatingSystem registryEntry key:'HKEY_CURRENT_USER\Software'. |
|
199 |
softwareEntry isNil ifTrue:[ |
|
200 |
Transcript showCR: 'Failed to get Software entry in registry'. |
|
201 |
^ nil. |
|
202 |
]. |
|
11103 | 203 |
|
11102 | 204 |
path do:[:subKey | |
205 |
|subEntry| |
|
206 |
||
11103 | 207 |
subEntry := softwareEntry createSubKeyNamed:subKey. |
11102 | 208 |
subEntry isNil ifTrue:[ |
209 |
Transcript showCR: 'Failed to create ',subKey,' entry in registry'. |
|
210 |
^ nil. |
|
211 |
]. |
|
212 |
softwareEntry := subEntry. |
|
213 |
]. |
|
214 |
applicationEntry := softwareEntry. |
|
215 |
]. |
|
216 |
^ applicationEntry |
|
217 |
! |
|
218 |
||
11107 | 219 |
confirmOpenNewApplicationInstance |
220 |
||
221 |
^ Dialog confirm: ('Continue opening a new instance of %1 or exit?' bindWith:self applicationName) |
|
222 |
title: ('%1 is already open!!' bindWith:self applicationName) |
|
223 |
yesLabel: 'Continue' |
|
224 |
noLabel: 'Exit' |
|
225 |
! |
|
226 |
||
11102 | 227 |
currentIDKeyInRegistry |
228 |
^ 'CurrentID' |
|
229 |
! |
|
230 |
||
231 |
getCurrentIDFromRegistry |
|
232 |
||
233 |
|applicationEntry| |
|
234 |
||
235 |
applicationEntry := self applicationRegistryEntry. |
|
236 |
applicationEntry isNil ifTrue:[^ nil.]. |
|
237 |
^ applicationEntry valueNamed: self currentIDKeyInRegistry |
|
238 |
||
239 |
" |
|
240 |
|hWnd externalAddress| |
|
241 |
hWnd := DapasXStartup getCurrentIDFromRegistry. |
|
242 |
hWnd isEmptyOrNil ifTrue:[^ self halt.]. |
|
243 |
hWnd := hWnd asInteger. |
|
244 |
externalAddress := ExternalAddress newAddress: hWnd. |
|
245 |
Display raiseWindow:externalAddress. |
|
246 |
Display setForegroundWindow:externalAddress |
|
247 |
" |
|
248 |
! |
|
249 |
||
250 |
getIDOfRunningApplicationFromRegistryEntry |
|
251 |
|applicationEntry| |
|
252 |
||
253 |
applicationEntry := self applicationRegistryEntry. |
|
254 |
applicationEntry isNil ifTrue:[^ nil.]. |
|
255 |
^ applicationEntry valueNamed: self currentIDKeyInRegistry |
|
256 |
! |
|
257 |
||
258 |
isAnotherApplicationInstanceRunning |
|
259 |
"answer true, if another instance of mzself is currently running. |
|
260 |
For now, it only works under win32, because it uses the underlying mutex mechanism." |
|
261 |
||
11106 | 262 |
| lastErrorCode alreadyExists handleAndLastErrorCode | |
11102 | 263 |
|
264 |
OperatingSystem isMSDOSlike ifTrue:[ |
|
265 |
handleAndLastErrorCode := OperatingSystem createMutexNamed: (self applicationUUID printString). |
|
266 |
MutexHandle := handleAndLastErrorCode first. |
|
267 |
lastErrorCode := handleAndLastErrorCode second. |
|
268 |
"/ self assert: lastErrorCode == 0. |
|
269 |
alreadyExists := |
|
270 |
MutexHandle isNil |
|
271 |
or:[lastErrorCode == 183 "ERROR_ALREADY_EXISTS" |
|
272 |
or:[lastErrorCode == 5 "ERROR_ACCESS_DENIED"]]. |
|
273 |
||
274 |
alreadyExists ifFalse:[OperatingSystem waitForSingleObject: MutexHandle]. |
|
275 |
^ alreadyExists |
|
276 |
]. |
|
277 |
||
278 |
^ false. |
|
279 |
! |
|
280 |
||
281 |
processStartupOfASecondInstance |
|
282 |
"This is executed when I have been started as a second instance of an already running application. |
|
283 |
If I can get the currentID (i.e. windowID) of the first one and there is a command line argument with a file, |
|
12935
49210cf2d978
comment/format in: #processStartupOfASecondInstance
Claus Gittinger <cg@exept.de>
parents:
12933
diff
changeset
|
284 |
send a message to the main window of the already running application, to ask it for another window. |
11102 | 285 |
If the currentID is unknown, ask if the user wants to open a new instance of the application anyway. |
286 |
Return true if the first instance has been notified, and this second instance should exit." |
|
287 |
||
11107 | 288 |
|currentIDStringFromRegistry currentIDFromRegistry fileArg commands aWindowId setForegroundWindowSucceeded| |
11102 | 289 |
|
290 |
commands := Smalltalk commandLineArguments. |
|
291 |
||
292 |
currentIDStringFromRegistry := self getCurrentIDFromRegistry. |
|
293 |
||
294 |
"If the currentID is not found and there are arguments from the command line, |
|
295 |
we should wait in case of starting the first instance of the application |
|
296 |
with a multiple selection of files." |
|
297 |
(currentIDStringFromRegistry isEmptyOrNil and:[commands notEmptyOrNil]) ifTrue:[ |
|
298 |
Delay waitForSeconds: 2. |
|
299 |
]. |
|
300 |
||
301 |
currentIDStringFromRegistry := self getCurrentIDFromRegistry. |
|
302 |
currentIDStringFromRegistry isEmptyOrNil ifTrue:[ |
|
11107 | 303 |
^ self confirmOpenNewApplicationInstance not. |
11102 | 304 |
]. |
305 |
||
11107 | 306 |
currentIDFromRegistry := Integer readFrom:currentIDStringFromRegistry onError: 0. |
11102 | 307 |
|
308 |
"/ bring the other application to the foreground |
|
309 |
aWindowId := ExternalAddress newAddress: currentIDFromRegistry. |
|
11107 | 310 |
setForegroundWindowSucceeded := Display primSetForegroundWindow: aWindowId. |
11379 | 311 |
"/ setForegroundWindowSucceeded ifFalse:[^ self confirmOpenNewApplicationInstance not]. |
11102 | 312 |
|
313 |
"Autostart for associated extension" |
|
314 |
commands notEmpty ifTrue:[ |
|
315 |
fileArg := commands last asFilename. |
|
316 |
fileArg exists ifTrue:[ |
|
317 |
self sendOpenPathCommand:(fileArg pathName) toWindowId: aWindowId. |
|
318 |
]. |
|
319 |
]. |
|
320 |
^ true |
|
12935
49210cf2d978
comment/format in: #processStartupOfASecondInstance
Claus Gittinger <cg@exept.de>
parents:
12933
diff
changeset
|
321 |
|
49210cf2d978
comment/format in: #processStartupOfASecondInstance
Claus Gittinger <cg@exept.de>
parents:
12933
diff
changeset
|
322 |
"Modified: / 08-07-2010 / 00:47:44 / cg" |
11102 | 323 |
! |
324 |
||
325 |
releaseApplicationMutex |
|
326 |
||
12933
4e196c41604d
changed: #releaseApplicationMutex set MutexHandle to nil
ca
parents:
12626
diff
changeset
|
327 |
(MutexHandle notNil and:[OperatingSystem isMSDOSlike]) ifTrue:[ |
4e196c41604d
changed: #releaseApplicationMutex set MutexHandle to nil
ca
parents:
12626
diff
changeset
|
328 |
OperatingSystem releaseMutex: MutexHandle. |
4e196c41604d
changed: #releaseApplicationMutex set MutexHandle to nil
ca
parents:
12626
diff
changeset
|
329 |
OperatingSystem primCloseHandle: MutexHandle. |
4e196c41604d
changed: #releaseApplicationMutex set MutexHandle to nil
ca
parents:
12626
diff
changeset
|
330 |
|
4e196c41604d
changed: #releaseApplicationMutex set MutexHandle to nil
ca
parents:
12626
diff
changeset
|
331 |
MutexHandle := nil. |
11102 | 332 |
]. |
333 |
! |
|
334 |
||
335 |
sendCommand:message toWindowId:aWindowId |
|
336 |
"use the event send mechanism to forward a command to the already running application" |
|
337 |
||
338 |
Display |
|
339 |
sendCopyDataString: message |
|
340 |
toWindowId: aWindowId. |
|
341 |
! |
|
342 |
||
343 |
sendOpenPathCommand:pathName toWindowId:aWindowId |
|
344 |
"use the event send mechanism to forward an open-Path command to the already running application" |
|
345 |
||
346 |
self sendCommand:('openPath:', pathName) toWindowId:aWindowId. |
|
347 |
! |
|
348 |
||
349 |
writeCurrentIDIntoRegistry: currentID |
|
350 |
||
11104 | 351 |
|applicationEntry currentIDEntry| |
11102 | 352 |
|
11104 | 353 |
applicationEntry := self applicationRegistryEntry. |
354 |
applicationEntry isNil ifTrue:[^ false.]. |
|
11102 | 355 |
|
11104 | 356 |
currentIDEntry := applicationEntry createSubKeyNamed:(self currentIDKeyInRegistry). |
11102 | 357 |
currentIDEntry isNil ifTrue:[ |
358 |
Transcript showCR: 'Failed to create CurrentID entry in registry'. |
|
359 |
^ false. |
|
360 |
]. |
|
361 |
||
11104 | 362 |
^ applicationEntry valueNamed:(self currentIDKeyInRegistry) put:(currentID printString). |
11102 | 363 |
|
364 |
" |
|
365 |
| currentID returnedCurrentID | |
|
366 |
currentID := 999. |
|
367 |
DapasXStartup writeCurrentIDIntoRegistry: currentID. |
|
368 |
returnedCurrentID := DapasXStartup getCurrentIDFromRegistry. |
|
369 |
self assert: currentID = returnedCurrentID asNumber. |
|
370 |
" |
|
371 |
! ! |
|
372 |
||
9944 | 373 |
!StandaloneStartup class methodsFor:'queries'! |
374 |
||
375 |
applicationName |
|
11352 | 376 |
"used in verbose messages - can/should be redefined in subclasses" |
9944 | 377 |
|
378 |
|nm| |
|
379 |
||
380 |
nm := self nameWithoutPrefix. |
|
381 |
(nm endsWith:'Startup') ifTrue:[ |
|
382 |
^ nm copyWithoutLast:('Startup' size). |
|
383 |
]. |
|
384 |
(nm endsWith:'Start') ifTrue:[ |
|
385 |
^ nm copyWithoutLast:('Start' size). |
|
386 |
]. |
|
387 |
^ nm |
|
388 |
||
389 |
"Created: / 19-09-2006 / 16:26:44 / cg" |
|
390 |
! |
|
391 |
||
12523
df8cb7ffe5eb
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
12335
diff
changeset
|
392 |
iconInBrowserSymbol |
df8cb7ffe5eb
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
12335
diff
changeset
|
393 |
<resource: #programImage> |
df8cb7ffe5eb
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
12335
diff
changeset
|
394 |
|
df8cb7ffe5eb
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
12335
diff
changeset
|
395 |
self == StandaloneStartup ifFalse:[ |
df8cb7ffe5eb
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
12335
diff
changeset
|
396 |
^ #standaloneStartupIcon |
df8cb7ffe5eb
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
12335
diff
changeset
|
397 |
]. |
df8cb7ffe5eb
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
12335
diff
changeset
|
398 |
^ super iconInBrowserSymbol |
df8cb7ffe5eb
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
12335
diff
changeset
|
399 |
! |
df8cb7ffe5eb
added: #iconInBrowserSymbol
Claus Gittinger <cg@exept.de>
parents:
12335
diff
changeset
|
400 |
|
10040
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
401 |
isBrowserStartable |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
402 |
"do not allow clicking on me in the browser" |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
403 |
|
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
404 |
^ false |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
405 |
|
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
406 |
"Created: / 06-10-2006 / 11:33:13 / cg" |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
407 |
! |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
408 |
|
12626
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
409 |
keepSplashWindowOpen |
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
410 |
"if true is returned here, the splashWindow is not closed and will be still open |
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
411 |
when the main: method is invoked. This allows for plugin-loads etc. to be shown in the |
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
412 |
splash screen. However, my subclass's main: has to make sure that the splashScreen is closed. |
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
413 |
(calling hideSplashWindow) |
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
414 |
The default is false here which means that the splashWindow will be already closed when the |
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
415 |
subclasses main: is invoked." |
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
416 |
|
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
417 |
^ false |
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
418 |
! |
f85aaddaea1d
added: keepSplashWindowOpen
Claus Gittinger <cg@exept.de>
parents:
12523
diff
changeset
|
419 |
|
9944 | 420 |
startupFilename |
11352 | 421 |
"used in verbose messages - can/should be redefined in subclasses" |
9944 | 422 |
|
423 |
^ self applicationName asLowercase,'Start.rc' |
|
424 |
||
425 |
" |
|
11352 | 426 |
ExpeccoStartup startupFilename -> 'expecco.rc' |
9944 | 427 |
" |
428 |
||
429 |
"Created: / 19-09-2006 / 16:38:28 / cg" |
|
430 |
! ! |
|
431 |
||
432 |
!StandaloneStartup class methodsFor:'startup'! |
|
433 |
||
11055
e600e19e2e7f
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
10956
diff
changeset
|
434 |
loadPatch:fileName |
11056
e2c4a6e948b6
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
11055
diff
changeset
|
435 |
self verboseInfo:('loading patch: ',fileName baseName). |
11055
e600e19e2e7f
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
10956
diff
changeset
|
436 |
Smalltalk fileIn:fileName pathName. |
e600e19e2e7f
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
10956
diff
changeset
|
437 |
! |
e600e19e2e7f
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
10956
diff
changeset
|
438 |
|
9944 | 439 |
loadPatches |
11764
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
440 |
|patchesDir prevMode| |
9944 | 441 |
|
10934 | 442 |
patchesDir := OperatingSystem pathOfSTXExecutable asFilename directory construct:'patches'. |
443 |
(patchesDir exists and:[patchesDir isDirectory]) ifTrue:[ |
|
11764
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
444 |
prevMode := ClassCategoryReader sourceMode. |
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
445 |
ClassCategoryReader sourceMode:#discard. |
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
446 |
[ |
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
447 |
patchesDir directoryContents sort do:[:eachFilenameString | |
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
448 |
self loadPatch:(patchesDir construct:eachFilenameString). |
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
449 |
]. |
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
450 |
] ensure:[ |
89c0c60feb24
Discard source code of patches that are loaded at startup
Stefan Vogel <sv@exept.de>
parents:
11753
diff
changeset
|
451 |
ClassCategoryReader sourceMode:prevMode. |
9944 | 452 |
]. |
453 |
]. |
|
454 |
||
455 |
"Modified: / 19-09-2006 / 16:30:58 / cg" |
|
456 |
! |
|
457 |
||
458 |
setupSmalltalkFromArguments:argv |
|
11352 | 459 |
"handle common command line arguments: |
460 |
--help ............... print usage and exit |
|
461 |
--verbose (-V) ....... be verbose during startup |
|
462 |
--debug .............. enable debugger & inspector |
|
463 |
--rcFileName ......... define a startup rc-file |
|
11435 | 464 |
--scripting portNr ... start a scripting server |
465 |
--allowHost host ..... add host to the allowed scripting hosts |
|
11352 | 466 |
" |
467 |
||
11435 | 468 |
|idx rcFilename nextArg debugging scripting allowedScriptingHosts portNr| |
9944 | 469 |
|
470 |
"/ Smalltalk beHeadless:true. |
|
471 |
"/ OperatingSystem disableSignal:(OperatingSystem sigHUP). |
|
472 |
"/ Smalltalk infoPrinting:true. |
|
473 |
||
474 |
(argv includes:'--help') ifTrue:[ |
|
475 |
self usage. |
|
476 |
AbortOperationRequest raise. |
|
477 |
]. |
|
478 |
||
479 |
idx := argv indexOfAny:#('--verbose' '-V'). |
|
480 |
idx ~~ 0 ifTrue:[ |
|
481 |
argv removeAtIndex:idx. |
|
482 |
Verbose := true. |
|
483 |
]. |
|
10773 | 484 |
self verboseInfo:('args: ',argv asArray printString). |
9944 | 485 |
|
11352 | 486 |
debugging := false. |
487 |
(self allowDebugOption) ifTrue:[ |
|
488 |
idx := argv indexOfAny:#('--debug'). |
|
489 |
idx ~~ 0 ifTrue:[ |
|
11357 | 490 |
self verboseInfo:('debug on'). |
11352 | 491 |
argv removeAtIndex:idx. |
492 |
debugging := true |
|
493 |
]. |
|
494 |
]. |
|
495 |
debugging ifTrue:[ |
|
9944 | 496 |
self setupToolsForDebug. |
497 |
] ifFalse:[ |
|
498 |
self setupToolsForNoDebug. |
|
499 |
]. |
|
500 |
||
11352 | 501 |
self suppressRCFileReading ifFalse:[ |
502 |
idx := argv indexOf:'--rcFileName'. |
|
503 |
idx ~~ 0 ifTrue:[ |
|
504 |
nextArg := argv at:(idx + 1) ifAbsent:nil. |
|
505 |
(nextArg notNil and:[ (nextArg startsWith:'-') not ]) ifTrue:[ |
|
506 |
rcFilename := nextArg. |
|
507 |
argv removeAtIndex:idx+1; removeAtIndex:idx. |
|
508 |
] |
|
509 |
]. |
|
510 |
||
511 |
rcFilename isNil ifTrue:[ |
|
512 |
rcFilename := self startupFilename. |
|
513 |
]. |
|
514 |
rcFilename asFilename exists ifTrue:[ |
|
515 |
self verboseInfo:('reading ',rcFilename,'...'). |
|
516 |
rcFilename isAbsolute ifFalse:[ |
|
517 |
rcFilename := OperatingSystem pathOfSTXExecutable asFilename directory constructString:rcFilename. |
|
518 |
]. |
|
519 |
Smalltalk secureFileIn:rcFilename |
|
520 |
]. |
|
9944 | 521 |
]. |
522 |
||
11352 | 523 |
scripting := false. |
524 |
(self allowScriptingOption) ifTrue:[ |
|
525 |
idx := argv indexOfAny:#('--scripting'). |
|
526 |
idx ~~ 0 ifTrue:[ |
|
527 |
nextArg := argv at:(idx + 1) ifAbsent:nil. |
|
528 |
(nextArg notNil and:[ (nextArg startsWith:'-') not ]) ifTrue:[ |
|
529 |
portNr := nextArg asInteger. |
|
530 |
argv removeAtIndex:idx+1. |
|
531 |
]. |
|
532 |
argv removeAtIndex:idx. |
|
533 |
||
534 |
scripting := true |
|
535 |
]. |
|
11435 | 536 |
|
537 |
allowedScriptingHosts := OrderedCollection new. |
|
538 |
||
539 |
idx := argv indexOfAny:#('--allowHost'). |
|
540 |
[idx ~~ 0] whileTrue:[ |
|
541 |
nextArg := argv at:(idx + 1) ifAbsent:nil. |
|
542 |
nextArg isNil ifTrue:[ |
|
543 |
self usage. |
|
544 |
AbortOperationRequest raise. |
|
545 |
]. |
|
546 |
allowedScriptingHosts add:nextArg. |
|
547 |
idx := argv indexOfAny:#('--allowHost'). |
|
548 |
]. |
|
9944 | 549 |
]. |
11435 | 550 |
|
11352 | 551 |
scripting ifTrue:[ |
11358 | 552 |
self verboseInfo:('scripting on'). |
11352 | 553 |
STXScriptingServer notNil ifTrue:[ |
11435 | 554 |
allowedScriptingHosts do:[:eachHost | STXScriptingServer allowHost:eachHost ]. |
555 |
||
11353 | 556 |
"/ scripting on port/stdin_out/8008 |
557 |
self verboseInfo:('start scripting'). |
|
558 |
STXScriptingServer startAt:portNr |
|
11359 | 559 |
] ifFalse:[ |
560 |
self verboseInfo:('missing STXScriptingServer class'). |
|
9944 | 561 |
]. |
562 |
]. |
|
11352 | 563 |
|
9944 | 564 |
^ true |
565 |
||
10773 | 566 |
"Modified: / 31-10-2007 / 16:05:59 / cg" |
9944 | 567 |
! |
568 |
||
11355 | 569 |
setupToolsForDebug |
570 |
Debugger := DebugView ? MiniDebugger. |
|
571 |
Inspector := InspectorView ? MiniInspector. |
|
11736 | 572 |
Verbose ifTrue:[ 'debug enabled - CTRL-C brings you into a debugger.' errorPrintCR ]. |
573 |
"/ self verboseInfo:('debug enabled - CTRL-C brings you into a debugger.'). |
|
9944 | 574 |
|
575 |
"Created: / 19-09-2006 / 16:40:32 / cg" |
|
576 |
! |
|
577 |
||
11355 | 578 |
setupToolsForNoDebug |
579 |
Smalltalk isStandAloneApp ifTrue:[ |
|
11600
1d98211fc0b0
also nil private classes of NewLauncher
Claus Gittinger <cg@exept.de>
parents:
11435
diff
changeset
|
580 |
Smalltalk at:#Debugger put:nil. |
1d98211fc0b0
also nil private classes of NewLauncher
Claus Gittinger <cg@exept.de>
parents:
11435
diff
changeset
|
581 |
Smalltalk at:#Inspector put:nil. |
11714
a2210199707b
Fix if no NewLauncher is present
Stefan Vogel <sv@exept.de>
parents:
11610
diff
changeset
|
582 |
NewLauncher notNil ifTrue:[ |
a2210199707b
Fix if no NewLauncher is present
Stefan Vogel <sv@exept.de>
parents:
11610
diff
changeset
|
583 |
NewLauncher allPrivateClasses do:[:cls | |
a2210199707b
Fix if no NewLauncher is present
Stefan Vogel <sv@exept.de>
parents:
11610
diff
changeset
|
584 |
Smalltalk at:(cls name) put:nil. |
a2210199707b
Fix if no NewLauncher is present
Stefan Vogel <sv@exept.de>
parents:
11610
diff
changeset
|
585 |
]. |
a2210199707b
Fix if no NewLauncher is present
Stefan Vogel <sv@exept.de>
parents:
11610
diff
changeset
|
586 |
Smalltalk at:#NewLauncher put:nil. |
11600
1d98211fc0b0
also nil private classes of NewLauncher
Claus Gittinger <cg@exept.de>
parents:
11435
diff
changeset
|
587 |
]. |
11736 | 588 |
Verbose ifTrue:[ 'debug disabled.' errorPrintCR ]. |
589 |
||
11355 | 590 |
self redirectStandardStreams. |
10773 | 591 |
]. |
9944 | 592 |
|
593 |
"Created: / 19-09-2006 / 16:40:47 / cg" |
|
10773 | 594 |
"Modified: / 31-10-2007 / 16:18:40 / cg" |
9944 | 595 |
! |
596 |
||
11355 | 597 |
start |
12992 | 598 |
GenericException handle:[:ex | |
599 |
self verboseInfo:('Error during startup:'). |
|
600 |
self verboseInfo:(ex description). |
|
12996 | 601 |
Verbose == true ifTrue:[ex suspendedContext fullPrintAllLevels:10]. |
12992 | 602 |
ex reject. |
603 |
] do:[ |
|
604 |
CommandLineArguments := (self additionalArgumentsFromRegistry) |
|
605 |
, Smalltalk commandLineArguments. |
|
9944 | 606 |
|
12992 | 607 |
self verboseInfo:('starting...'). |
608 |
self verboseInfo:('args: ', CommandLineArguments asStringCollection asString). |
|
609 |
||
610 |
Smalltalk isStandAloneApp ifTrue:[ |
|
611 |
self loadPatches. |
|
612 |
self verboseInfo:('setup Smalltalk'). |
|
613 |
]. |
|
614 |
self setupSmalltalkFromArguments:CommandLineArguments. |
|
615 |
self main |
|
9944 | 616 |
]. |
617 |
||
12992 | 618 |
"Modified: / 04-08-2010 / 12:30:05 / cg" |
9944 | 619 |
! |
620 |
||
11807
f9e3c45c53c8
Moved #startStartBlockProcess from ExpeccoStandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
11806
diff
changeset
|
621 |
startStartBlockProcess |
f9e3c45c53c8
Moved #startStartBlockProcess from ExpeccoStandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
11806
diff
changeset
|
622 |
Smalltalk startStartBlockProcess |
f9e3c45c53c8
Moved #startStartBlockProcess from ExpeccoStandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
11806
diff
changeset
|
623 |
! |
f9e3c45c53c8
Moved #startStartBlockProcess from ExpeccoStandaloneStartup
Stefan Vogel <sv@exept.de>
parents:
11806
diff
changeset
|
624 |
|
11355 | 625 |
usage |
626 |
Stderr nextPutLine:'usage:'. |
|
627 |
Stderr nextPutLine:' ',self applicationName,' [options...]'. |
|
628 |
Stderr nextPutLine:' options:'. |
|
629 |
Stderr nextPutLine:' --help .................. output this message'. |
|
9944 | 630 |
Stderr nextPutLine:' --verbose ............... verbose startup'. |
11610 | 631 |
Stderr nextPutLine:' --noBanner .............. no splash screen'. |
11352 | 632 |
self allowScriptingOption ifTrue:[ |
633 |
Stderr nextPutLine:' --scripting portNr ...... enable scripting via port (or stdin/stdOut, if 0)'. |
|
634 |
]. |
|
635 |
self allowDebugOption ifTrue:[ |
|
636 |
Stderr nextPutLine:' --debug ................. enable Debugger'. |
|
637 |
]. |
|
638 |
self suppressRCFileReading ifFalse:[ |
|
639 |
Stderr nextPutLine:' --rcFileName file ....... execute code from file on startup (default: ',self startupFilename,')'. |
|
640 |
]. |
|
9944 | 641 |
|
642 |
"Created: / 19-09-2006 / 16:37:55 / cg" |
|
643 |
! ! |
|
644 |
||
645 |
!StandaloneStartup class methodsFor:'startup-to be redefined'! |
|
646 |
||
12991
f9c0f556ea86
added: #additionalArgumentsFromRegistry
Claus Gittinger <cg@exept.de>
parents:
12988
diff
changeset
|
647 |
additionalArgumentsFromRegistry |
f9c0f556ea86
added: #additionalArgumentsFromRegistry
Claus Gittinger <cg@exept.de>
parents:
12988
diff
changeset
|
648 |
"can be redefined to fetch and return additional arguments from the registry |
f9c0f556ea86
added: #additionalArgumentsFromRegistry
Claus Gittinger <cg@exept.de>
parents:
12988
diff
changeset
|
649 |
(or other .ini file). These are added to the beginning of the command line arguments." |
f9c0f556ea86
added: #additionalArgumentsFromRegistry
Claus Gittinger <cg@exept.de>
parents:
12988
diff
changeset
|
650 |
|
f9c0f556ea86
added: #additionalArgumentsFromRegistry
Claus Gittinger <cg@exept.de>
parents:
12988
diff
changeset
|
651 |
^ #() |
f9c0f556ea86
added: #additionalArgumentsFromRegistry
Claus Gittinger <cg@exept.de>
parents:
12988
diff
changeset
|
652 |
|
f9c0f556ea86
added: #additionalArgumentsFromRegistry
Claus Gittinger <cg@exept.de>
parents:
12988
diff
changeset
|
653 |
"Created: / 04-08-2010 / 12:20:27 / cg" |
f9c0f556ea86
added: #additionalArgumentsFromRegistry
Claus Gittinger <cg@exept.de>
parents:
12988
diff
changeset
|
654 |
! |
f9c0f556ea86
added: #additionalArgumentsFromRegistry
Claus Gittinger <cg@exept.de>
parents:
12988
diff
changeset
|
655 |
|
11806
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
656 |
isHeadless |
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
657 |
"this is invoked early by Smalltalk>>mainStartup, to ask if I like to |
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
658 |
have a Display or if I am a non-GUI headless application. |
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
659 |
|
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
660 |
Redefine in subclass, if your application is a non-GUI application" |
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
661 |
|
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
662 |
^ false |
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
663 |
! |
6508528f9499
Define #isHeadless with default value (false)
Stefan Vogel <sv@exept.de>
parents:
11764
diff
changeset
|
664 |
|
11355 | 665 |
main |
666 |
self verboseInfo:('entering main'). |
|
667 |
||
668 |
self main:CommandLineArguments. |
|
669 |
||
670 |
" |
|
671 |
self main |
|
672 |
self main:#('--info') |
|
673 |
" |
|
674 |
||
675 |
"Modified: / 31-10-2007 / 16:03:22 / cg" |
|
10636 | 676 |
! |
677 |
||
11355 | 678 |
main:argv |
679 |
self subclassResponsibility. |
|
680 |
||
681 |
"/ a typical main: looks like (in a subclass): |
|
682 |
||
683 |
"/ |app fileArg| |
|
684 |
"/ |
|
685 |
"/ self verboseInfo:('starting application'). |
|
9944 | 686 |
"/ app := <someGUIApplicationModelClass> open. |
687 |
"/ |
|
688 |
"/ self verboseInfo:('looking for args in ',argv). |
|
689 |
"/ argv notEmptyOrNil ifTrue:[ |
|
690 |
"/ fileArg := argv last asFilename. |
|
691 |
"/ self verboseInfo:('fileArg is ',fileArg name). |
|
692 |
"/ fileArg exists ifTrue:[ |
|
693 |
"/ self verboseInfo:('file exists'). |
|
694 |
"/ |
|
695 |
"/ ( #('foo' 'bar' 'baz' ) includes:fileArg suffix) ifTrue:[ |
|
696 |
"/ self verboseInfo:('loading'). |
|
697 |
"/ |
|
698 |
"/ Error handle:[:ex | |
|
699 |
"/ self verboseInfo:'error while loading'. |
|
700 |
"/ ex suspendedContext fullPrintAll. |
|
701 |
"/ ] do:[ |
|
702 |
"/ app menuLoadFromFile:fileArg |
|
703 |
"/ ]. |
|
704 |
"/ ]. |
|
705 |
"/ ]. |
|
706 |
"/ ]. |
|
707 |
||
708 |
"Created: / 19-09-2006 / 16:48:29 / cg" |
|
709 |
! ! |
|
710 |
||
711 |
!StandaloneStartup class methodsFor:'documentation'! |
|
712 |
||
713 |
version |
|
12996 | 714 |
^ '$Header: /cvs/stx/stx/libbasic/StandaloneStartup.st,v 1.48 2010-08-05 13:16:45 stefan Exp $' |
12335 | 715 |
! |
716 |
||
717 |
version_CVS |
|
12996 | 718 |
^ '$Header: /cvs/stx/stx/libbasic/StandaloneStartup.st,v 1.48 2010-08-05 13:16:45 stefan Exp $' |
9944 | 719 |
! ! |
720 |
||
721 |
StandaloneStartup initialize! |