867
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1997 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 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
ToolApplicationModel subclass:#ResourceSpecEditor
|
|
18 |
instanceVariableNames:'modified aspects specClass specSelector tabSelection hasSaved'
|
|
19 |
classVariableNames:''
|
|
20 |
poolDictionaries:''
|
|
21 |
category:'Interface-Framework'
|
|
22 |
!
|
|
23 |
|
|
24 |
!ResourceSpecEditor class methodsFor:'documentation'!
|
|
25 |
|
|
26 |
copyright
|
|
27 |
"
|
|
28 |
COPYRIGHT (c) 1997 by eXept Software AG
|
|
29 |
All Rights Reserved
|
|
30 |
|
|
31 |
This software is furnished under a license and may be used
|
|
32 |
only in accordance with the terms of that license and with the
|
|
33 |
inclusion of the above copyright notice. This software may not
|
|
34 |
be provided or otherwise made available to, or used by, any
|
|
35 |
other person. No title to or ownership of the software is
|
|
36 |
hereby transferred.
|
|
37 |
"
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
!
|
|
43 |
|
|
44 |
documentation
|
|
45 |
"
|
|
46 |
Abstract super class for the MenuEditor, DataSetBuilder,
|
|
47 |
HierarchicalListEditor, and the TabListEditor.
|
|
48 |
|
|
49 |
[author:]
|
876
|
50 |
Thomas Zwick, eXept Software AG
|
867
|
51 |
"
|
|
52 |
! !
|
|
53 |
|
|
54 |
!ResourceSpecEditor class methodsFor:'instance creation'!
|
|
55 |
|
|
56 |
openModalOnClass:aClass andSelector:aSelector
|
|
57 |
"Open modal a ListSpecEditor on aClass and aSelector"
|
|
58 |
|
|
59 |
^self new openModalOnClass:aClass andSelector:aSelector
|
|
60 |
|
|
61 |
!
|
|
62 |
|
|
63 |
openOnClass:aClass andSelector:aSelector
|
|
64 |
"Open a ListSpecEditor on aClass and aSelector"
|
|
65 |
|
|
66 |
^self new openOnClass:aClass andSelector:aSelector
|
|
67 |
! !
|
|
68 |
|
|
69 |
!ResourceSpecEditor class methodsFor:'accessing'!
|
|
70 |
|
|
71 |
codeGenerationComment
|
|
72 |
|
|
73 |
^self codeGenerationCommentForClass: self
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
!
|
|
79 |
|
|
80 |
codeGenerationCommentForClass: aClass
|
|
81 |
|
|
82 |
^' "This resource specification was automatically generated\',
|
|
83 |
' by the ', aClass name, ' of ST/X."\\',
|
|
84 |
|
|
85 |
' "Do not manually edit this!! If it is corrupted,\',
|
|
86 |
' the ', aClass name, ' may not be able to read the specification."'
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
!
|
|
93 |
|
|
94 |
resourceType
|
|
95 |
|
868
|
96 |
^self subclassResponsibility
|
867
|
97 |
! !
|
|
98 |
|
|
99 |
!ResourceSpecEditor class methodsFor:'aspects'!
|
|
100 |
|
|
101 |
aspects
|
|
102 |
"get the aspects for the attributes of the list spec components"
|
|
103 |
|
|
104 |
^#()
|
|
105 |
! !
|
|
106 |
|
876
|
107 |
!ResourceSpecEditor class methodsFor:'startup / release'!
|
|
108 |
|
|
109 |
preSnapshot
|
|
110 |
|
|
111 |
super preSnapshot.
|
|
112 |
|
|
113 |
(self settings at: #Instances ifAbsent: [^nil]) do:
|
|
114 |
[:inst|
|
|
115 |
inst updateChannels.
|
|
116 |
inst valueOfEnablingCommitButtons value: false
|
|
117 |
]
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
! !
|
|
123 |
|
867
|
124 |
!ResourceSpecEditor methodsFor:'accessing'!
|
|
125 |
|
|
126 |
modified
|
|
127 |
"return true, if the resource spec was modified"
|
|
128 |
|
|
129 |
^modified
|
|
130 |
!
|
|
131 |
|
|
132 |
modified: aBoolean
|
|
133 |
"set the resource spec modified as aBoolean"
|
|
134 |
|
|
135 |
modified := aBoolean
|
|
136 |
!
|
|
137 |
|
|
138 |
specClass
|
|
139 |
"get the class where the resource spec is implemented"
|
|
140 |
|
|
141 |
^specClass
|
|
142 |
!
|
|
143 |
|
|
144 |
specClass:aClass
|
|
145 |
"set the class (or name) where the resource spec is (or should be) implemented"
|
|
146 |
|
|
147 |
aClass isBehavior ifTrue:[specClass := aClass name]
|
|
148 |
ifFalse:[specClass := aClass]
|
|
149 |
!
|
|
150 |
|
|
151 |
specSelector
|
|
152 |
"get the method selector of the resource spec"
|
|
153 |
|
|
154 |
^specSelector
|
|
155 |
|
|
156 |
!
|
|
157 |
|
|
158 |
specSelector:aSelector
|
|
159 |
"set the method selector of the resource spec"
|
|
160 |
|
|
161 |
specSelector := aSelector
|
|
162 |
! !
|
|
163 |
|
|
164 |
!ResourceSpecEditor methodsFor:'aspects'!
|
|
165 |
|
|
166 |
aspectFor:aKey
|
|
167 |
"get the aspect for a aKey or nil"
|
|
168 |
|
|
169 |
^aspects at: aKey ifAbsent: [super aspectFor:aKey]
|
|
170 |
|
|
171 |
!
|
|
172 |
|
|
173 |
tabModel
|
|
174 |
"get the value holder for the tab selection"
|
|
175 |
|
|
176 |
|holder|
|
|
177 |
(holder := builder bindingAt:#tabModel) isNil ifTrue:[
|
|
178 |
holder := AspectAdaptor new subject:self; forAspect:#tabSelection.
|
|
179 |
builder aspectAt:#tabModel put:holder.
|
|
180 |
].
|
|
181 |
^ holder
|
|
182 |
!
|
|
183 |
|
876
|
184 |
valueOfCanPaste
|
|
185 |
|
|
186 |
|holder|
|
|
187 |
holder := super valueOfCanPaste.
|
|
188 |
holder value: self class clipboard notNil.
|
|
189 |
^ holder
|
|
190 |
|
|
191 |
|
|
192 |
!
|
|
193 |
|
867
|
194 |
valueOfEnableMovingIn
|
|
195 |
|
|
196 |
^builder booleanValueAspectFor: #valueOfEnableMovingIn
|
|
197 |
|
|
198 |
|
|
199 |
|
|
200 |
!
|
|
201 |
|
|
202 |
valueOfEnableMovingOut
|
|
203 |
|
|
204 |
^builder booleanValueAspectFor: #valueOfEnableMovingOut
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
!
|
|
209 |
|
|
210 |
valueOfEnableMovingUpOrDown
|
|
211 |
|
|
212 |
^builder booleanValueAspectFor: #valueOfEnableMovingUpOrDown
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
! !
|
|
218 |
|
|
219 |
!ResourceSpecEditor methodsFor:'building'!
|
|
220 |
|
|
221 |
buildFromResourceSpec: aResourceSpec
|
868
|
222 |
"concrete subclass has to reimplement this method
|
867
|
223 |
in order to build its resource spec from aResourceSpec"
|
|
224 |
|
868
|
225 |
^self subclassResponsibility
|
867
|
226 |
! !
|
|
227 |
|
|
228 |
!ResourceSpecEditor methodsFor:'change & update'!
|
|
229 |
|
|
230 |
update:something with:aParameter from:someObject
|
|
231 |
"one of my aspects has changed; update modified channel for the commit buttons"
|
|
232 |
|
|
233 |
self valueOfEnablingCommitButtons value: true
|
|
234 |
|
876
|
235 |
!
|
|
236 |
|
|
237 |
updateAllToolInstances
|
|
238 |
|
|
239 |
self allToolInstances do: [:inst| inst updateChannels]
|
|
240 |
|
|
241 |
!
|
|
242 |
|
|
243 |
updateChannels
|
|
244 |
|
|
245 |
self valueOfCanPaste
|
|
246 |
|
|
247 |
|
867
|
248 |
! !
|
|
249 |
|
|
250 |
!ResourceSpecEditor methodsFor:'help'!
|
|
251 |
|
|
252 |
defaultInfoLabel
|
|
253 |
"get default label for the info bar"
|
|
254 |
|
|
255 |
|cls|
|
|
256 |
(specClass isSymbol and: [(cls := Smalltalk at: specClass) isClass])
|
|
257 |
ifTrue:
|
|
258 |
[
|
|
259 |
(cls class implements: specSelector)
|
876
|
260 |
ifFalse:
|
|
261 |
[
|
|
262 |
^specSelector isNil
|
|
263 |
ifTrue: [specClass, ' >> ? (no selector defined)']
|
|
264 |
ifFalse: [specClass, ' >> ', specSelector, ' (not implemented)']
|
|
265 |
].
|
867
|
266 |
^specClass, ' >> ', specSelector
|
|
267 |
].
|
|
268 |
^'No class and selector defined.'
|
|
269 |
|
|
270 |
! !
|
|
271 |
|
|
272 |
!ResourceSpecEditor methodsFor:'initialization'!
|
|
273 |
|
|
274 |
initialize
|
|
275 |
"initialize the flags and the aspects"
|
|
276 |
|
|
277 |
super initialize.
|
|
278 |
|
|
279 |
hasSaved := modified := false.
|
|
280 |
aspects := IdentityDictionary new.
|
|
281 |
tabSelection := 0.
|
|
282 |
|
|
283 |
self class aspects do:
|
|
284 |
[:aKey|
|
|
285 |
|holder|
|
|
286 |
aspects at:aKey put: (holder := ValueHolder new).
|
|
287 |
holder addDependent: self
|
|
288 |
].
|
|
289 |
! !
|
|
290 |
|
|
291 |
!ResourceSpecEditor methodsFor:'private'!
|
|
292 |
|
|
293 |
askForItemModification
|
|
294 |
"ask for resource item modification"
|
|
295 |
|
|
296 |
self valueOfEnablingCommitButtons value
|
|
297 |
ifTrue:
|
|
298 |
[
|
|
299 |
((YesNoBox title:'Resource item was modified!!\Save it?\' withCRs)
|
|
300 |
noText:'No';
|
|
301 |
yesText:'Yes';
|
|
302 |
showAtPointer;
|
|
303 |
accepted)
|
|
304 |
ifFalse:
|
|
305 |
[
|
|
306 |
self valueOfEnablingCommitButtons value: false.
|
|
307 |
modified := false.
|
|
308 |
^true
|
|
309 |
].
|
|
310 |
self accept
|
|
311 |
].
|
|
312 |
^true
|
|
313 |
|
|
314 |
!
|
|
315 |
|
|
316 |
askForListModification
|
|
317 |
"ask for resource modification"
|
|
318 |
|
|
319 |
modified
|
|
320 |
ifTrue:
|
|
321 |
[
|
|
322 |
((YesNoBox title: 'List was modified!!')
|
|
323 |
noText:'Cancel';
|
|
324 |
yesText:'Waste it and proceed';
|
|
325 |
showAtPointer;
|
|
326 |
accepted) ifFalse: [^false].
|
|
327 |
modified := false
|
|
328 |
].
|
|
329 |
^true
|
|
330 |
!
|
|
331 |
|
|
332 |
askForModification
|
|
333 |
"ask first for item and then for resource modification"
|
|
334 |
|
|
335 |
^self askForItemModification and: [self askForListModification]
|
|
336 |
|
|
337 |
!
|
|
338 |
|
|
339 |
resolveClassNamed
|
|
340 |
"get current class or nil"
|
|
341 |
|
|
342 |
^Smalltalk resolveName:specClass inClass:self class
|
|
343 |
!
|
|
344 |
|
|
345 |
resourceMessage: aString
|
|
346 |
"extract from aString the specClass and the specSelector"
|
|
347 |
|
|
348 |
(aString notNil and: [self askForModification])
|
|
349 |
ifTrue:
|
|
350 |
[
|
|
351 |
|msg cls sel|
|
|
352 |
msg := aString asCollectionOfWords.
|
|
353 |
(msg size == 2 and:
|
|
354 |
[(cls := self resolveName:(msg at:1)) notNil])
|
|
355 |
ifTrue:
|
|
356 |
[
|
|
357 |
specClass := cls name.
|
|
358 |
specSelector := (msg at: 2) asSymbol.
|
|
359 |
^true
|
|
360 |
]
|
|
361 |
].
|
|
362 |
^false
|
|
363 |
!
|
|
364 |
|
|
365 |
updateHistory
|
|
366 |
"if there was loaded a resource spec, update the history"
|
|
367 |
|
|
368 |
|cls|
|
|
369 |
((cls := self resolveClassNamed) notNil and: [cls class implements: specSelector])
|
|
370 |
ifTrue:
|
|
371 |
[
|
|
372 |
|className message|
|
|
373 |
specClass isClass ifTrue: [className := specClass name].
|
|
374 |
specClass isString ifTrue: [className := specClass].
|
|
375 |
message := className, ' ', specSelector.
|
|
376 |
self addToHistory: message -> #loadFromMessage:
|
|
377 |
]
|
|
378 |
! !
|
|
379 |
|
|
380 |
!ResourceSpecEditor methodsFor:'queries'!
|
|
381 |
|
|
382 |
hasSaved
|
|
383 |
"return true if resource spec has saved"
|
|
384 |
|
|
385 |
^hasSaved
|
|
386 |
|
|
387 |
!
|
|
388 |
|
|
389 |
isStandAlone
|
|
390 |
"return true if the editor was not started from another tool"
|
|
391 |
|
|
392 |
^self masterApplication isNil
|
|
393 |
! !
|
|
394 |
|
|
395 |
!ResourceSpecEditor methodsFor:'selection'!
|
|
396 |
|
|
397 |
tabSelection
|
|
398 |
"returns selected tab index or 0"
|
|
399 |
|
|
400 |
^tabSelection
|
|
401 |
|
|
402 |
! !
|
|
403 |
|
|
404 |
!ResourceSpecEditor methodsFor:'startup / release'!
|
|
405 |
|
876
|
406 |
allButOpenInterface:aSymbol
|
|
407 |
|
|
408 |
super allButOpenInterface:aSymbol.
|
|
409 |
|
|
410 |
self class settings
|
|
411 |
at: #Instances
|
|
412 |
put: ((self class settings at: #Instances ifAbsent: [OrderedCollection new]) add: self; yourself).
|
|
413 |
|
|
414 |
^builder
|
|
415 |
|
|
416 |
!
|
|
417 |
|
867
|
418 |
closeRequest
|
|
419 |
"first ask for modification then send close request to super"
|
|
420 |
|
|
421 |
self askForModification ifTrue: [super closeRequest]
|
|
422 |
|
|
423 |
!
|
|
424 |
|
|
425 |
loadFromMessage:aString
|
|
426 |
"load a spec from class and selector"
|
|
427 |
|
|
428 |
(aString notNil and: [self askForModification])
|
|
429 |
ifTrue:
|
|
430 |
[
|
|
431 |
|msg cls sel|
|
|
432 |
msg := aString asCollectionOfWords.
|
|
433 |
(msg size == 2 and:
|
|
434 |
[(cls := self resolveName:(msg at:1)) notNil and:
|
|
435 |
[cls class implements: (sel := (msg at: 2) asSymbol)]])
|
|
436 |
ifTrue:
|
|
437 |
[
|
|
438 |
self isStandAlone
|
|
439 |
ifFalse: [self buildFromResourceSpec: (cls perform: sel)]
|
|
440 |
ifTrue: [self buildFromClass: (specClass := cls name) andSelector: (specSelector := sel)].
|
|
441 |
^true
|
|
442 |
]
|
|
443 |
].
|
|
444 |
^false
|
|
445 |
!
|
|
446 |
|
|
447 |
openModalOnClass:aClass andSelector:aSelector
|
|
448 |
|
|
449 |
specClass := aClass isClass ifTrue: [aClass name] ifFalse: [aClass].
|
|
450 |
specSelector := aSelector.
|
|
451 |
|
|
452 |
super openInterfaceModal.
|
|
453 |
|
|
454 |
!
|
|
455 |
|
|
456 |
openModalOnResourceSpec: aListSpec
|
|
457 |
|
|
458 |
self buildFromResourceSpec: aListSpec.
|
|
459 |
|
|
460 |
super openInterfaceModal.
|
|
461 |
|
|
462 |
!
|
|
463 |
|
|
464 |
openOnClass:aClass andSelector:aSelector
|
|
465 |
|
|
466 |
specClass := aClass isClass ifTrue: [aClass name] ifFalse: [aClass].
|
|
467 |
specSelector := aSelector.
|
|
468 |
|
|
469 |
super openInterface.
|
|
470 |
!
|
|
471 |
|
|
472 |
postOpenWith:aBuilder
|
|
473 |
|
|
474 |
super postOpenWith:aBuilder.
|
|
475 |
|
|
476 |
self buildFromClass: specClass andSelector: specSelector.
|
|
477 |
|
876
|
478 |
!
|
|
479 |
|
|
480 |
uninitialize
|
|
481 |
|
|
482 |
super uninitialize.
|
|
483 |
|
|
484 |
(self class settings at: #Instances ifAbsent: [^nil]) remove: self ifAbsent: nil
|
|
485 |
|
867
|
486 |
! !
|
|
487 |
|
|
488 |
!ResourceSpecEditor methodsFor:'user actions'!
|
|
489 |
|
|
490 |
accept
|
|
491 |
"invoked by the OK button; disable the commit buttons and set modified"
|
|
492 |
|
|
493 |
self valueOfEnablingCommitButtons value: false.
|
|
494 |
modified := true
|
|
495 |
!
|
|
496 |
|
|
497 |
doBrowseClass
|
|
498 |
"open a System Browser on the specClass and specSelector"
|
|
499 |
|
|
500 |
|cls|
|
|
501 |
|
|
502 |
(cls := self resolveClassNamed) notNil
|
|
503 |
ifTrue: [SystemBrowser openInClass:cls class selector: specSelector]
|
|
504 |
ifFalse:[self information:'No class defined!!']
|
|
505 |
!
|
|
506 |
|
|
507 |
doEditImage
|
|
508 |
"open the Image Editor on a resource retriever and icon selector"
|
|
509 |
|
|
510 |
|cls resourceClass resourceSelector imageResourceMessage readStream|
|
|
511 |
|
|
512 |
cls := self resolveName: specClass.
|
|
513 |
cls isNil ifTrue:[
|
|
514 |
^ self information:'No valid class defined!!'.
|
|
515 |
].
|
|
516 |
(aspects at:#icon) value size > 0
|
|
517 |
ifTrue: [resourceSelector := (aspects at:#icon) value]
|
|
518 |
ifFalse: [resourceSelector := #icon].
|
|
519 |
(aspects at:#retriever) value size > 0
|
|
520 |
ifTrue: [resourceClass := (aspects at:#retriever) value]
|
|
521 |
ifFalse: [resourceClass := cls withAllSuperclasses detect: [:cls| cls class implements: resourceSelector] ifNone: [cls]].
|
|
522 |
|
|
523 |
(imageResourceMessage := ImageEditor openModalOnClass: resourceClass andSelector: resourceSelector) notNil
|
|
524 |
ifTrue:
|
|
525 |
[
|
|
526 |
readStream := imageResourceMessage readStream.
|
|
527 |
resourceClass := (readStream upTo: $ ) asSymbol.
|
|
528 |
resourceSelector := readStream upToEnd asSymbol.
|
|
529 |
resourceClass size > 0 ifTrue: [(aspects at:#retriever) value: resourceClass].
|
|
530 |
resourceSelector size > 0 ifTrue: [(aspects at:#icon) value: resourceSelector. self valueOfEnablingCommitButtons value: true]
|
|
531 |
]
|
|
532 |
|
|
533 |
|
|
534 |
!
|
|
535 |
|
|
536 |
doLoad
|
|
537 |
"open a Resource Selection Browser in order to get a resource message"
|
|
538 |
|
|
539 |
self loadFromMessage:
|
|
540 |
(ResourceSelectionBrowser
|
|
541 |
request: 'Load ', self class resourceType asUppercaseFirst, ' Spec From Class'
|
|
542 |
onSuperclass: nil
|
|
543 |
andClass: specClass
|
|
544 |
andSelector: specSelector ? self class resourceType
|
|
545 |
withResourceTypes: (Array with: self class resourceType))
|
|
546 |
!
|
|
547 |
|
|
548 |
doNew
|
|
549 |
"first ask for modification; then clean specClass and specSelector,
|
|
550 |
but only, if the editor is opened as stand alone;
|
|
551 |
finally make a build of a resource spec containing no items"
|
|
552 |
|
|
553 |
self askForModification
|
|
554 |
ifTrue:
|
|
555 |
[
|
|
556 |
self isStandAlone ifTrue: [specClass := specSelector := nil].
|
|
557 |
self buildFromClass: nil andSelector: self class resourceType.
|
|
558 |
^true
|
|
559 |
].
|
|
560 |
^false
|
|
561 |
|
|
562 |
!
|
|
563 |
|
|
564 |
doSave
|
|
565 |
"before saving ask for modification; if no specClass and specSelector
|
|
566 |
is defined, do save as"
|
|
567 |
|
|
568 |
self askForItemModification.
|
|
569 |
|
|
570 |
(specClass isNil or:[specSelector isNil]) ifTrue:[
|
|
571 |
self doSaveAs.
|
|
572 |
^false
|
|
573 |
].
|
|
574 |
^true
|
|
575 |
!
|
|
576 |
|
|
577 |
doSaveAs
|
|
578 |
"first ask for modification;
|
|
579 |
then open a ResourceSelectionBrowser;
|
|
580 |
after that extract the resource message;
|
|
581 |
finally do save and make a new build"
|
|
582 |
|
|
583 |
|resourceMessage|
|
|
584 |
|
|
585 |
self askForItemModification.
|
|
586 |
|
|
587 |
(resourceMessage := ResourceSelectionBrowser
|
|
588 |
request: 'Save ', self class resourceType asUppercaseFirst, ' Spec In Class'
|
|
589 |
onSuperclass: #Object
|
|
590 |
andClass: specClass
|
|
591 |
andSelector: specSelector ? self class resourceType
|
|
592 |
withResourceTypes: (Array with: self class resourceType)) notNil
|
|
593 |
ifTrue:
|
|
594 |
[
|
|
595 |
modified := false.
|
|
596 |
(self resourceMessage: resourceMessage)
|
|
597 |
ifTrue:
|
|
598 |
[
|
|
599 |
self doSave.
|
|
600 |
self buildFromClass: specClass andSelector: specSelector.
|
|
601 |
^true
|
|
602 |
]
|
|
603 |
].
|
|
604 |
^false
|
|
605 |
! !
|
|
606 |
|
|
607 |
!ResourceSpecEditor class methodsFor:'documentation'!
|
|
608 |
|
|
609 |
version
|
876
|
610 |
^ '$Header: /cvs/stx/stx/libview2/ResourceSpecEditor.st,v 1.3 1998-03-30 12:10:21 tz Exp $'
|
867
|
611 |
! !
|