author | Claus Gittinger <cg@exept.de> |
Fri, 13 Jun 2008 12:59:28 +0200 | |
changeset 11055 | e600e19e2e7f |
parent 10956 | ab4f2618182f |
child 11056 | e2c4a6e948b6 |
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 |
||
21 |
!StandaloneStartup class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
39 |
a subclassable template class for a standalone GUI-application's startup; |
|
40 |
For your own stand alone programs, define a subclass of this, |
|
41 |
and redefine the #main method there. |
|
42 |
(of course, the other methods can also be redefined.) |
|
43 |
||
44 |
[author:] |
|
45 |
Claus Gittinger |
|
46 |
||
47 |
[start with:] |
|
48 |
<yourNamehere>Startup start |
|
10886 | 49 |
|
50 |
[see also:] |
|
51 |
Smalltalk |
|
52 |
GetOpt |
|
53 |
ReadEvalPrintLoop |
|
9944 | 54 |
" |
55 |
! ! |
|
56 |
||
57 |
!StandaloneStartup class methodsFor:'initialization'! |
|
58 |
||
59 |
initialize |
|
60 |
"/ Verbose := true. |
|
61 |
Verbose := false. |
|
62 |
! ! |
|
63 |
||
64 |
!StandaloneStartup class methodsFor:'helpers'! |
|
65 |
||
66 |
redirectStandardStreams |
|
67 |
Stdout := Stderr. |
|
68 |
Transcript := Stderr. |
|
69 |
! |
|
70 |
||
71 |
verboseInfo:msg |
|
72 |
Verbose == true ifFalse:[^ self]. |
|
73 |
||
74 |
Transcript |
|
75 |
show:('%1 [info]: ' bindWith:(self applicationName)); |
|
76 |
showCR:msg |
|
77 |
||
78 |
"Modified: / 19-09-2006 / 16:30:27 / cg" |
|
79 |
! ! |
|
80 |
||
81 |
!StandaloneStartup class methodsFor:'queries'! |
|
82 |
||
83 |
applicationName |
|
84 |
"used in verbose messages - can be redefined in subclasses" |
|
85 |
||
86 |
|nm| |
|
87 |
||
88 |
nm := self nameWithoutPrefix. |
|
89 |
(nm endsWith:'Startup') ifTrue:[ |
|
90 |
^ nm copyWithoutLast:('Startup' size). |
|
91 |
]. |
|
92 |
(nm endsWith:'Start') ifTrue:[ |
|
93 |
^ nm copyWithoutLast:('Start' size). |
|
94 |
]. |
|
95 |
^ nm |
|
96 |
||
97 |
"Created: / 19-09-2006 / 16:26:44 / cg" |
|
98 |
! |
|
99 |
||
10040
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
100 |
isBrowserStartable |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
101 |
"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
|
102 |
|
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
103 |
^ false |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
104 |
|
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
105 |
"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
|
106 |
! |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
107 |
|
9944 | 108 |
startupFilename |
109 |
"used in verbose messages - can be redefined in subclasses" |
|
110 |
||
111 |
^ self applicationName asLowercase,'Start.rc' |
|
112 |
||
113 |
" |
|
114 |
ExpeccoStartup startupFilename |
|
115 |
" |
|
116 |
||
117 |
"Created: / 19-09-2006 / 16:38:28 / cg" |
|
118 |
! ! |
|
119 |
||
120 |
!StandaloneStartup class methodsFor:'startup'! |
|
121 |
||
11055
e600e19e2e7f
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
10956
diff
changeset
|
122 |
loadPatch:fileName |
e600e19e2e7f
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
10956
diff
changeset
|
123 |
Smalltalk fileIn:fileName pathName. |
e600e19e2e7f
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
10956
diff
changeset
|
124 |
! |
e600e19e2e7f
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
10956
diff
changeset
|
125 |
|
9944 | 126 |
loadPatches |
10934 | 127 |
|patchesDir| |
9944 | 128 |
|
10934 | 129 |
patchesDir := OperatingSystem pathOfSTXExecutable asFilename directory construct:'patches'. |
130 |
(patchesDir exists and:[patchesDir isDirectory]) ifTrue:[ |
|
131 |
patchesDir directoryContents sort do:[:eachFile | |
|
132 |
self verboseInfo:('loading patch: ',eachFile). |
|
11055
e600e19e2e7f
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
10956
diff
changeset
|
133 |
self loadPatch:(patchesDir construct:eachFile). |
9944 | 134 |
]. |
135 |
]. |
|
136 |
||
137 |
"Modified: / 19-09-2006 / 16:30:58 / cg" |
|
138 |
! |
|
139 |
||
140 |
setupSmalltalkFromArguments:argv |
|
141 |
|idx rcFilename nextArg| |
|
142 |
||
143 |
"/ Smalltalk beHeadless:true. |
|
144 |
"/ OperatingSystem disableSignal:(OperatingSystem sigHUP). |
|
145 |
"/ Smalltalk infoPrinting:true. |
|
146 |
||
147 |
(argv includes:'--help') ifTrue:[ |
|
148 |
self usage. |
|
149 |
AbortOperationRequest raise. |
|
150 |
]. |
|
151 |
||
152 |
idx := argv indexOfAny:#('--verbose' '-V'). |
|
153 |
idx ~~ 0 ifTrue:[ |
|
154 |
argv removeAtIndex:idx. |
|
155 |
Verbose := true. |
|
156 |
]. |
|
10773 | 157 |
self verboseInfo:('args: ',argv asArray printString). |
9944 | 158 |
|
159 |
idx := argv indexOfAny:#('--debug'). |
|
160 |
idx ~~ 0 ifTrue:[ |
|
161 |
argv removeAtIndex:idx. |
|
162 |
self setupToolsForDebug. |
|
163 |
] ifFalse:[ |
|
164 |
self setupToolsForNoDebug. |
|
165 |
]. |
|
166 |
||
167 |
idx := argv indexOf:'--rcFileName'. |
|
168 |
idx ~~ 0 ifTrue:[ |
|
169 |
nextArg := argv at:(idx + 1) ifAbsent:nil. |
|
170 |
(nextArg notNil and:[ (nextArg startsWith:'-') not ]) ifTrue:[ |
|
171 |
rcFilename := nextArg. |
|
172 |
argv removeAtIndex:idx+1; removeAtIndex:idx. |
|
173 |
] |
|
174 |
]. |
|
175 |
||
176 |
rcFilename isNil ifTrue:[ |
|
177 |
rcFilename := self startupFilename. |
|
178 |
]. |
|
179 |
rcFilename asFilename exists ifTrue:[ |
|
180 |
self verboseInfo:('reading ',rcFilename,'...'). |
|
181 |
rcFilename isAbsolute ifFalse:[ |
|
182 |
rcFilename := OperatingSystem pathOfSTXExecutable asFilename directory constructString:rcFilename. |
|
183 |
]. |
|
184 |
Smalltalk secureFileIn:rcFilename |
|
185 |
]. |
|
186 |
^ true |
|
187 |
||
10773 | 188 |
"Modified: / 31-10-2007 / 16:05:59 / cg" |
9944 | 189 |
! |
190 |
||
191 |
setupToolsForDebug |
|
192 |
Debugger := DebugView ? MiniDebugger. |
|
193 |
Inspector := InspectorView ? MiniInspector. |
|
194 |
self verboseInfo:('debug enabled - CTRL-C brings you into a debugger.'). |
|
195 |
||
196 |
"Created: / 19-09-2006 / 16:40:32 / cg" |
|
197 |
! |
|
198 |
||
199 |
setupToolsForNoDebug |
|
10773 | 200 |
Smalltalk isStandAloneApp ifTrue:[ |
201 |
Debugger := nil. |
|
202 |
Inspector := nil. |
|
203 |
NewLauncher := nil. |
|
204 |
self redirectStandardStreams. |
|
205 |
]. |
|
9944 | 206 |
|
207 |
"Created: / 19-09-2006 / 16:40:47 / cg" |
|
10773 | 208 |
"Modified: / 31-10-2007 / 16:18:40 / cg" |
9944 | 209 |
! |
210 |
||
211 |
start |
|
10772 | 212 |
CommandLineArguments := Smalltalk commandLineArguments. |
213 |
||
9944 | 214 |
self verboseInfo:('starting...'). |
10956 | 215 |
self verboseInfo:('args: ', CommandLineArguments asStringCollection asString). |
9944 | 216 |
|
217 |
Smalltalk isStandAloneApp ifTrue:[ |
|
218 |
self loadPatches. |
|
219 |
self verboseInfo:('setup Smalltalk'). |
|
220 |
]. |
|
10772 | 221 |
self setupSmalltalkFromArguments:CommandLineArguments. |
9944 | 222 |
self main |
223 |
||
10772 | 224 |
"Modified: / 31-10-2007 / 16:03:44 / cg" |
9944 | 225 |
! |
226 |
||
227 |
usage |
|
228 |
Stderr nextPutLine:'usage:'. |
|
229 |
Stderr nextPutLine:' ',self applicationName,' [options...]'. |
|
230 |
Stderr nextPutLine:' options:'. |
|
231 |
Stderr nextPutLine:' --help .................. output this message'. |
|
232 |
Stderr nextPutLine:' --verbose ............... verbose startup'. |
|
233 |
Stderr nextPutLine:' --debug ................. enable Debugger'. |
|
234 |
Stderr nextPutLine:' --rcFileName file ....... execute code from file on startup (default: ',self startupFilename,')'. |
|
235 |
||
236 |
"Created: / 19-09-2006 / 16:37:55 / cg" |
|
237 |
! ! |
|
238 |
||
239 |
!StandaloneStartup class methodsFor:'startup-to be redefined'! |
|
240 |
||
241 |
main |
|
242 |
self verboseInfo:('entering main'). |
|
243 |
||
10772 | 244 |
self main:CommandLineArguments. |
10636 | 245 |
|
246 |
" |
|
247 |
self main |
|
248 |
self main:#('--info') |
|
249 |
" |
|
250 |
||
10772 | 251 |
"Modified: / 31-10-2007 / 16:03:22 / cg" |
10636 | 252 |
! |
253 |
||
254 |
main:argv |
|
9944 | 255 |
self subclassResponsibility. |
256 |
||
10636 | 257 |
"/ a typical main: looks like (in a subclass): |
9944 | 258 |
|
10636 | 259 |
"/ |app fileArg| |
260 |
"/ |
|
9944 | 261 |
"/ self verboseInfo:('starting application'). |
262 |
"/ app := <someGUIApplicationModelClass> open. |
|
263 |
"/ |
|
264 |
"/ self verboseInfo:('looking for args in ',argv). |
|
265 |
"/ argv notEmptyOrNil ifTrue:[ |
|
266 |
"/ fileArg := argv last asFilename. |
|
267 |
"/ self verboseInfo:('fileArg is ',fileArg name). |
|
268 |
"/ fileArg exists ifTrue:[ |
|
269 |
"/ self verboseInfo:('file exists'). |
|
270 |
"/ |
|
271 |
"/ ( #('foo' 'bar' 'baz' ) includes:fileArg suffix) ifTrue:[ |
|
272 |
"/ self verboseInfo:('loading'). |
|
273 |
"/ |
|
274 |
"/ Error handle:[:ex | |
|
275 |
"/ self verboseInfo:'error while loading'. |
|
276 |
"/ ex suspendedContext fullPrintAll. |
|
277 |
"/ ] do:[ |
|
278 |
"/ app menuLoadFromFile:fileArg |
|
279 |
"/ ]. |
|
280 |
"/ ]. |
|
281 |
"/ ]. |
|
282 |
"/ ]. |
|
283 |
||
284 |
"Created: / 19-09-2006 / 16:48:29 / cg" |
|
285 |
! ! |
|
286 |
||
287 |
!StandaloneStartup class methodsFor:'documentation'! |
|
288 |
||
289 |
version |
|
11055
e600e19e2e7f
loadPatch extracted to be redefinable.
Claus Gittinger <cg@exept.de>
parents:
10956
diff
changeset
|
290 |
^ '$Header: /cvs/stx/stx/libbasic/StandaloneStartup.st,v 1.9 2008-06-13 10:59:28 cg Exp $' |
9944 | 291 |
! ! |
292 |
||
293 |
StandaloneStartup initialize! |