author | Claus Gittinger <cg@exept.de> |
Mon, 22 Apr 1996 13:02:23 +0200 | |
changeset 191 | cb2815b77100 |
parent 187 | 9e35ae67f07c |
child 215 | 369b0376e859 |
permissions | -rw-r--r-- |
50 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
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 |
||
13 |
Model subclass:#ApplicationModel |
|
142
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
14 |
instanceVariableNames:'builder resources' |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
15 |
classVariableNames:'' |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
16 |
poolDictionaries:'' |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
17 |
category:'Interface-Framework' |
50 | 18 |
! |
19 |
||
138 | 20 |
ApplicationModel class instanceVariableNames:'ClassResources' |
21 |
||
22 |
" |
|
23 |
The following class instance variables are inherited by this class: |
|
24 |
||
25 |
Model - |
|
26 |
Object - |
|
27 |
" |
|
28 |
! |
|
52 | 29 |
|
50 | 30 |
!ApplicationModel class methodsFor:'documentation'! |
31 |
||
32 |
copyright |
|
33 |
" |
|
34 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
35 |
All Rights Reserved |
|
36 |
||
37 |
This software is furnished under a license and may be used |
|
38 |
only in accordance with the terms of that license and with the |
|
39 |
inclusion of the above copyright notice. This software may not |
|
40 |
be provided or otherwise made available to, or used by, any |
|
41 |
other person. No title to or ownership of the software is |
|
42 |
hereby transferred. |
|
43 |
" |
|
44 |
! |
|
45 |
||
46 |
documentation |
|
47 |
" |
|
48 |
Since many ST-80 classes are subclasses of ApplicationModel, this class |
|
49 |
is provided here to allow easier porting of ST-80 code. |
|
57 | 50 |
|
63 | 51 |
It does not (currently) provide much functionality and is NOT |
52 |
compatible to the corresponding ST80 class; therefore, manual |
|
50 | 53 |
changes have to be made to get those applications to run under ST/X. |
57 | 54 |
(but at least, this enables you to fileIn that code and have a superclass |
78 | 55 |
for them) |
56 |
||
57 |
As time goes by, ST/X applications are going to be converted to |
|
58 |
become subclasses of this abstract class - see NewLauncher for a |
|
59 |
first concrete example. |
|
60 |
||
61 |
ApplicationModel is prepared to build a view from a windowSpec, as |
|
62 |
created by the windowBuilder. If you subclass does not provide such |
|
63 |
a spec, you should at least redefine: |
|
64 |
||
65 |
openInterface - to create a topview and open it |
|
66 |
||
67 |
you may want to redefine: |
|
68 |
||
69 |
closeRequest - to catch window closing |
|
70 |
focusSequence - to define a sequence for focus-stepping |
|
71 |
||
50 | 72 |
|
52 | 73 |
The classResources have been put into this class to allow ST/X |
57 | 74 |
applications (which used to be subclasses of StandardSystemView) |
75 |
to migrate smoothly into ApplicationModels (which is better design ...). |
|
52 | 76 |
|
50 | 77 |
Instance variables: |
52 | 78 |
resources ResourcePack language string translation |
79 |
||
78 | 80 |
builder WindowBuilder a builder who knows how to create |
81 |
a window hierarchy from a specification |
|
82 |
||
83 |
||
84 |
Notice: this class was implemented using protocol information |
|
85 |
from alpha testers and PD code - it may not be complete or compatible to |
|
86 |
the corresponding ST-80 class. If you encounter any incompatibilities, |
|
87 |
please forward a note to the ST/X team. |
|
50 | 88 |
" |
89 |
! ! |
|
90 |
||
52 | 91 |
!ApplicationModel class methodsFor:'initialization'! |
92 |
||
93 |
initialize |
|
94 |
self == ApplicationModel ifTrue:[ |
|
95 |
Smalltalk addDependent:self |
|
96 |
] |
|
97 |
||
98 |
" |
|
99 |
ApplicationModel initialize |
|
100 |
" |
|
101 |
! ! |
|
102 |
||
103 |
!ApplicationModel class methodsFor:'instance creation'! |
|
104 |
||
105 |
new |
|
63 | 106 |
^ super new basicInitialize initialize |
52 | 107 |
! ! |
108 |
||
109 |
!ApplicationModel class methodsFor:'change & update'! |
|
110 |
||
111 |
update:something |
|
69 | 112 |
"flush resources on language changes" |
113 |
||
52 | 114 |
something == #Language ifTrue:[ |
115 |
"flush resources on language changes" |
|
116 |
self flushAllClassResources |
|
117 |
] |
|
118 |
! ! |
|
119 |
||
63 | 120 |
!ApplicationModel class methodsFor:'queries'! |
121 |
||
122 |
interfaceSpecFor:aSelector |
|
69 | 123 |
"return an interface spec" |
124 |
||
63 | 125 |
^ self perform:aSelector |
126 |
! ! |
|
127 |
||
52 | 128 |
!ApplicationModel class methodsFor:'resources'! |
129 |
||
130 |
classResources |
|
131 |
"if not already loaded, get the classes resourcePack |
|
132 |
and return it" |
|
133 |
||
134 |
ClassResources isNil ifTrue:[ |
|
135 |
ClassResources := ResourcePack for:self. |
|
136 |
]. |
|
137 |
^ ClassResources |
|
138 |
! |
|
139 |
||
140 |
classResources:aResourcePack |
|
141 |
"allow setting of the classResources" |
|
142 |
||
143 |
ClassResources := aResourcePack |
|
144 |
! |
|
145 |
||
146 |
flushAllClassResources |
|
147 |
"flush all classes resource translations. |
|
148 |
Needed after a resource file / language setting has changed." |
|
149 |
||
150 |
ResourcePack flushCachedResourcePacks. |
|
151 |
self flushClassResources. |
|
152 |
self allSubclassesDo:[:aClass | |
|
153 |
aClass flushClassResources. |
|
154 |
] |
|
155 |
! |
|
156 |
||
157 |
flushClassResources |
|
158 |
"flush classes resource string translations. |
|
159 |
Needed whenever a resource file / language setting has changed" |
|
160 |
||
161 |
ClassResources := nil. |
|
63 | 162 |
! |
163 |
||
164 |
updateClassResources |
|
165 |
"update my classResources" |
|
166 |
||
167 |
ClassResources := nil. |
|
168 |
self classResources |
|
52 | 169 |
! ! |
170 |
||
138 | 171 |
!ApplicationModel class methodsFor:'startup'! |
172 |
||
173 |
open |
|
174 |
"create an instance of the application and open its view" |
|
175 |
||
176 |
self new open |
|
177 |
||
178 |
" |
|
179 |
self open |
|
180 |
" |
|
181 |
! |
|
182 |
||
183 |
openInterface:anInterfaceSymbol |
|
184 |
"create an instance of the application and open a view as |
|
185 |
specified by anInterfaceSymbol." |
|
186 |
||
187 |
self new openInterface:anInterfaceSymbol |
|
188 |
||
189 |
"Modified: 5.9.1995 / 17:54:50 / claus" |
|
190 |
! |
|
191 |
||
192 |
openOn:anApplicationModel |
|
193 |
"I dont really understand what this method is useful for ..." |
|
194 |
||
195 |
anApplicationModel open |
|
196 |
! |
|
197 |
||
198 |
openOnDevice:aDevice |
|
199 |
"create an instance of the application and open its view |
|
200 |
on another device. |
|
201 |
EXPERIMENTAL and unfinished." |
|
202 |
||
203 |
self new openOnDevice:aDevice |
|
204 |
! ! |
|
205 |
||
206 |
!ApplicationModel methodsFor:'accessing'! |
|
207 |
||
208 |
builder |
|
209 |
"return the applications builder; this one has more information |
|
210 |
about views, components etc." |
|
211 |
||
212 |
^ builder |
|
213 |
! |
|
214 |
||
215 |
builder:aBuilder |
|
216 |
"set the applications builder. Normally, you should not set it |
|
217 |
directly, but depend on the default builder, as created when the application |
|
218 |
was created." |
|
219 |
||
220 |
builder := aBuilder |
|
221 |
! |
|
222 |
||
223 |
focusSequence |
|
224 |
"return a focusSequence for stepping through the applications views. |
|
225 |
The builder usually keeps track of so-called 'tabable' views. |
|
226 |
Stepping is done with the FocusNext/FocusPrevius keys, which are |
|
227 |
typically bound to Meta-CursorUp/Meta-CursorDown. |
|
228 |
Subclasses which do not use the builder (but instead build their view |
|
229 |
programmatically) should redefine this method to return a collection of |
|
230 |
views which defines the sequence." |
|
231 |
||
232 |
builder notNil ifTrue:[ |
|
233 |
^ builder focusSequence |
|
234 |
]. |
|
235 |
^ nil |
|
236 |
! |
|
237 |
||
238 |
resources |
|
239 |
"return the applications resources - thats a ResourcePack containing |
|
240 |
language strings" |
|
241 |
||
242 |
^ resources |
|
243 |
! |
|
244 |
||
245 |
window |
|
246 |
"return my topWindow" |
|
247 |
||
248 |
^ builder window |
|
249 |
! |
|
250 |
||
187 | 251 |
window:aTopView |
252 |
"set my topWindow" |
|
253 |
||
254 |
builder window:aTopView |
|
255 |
||
256 |
"Created: 18.4.1996 / 14:55:26 / cg" |
|
257 |
! |
|
258 |
||
138 | 259 |
windowGroup |
260 |
"return the applications windowGroup" |
|
261 |
||
262 |
^ builder window windowGroup |
|
263 |
! ! |
|
264 |
||
52 | 265 |
!ApplicationModel methodsFor:'initialization'! |
266 |
||
138 | 267 |
addTopViewsToCurrentProject |
268 |
"add all of my topViews to the current projects list of views. |
|
269 |
This allows hiding views on a per-project basis." |
|
85 | 270 |
|
138 | 271 |
self windowGroup topViews do:[:aView | |
272 |
aView addToCurrentProject |
|
273 |
] |
|
85 | 274 |
! |
275 |
||
63 | 276 |
basicInitialize |
69 | 277 |
"initialize the application. |
278 |
Since ST-80 applications seem commonly to redefine initialize |
|
279 |
without doing a super initialize, the real initialization is |
|
280 |
done here ..." |
|
281 |
||
52 | 282 |
super initialize. |
72 | 283 |
|
284 |
"claus: I wanted to delay the creation & assignment of the |
|
285 |
builder till later, to allow setting to another builder. |
|
286 |
however, some ST-80 code accesses the builder right after instance |
|
287 |
creation ..." |
|
288 |
||
289 |
"/ " |
|
290 |
"/ Create a windowBuilder to have someone around which |
|
291 |
"/ understands the builder protocol. Since UIBuilder is not present |
|
292 |
"/ in all systems, this allows operation without one (unless a spec |
|
293 |
"/ is read later ...) |
|
294 |
"/ " |
|
85 | 295 |
builder := self createBuilder. |
78 | 296 |
builder notNil ifTrue:[builder application:self]. |
52 | 297 |
resources := self class classResources. |
63 | 298 |
! |
299 |
||
138 | 300 |
createBuilder |
301 |
"create a UI Builder for me. |
|
302 |
This method can be redefined if (eventually) there are |
|
303 |
spec readers for other UI languages (motif UIL ?)" |
|
304 |
||
305 |
|cls| |
|
306 |
||
307 |
(cls := UIBuilder) isNil ifTrue:[ |
|
308 |
(cls := WindowBuilder) isNil ifTrue:[ |
|
309 |
^ nil |
|
310 |
] |
|
311 |
]. |
|
312 |
^ cls new |
|
313 |
! |
|
314 |
||
63 | 315 |
initialize |
83 | 316 |
"nothing done here; |
317 |
but can be redefined in concrete applications" |
|
138 | 318 |
! ! |
319 |
||
320 |
!ApplicationModel methodsFor:'misc'! |
|
321 |
||
322 |
withCursor:aCursor do:aBlock |
|
323 |
"evaluate aBlock, showing aCursor in my topView and all of its subviews. |
|
324 |
Return the value of aBlock." |
|
325 |
||
326 |
^ self window withCursor:aCursor do:aBlock |
|
63 | 327 |
! |
328 |
||
142
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
329 |
withExecuteCursorDo:aBlock |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
330 |
"evaluate aBlock, showing an executeCursor in my topView and all of its subviews. |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
331 |
Return the value of aBlock." |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
332 |
|
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
333 |
^ self withCursor:(Cursor execute) do:aBlock |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
334 |
|
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
335 |
"Created: 14.12.1995 / 20:57:03 / cg" |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
336 |
! |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
337 |
|
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
338 |
withReadCursorDo:aBlock |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
339 |
"evaluate aBlock, showing a readCursor in my topView and all of its subviews. |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
340 |
Return the value of aBlock." |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
341 |
|
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
342 |
^ self withCursor:(Cursor read) do:aBlock |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
343 |
|
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
344 |
"Created: 14.12.1995 / 20:56:47 / cg" |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
345 |
"Modified: 14.12.1995 / 20:57:36 / cg" |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
346 |
! |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
347 |
|
138 | 348 |
withWaitCursorDo:aBlock |
349 |
"evaluate aBlock, showing a waitCursor in my topView and all of its subviews. |
|
350 |
Return the value of aBlock." |
|
63 | 351 |
|
138 | 352 |
^ self withCursor:Cursor wait do:aBlock |
52 | 353 |
! ! |
57 | 354 |
|
71 | 355 |
!ApplicationModel methodsFor:'queries'! |
356 |
||
357 |
processName |
|
358 |
"return a name to be shown for me in the process monitor" |
|
359 |
||
360 |
^ 'Application' |
|
361 |
! ! |
|
362 |
||
57 | 363 |
!ApplicationModel methodsFor:'startup'! |
364 |
||
63 | 365 |
allButOpenFrom:aSpec |
69 | 366 |
"create my views but do not open the main window" |
367 |
||
71 | 368 |
|realBuilder| |
369 |
||
72 | 370 |
"/ DISABLED; see comment in basicInitialize |
371 |
"/ |
|
372 |
"/ " |
|
373 |
"/ here, we kludge a bit: up to now, the builder was an |
|
374 |
"/ instance of the no-op WindowBuilder. Now, it becomes |
|
375 |
"/ a UIBuilder .... |
|
376 |
"/ This allows for ApplicationModels without a UIBuilder |
|
377 |
"/ if not needed. |
|
378 |
"/ " |
|
379 |
"/ realBuilder := UIBuilder new. |
|
380 |
"/ builder := realBuilder. |
|
381 |
"/ builder application:self. |
|
382 |
"/ builder bindings:builder bindings. |
|
71 | 383 |
|
63 | 384 |
self preBuildWith:builder. |
385 |
builder buildFromSpec:aSpec. |
|
85 | 386 |
builder window model:self. |
387 |
builder window application:self. |
|
63 | 388 |
self postBuildWith:builder. |
389 |
! |
|
57 | 390 |
|
138 | 391 |
allButOpenInterface:aSymbol |
392 |
"create my views but do not open the main window" |
|
393 |
||
394 |
|spec| |
|
395 |
||
396 |
spec := self class interfaceSpecFor:aSymbol. |
|
397 |
self allButOpenFrom:spec. |
|
398 |
^ builder |
|
399 |
! |
|
400 |
||
401 |
close |
|
402 |
"this is sent by my topView when about to be closed |
|
403 |
by the program (not by the windowManager). |
|
404 |
Could be redefined in subclasses." |
|
405 |
||
406 |
self closeDownViews |
|
407 |
! |
|
408 |
||
409 |
closeDownViews |
|
410 |
"close down the applications view" |
|
411 |
||
412 |
|wg views| |
|
413 |
||
414 |
(wg := self windowGroup) notNil ifTrue:[ |
|
415 |
views := wg topViews. |
|
416 |
views notNil ifTrue:[ |
|
417 |
views copy do:[:aView | |
|
418 |
aView notNil ifTrue:[aView destroy] |
|
419 |
] |
|
420 |
] |
|
421 |
] |
|
422 |
! |
|
423 |
||
424 |
closeRequest |
|
425 |
"this is sent by my topView when about to be closed by the |
|
426 |
windowmanager. Can be redefined to inform & query about unsafed |
|
427 |
view contents, to send #close on ok, or ignore the closeRequest." |
|
428 |
||
429 |
self closeDownViews |
|
430 |
! |
|
431 |
||
432 |
menuFor:aSymbol |
|
433 |
"create a new menuBuilder, to read specs and |
|
434 |
create a menu from it. Return this menu" |
|
435 |
||
436 |
|spec mbuilder| |
|
437 |
||
438 |
spec := self class interfaceSpecFor:aSymbol. |
|
439 |
mbuilder := UIBuilder new. |
|
440 |
mbuilder buildFromSpec:spec. |
|
441 |
||
442 |
builder componentAt:#windowMenuHolder put:(mbuilder window asValue). |
|
443 |
^ mbuilder window |
|
444 |
! |
|
445 |
||
69 | 446 |
open |
447 |
"open a standard interface" |
|
448 |
||
78 | 449 |
self openInterface |
69 | 450 |
! |
451 |
||
63 | 452 |
openInterface |
78 | 453 |
"open a standard interface on another device. |
454 |
Subclasses which do not have an interfaceSpec |
|
455 |
may want to redefine this method and create & open their view(s) |
|
456 |
there. (see NewLauncher as an example)." |
|
69 | 457 |
|
63 | 458 |
self openInterface:#windowSpec |
57 | 459 |
! |
460 |
||
63 | 461 |
openInterface:aSymbol |
78 | 462 |
"open an interface on another display; |
463 |
the argument, aSymbol specifies which interface. |
|
69 | 464 |
Typically, applications only use one interface, |
78 | 465 |
returned by the #windowSpec method." |
69 | 466 |
|
85 | 467 |
self allButOpenInterface:aSymbol. |
78 | 468 |
builder openWithExtent:nil. |
469 |
||
63 | 470 |
^ builder |
471 |
! |
|
472 |
||
473 |
opened |
|
474 |
"this is sent by my topView when its finally open" |
|
475 |
||
476 |
self addTopViewsToCurrentProject. |
|
477 |
self postOpenWith:builder |
|
57 | 478 |
! |
479 |
||
138 | 480 |
postBuildWith:aBuilder |
481 |
"this is sent after an interface is built from a spec. |
|
482 |
Can be redefined in subclasses. |
|
483 |
mhmh - what should this do here ?" |
|
484 |
! |
|
485 |
||
486 |
postOpenWith:aBuilder |
|
487 |
"this is sent after the applications main window is opened. |
|
488 |
Can be redefined in subclasses. |
|
489 |
mhmh - what should this do here ?" |
|
490 |
! |
|
491 |
||
492 |
preBuildWith:aBuilder |
|
493 |
"this is sent before an interface is built from a spec. |
|
494 |
Can be redefined in subclasses. |
|
495 |
mhmh - what should this do here ?" |
|
496 |
! |
|
497 |
||
69 | 498 |
restarted |
499 |
"sent by my windowGroup, when restarted from an image. |
|
500 |
Nothing done here, but can be redefined to perform any actions |
|
501 |
required to reset the application after an image-restart. |
|
502 |
(for example: check if application files are still around, restart |
|
503 |
subprocesses etc.)." |
|
63 | 504 |
! |
57 | 505 |
|
63 | 506 |
saveAndTerminateRequest |
507 |
"some windowManagers send this to shut down an application |
|
508 |
and have it save its state for restart. |
|
509 |
Can be redefined in subclasses" |
|
510 |
||
511 |
self closeRequest |
|
57 | 512 |
! ! |
72 | 513 |
|
85 | 514 |
!ApplicationModel methodsFor:'window events'! |
515 |
||
144 | 516 |
showActivity:someMessage |
517 |
^ self |
|
518 |
||
519 |
"Created: 16.12.1995 / 18:41:04 / cg" |
|
520 |
! |
|
521 |
||
85 | 522 |
windowEvent:anEvent from:anApplicationWindow |
523 |
^ self |
|
524 |
! ! |
|
525 |
||
138 | 526 |
!ApplicationModel class methodsFor:'documentation'! |
72 | 527 |
|
138 | 528 |
version |
187 | 529 |
^ '$Header: /cvs/stx/stx/libview2/Attic/AppModel.st,v 1.21 1996-04-18 14:42:30 cg Exp $' |
81 | 530 |
! ! |
138 | 531 |
ApplicationModel initialize! |