author | Claus Gittinger <cg@exept.de> |
Wed, 31 Oct 2007 16:05:38 +0100 | |
changeset 10772 | 13bb80f40496 |
parent 10636 | ba91c2d292f3 |
child 10773 | 98a51414b27f |
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 |
|
49 |
" |
|
50 |
! ! |
|
51 |
||
52 |
!StandaloneStartup class methodsFor:'initialization'! |
|
53 |
||
54 |
initialize |
|
55 |
"/ Verbose := true. |
|
56 |
Verbose := false. |
|
57 |
! ! |
|
58 |
||
59 |
!StandaloneStartup class methodsFor:'helpers'! |
|
60 |
||
61 |
redirectStandardStreams |
|
62 |
Stdout := Stderr. |
|
63 |
Transcript := Stderr. |
|
64 |
! |
|
65 |
||
66 |
verboseInfo:msg |
|
67 |
Verbose == true ifFalse:[^ self]. |
|
68 |
||
69 |
Transcript |
|
70 |
show:('%1 [info]: ' bindWith:(self applicationName)); |
|
71 |
showCR:msg |
|
72 |
||
73 |
"Modified: / 19-09-2006 / 16:30:27 / cg" |
|
74 |
! ! |
|
75 |
||
76 |
!StandaloneStartup class methodsFor:'queries'! |
|
77 |
||
78 |
applicationName |
|
79 |
"used in verbose messages - can be redefined in subclasses" |
|
80 |
||
81 |
|nm| |
|
82 |
||
83 |
nm := self nameWithoutPrefix. |
|
84 |
(nm endsWith:'Startup') ifTrue:[ |
|
85 |
^ nm copyWithoutLast:('Startup' size). |
|
86 |
]. |
|
87 |
(nm endsWith:'Start') ifTrue:[ |
|
88 |
^ nm copyWithoutLast:('Start' size). |
|
89 |
]. |
|
90 |
^ nm |
|
91 |
||
92 |
"Created: / 19-09-2006 / 16:26:44 / cg" |
|
93 |
! |
|
94 |
||
10040
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
95 |
isBrowserStartable |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
96 |
"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
|
97 |
|
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
98 |
^ false |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
99 |
|
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
100 |
"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
|
101 |
! |
59d0c20b139f
protocol for startability via browser slightly changed
Claus Gittinger <cg@exept.de>
parents:
9944
diff
changeset
|
102 |
|
9944 | 103 |
startupFilename |
104 |
"used in verbose messages - can be redefined in subclasses" |
|
105 |
||
106 |
^ self applicationName asLowercase,'Start.rc' |
|
107 |
||
108 |
" |
|
109 |
ExpeccoStartup startupFilename |
|
110 |
" |
|
111 |
||
112 |
"Created: / 19-09-2006 / 16:38:28 / cg" |
|
113 |
! ! |
|
114 |
||
115 |
!StandaloneStartup class methodsFor:'startup'! |
|
116 |
||
117 |
loadPatches |
|
118 |
|patchesFile| |
|
119 |
||
120 |
patchesFile := OperatingSystem pathOfSTXExecutable asFilename directory construct:'patches'. |
|
121 |
(patchesFile exists and:[patchesFile isDirectory]) ifTrue:[ |
|
122 |
patchesFile directoryContentsAsFilenamesDo:[:eachFile | |
|
123 |
self verboseInfo:('loading patch: ',eachFile pathName). |
|
124 |
Smalltalk fileIn:(eachFile pathName). |
|
125 |
]. |
|
126 |
]. |
|
127 |
||
128 |
"Modified: / 19-09-2006 / 16:30:58 / cg" |
|
129 |
! |
|
130 |
||
131 |
setupSmalltalkFromArguments:argv |
|
132 |
|idx rcFilename nextArg| |
|
133 |
||
134 |
"/ Smalltalk beHeadless:true. |
|
135 |
"/ OperatingSystem disableSignal:(OperatingSystem sigHUP). |
|
136 |
"/ Smalltalk infoPrinting:true. |
|
137 |
||
138 |
(argv includes:'--help') ifTrue:[ |
|
139 |
self usage. |
|
140 |
AbortOperationRequest raise. |
|
141 |
]. |
|
142 |
||
143 |
idx := argv indexOfAny:#('--verbose' '-V'). |
|
144 |
idx ~~ 0 ifTrue:[ |
|
145 |
argv removeAtIndex:idx. |
|
146 |
Verbose := true. |
|
147 |
]. |
|
148 |
self verboseInfo:('args: ',argv printString). |
|
149 |
||
150 |
idx := argv indexOfAny:#('--debug'). |
|
151 |
idx ~~ 0 ifTrue:[ |
|
152 |
argv removeAtIndex:idx. |
|
153 |
self setupToolsForDebug. |
|
154 |
] ifFalse:[ |
|
155 |
self setupToolsForNoDebug. |
|
156 |
]. |
|
157 |
||
158 |
idx := argv indexOf:'--rcFileName'. |
|
159 |
idx ~~ 0 ifTrue:[ |
|
160 |
nextArg := argv at:(idx + 1) ifAbsent:nil. |
|
161 |
(nextArg notNil and:[ (nextArg startsWith:'-') not ]) ifTrue:[ |
|
162 |
rcFilename := nextArg. |
|
163 |
argv removeAtIndex:idx+1; removeAtIndex:idx. |
|
164 |
] |
|
165 |
]. |
|
166 |
||
167 |
rcFilename isNil ifTrue:[ |
|
168 |
rcFilename := self startupFilename. |
|
169 |
]. |
|
170 |
rcFilename asFilename exists ifTrue:[ |
|
171 |
self verboseInfo:('reading ',rcFilename,'...'). |
|
172 |
rcFilename isAbsolute ifFalse:[ |
|
173 |
rcFilename := OperatingSystem pathOfSTXExecutable asFilename directory constructString:rcFilename. |
|
174 |
]. |
|
175 |
Smalltalk secureFileIn:rcFilename |
|
176 |
]. |
|
177 |
^ true |
|
178 |
||
179 |
"Modified: / 19-09-2006 / 16:41:00 / cg" |
|
180 |
! |
|
181 |
||
182 |
setupToolsForDebug |
|
183 |
Debugger := DebugView ? MiniDebugger. |
|
184 |
Inspector := InspectorView ? MiniInspector. |
|
185 |
self verboseInfo:('debug enabled - CTRL-C brings you into a debugger.'). |
|
186 |
||
187 |
"Created: / 19-09-2006 / 16:40:32 / cg" |
|
188 |
! |
|
189 |
||
190 |
setupToolsForNoDebug |
|
191 |
Debugger := nil. |
|
192 |
Inspector := nil. |
|
193 |
NewLauncher := nil. |
|
194 |
self redirectStandardStreams. |
|
195 |
||
196 |
"Created: / 19-09-2006 / 16:40:47 / cg" |
|
197 |
! |
|
198 |
||
199 |
start |
|
10772 | 200 |
CommandLineArguments := Smalltalk commandLineArguments. |
201 |
||
9944 | 202 |
self verboseInfo:('starting...'). |
203 |
||
204 |
Smalltalk isStandAloneApp ifTrue:[ |
|
205 |
self loadPatches. |
|
206 |
self verboseInfo:('setup Smalltalk'). |
|
207 |
]. |
|
10772 | 208 |
self setupSmalltalkFromArguments:CommandLineArguments. |
9944 | 209 |
self main |
210 |
||
10772 | 211 |
"Modified: / 31-10-2007 / 16:03:44 / cg" |
9944 | 212 |
! |
213 |
||
214 |
usage |
|
215 |
Stderr nextPutLine:'usage:'. |
|
216 |
Stderr nextPutLine:' ',self applicationName,' [options...]'. |
|
217 |
Stderr nextPutLine:' options:'. |
|
218 |
Stderr nextPutLine:' --help .................. output this message'. |
|
219 |
Stderr nextPutLine:' --verbose ............... verbose startup'. |
|
220 |
Stderr nextPutLine:' --debug ................. enable Debugger'. |
|
221 |
Stderr nextPutLine:' --rcFileName file ....... execute code from file on startup (default: ',self startupFilename,')'. |
|
222 |
||
223 |
"Created: / 19-09-2006 / 16:37:55 / cg" |
|
224 |
! ! |
|
225 |
||
226 |
!StandaloneStartup class methodsFor:'startup-to be redefined'! |
|
227 |
||
228 |
main |
|
229 |
self verboseInfo:('entering main'). |
|
230 |
||
10772 | 231 |
self main:CommandLineArguments. |
10636 | 232 |
|
233 |
" |
|
234 |
self main |
|
235 |
self main:#('--info') |
|
236 |
" |
|
237 |
||
10772 | 238 |
"Modified: / 31-10-2007 / 16:03:22 / cg" |
10636 | 239 |
! |
240 |
||
241 |
main:argv |
|
9944 | 242 |
self subclassResponsibility. |
243 |
||
10636 | 244 |
"/ a typical main: looks like (in a subclass): |
9944 | 245 |
|
10636 | 246 |
"/ |app fileArg| |
247 |
"/ |
|
9944 | 248 |
"/ self verboseInfo:('starting application'). |
249 |
"/ app := <someGUIApplicationModelClass> open. |
|
250 |
"/ |
|
251 |
"/ self verboseInfo:('looking for args in ',argv). |
|
252 |
"/ argv notEmptyOrNil ifTrue:[ |
|
253 |
"/ fileArg := argv last asFilename. |
|
254 |
"/ self verboseInfo:('fileArg is ',fileArg name). |
|
255 |
"/ fileArg exists ifTrue:[ |
|
256 |
"/ self verboseInfo:('file exists'). |
|
257 |
"/ |
|
258 |
"/ ( #('foo' 'bar' 'baz' ) includes:fileArg suffix) ifTrue:[ |
|
259 |
"/ self verboseInfo:('loading'). |
|
260 |
"/ |
|
261 |
"/ Error handle:[:ex | |
|
262 |
"/ self verboseInfo:'error while loading'. |
|
263 |
"/ ex suspendedContext fullPrintAll. |
|
264 |
"/ ] do:[ |
|
265 |
"/ app menuLoadFromFile:fileArg |
|
266 |
"/ ]. |
|
267 |
"/ ]. |
|
268 |
"/ ]. |
|
269 |
"/ ]. |
|
270 |
||
271 |
"Created: / 19-09-2006 / 16:48:29 / cg" |
|
272 |
! ! |
|
273 |
||
274 |
!StandaloneStartup class methodsFor:'documentation'! |
|
275 |
||
276 |
version |
|
10772 | 277 |
^ '$Header: /cvs/stx/stx/libbasic/StandaloneStartup.st,v 1.4 2007-10-31 15:05:38 cg Exp $' |
9944 | 278 |
! ! |
279 |
||
280 |
StandaloneStartup initialize! |