author | Claus Gittinger <cg@exept.de> |
Sat, 27 Jan 1996 19:36:37 +0100 | |
changeset 158 | 16f2237474fe |
parent 144 | a75a0c558a77 |
child 187 | 9e35ae67f07c |
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 |
||
251 |
windowGroup |
|
252 |
"return the applications windowGroup" |
|
253 |
||
254 |
^ builder window windowGroup |
|
255 |
! ! |
|
256 |
||
52 | 257 |
!ApplicationModel methodsFor:'initialization'! |
258 |
||
138 | 259 |
addTopViewsToCurrentProject |
260 |
"add all of my topViews to the current projects list of views. |
|
261 |
This allows hiding views on a per-project basis." |
|
85 | 262 |
|
138 | 263 |
self windowGroup topViews do:[:aView | |
264 |
aView addToCurrentProject |
|
265 |
] |
|
85 | 266 |
! |
267 |
||
63 | 268 |
basicInitialize |
69 | 269 |
"initialize the application. |
270 |
Since ST-80 applications seem commonly to redefine initialize |
|
271 |
without doing a super initialize, the real initialization is |
|
272 |
done here ..." |
|
273 |
||
52 | 274 |
super initialize. |
72 | 275 |
|
276 |
"claus: I wanted to delay the creation & assignment of the |
|
277 |
builder till later, to allow setting to another builder. |
|
278 |
however, some ST-80 code accesses the builder right after instance |
|
279 |
creation ..." |
|
280 |
||
281 |
"/ " |
|
282 |
"/ Create a windowBuilder to have someone around which |
|
283 |
"/ understands the builder protocol. Since UIBuilder is not present |
|
284 |
"/ in all systems, this allows operation without one (unless a spec |
|
285 |
"/ is read later ...) |
|
286 |
"/ " |
|
85 | 287 |
builder := self createBuilder. |
78 | 288 |
builder notNil ifTrue:[builder application:self]. |
52 | 289 |
resources := self class classResources. |
63 | 290 |
! |
291 |
||
138 | 292 |
createBuilder |
293 |
"create a UI Builder for me. |
|
294 |
This method can be redefined if (eventually) there are |
|
295 |
spec readers for other UI languages (motif UIL ?)" |
|
296 |
||
297 |
|cls| |
|
298 |
||
299 |
(cls := UIBuilder) isNil ifTrue:[ |
|
300 |
(cls := WindowBuilder) isNil ifTrue:[ |
|
301 |
^ nil |
|
302 |
] |
|
303 |
]. |
|
304 |
^ cls new |
|
305 |
! |
|
306 |
||
63 | 307 |
initialize |
83 | 308 |
"nothing done here; |
309 |
but can be redefined in concrete applications" |
|
138 | 310 |
! ! |
311 |
||
312 |
!ApplicationModel methodsFor:'misc'! |
|
313 |
||
314 |
withCursor:aCursor do:aBlock |
|
315 |
"evaluate aBlock, showing aCursor in my topView and all of its subviews. |
|
316 |
Return the value of aBlock." |
|
317 |
||
318 |
^ self window withCursor:aCursor do:aBlock |
|
63 | 319 |
! |
320 |
||
142
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
321 |
withExecuteCursorDo:aBlock |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
322 |
"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
|
323 |
Return the value of aBlock." |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
324 |
|
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
325 |
^ self withCursor:(Cursor execute) do:aBlock |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
326 |
|
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
327 |
"Created: 14.12.1995 / 20:57:03 / cg" |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
328 |
! |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
329 |
|
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
330 |
withReadCursorDo:aBlock |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
331 |
"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
|
332 |
Return the value of aBlock." |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
333 |
|
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
334 |
^ self withCursor:(Cursor read) do:aBlock |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
335 |
|
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
336 |
"Created: 14.12.1995 / 20:56:47 / cg" |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
337 |
"Modified: 14.12.1995 / 20:57:36 / cg" |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
338 |
! |
6c6259d788a4
added withReadCursorDo: / withExecuteCursorDo:
Claus Gittinger <cg@exept.de>
parents:
138
diff
changeset
|
339 |
|
138 | 340 |
withWaitCursorDo:aBlock |
341 |
"evaluate aBlock, showing a waitCursor in my topView and all of its subviews. |
|
342 |
Return the value of aBlock." |
|
63 | 343 |
|
138 | 344 |
^ self withCursor:Cursor wait do:aBlock |
52 | 345 |
! ! |
57 | 346 |
|
71 | 347 |
!ApplicationModel methodsFor:'queries'! |
348 |
||
349 |
processName |
|
350 |
"return a name to be shown for me in the process monitor" |
|
351 |
||
352 |
^ 'Application' |
|
353 |
! ! |
|
354 |
||
57 | 355 |
!ApplicationModel methodsFor:'startup'! |
356 |
||
63 | 357 |
allButOpenFrom:aSpec |
69 | 358 |
"create my views but do not open the main window" |
359 |
||
71 | 360 |
|realBuilder| |
361 |
||
72 | 362 |
"/ DISABLED; see comment in basicInitialize |
363 |
"/ |
|
364 |
"/ " |
|
365 |
"/ here, we kludge a bit: up to now, the builder was an |
|
366 |
"/ instance of the no-op WindowBuilder. Now, it becomes |
|
367 |
"/ a UIBuilder .... |
|
368 |
"/ This allows for ApplicationModels without a UIBuilder |
|
369 |
"/ if not needed. |
|
370 |
"/ " |
|
371 |
"/ realBuilder := UIBuilder new. |
|
372 |
"/ builder := realBuilder. |
|
373 |
"/ builder application:self. |
|
374 |
"/ builder bindings:builder bindings. |
|
71 | 375 |
|
63 | 376 |
self preBuildWith:builder. |
377 |
builder buildFromSpec:aSpec. |
|
85 | 378 |
builder window model:self. |
379 |
builder window application:self. |
|
63 | 380 |
self postBuildWith:builder. |
381 |
! |
|
57 | 382 |
|
138 | 383 |
allButOpenInterface:aSymbol |
384 |
"create my views but do not open the main window" |
|
385 |
||
386 |
|spec| |
|
387 |
||
388 |
spec := self class interfaceSpecFor:aSymbol. |
|
389 |
self allButOpenFrom:spec. |
|
390 |
^ builder |
|
391 |
! |
|
392 |
||
393 |
close |
|
394 |
"this is sent by my topView when about to be closed |
|
395 |
by the program (not by the windowManager). |
|
396 |
Could be redefined in subclasses." |
|
397 |
||
398 |
self closeDownViews |
|
399 |
! |
|
400 |
||
401 |
closeDownViews |
|
402 |
"close down the applications view" |
|
403 |
||
404 |
|wg views| |
|
405 |
||
406 |
(wg := self windowGroup) notNil ifTrue:[ |
|
407 |
views := wg topViews. |
|
408 |
views notNil ifTrue:[ |
|
409 |
views copy do:[:aView | |
|
410 |
aView notNil ifTrue:[aView destroy] |
|
411 |
] |
|
412 |
] |
|
413 |
] |
|
414 |
! |
|
415 |
||
416 |
closeRequest |
|
417 |
"this is sent by my topView when about to be closed by the |
|
418 |
windowmanager. Can be redefined to inform & query about unsafed |
|
419 |
view contents, to send #close on ok, or ignore the closeRequest." |
|
420 |
||
421 |
self closeDownViews |
|
422 |
! |
|
423 |
||
424 |
menuFor:aSymbol |
|
425 |
"create a new menuBuilder, to read specs and |
|
426 |
create a menu from it. Return this menu" |
|
427 |
||
428 |
|spec mbuilder| |
|
429 |
||
430 |
spec := self class interfaceSpecFor:aSymbol. |
|
431 |
mbuilder := UIBuilder new. |
|
432 |
mbuilder buildFromSpec:spec. |
|
433 |
||
434 |
builder componentAt:#windowMenuHolder put:(mbuilder window asValue). |
|
435 |
^ mbuilder window |
|
436 |
! |
|
437 |
||
69 | 438 |
open |
439 |
"open a standard interface" |
|
440 |
||
78 | 441 |
self openInterface |
69 | 442 |
! |
443 |
||
63 | 444 |
openInterface |
78 | 445 |
"open a standard interface on another device. |
446 |
Subclasses which do not have an interfaceSpec |
|
447 |
may want to redefine this method and create & open their view(s) |
|
448 |
there. (see NewLauncher as an example)." |
|
69 | 449 |
|
63 | 450 |
self openInterface:#windowSpec |
57 | 451 |
! |
452 |
||
63 | 453 |
openInterface:aSymbol |
78 | 454 |
"open an interface on another display; |
455 |
the argument, aSymbol specifies which interface. |
|
69 | 456 |
Typically, applications only use one interface, |
78 | 457 |
returned by the #windowSpec method." |
69 | 458 |
|
85 | 459 |
self allButOpenInterface:aSymbol. |
78 | 460 |
builder openWithExtent:nil. |
461 |
||
63 | 462 |
^ builder |
463 |
! |
|
464 |
||
465 |
opened |
|
466 |
"this is sent by my topView when its finally open" |
|
467 |
||
468 |
self addTopViewsToCurrentProject. |
|
469 |
self postOpenWith:builder |
|
57 | 470 |
! |
471 |
||
138 | 472 |
postBuildWith:aBuilder |
473 |
"this is sent after an interface is built from a spec. |
|
474 |
Can be redefined in subclasses. |
|
475 |
mhmh - what should this do here ?" |
|
476 |
! |
|
477 |
||
478 |
postOpenWith:aBuilder |
|
479 |
"this is sent after the applications main window is opened. |
|
480 |
Can be redefined in subclasses. |
|
481 |
mhmh - what should this do here ?" |
|
482 |
! |
|
483 |
||
484 |
preBuildWith:aBuilder |
|
485 |
"this is sent before an interface is built from a spec. |
|
486 |
Can be redefined in subclasses. |
|
487 |
mhmh - what should this do here ?" |
|
488 |
! |
|
489 |
||
69 | 490 |
restarted |
491 |
"sent by my windowGroup, when restarted from an image. |
|
492 |
Nothing done here, but can be redefined to perform any actions |
|
493 |
required to reset the application after an image-restart. |
|
494 |
(for example: check if application files are still around, restart |
|
495 |
subprocesses etc.)." |
|
63 | 496 |
! |
57 | 497 |
|
63 | 498 |
saveAndTerminateRequest |
499 |
"some windowManagers send this to shut down an application |
|
500 |
and have it save its state for restart. |
|
501 |
Can be redefined in subclasses" |
|
502 |
||
503 |
self closeRequest |
|
57 | 504 |
! ! |
72 | 505 |
|
85 | 506 |
!ApplicationModel methodsFor:'window events'! |
507 |
||
144 | 508 |
showActivity:someMessage |
509 |
^ self |
|
510 |
||
511 |
"Created: 16.12.1995 / 18:41:04 / cg" |
|
512 |
! |
|
513 |
||
85 | 514 |
windowEvent:anEvent from:anApplicationWindow |
515 |
^ self |
|
516 |
! ! |
|
517 |
||
138 | 518 |
!ApplicationModel class methodsFor:'documentation'! |
72 | 519 |
|
138 | 520 |
version |
144 | 521 |
^ '$Header: /cvs/stx/stx/libview2/ApplicationModel.st,v 1.20 1995-12-16 17:42:45 cg Exp $' |
81 | 522 |
! ! |
138 | 523 |
ApplicationModel initialize! |