author | Stefan Vogel <sv@exept.de> |
Fri, 20 May 2016 14:45:31 +0200 | |
changeset 3304 | eb8835656382 |
parent 3293 | 911a495e2ed7 |
child 3314 | a2f087b57f90 |
permissions | -rw-r--r-- |
60 | 1 |
" |
156 | 2 |
COPYRIGHT (c) 1995 by Claus Gittinger / eXept Software AG |
1834 | 3 |
All Rights Reserved |
60 | 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 |
|
742 | 7 |
inclusion of the above copyright notice. This software may not |
60 | 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 |
" |
|
1387 | 12 |
"{ Package: 'stx:libtool2' }" |
13 |
||
3223 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
60 | 16 |
UIObjectView subclass:#UIPainterView |
278 | 17 |
instanceVariableNames:'treeView listHolder superclassName className methodName |
2244 | 18 |
categoryName handleColorBlack handleColorWhite handleMasterColor |
2276
485bda17023f
more changes to allow for non-class/selector (i.e. spec-only) use
Claus Gittinger <cg@exept.de>
parents:
2265
diff
changeset
|
19 |
sketchPainter listOfAspectsHolder' |
3097 | 20 |
classVariableNames:'HandCursor RedefineAspectMethods AspectsAsInstances' |
60 | 21 |
poolDictionaries:'' |
22 |
category:'Interface-UIPainter' |
|
23 |
! |
|
24 |
||
211 | 25 |
Object subclass:#ViewProperty |
26 |
instanceVariableNames:'view spec identifier' |
|
27 |
classVariableNames:'Identifier' |
|
28 |
poolDictionaries:'' |
|
29 |
privateIn:UIPainterView |
|
30 |
! |
|
31 |
||
60 | 32 |
!UIPainterView class methodsFor:'documentation'! |
33 |
||
34 |
copyright |
|
35 |
" |
|
156 | 36 |
COPYRIGHT (c) 1995 by Claus Gittinger / eXept Software AG |
1834 | 37 |
All Rights Reserved |
60 | 38 |
|
39 |
This software is furnished under a license and may be used |
|
40 |
only in accordance with the terms of that license and with the |
|
742 | 41 |
inclusion of the above copyright notice. This software may not |
60 | 42 |
be provided or otherwise made available to, or used by, any |
43 |
other person. No title to or ownership of the software is |
|
44 |
hereby transferred. |
|
45 |
" |
|
46 |
! |
|
47 |
||
48 |
documentation |
|
49 |
" |
|
128 | 50 |
buildIn view used by the UIPainter; from this view, the layout of the |
51 |
new application derives from. |
|
52 |
||
53 |
[see also:] |
|
1834 | 54 |
UIBuilder |
55 |
UIObjectView |
|
156 | 56 |
|
57 |
[author:] |
|
1834 | 58 |
Claus Gittinger |
59 |
Claus Atzkern |
|
60 | 60 |
" |
61 |
! ! |
|
62 |
||
1225 | 63 |
!UIPainterView class methodsFor:'initialization'! |
64 |
||
65 |
initialize |
|
66 |
||
1494 | 67 |
AspectsAsInstances := true. "/ false. |
1225 | 68 |
RedefineAspectMethods := false. |
69 |
||
70 |
"Created: / 22.9.1999 / 12:32:31 / stefan" |
|
71 |
! ! |
|
72 |
||
698 | 73 |
!UIPainterView class methodsFor:'code generation mode'! |
74 |
||
925
e6ddd46581c3
added option of generating aspects as instvars.
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
75 |
generateAspectsAsInstanceVariables |
e6ddd46581c3
added option of generating aspects as instvars.
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
76 |
"if on, aspects are held as instance variables; |
2244 | 77 |
if off (the default), they are kept in the bindings dictionary." |
78 |
||
925
e6ddd46581c3
added option of generating aspects as instvars.
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
79 |
^ AspectsAsInstances |
e6ddd46581c3
added option of generating aspects as instvars.
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
80 |
|
e6ddd46581c3
added option of generating aspects as instvars.
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
81 |
"Created: / 29.7.1998 / 11:21:38 / cg" |
e6ddd46581c3
added option of generating aspects as instvars.
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
82 |
"Modified: / 29.7.1998 / 11:22:01 / cg" |
e6ddd46581c3
added option of generating aspects as instvars.
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
83 |
! |
e6ddd46581c3
added option of generating aspects as instvars.
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
84 |
|
e6ddd46581c3
added option of generating aspects as instvars.
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
85 |
generateAspectsAsInstanceVariables:aBoolean |
e6ddd46581c3
added option of generating aspects as instvars.
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
86 |
"if on, aspects are held as instance variables; |
2244 | 87 |
if off (the default), they are kept in the bindings dictionary." |
88 |
||
925
e6ddd46581c3
added option of generating aspects as instvars.
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
89 |
AspectsAsInstances := aBoolean |
e6ddd46581c3
added option of generating aspects as instvars.
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
90 |
|
e6ddd46581c3
added option of generating aspects as instvars.
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
91 |
"Created: / 29.7.1998 / 11:21:26 / cg" |
e6ddd46581c3
added option of generating aspects as instvars.
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
92 |
"Modified: / 29.7.1998 / 11:22:11 / cg" |
e6ddd46581c3
added option of generating aspects as instvars.
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
93 |
! |
e6ddd46581c3
added option of generating aspects as instvars.
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
94 |
|
2244 | 95 |
generateCommentedCode |
96 |
"comments in generated aspect methods; yes or no." |
|
97 |
||
2714
abaae556bec8
commentCode flags now in userPrefs
Claus Gittinger <cg@exept.de>
parents:
2627
diff
changeset
|
98 |
^ UserPreferences current generateComments |
abaae556bec8
commentCode flags now in userPrefs
Claus Gittinger <cg@exept.de>
parents:
2627
diff
changeset
|
99 |
and:[ UserPreferences current generateCommentsForAspectMethods ] |
2244 | 100 |
! |
101 |
||
102 |
generateCommentedCode:aBoolean |
|
103 |
"comments in generated aspect methods; yes or no." |
|
104 |
||
2716
ed0006640fb4
changed: #generateCommentedCode:
Claus Gittinger <cg@exept.de>
parents:
2714
diff
changeset
|
105 |
UserPreferences current generateComments ifFalse:[ |
ed0006640fb4
changed: #generateCommentedCode:
Claus Gittinger <cg@exept.de>
parents:
2714
diff
changeset
|
106 |
aBoolean ifTrue:[ |
ed0006640fb4
changed: #generateCommentedCode:
Claus Gittinger <cg@exept.de>
parents:
2714
diff
changeset
|
107 |
UserPreferences current generateComments:true |
ed0006640fb4
changed: #generateCommentedCode:
Claus Gittinger <cg@exept.de>
parents:
2714
diff
changeset
|
108 |
]. |
ed0006640fb4
changed: #generateCommentedCode:
Claus Gittinger <cg@exept.de>
parents:
2714
diff
changeset
|
109 |
]. |
ed0006640fb4
changed: #generateCommentedCode:
Claus Gittinger <cg@exept.de>
parents:
2714
diff
changeset
|
110 |
|
2714
abaae556bec8
commentCode flags now in userPrefs
Claus Gittinger <cg@exept.de>
parents:
2627
diff
changeset
|
111 |
UserPreferences current |
2716
ed0006640fb4
changed: #generateCommentedCode:
Claus Gittinger <cg@exept.de>
parents:
2714
diff
changeset
|
112 |
generateCommentsForAspectMethods:aBoolean. |
2244 | 113 |
! |
114 |
||
742 | 115 |
redefineAspectMethods |
2244 | 116 |
"redefine methods yes or no. |
117 |
If a method is defined in super class should the message be reinstalled ?" |
|
118 |
||
1225 | 119 |
^ RedefineAspectMethods |
698 | 120 |
|
1225 | 121 |
"Modified: / 22.9.1999 / 12:33:03 / stefan" |
698 | 122 |
! |
123 |
||
742 | 124 |
redefineAspectMethods:aBoolean |
2244 | 125 |
"redefine methods yes or no. |
126 |
If a method is defined in super class should the message be reinstalled ?" |
|
127 |
||
742 | 128 |
RedefineAspectMethods := aBoolean |
698 | 129 |
! ! |
130 |
||
60 | 131 |
!UIPainterView class methodsFor:'defaults'! |
132 |
||
1834 | 133 |
defaultMenuMessage |
60 | 134 |
"This message is the default yo be sent to the menuHolder to get a menu |
135 |
" |
|
121 | 136 |
^ #showMiddleButtonMenu |
60 | 137 |
|
138 |
||
139 |
! ! |
|
140 |
||
141 |
!UIPainterView methodsFor:'accessing'! |
|
142 |
||
143 |
application |
|
144 |
^ nil |
|
145 |
||
146 |
"Modified: 6.9.1995 / 00:46:44 / claus" |
|
147 |
! |
|
148 |
||
78 | 149 |
applicationName |
150 |
^ self className |
|
151 |
! |
|
152 |
||
153 |
applicationName:aName |
|
154 |
self className:aName |
|
155 |
! |
|
156 |
||
1977 | 157 |
class:aClass superclassName:aSuperclassName selector:aSelector |
158 |
self assert:(aClass isBehavior). |
|
159 |
className := aClass name. |
|
160 |
superclassName := aSuperclassName. |
|
161 |
methodName := aSelector. |
|
162 |
! |
|
163 |
||
60 | 164 |
className |
165 |
^ className |
|
166 |
! |
|
167 |
||
78 | 168 |
className:aName |
1977 | 169 |
self assert:(aName isString). |
78 | 170 |
className := aName |
60 | 171 |
! |
172 |
||
173 |
className:aClassName superclassName:aSuperclassName selector:aSelector |
|
1977 | 174 |
self assert:(aClassName isString). |
78 | 175 |
className := aClassName. |
60 | 176 |
superclassName := aSuperclassName. |
78 | 177 |
methodName := aSelector. |
60 | 178 |
! |
179 |
||
2276
485bda17023f
more changes to allow for non-class/selector (i.e. spec-only) use
Claus Gittinger <cg@exept.de>
parents:
2265
diff
changeset
|
180 |
listOfAspectsHolder:something |
485bda17023f
more changes to allow for non-class/selector (i.e. spec-only) use
Claus Gittinger <cg@exept.de>
parents:
2265
diff
changeset
|
181 |
listOfAspectsHolder := something. |
485bda17023f
more changes to allow for non-class/selector (i.e. spec-only) use
Claus Gittinger <cg@exept.de>
parents:
2265
diff
changeset
|
182 |
! |
485bda17023f
more changes to allow for non-class/selector (i.e. spec-only) use
Claus Gittinger <cg@exept.de>
parents:
2265
diff
changeset
|
183 |
|
60 | 184 |
methodName |
185 |
^ methodName |
|
186 |
! |
|
187 |
||
78 | 188 |
methodName:aName |
189 |
methodName := aName |
|
60 | 190 |
! |
191 |
||
192 |
selectNames:aStringOrCollection |
|
1031 | 193 |
|prop coll s n newSel| |
194 |
||
195 |
(aStringOrCollection size == 0) ifTrue:[ |
|
1834 | 196 |
newSel := nil. |
1031 | 197 |
] ifFalse:[ |
1834 | 198 |
(s := aStringOrCollection) isString ifFalse:[ |
199 |
s size == 1 ifTrue:[ |
|
200 |
s := s first |
|
201 |
] ifFalse:[ |
|
202 |
coll := OrderedCollection new. |
|
203 |
||
204 |
s do:[:aName| |
|
205 |
(prop := self propertyOfName:aName) notNil ifTrue:[ |
|
206 |
coll add:(prop view) |
|
207 |
] |
|
208 |
]. |
|
209 |
(n := coll size) == 1 ifTrue:[ |
|
210 |
newSel := coll at:1 |
|
211 |
] ifFalse:[ |
|
212 |
n == 0 ifTrue:[ |
|
213 |
newSel := nil |
|
214 |
] ifFalse:[ |
|
215 |
newSel := coll |
|
216 |
] |
|
217 |
]. |
|
218 |
^ self select:newSel. |
|
219 |
] |
|
220 |
]. |
|
221 |
||
222 |
prop := self propertyOfName:s. |
|
223 |
prop isNil ifTrue:[ |
|
224 |
newSel := nil |
|
225 |
] ifFalse:[ |
|
226 |
newSel := prop view |
|
227 |
]. |
|
60 | 228 |
]. |
229 |
||
1031 | 230 |
^ self select:newSel |
60 | 231 |
! ! |
232 |
||
111 | 233 |
!UIPainterView methodsFor:'change & update'! |
234 |
||
223 | 235 |
layoutChanged |
1445 | 236 |
treeView notNil ifTrue:[ |
1834 | 237 |
treeView layoutChanged |
1445 | 238 |
] |
111 | 239 |
! ! |
240 |
||
60 | 241 |
!UIPainterView methodsFor:'copy & cut & paste'! |
242 |
||
2221 | 243 |
changeSelectionAfterPasteOf:sel |
244 |
sel notNil ifTrue:[ |
|
245 |
self select:sel. |
|
246 |
]. |
|
247 |
! |
|
248 |
||
1744
c59a91953b64
paste with no container selected: search for a good one
Claus Gittinger <cg@exept.de>
parents:
1733
diff
changeset
|
249 |
commonContainerOf:someComponents |
c59a91953b64
paste with no container selected: search for a good one
Claus Gittinger <cg@exept.de>
parents:
1733
diff
changeset
|
250 |
|container| |
c59a91953b64
paste with no container selected: search for a good one
Claus Gittinger <cg@exept.de>
parents:
1733
diff
changeset
|
251 |
|
c59a91953b64
paste with no container selected: search for a good one
Claus Gittinger <cg@exept.de>
parents:
1733
diff
changeset
|
252 |
container := someComponents first container. |
c59a91953b64
paste with no container selected: search for a good one
Claus Gittinger <cg@exept.de>
parents:
1733
diff
changeset
|
253 |
[container notNil |
c59a91953b64
paste with no container selected: search for a good one
Claus Gittinger <cg@exept.de>
parents:
1733
diff
changeset
|
254 |
and:[ (someComponents conform:[:eachComponent | eachComponent isComponentOf:container]) not]] |
1834 | 255 |
whileTrue:[ |
256 |
container := container container. |
|
1744
c59a91953b64
paste with no container selected: search for a good one
Claus Gittinger <cg@exept.de>
parents:
1733
diff
changeset
|
257 |
]. |
c59a91953b64
paste with no container selected: search for a good one
Claus Gittinger <cg@exept.de>
parents:
1733
diff
changeset
|
258 |
^ container |
c59a91953b64
paste with no container selected: search for a good one
Claus Gittinger <cg@exept.de>
parents:
1733
diff
changeset
|
259 |
! |
c59a91953b64
paste with no container selected: search for a good one
Claus Gittinger <cg@exept.de>
parents:
1733
diff
changeset
|
260 |
|
60 | 261 |
copySelection |
1959 | 262 |
"copy the selection into the cut & paste-buffer" |
263 |
||
2362
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
264 |
|specs coll| |
71 | 265 |
|
2257
badd429a2a2a
code beautification; reasonable methodNames;
Claus Gittinger <cg@exept.de>
parents:
2250
diff
changeset
|
266 |
coll := self minClosedViewSetFor:(self selection). |
60 | 267 |
|
71 | 268 |
coll notNil ifTrue:[ |
776 | 269 |
"/ self select:nil. |
2362
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
270 |
specs := coll collect:[:eachView | self fullSpecWithAbsolutePositionFor:eachView]. |
1870 | 271 |
self setClipboardObject:specs. |
776 | 272 |
"/ treeView selection: sel |
60 | 273 |
]. |
274 |
! |
|
275 |
||
723 | 276 |
deleteSelection |
1959 | 277 |
"delete the selection buffered" |
278 |
||
887
79a6e12e1d0f
after deleting a widget do select the neighbour then the parent (step 2)
tz
parents:
886
diff
changeset
|
279 |
self deleteSelectionBuffered: true |
79a6e12e1d0f
after deleting a widget do select the neighbour then the parent (step 2)
tz
parents:
886
diff
changeset
|
280 |
! |
79a6e12e1d0f
after deleting a widget do select the neighbour then the parent (step 2)
tz
parents:
886
diff
changeset
|
281 |
|
2396 | 282 |
deleteSelectionBuffered:buffered |
2257
badd429a2a2a
code beautification; reasonable methodNames;
Claus Gittinger <cg@exept.de>
parents:
2250
diff
changeset
|
283 |
"cut the selection. If buffered is true, place it into the cut&paste-buffer" |
badd429a2a2a
code beautification; reasonable methodNames;
Claus Gittinger <cg@exept.de>
parents:
2250
diff
changeset
|
284 |
|
2396 | 285 |
|specs viewsToRemove newSelection firstView| |
71 | 286 |
|
1621
112670159075
cg: check if selection change is allowed BEFORE changing the
tm
parents:
1574
diff
changeset
|
287 |
treeView askForSelectionChangeAllowed ifFalse:[^ self]. |
112670159075
cg: check if selection change is allowed BEFORE changing the
tm
parents:
1574
diff
changeset
|
288 |
|
2396 | 289 |
viewsToRemove := self minClosedViewSetFor:(self selection). |
290 |
viewsToRemove isEmptyOrNil ifTrue:[ ^ self]. |
|
291 |
||
292 |
buffered ifTrue:[ |
|
293 |
specs := viewsToRemove collect:[:aView| self fullSpecWithAbsolutePositionFor:aView ]. |
|
294 |
self setClipboardObject:specs |
|
295 |
]. |
|
296 |
firstView := viewsToRemove first. |
|
297 |
newSelection := self findContainerOfView:firstView. |
|
298 |
||
299 |
newSelection isNil ifTrue:[ |
|
300 |
newSelection := self. |
|
301 |
] ifFalse:[ |
|
302 |
viewsToRemove size == 1 ifTrue:[ |
|
303 |
|subviews index| |
|
304 |
||
2508 | 305 |
"/ newSelection components notEmptyOrNil ifTrue:[ self halt ]. |
2396 | 306 |
subviews := newSelection subViews. |
307 |
||
308 |
subviews size > 1 ifTrue:[ |
|
309 |
index := subviews findFirst:[:eachView| eachView isSameOrComponentOf:firstView ]. |
|
310 |
index > 0 ifTrue:[ |
|
311 |
newSelection := subviews |
|
312 |
at:(index + 1) |
|
313 |
ifAbsent:[subviews at:index -1]. |
|
314 |
]. |
|
315 |
]. |
|
316 |
]. |
|
317 |
]. |
|
318 |
||
319 |
self withSelectionHiddenDo:[ |
|
320 |
self select:newSelection. |
|
321 |
||
2257
badd429a2a2a
code beautification; reasonable methodNames;
Claus Gittinger <cg@exept.de>
parents:
2250
diff
changeset
|
322 |
treeView canvasEventsDisabledDo:[ |
2396 | 323 |
self withinTransaction:#cut objects:viewsToRemove do:[ |
324 |
viewsToRemove reverseDo:[:aView| |
|
1870 | 325 |
self createUndoRemove:aView. |
326 |
self remove:aView. |
|
327 |
] |
|
328 |
]. |
|
2396 | 329 |
]. |
330 |
self windowGroup processRealExposeEvents. |
|
331 |
]. |
|
698 | 332 |
! |
333 |
||
723 | 334 |
deleteTotalSelection |
1959 | 335 |
"delete the selection" |
336 |
||
887
79a6e12e1d0f
after deleting a widget do select the neighbour then the parent (step 2)
tz
parents:
886
diff
changeset
|
337 |
self deleteSelectionBuffered: false |
60 | 338 |
! |
339 |
||
1832 | 340 |
getSelectedViewsAndSpecs |
341 |
"return an array filed with selected views and corresponding specs. |
|
1959 | 342 |
Nil if there is none." |
343 |
||
1832 | 344 |
|specs coll sel| |
345 |
||
346 |
sel := treeView selection. |
|
347 |
||
2257
badd429a2a2a
code beautification; reasonable methodNames;
Claus Gittinger <cg@exept.de>
parents:
2250
diff
changeset
|
348 |
coll := self minClosedViewSetFor:(self selection). |
1832 | 349 |
|
350 |
coll isNil ifTrue:[^ nil]. |
|
351 |
||
352 |
specs := coll collect:[:aView| self fullSpecFor:aView ]. |
|
353 |
^ Array with: coll with: specs |
|
354 |
! |
|
355 |
||
60 | 356 |
pasteBuffer |
2311
67811bdeb0f5
Support sorting of items in tree
Stefan Vogel <sv@exept.de>
parents:
2295
diff
changeset
|
357 |
"add the objects in the paste-buffer to the object view; |
67811bdeb0f5
Support sorting of items in tree
Stefan Vogel <sv@exept.de>
parents:
2295
diff
changeset
|
358 |
don't change the layout if more than a single item has been selected" |
67811bdeb0f5
Support sorting of items in tree
Stefan Vogel <sv@exept.de>
parents:
2295
diff
changeset
|
359 |
|
67811bdeb0f5
Support sorting of items in tree
Stefan Vogel <sv@exept.de>
parents:
2295
diff
changeset
|
360 |
|sel clipboard| |
67811bdeb0f5
Support sorting of items in tree
Stefan Vogel <sv@exept.de>
parents:
2295
diff
changeset
|
361 |
|
2362
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
362 |
self enabled ifFalse:[ |
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
363 |
Dialog warn:'Operation currently disabled (In geometry test mode)'. |
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
364 |
^ self |
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
365 |
]. |
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
366 |
|
2311
67811bdeb0f5
Support sorting of items in tree
Stefan Vogel <sv@exept.de>
parents:
2295
diff
changeset
|
367 |
clipboard := self getClipboardObject. |
2951 | 368 |
clipboard isString ifTrue:[ |
369 |
Dialog warn:'can only paste widgets here'. |
|
370 |
] ifFalse:[ |
|
371 |
sel := self pasteSpecifications:clipboard keepLayout:true "(clipboard size > 1)". |
|
372 |
self changeSelectionAfterPasteOf:sel. |
|
373 |
]. |
|
89 | 374 |
! |
375 |
||
1338
3c1a528c50db
added paste-keeping-absolute-position function
Claus Gittinger <cg@exept.de>
parents:
1308
diff
changeset
|
376 |
pasteKeepingPosition |
1834 | 377 |
"add the objects in the paste-buffer to the object view; |
1338
3c1a528c50db
added paste-keeping-absolute-position function
Claus Gittinger <cg@exept.de>
parents:
1308
diff
changeset
|
378 |
translate the layout as appropriate, to position the component |
1959 | 379 |
at the same absolute position (relative to topView) as before" |
380 |
||
1338
3c1a528c50db
added paste-keeping-absolute-position function
Claus Gittinger <cg@exept.de>
parents:
1308
diff
changeset
|
381 |
|sel| |
3c1a528c50db
added paste-keeping-absolute-position function
Claus Gittinger <cg@exept.de>
parents:
1308
diff
changeset
|
382 |
|
3c1a528c50db
added paste-keeping-absolute-position function
Claus Gittinger <cg@exept.de>
parents:
1308
diff
changeset
|
383 |
sel := self |
1872 | 384 |
pasteSpecifications:(self getClipboardObject) |
385 |
keepLayout:true |
|
386 |
keepPosition:true |
|
3055 | 387 |
at:#keep. |
1338
3c1a528c50db
added paste-keeping-absolute-position function
Claus Gittinger <cg@exept.de>
parents:
1308
diff
changeset
|
388 |
|
2221 | 389 |
self changeSelectionAfterPasteOf:sel. |
1338
3c1a528c50db
added paste-keeping-absolute-position function
Claus Gittinger <cg@exept.de>
parents:
1308
diff
changeset
|
390 |
! |
3c1a528c50db
added paste-keeping-absolute-position function
Claus Gittinger <cg@exept.de>
parents:
1308
diff
changeset
|
391 |
|
2395 | 392 |
pasteSpecifications:aSpecificationOrList into:aContainerOrNil beforeIndex:anIndexOrNil keepLayout:keepLayout keepPosition:keepPosition at:aPointOrNilOrKeep |
2537 | 393 |
"add the specs to the object view; |
394 |
if given a collection of specs, returns a list of pasted widgets; |
|
395 |
if given a single spec, returns that view (sigh - a stupid bw-compatibility kludge)" |
|
2257
badd429a2a2a
code beautification; reasonable methodNames;
Claus Gittinger <cg@exept.de>
parents:
2250
diff
changeset
|
396 |
|
2494 | 397 |
|sensor specsToPaste pasteOffset builder newSel |
2560
efad0ef440c7
oops - need repairDamage for shown to be set (under unix; it used to
Michael Beyl <mb@exept.de>
parents:
2537
diff
changeset
|
398 |
bounds containerToPasteInto pastePoint beforeIndex count| |
1621
112670159075
cg: check if selection change is allowed BEFORE changing the
tm
parents:
1574
diff
changeset
|
399 |
|
112670159075
cg: check if selection change is allowed BEFORE changing the
tm
parents:
1574
diff
changeset
|
400 |
treeView askForSelectionChangeAllowed ifFalse:[^ nil]. |
112670159075
cg: check if selection change is allowed BEFORE changing the
tm
parents:
1574
diff
changeset
|
401 |
|
2494 | 402 |
sensor := self window sensor. |
403 |
||
2387 | 404 |
containerToPasteInto := aContainerOrNil. |
405 |
||
2366 | 406 |
(aPointOrNilOrKeep == #keep |
2494 | 407 |
or:[ sensor shiftDown |
408 |
or:[ sensor ctrlDown ]]) ifTrue:[ |
|
2362
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
409 |
"/ paste into the selection |
2387 | 410 |
containerToPasteInto isNil ifTrue:[ |
411 |
containerToPasteInto := self singleSelection. |
|
412 |
]. |
|
2362
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
413 |
] ifFalse:[ |
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
414 |
"/ ignore the selection and paste where we drop!! |
2366 | 415 |
pastePoint := aPointOrNilOrKeep. |
2362
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
416 |
pastePoint isNil ifTrue:[ |
3262 | 417 |
pastePoint := device |
2494 | 418 |
translatePoint:(sensor mousePoint) |
2362
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
419 |
fromView:nil |
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
420 |
toView:self. |
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
421 |
]. |
2387 | 422 |
containerToPasteInto isNil ifTrue:[ |
423 |
containerToPasteInto := self findObjectAt:pastePoint. |
|
424 |
]. |
|
2362
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
425 |
]. |
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
426 |
|
1744
c59a91953b64
paste with no container selected: search for a good one
Claus Gittinger <cg@exept.de>
parents:
1733
diff
changeset
|
427 |
containerToPasteInto isNil ifTrue:[ |
1878
6ae0cf83738f
Use #setClipboardText: instead of obsolete #setTextSelection:
Stefan Vogel <sv@exept.de>
parents:
1872
diff
changeset
|
428 |
self selection size > 0 ifTrue:[ |
6ae0cf83738f
Use #setClipboardText: instead of obsolete #setTextSelection:
Stefan Vogel <sv@exept.de>
parents:
1872
diff
changeset
|
429 |
containerToPasteInto := self commonContainerOf:self selection |
6ae0cf83738f
Use #setClipboardText: instead of obsolete #setTextSelection:
Stefan Vogel <sv@exept.de>
parents:
1872
diff
changeset
|
430 |
] ifFalse:[ |
6ae0cf83738f
Use #setClipboardText: instead of obsolete #setTextSelection:
Stefan Vogel <sv@exept.de>
parents:
1872
diff
changeset
|
431 |
containerToPasteInto := self |
6ae0cf83738f
Use #setClipboardText: instead of obsolete #setTextSelection:
Stefan Vogel <sv@exept.de>
parents:
1872
diff
changeset
|
432 |
]. |
2221 | 433 |
"/ self selection:containerToPasteInto. |
1744
c59a91953b64
paste with no container selected: search for a good one
Claus Gittinger <cg@exept.de>
parents:
1733
diff
changeset
|
434 |
]. |
c59a91953b64
paste with no container selected: search for a good one
Claus Gittinger <cg@exept.de>
parents:
1733
diff
changeset
|
435 |
|
2362
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
436 |
"/ search up parent list for something we can paste into |
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
437 |
[containerToPasteInto notNil and:[(self canPasteInto:containerToPasteInto) not]] whileTrue:[ |
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
438 |
containerToPasteInto == self ifTrue:[ |
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
439 |
containerToPasteInto := nil |
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
440 |
] ifFalse:[ |
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
441 |
containerToPasteInto := containerToPasteInto container. |
1878
6ae0cf83738f
Use #setClipboardText: instead of obsolete #setTextSelection:
Stefan Vogel <sv@exept.de>
parents:
1872
diff
changeset
|
442 |
]. |
1621
112670159075
cg: check if selection change is allowed BEFORE changing the
tm
parents:
1574
diff
changeset
|
443 |
]. |
1752 | 444 |
containerToPasteInto isNil ifTrue:[ |
1878
6ae0cf83738f
Use #setClipboardText: instead of obsolete #setTextSelection:
Stefan Vogel <sv@exept.de>
parents:
1872
diff
changeset
|
445 |
containerToPasteInto := self |
1752 | 446 |
]. |
60 | 447 |
|
2221 | 448 |
(self canPaste:aSpecificationOrList into:containerToPasteInto) |
449 |
ifFalse:[ |
|
2362
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
450 |
self enabled ifTrue:[ |
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
451 |
Dialog warn:'Cannot paste into selected component (not a container ?)'. |
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
452 |
] ifFalse:[ |
2951 | 453 |
Dialog warn:'Operation currently disabled (In geometry test mode)'. |
2362
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
454 |
]. |
1878
6ae0cf83738f
Use #setClipboardText: instead of obsolete #setTextSelection:
Stefan Vogel <sv@exept.de>
parents:
1872
diff
changeset
|
455 |
^ nil |
89 | 456 |
]. |
223 | 457 |
|
2537 | 458 |
self hideSelection. |
459 |
||
776 | 460 |
aSpecificationOrList isCollection ifTrue:[ |
2257
badd429a2a2a
code beautification; reasonable methodNames;
Claus Gittinger <cg@exept.de>
parents:
2250
diff
changeset
|
461 |
specsToPaste := aSpecificationOrList |
776 | 462 |
] ifFalse:[ |
2257
badd429a2a2a
code beautification; reasonable methodNames;
Claus Gittinger <cg@exept.de>
parents:
2250
diff
changeset
|
463 |
specsToPaste := Array with:aSpecificationOrList |
776 | 464 |
]. |
2221 | 465 |
"/ self setClipboardObject:nil. |
776 | 466 |
|
467 |
newSel := OrderedCollection new. |
|
468 |
builder := UIBuilder new isEditing:true. |
|
469 |
||
470 |
className notNil ifTrue:[ |
|
1878
6ae0cf83738f
Use #setClipboardText: instead of obsolete #setTextSelection:
Stefan Vogel <sv@exept.de>
parents:
1872
diff
changeset
|
471 |
builder applicationClass:(self resolveName:className) |
776 | 472 |
]. |
2362
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
473 |
bounds := Rectangle origin:0@0 extent:(containerToPasteInto bounds extent). |
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
474 |
|
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
475 |
pasteOffset := 0. |
60 | 476 |
|
2395 | 477 |
(anIndexOrNil notNil and:[anIndexOrNil > 0]) ifTrue:[ |
478 |
beforeIndex := anIndexOrNil. |
|
479 |
]. |
|
2257
badd429a2a2a
code beautification; reasonable methodNames;
Claus Gittinger <cg@exept.de>
parents:
2250
diff
changeset
|
480 |
specsToPaste do:[:eachSpec| |
2362
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
481 |
|view newOrigin uiPainterAttributes thisAbsOrigin| |
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
482 |
|
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
483 |
uiPainterAttributes := eachSpec otherAttributeAt:#uiPainterAttributes. |
2388 | 484 |
eachSpec otherAttributeAt:#uiPainterAttributes put:nil. |
1878
6ae0cf83738f
Use #setClipboardText: instead of obsolete #setTextSelection:
Stefan Vogel <sv@exept.de>
parents:
1872
diff
changeset
|
485 |
|
2395 | 486 |
view := self addSpec:eachSpec builder:builder in:containerToPasteInto beforeIndex:beforeIndex. |
487 |
beforeIndex notNil ifTrue:[ |
|
488 |
beforeIndex := beforeIndex + 1 |
|
489 |
]. |
|
3244 | 490 |
(keepLayout or:[eachSpec keepUILayout]) ifTrue:[ |
3249 | 491 |
eachSpec layout isAssociation ifTrue:[ |
492 |
eachSpec layout key == #extent ifTrue:[ |
|
493 |
view pixelExtent:eachSpec layout value |
|
494 |
] ifFalse:[ |
|
495 |
"/ self halt. |
|
496 |
view geometryLayout:eachSpec layout value |
|
497 |
]. |
|
498 |
] ifFalse:[ |
|
499 |
view geometryLayout:eachSpec layout. |
|
500 |
] |
|
3129 | 501 |
] ifFalse:[ |
502 |
(keepPosition and:[ uiPainterAttributes notNil ]) ifTrue:[ |
|
503 |
aPointOrNilOrKeep == #keep ifTrue:[ |
|
504 |
newOrigin := uiPainterAttributes at:#origin. |
|
505 |
] ifFalse:[ |
|
506 |
thisAbsOrigin := uiPainterAttributes at:#absOrigin. |
|
507 |
||
3262 | 508 |
newOrigin := device |
3129 | 509 |
translatePoint:thisAbsOrigin |
510 |
fromView:self |
|
511 |
toView:containerToPasteInto. |
|
512 |
]. |
|
2386 | 513 |
] ifFalse:[ |
3129 | 514 |
pastePoint isNil ifTrue:[ pastePoint := 0@0 ]. |
3262 | 515 |
newOrigin := device |
3129 | 516 |
translatePoint:pastePoint |
2386 | 517 |
fromView:self |
518 |
toView:containerToPasteInto. |
|
519 |
]. |
|
3129 | 520 |
|
521 |
(bounds containsPoint:newOrigin) ifFalse:[ |
|
522 |
newOrigin := pasteOffset asPoint. |
|
523 |
pasteOffset := pasteOffset + 4. |
|
524 |
]. |
|
525 |
newOrigin notNil ifTrue:[ |
|
526 |
self moveObject:view to:newOrigin. |
|
527 |
]. |
|
1878
6ae0cf83738f
Use #setClipboardText: instead of obsolete #setTextSelection:
Stefan Vogel <sv@exept.de>
parents:
1872
diff
changeset
|
528 |
]. |
2395 | 529 |
view realized ifFalse:[ |
530 |
view realize. |
|
531 |
]. |
|
1878
6ae0cf83738f
Use #setClipboardText: instead of obsolete #setTextSelection:
Stefan Vogel <sv@exept.de>
parents:
1872
diff
changeset
|
532 |
newSel add:view. |
776 | 533 |
]. |
60 | 534 |
|
2537 | 535 |
self |
536 |
withinTransaction:#paste |
|
537 |
objects:newSel |
|
538 |
do:[ |
|
539 |
undoHistory |
|
540 |
addUndoSelector:#undoCreate: |
|
541 |
withArgs:(newSel collect:[:v| (self propertyOfView:v) identifier]). |
|
542 |
self undoHistoryChanged. |
|
543 |
]. |
|
60 | 544 |
|
776 | 545 |
self realizeAllSubViews. |
2395 | 546 |
"/ newSel do:[:v| v raise]. |
1744
c59a91953b64
paste with no container selected: search for a good one
Claus Gittinger <cg@exept.de>
parents:
1733
diff
changeset
|
547 |
self elementChangedSize:containerToPasteInto. |
134 | 548 |
|
2818
6d5a0ea87cb7
changed: #pasteSpecifications:into:beforeIndex:keepLayout:keepPosition:at:
Claus Gittinger <cg@exept.de>
parents:
2716
diff
changeset
|
549 |
"/ nil wg if embedded in a browser |
6d5a0ea87cb7
changed: #pasteSpecifications:into:beforeIndex:keepLayout:keepPosition:at:
Claus Gittinger <cg@exept.de>
parents:
2716
diff
changeset
|
550 |
self windowGroup notNil ifTrue:[ |
6d5a0ea87cb7
changed: #pasteSpecifications:into:beforeIndex:keepLayout:keepPosition:at:
Claus Gittinger <cg@exept.de>
parents:
2716
diff
changeset
|
551 |
"/ because the new-created view will destroy the handles, when it redraws itself, |
6d5a0ea87cb7
changed: #pasteSpecifications:into:beforeIndex:keepLayout:keepPosition:at:
Claus Gittinger <cg@exept.de>
parents:
2716
diff
changeset
|
552 |
"/ give it a chance to do so, before we return. (bail out after half a second, in case of trouble) |
6d5a0ea87cb7
changed: #pasteSpecifications:into:beforeIndex:keepLayout:keepPosition:at:
Claus Gittinger <cg@exept.de>
parents:
2716
diff
changeset
|
553 |
count := 0. |
6d5a0ea87cb7
changed: #pasteSpecifications:into:beforeIndex:keepLayout:keepPosition:at:
Claus Gittinger <cg@exept.de>
parents:
2716
diff
changeset
|
554 |
[ (newSel conform:[:v | v shown]) or:[count > 50] ] whileFalse:[ |
6d5a0ea87cb7
changed: #pasteSpecifications:into:beforeIndex:keepLayout:keepPosition:at:
Claus Gittinger <cg@exept.de>
parents:
2716
diff
changeset
|
555 |
self windowGroup repairDamage. |
6d5a0ea87cb7
changed: #pasteSpecifications:into:beforeIndex:keepLayout:keepPosition:at:
Claus Gittinger <cg@exept.de>
parents:
2716
diff
changeset
|
556 |
Delay waitForSeconds:0.01. |
6d5a0ea87cb7
changed: #pasteSpecifications:into:beforeIndex:keepLayout:keepPosition:at:
Claus Gittinger <cg@exept.de>
parents:
2716
diff
changeset
|
557 |
count := count+1. |
6d5a0ea87cb7
changed: #pasteSpecifications:into:beforeIndex:keepLayout:keepPosition:at:
Claus Gittinger <cg@exept.de>
parents:
2716
diff
changeset
|
558 |
]. |
6d5a0ea87cb7
changed: #pasteSpecifications:into:beforeIndex:keepLayout:keepPosition:at:
Claus Gittinger <cg@exept.de>
parents:
2716
diff
changeset
|
559 |
Delay waitForSeconds:0.01. |
2560
efad0ef440c7
oops - need repairDamage for shown to be set (under unix; it used to
Michael Beyl <mb@exept.de>
parents:
2537
diff
changeset
|
560 |
self windowGroup repairDamage. |
2537 | 561 |
]. |
562 |
||
776 | 563 |
newSel size == 1 ifTrue:[newSel := newSel at:1]. |
223 | 564 |
^ newSel |
1500
36c0b4b268b8
use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents:
1494
diff
changeset
|
565 |
|
2818
6d5a0ea87cb7
changed: #pasteSpecifications:into:beforeIndex:keepLayout:keepPosition:at:
Claus Gittinger <cg@exept.de>
parents:
2716
diff
changeset
|
566 |
"Modified: / 03-11-2010 / 07:20:06 / cg" |
89 | 567 |
! |
568 |
||
3055 | 569 |
pasteSpecifications:aSpecificationOrList into:aContainerOrNil keepLayout:keepLayout keepPosition:keepPosition at:aPointOrNilOrKeep |
2395 | 570 |
"add the specs to the object view; returns list of pasted widgets" |
3055 | 571 |
|
572 |
^ self |
|
573 |
pasteSpecifications:aSpecificationOrList |
|
574 |
into:aContainerOrNil |
|
575 |
beforeIndex:nil |
|
576 |
keepLayout:keepLayout |
|
577 |
keepPosition:keepPosition |
|
578 |
at:aPointOrNilOrKeep |
|
2395 | 579 |
! |
580 |
||
2387 | 581 |
pasteSpecifications:aSpecificationOrList keepLayout:keepLayout |
582 |
"add the specs to the object view; returns list of pasted widgets" |
|
583 |
||
584 |
^ self |
|
585 |
pasteSpecifications:aSpecificationOrList |
|
586 |
keepLayout:keepLayout |
|
587 |
keepPosition:true |
|
2627
07d40cde2ac9
changed: #pasteSpecifications:keepLayout:
Claus Gittinger <cg@exept.de>
parents:
2583
diff
changeset
|
588 |
at:#keep "/ nil |
2387 | 589 |
|
590 |
"Modified: 11.8.1997 / 01:00:35 / cg" |
|
591 |
! |
|
592 |
||
593 |
pasteSpecifications:aSpecificationOrList keepLayout:keepLayout at:aPointOrNil |
|
594 |
"add the specs to the object view; returns list of pasted widgets" |
|
595 |
||
596 |
^ self |
|
597 |
pasteSpecifications:aSpecificationOrList |
|
598 |
keepLayout:keepLayout |
|
599 |
keepPosition:true |
|
600 |
at:aPointOrNil |
|
601 |
! |
|
602 |
||
603 |
pasteSpecifications:aSpecificationOrList keepLayout:keepLayout keepPosition:keepPosition at:aPointOrNilOrKeep |
|
604 |
"add the specs to the object view; returns list of pasted widgets" |
|
605 |
||
606 |
^ self pasteSpecifications:aSpecificationOrList |
|
607 |
into:nil |
|
2395 | 608 |
beforeIndex:nil |
2387 | 609 |
keepLayout:keepLayout |
610 |
keepPosition:keepPosition |
|
611 |
at:aPointOrNilOrKeep |
|
612 |
! |
|
613 |
||
2315 | 614 |
pasteWithLayout |
2369 | 615 |
"add the objects in the paste-buffer to the object view - keep the old layout" |
2315 | 616 |
|
617 |
|sel| |
|
618 |
||
2366 | 619 |
sel := self |
620 |
pasteSpecifications:(self getClipboardObject) |
|
621 |
keepLayout:true |
|
622 |
keepPosition:true |
|
623 |
at:#keep. |
|
2315 | 624 |
self changeSelectionAfterPasteOf:sel. |
625 |
! |
|
626 |
||
2311
67811bdeb0f5
Support sorting of items in tree
Stefan Vogel <sv@exept.de>
parents:
2295
diff
changeset
|
627 |
pasteWithoutLayout |
2369 | 628 |
"add the objects in the paste-buffer to the object view - do not keep the old layout" |
1959 | 629 |
|
223 | 630 |
|sel| |
631 |
||
2367 | 632 |
sel := self |
633 |
pasteSpecifications:(self getClipboardObject) |
|
634 |
keepLayout:false |
|
635 |
keepPosition:true |
|
636 |
at:#keep. |
|
2221 | 637 |
self changeSelectionAfterPasteOf:sel. |
2257
badd429a2a2a
code beautification; reasonable methodNames;
Claus Gittinger <cg@exept.de>
parents:
2250
diff
changeset
|
638 |
! |
badd429a2a2a
code beautification; reasonable methodNames;
Claus Gittinger <cg@exept.de>
parents:
2250
diff
changeset
|
639 |
|
badd429a2a2a
code beautification; reasonable methodNames;
Claus Gittinger <cg@exept.de>
parents:
2250
diff
changeset
|
640 |
replaceSelectionBy:aNewSpec |
badd429a2a2a
code beautification; reasonable methodNames;
Claus Gittinger <cg@exept.de>
parents:
2250
diff
changeset
|
641 |
"replace the selected widget by another one." |
badd429a2a2a
code beautification; reasonable methodNames;
Claus Gittinger <cg@exept.de>
parents:
2250
diff
changeset
|
642 |
|
2395 | 643 |
|oldSelection treeModel newView oldView container specs| |
2387 | 644 |
|
645 |
(self singleSelection notNil and:[treeView askForSelectionChangeAllowed]) ifFalse:[ |
|
646 |
^ self |
|
647 |
]. |
|
648 |
treeModel := treeView model. |
|
2257
badd429a2a2a
code beautification; reasonable methodNames;
Claus Gittinger <cg@exept.de>
parents:
2250
diff
changeset
|
649 |
oldSelection := treeModel selectedNodes at:1 ifAbsent: nil. |
2387 | 650 |
oldSelection isNil ifTrue:[^ self]. |
651 |
||
2395 | 652 |
oldView := oldSelection contents view. |
653 |
||
654 |
(oldSelection hasChildren and:[aNewSpec class supportsSubComponents]) ifTrue:[ |
|
655 |
specs := oldSelection children collect:[:each| |
|
656 |
self fullSpecWithAbsolutePositionFor:(each contents view) |
|
657 |
]. |
|
658 |
]. |
|
2387 | 659 |
|
660 |
aNewSpec |
|
661 |
otherAttributeAt:#uiPainterAttributes |
|
662 |
put:(Dictionary new |
|
663 |
at:#origin put:oldView origin; |
|
664 |
at:#extent put:oldView extent; |
|
665 |
at:#absOrigin put:(oldView originRelativeTo:self); |
|
666 |
yourself). |
|
667 |
||
668 |
container := self singleSelection container. |
|
669 |
||
670 |
self withinTransaction:#replaceBy objects:(Array with:oldView) do:[ |
|
2395 | 671 |
self withSelectionHiddenDo:[ |
672 |
newView := self |
|
673 |
pasteSpecifications:(Array with:aNewSpec) |
|
674 |
into:container |
|
675 |
beforeIndex:1 |
|
676 |
keepLayout:true |
|
677 |
keepPosition:true |
|
678 |
at:#keep. |
|
679 |
||
680 |
self deleteSelectionBuffered:false. |
|
681 |
||
682 |
specs size > 0 ifTrue:[ |
|
683 |
self pasteSpecifications:specs |
|
684 |
into:newView |
|
685 |
keepLayout:(aNewSpec class canResizeSubComponents) |
|
686 |
keepPosition:(aNewSpec class isLayoutContainer not) |
|
687 |
at:nil. |
|
688 |
]. |
|
689 |
self select:newView. |
|
690 |
]. |
|
2387 | 691 |
]. |
2395 | 692 |
^ newView. |
60 | 693 |
! ! |
694 |
||
695 |
!UIPainterView methodsFor:'drag & drop'! |
|
696 |
||
2116 | 697 |
canDrop:aDropContext |
698 |
^ self canDropObjects:aDropContext dropObjects |
|
699 |
||
700 |
"Created: / 13-10-2006 / 17:46:11 / cg" |
|
701 |
! |
|
702 |
||
703 |
canDropObjects:aCollectionOfDropObjects |
|
1914 | 704 |
"returns true if something can be dropped" |
705 |
||
2362
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
706 |
^ (true "aCollectionOfDropObjects size == 1" |
2112 | 707 |
and:[ self enabled |
2362
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
708 |
and:[ true "self numberOfSelections <= 1" |
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
709 |
and:[ aCollectionOfDropObjects conform:[:each| each theObject isKindOf:UISpecification] |
a6a7ef98fdc3
can resize - allow resizing all;
Claus Gittinger <cg@exept.de>
parents:
2358
diff
changeset
|
710 |
]]]) |
2112 | 711 |
|
2116 | 712 |
"Created: / 13-10-2006 / 16:09:24 / cg" |
223 | 713 |
! |
714 |
||
285 | 715 |
canPaste |
1914 | 716 |
"returns true if there is something which can be pasted in the clipboard" |
717 |
||
1872 | 718 |
^ self canPaste:(self getClipboardObject) |
285 | 719 |
! |
720 |
||
223 | 721 |
canPaste:something |
1914 | 722 |
"returns true if something could be pasted" |
723 |
||
2221 | 724 |
^ self canPaste:something into:(self singleSelection) |
725 |
! |
|
726 |
||
727 |
canPaste:something into:containerToPasteInto |
|
728 |
"returns true if something could be pasted" |
|
729 |
||
2276
485bda17023f
more changes to allow for non-class/selector (i.e. spec-only) use
Claus Gittinger <cg@exept.de>
parents:
2265
diff
changeset
|
730 |
(self enabled) ifFalse:[ |
1914 | 731 |
^ false |
223 | 732 |
]. |
2276
485bda17023f
more changes to allow for non-class/selector (i.e. spec-only) use
Claus Gittinger <cg@exept.de>
parents:
2265
diff
changeset
|
733 |
something isCollection ifTrue:[ |
485bda17023f
more changes to allow for non-class/selector (i.e. spec-only) use
Claus Gittinger <cg@exept.de>
parents:
2265
diff
changeset
|
734 |
something isEmpty ifTrue:[ ^ false]. |
485bda17023f
more changes to allow for non-class/selector (i.e. spec-only) use
Claus Gittinger <cg@exept.de>
parents:
2265
diff
changeset
|
735 |
^ something conform:[:el | (self canPaste:el into:containerToPasteInto)] |
485bda17023f
more changes to allow for non-class/selector (i.e. spec-only) use
Claus Gittinger <cg@exept.de>
parents:
2265
diff
changeset
|
736 |
]. |
485bda17023f
more changes to allow for non-class/selector (i.e. spec-only) use
Claus Gittinger <cg@exept.de>
parents:
2265
diff
changeset
|
737 |
|
485bda17023f
more changes to allow for non-class/selector (i.e. spec-only) use
Claus Gittinger <cg@exept.de>
parents:
2265
diff
changeset
|
738 |
(something isKindOf:UISpecification) ifFalse:[ |
1914 | 739 |
^ false |
223 | 740 |
]. |
741 |
||
2276
485bda17023f
more changes to allow for non-class/selector (i.e. spec-only) use
Claus Gittinger <cg@exept.de>
parents:
2265
diff
changeset
|
742 |
^ self canPasteInto:containerToPasteInto |
223 | 743 |
! |
744 |
||
745 |
canPasteInto:aView |
|
1914 | 746 |
"return true, if I can paste into a view" |
747 |
||
285 | 748 |
|prop| |
60 | 749 |
|
1870 | 750 |
aView isNil ifTrue:[ ^ false ]. |
2265 | 751 |
aView == self ifTrue:[ ^ true ]. |
1870 | 752 |
|
753 |
(prop := self propertyOfView:aView) notNil ifTrue:[ |
|
754 |
^ prop spec class supportsSubComponents |
|
89 | 755 |
]. |
1870 | 756 |
^ aView specClass supportsSubComponents. |
60 | 757 |
! |
758 |
||
2116 | 759 |
dropObjects:aCollectionOfDropObjects at:aPoint |
2537 | 760 |
|spec newSel oldSel dragOffset dropPoint widg| |
761 |
||
288 | 762 |
self selection notNil ifTrue:[ |
1953 | 763 |
oldSel := self singleSelection. |
764 |
||
765 |
"/ search selections hierarchy for a widget into which we can paste |
|
766 |
widg := oldSel. |
|
767 |
[widg isNil or:[self canPasteInto:widg]] whileFalse:[ |
|
768 |
widg notNil ifTrue:[ |
|
769 |
widg := widg container |
|
770 |
]. |
|
771 |
]. |
|
772 |
||
773 |
oldSel := nil. |
|
774 |
self setSelection:widg withRedraw:true. |
|
231 | 775 |
]. |
1953 | 776 |
spec := (aCollectionOfDropObjects at:1) theObject. |
2537 | 777 |
|
778 |
dragOffset := DragAndDropManager dragOffsetQuerySignal query. |
|
779 |
aPoint isNil ifTrue:[ |
|
780 |
dropPoint := #keep. |
|
781 |
] ifFalse:[ |
|
782 |
dropPoint := aPoint - dragOffset. |
|
1833 | 783 |
]. |
2537 | 784 |
newSel := self pasteSpecifications:spec keepLayout:false keepPosition:false at:dropPoint. |
785 |
||
786 |
self select:(oldSel ? newSel). |
|
1060
0332a41de5c5
Use #query instead of #raise when invoking QuerySignals
Stefan Vogel <sv@exept.de>
parents:
1058
diff
changeset
|
787 |
|
2116 | 788 |
"Modified: / 18-03-1999 / 18:29:43 / stefan" |
789 |
"Created: / 13-10-2006 / 16:09:27 / cg" |
|
60 | 790 |
! ! |
791 |
||
2244 | 792 |
!UIPainterView methodsFor:'drawing'! |
793 |
||
794 |
clearRectangle:visRect |
|
795 |
super clearRectangle:visRect. |
|
796 |
sketchPainter notNil ifTrue:[ |
|
797 |
sketchPainter redrawInTargetView |
|
798 |
]. |
|
799 |
||
800 |
"Created: / 16-01-2008 / 17:52:27 / cg" |
|
801 |
! |
|
802 |
||
803 |
clearView |
|
804 |
super clearView. |
|
805 |
sketchPainter notNil ifTrue:[ |
|
806 |
sketchPainter redrawInTargetView |
|
807 |
]. |
|
808 |
||
809 |
"Created: / 16-01-2008 / 17:46:08 / cg" |
|
810 |
! |
|
811 |
||
2248 | 812 |
useSketchFile:aFilename |
2443 | 813 |
"a little neat goody: allow for a tablet-sketch file (WALTROP digital notepad) |
814 |
to be used as a background of the UIPainter window. This allows for sketches to |
|
815 |
be drawn, shown in the UIPainter, and then used as a placement hint (manual placement) |
|
816 |
for the user. Not a high-tech solution, but helped a lot, when we protoyped GUIs." |
|
817 |
||
2248 | 818 |
|mime sketchPainterClass| |
819 |
||
820 |
mime := aFilename asFilename mimeTypeFromName. |
|
821 |
mime isNil ifTrue:[ |
|
822 |
mime := aFilename asFilename mimeTypeOfContents. |
|
823 |
]. |
|
824 |
||
825 |
mime notNil ifTrue:[ |
|
2278
8ff3bd6f0820
Allow to load background from image file #useSketchFile:
Stefan Vogel <sv@exept.de>
parents:
2276
diff
changeset
|
826 |
(mime startsWith:'image') ifTrue:[ |
8ff3bd6f0820
Allow to load background from image file #useSketchFile:
Stefan Vogel <sv@exept.de>
parents:
2276
diff
changeset
|
827 |
self viewBackground:(ImageReader fromFile:aFilename). |
8ff3bd6f0820
Allow to load background from image file #useSketchFile:
Stefan Vogel <sv@exept.de>
parents:
2276
diff
changeset
|
828 |
^ self. |
8ff3bd6f0820
Allow to load background from image file #useSketchFile:
Stefan Vogel <sv@exept.de>
parents:
2276
diff
changeset
|
829 |
]. |
2444 | 830 |
mime = 'application/x-waltop-digital-notepad' ifTrue:[ |
831 |
sketchPainterClass := TOPFileDrawer. |
|
832 |
]. |
|
2248 | 833 |
]. |
834 |
sketchPainterClass isNil ifTrue:[ |
|
2444 | 835 |
self error:'Unsupported sketch file format' |
2248 | 836 |
]. |
837 |
||
838 |
sketchPainter := sketchPainterClass new. |
|
2244 | 839 |
sketchPainter targetView:self. |
840 |
sketchPainter readFile:aFilename. |
|
841 |
sketchPainter ajustSketch. |
|
842 |
self invalidate. |
|
843 |
||
844 |
"Created: / 16-01-2008 / 17:46:26 / cg" |
|
845 |
! ! |
|
846 |
||
361 | 847 |
!UIPainterView methodsFor:'event handling'! |
848 |
||
849 |
keyPress:key x:x y:y view:aView |
|
376 | 850 |
"a delegated keyEvent from aView" |
851 |
||
361 | 852 |
self keyPress:key x:x y:y |
853 |
||
376 | 854 |
"Modified: / 31.10.1997 / 20:27:22 / cg" |
361 | 855 |
! |
856 |
||
857 |
keyRelease:key x:x y:y view:aView |
|
376 | 858 |
"a delegated keyEvent from aView" |
859 |
||
361 | 860 |
self keyRelease:key x:x y:y |
861 |
||
376 | 862 |
"Modified: / 31.10.1997 / 20:27:32 / cg" |
754 | 863 |
! |
864 |
||
865 |
sizeChanged:how |
|
866 |
||
1834 | 867 |
super sizeChanged:how. |
754 | 868 |
|
869 |
self layoutChanged |
|
361 | 870 |
! ! |
871 |
||
78 | 872 |
!UIPainterView methodsFor:'generating output'! |
873 |
||
352 | 874 |
aspectMethods |
875 |
"extract a list of aspect methods - for browsing" |
|
876 |
||
1683
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
877 |
|cls methods| |
352 | 878 |
|
879 |
className isNil ifTrue:[ |
|
1834 | 880 |
self warn:'No class defined !!'. |
881 |
^ #() |
|
352 | 882 |
]. |
883 |
||
884 |
cls := self resolveName:className. |
|
885 |
methods := IdentitySet new. |
|
886 |
||
1683
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
887 |
self aspectSelectorsAndTypesDo: |
1834 | 888 |
[:selector :typeSymbol | |
889 |
|skip| |
|
890 |
||
891 |
(cls includesSelector:selector) ifTrue:[ |
|
892 |
||
893 |
skip := false. |
|
894 |
(typeSymbol == #modelAspect) ifTrue:[ |
|
895 |
(cls isSubclassOf:SimpleDialog) ifTrue:[ |
|
896 |
skip := SimpleDialog includesSelector:(selector asSymbol) |
|
897 |
]. |
|
898 |
]. |
|
899 |
skip ifFalse:[ |
|
900 |
methods add:(cls compiledMethodAt:selector) |
|
901 |
]. |
|
902 |
] |
|
903 |
]. |
|
1683
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
904 |
|
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
905 |
^ methods |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
906 |
|
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
907 |
"Created: / 25.10.1997 / 18:58:25 / cg" |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
908 |
"Modified: / 26.10.1997 / 15:06:18 / cg" |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
909 |
! |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
910 |
|
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
911 |
aspectSelectorsAndTypesDo:aTwoArgBlock |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
912 |
"evaluate aBlock for every aspect methods selector; 2nd arg describes the aspects type" |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
913 |
|
1726 | 914 |
|cls selector protoSpec| |
1683
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
915 |
|
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
916 |
className isNil ifTrue:[ |
2195
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
917 |
self warn:'No class defined !!'. |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
918 |
^ self |
1683
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
919 |
]. |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
920 |
|
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
921 |
cls := self resolveName:className. |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
922 |
|
352 | 923 |
treeView propertiesDo:[:aProp| |
2195
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
924 |
|selector| |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
925 |
|
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
926 |
(selector := aProp model) notNil ifTrue:[ |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
927 |
selector isArray ifFalse:[ |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
928 |
aTwoArgBlock value:(selector asSymbol) value:#modelAspect |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
929 |
]. |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
930 |
]. |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
931 |
|
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
932 |
(selector := aProp menu) notNil ifTrue:[ |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
933 |
selector isArray ifFalse:[ |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
934 |
aTwoArgBlock value:(selector asSymbol) value:#menu |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
935 |
]. |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
936 |
]. |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
937 |
|
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
938 |
(aProp spec aspectSelectors) do:[:aSel | |
2250
e65b8bf6224b
care for non-symbolic aspects (false)
Claus Gittinger <cg@exept.de>
parents:
2248
diff
changeset
|
939 |
(aSel isString or:[aSel isSymbol]) ifTrue:[ |
2195
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
940 |
aTwoArgBlock value:(aSel asSymbol) value:#channelAspect |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
941 |
]. |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
942 |
]. |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
943 |
aProp spec actionSelectors do:[:aSel| |
2250
e65b8bf6224b
care for non-symbolic aspects (false)
Claus Gittinger <cg@exept.de>
parents:
2248
diff
changeset
|
944 |
(aSel isString or:[aSel isSymbol]) ifTrue:[ |
2195
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
945 |
aTwoArgBlock value:(aSel asSymbol) value:#actionSelector |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
946 |
]. |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
947 |
]. |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
948 |
aProp spec valueSelectors do:[:aSel| |
2250
e65b8bf6224b
care for non-symbolic aspects (false)
Claus Gittinger <cg@exept.de>
parents:
2248
diff
changeset
|
949 |
(aSel isString or:[aSel isSymbol]) ifTrue:[ |
2195
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
950 |
aTwoArgBlock value:(aSel asSymbol) value:#valueSelector |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
951 |
]. |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
952 |
] |
352 | 953 |
]. |
954 |
||
955 |
protoSpec := treeView canvasSpec. |
|
956 |
||
957 |
(selector := protoSpec menu) notNil ifTrue:[ |
|
2195
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
958 |
selector isArray ifFalse:[ |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
959 |
aTwoArgBlock value:(selector asSymbol) value:#menu |
bb6de5f8fd03
Take care of true or false as pseudo-aspect-selectors
Stefan Vogel <sv@exept.de>
parents:
2191
diff
changeset
|
960 |
]. |
352 | 961 |
]. |
962 |
! |
|
963 |
||
60 | 964 |
generateActionMethodFor:aspect spec:protoSpec inClass:targetClass |
2244 | 965 |
|selector args showIt codeStream alreadyInSuperclass numArgs method| |
288 | 966 |
|
967 |
selector := aspect asSymbol. |
|
141 | 968 |
|
288 | 969 |
alreadyInSuperclass := targetClass superclass canUnderstand:selector. |
970 |
||
568 | 971 |
numArgs := selector numArgs. |
972 |
method := aspect. |
|
973 |
||
974 |
numArgs == 1 ifTrue:[ |
|
2244 | 975 |
args := 'anArgument'. |
2295 | 976 |
showIt := ''' , anArgument printString , ''...''.'. |
1834 | 977 |
] ifFalse:[ |
2244 | 978 |
args := ''. |
979 |
showIt := ' ...''.'. |
|
980 |
||
981 |
numArgs ~~ 0 ifTrue:[ |
|
982 |
method := ''. |
|
983 |
||
984 |
selector keywords keysAndValuesDo:[:i :key| |
|
985 |
method := method, key, 'arg', i printString, ' ' |
|
986 |
] |
|
987 |
] |
|
149 | 988 |
]. |
2244 | 989 |
codeStream := WriteStream on:(String new:100). |
990 |
codeStream |
|
991 |
nextPutLine:('!!',targetClass name,' methodsFor:''actions''!!'); |
|
992 |
nextPutLine:(method,args); |
|
993 |
nextPutLine:' <resource: #uiCallback>'; |
|
994 |
cr. |
|
995 |
||
996 |
self class generateCommentedCode ifTrue:[ |
|
997 |
codeStream |
|
2295 | 998 |
nextPutAll:' "automatically generated by UIPainter..." |
2244 | 999 |
|
1000 |
"*** the code below performs no action" |
|
1001 |
"*** (except for some feedback on the Transcript)" |
|
1002 |
"*** Please change as required and accept in the browser." |
|
1003 |
"*** (and replace this comment by something more useful ;-)" |
|
1004 |
||
1005 |
'. |
|
1006 |
||
1007 |
alreadyInSuperclass ifTrue:[ |
|
1008 |
codeStream |
|
1009 |
nextPutLine:' "action for ' , aspect , ' is already provided in a superclass."'; |
|
1010 |
nextPutLine:' "It may be redefined here..."'; |
|
1011 |
cr. |
|
1012 |
] ifFalse:[ |
|
1013 |
codeStream |
|
1014 |
nextPutLine:' "action to be defined here..."'; |
|
1015 |
cr. |
|
1016 |
]. |
|
1017 |
]. |
|
1018 |
||
1019 |
codeStream |
|
3304 | 1020 |
nextPutAll:' Logger info:'''. |
288 | 1021 |
|
1022 |
alreadyInSuperclass ifTrue:[ |
|
2244 | 1023 |
codeStream |
1024 |
nextPutAll:'inherited '. |
|
288 | 1025 |
]. |
2244 | 1026 |
codeStream |
1027 |
nextPutAll:'action for '; |
|
1028 |
nextPutAll:aspect; |
|
1029 |
nextPutLine:showIt. |
|
288 | 1030 |
|
1031 |
alreadyInSuperclass ifTrue:[ |
|
2244 | 1032 |
codeStream |
1033 |
nextPutAll:' super '; |
|
1034 |
nextPutAll:aspect; |
|
1035 |
nextPutAll:args; |
|
1036 |
nextPutLine:'.'. |
|
288 | 1037 |
]. |
1038 |
||
2244 | 1039 |
codeStream |
1040 |
nextPutLine:'!! !!'; cr. |
|
1041 |
||
1042 |
^ codeStream contents. |
|
1043 |
||
1044 |
"Modified: / 12-01-2008 / 10:21:52 / cg" |
|
60 | 1045 |
! |
1046 |
||
1683
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1047 |
generateAspectMethodCode |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1048 |
"generate aspect, action & menu methods |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1049 |
- but do not overwrite existing ones. |
2714
abaae556bec8
commentCode flags now in userPrefs
Claus Gittinger <cg@exept.de>
parents:
2627
diff
changeset
|
1050 |
Return a string ready to compile into the application class. |
abaae556bec8
commentCode flags now in userPrefs
Claus Gittinger <cg@exept.de>
parents:
2627
diff
changeset
|
1051 |
TODO: refactor and move to CodeGenerator" |
1683
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1052 |
|
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1053 |
^ self generateAspectMethodCodeFiltering:nil |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1054 |
! |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1055 |
|
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1056 |
generateAspectMethodCodeFiltering:aFilterOrEmpty |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1057 |
"generate aspect, action & menu methods |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1058 |
- but do not overwrite existing ones. |
2714
abaae556bec8
commentCode flags now in userPrefs
Claus Gittinger <cg@exept.de>
parents:
2627
diff
changeset
|
1059 |
Return a string ready to compile into the application class. |
abaae556bec8
commentCode flags now in userPrefs
Claus Gittinger <cg@exept.de>
parents:
2627
diff
changeset
|
1060 |
TODO: refactor and move to CodeGenerator" |
1683
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1061 |
|
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1062 |
|cls codePieces skip protoSpec thisCode |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1063 |
definedMethodSelectors iVars t exportSels| |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1064 |
|
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1065 |
cls := self targetClass. |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1066 |
cls isNil ifTrue:[ |
2024 | 1067 |
^ nil |
1683
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1068 |
]. |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1069 |
|
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1070 |
codePieces := OrderedCollection new. |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1071 |
definedMethodSelectors := IdentitySet new. |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1072 |
|
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1073 |
treeView propertiesDo:[:aProp| |
2024 | 1074 |
|modelSelector| |
1075 |
||
1076 |
protoSpec := aProp spec. |
|
1077 |
||
1078 |
(modelSelector := aProp model) notNil ifTrue:[ |
|
1079 |
self generateCodeFrom:(Array with:modelSelector) in:cls |
|
1080 |
do:[:aSel| |
|
1081 |
(aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[ |
|
1082 |
skip := false. |
|
1083 |
||
1084 |
(cls isSubclassOf:SimpleDialog) ifTrue:[ |
|
1085 |
skip := SimpleDialog includesSelector:aSel |
|
1086 |
]. |
|
1087 |
(definedMethodSelectors includes:aSel) ifTrue:[ |
|
1088 |
skip := true. |
|
1089 |
]. |
|
1090 |
||
1091 |
skip ifFalse:[ |
|
1092 |
"/ kludge .. |
|
1093 |
"/ (protoSpec isKindOf:ActionButtonSpec) |
|
1094 |
(protoSpec defaultModelIsCallBackMethodSelector:aSel) |
|
1095 |
ifTrue:[ |
|
1096 |
thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls). |
|
1097 |
] ifFalse:[ |
|
1098 |
thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls). |
|
1099 |
]. |
|
1100 |
codePieces add:thisCode. |
|
1101 |
definedMethodSelectors add:aSel. |
|
1102 |
Transcript showCR:'code generated for aspect: ' , aSel |
|
1103 |
] ifTrue:[ |
|
1104 |
Transcript showCR:'*** no code generated for aspect: ' , aSel , ' (method already exists)' |
|
1105 |
]. |
|
1106 |
]. |
|
1107 |
]. |
|
1108 |
]. |
|
1109 |
||
1110 |
"/ for each aspect, generate getter (if not yet implemented) |
|
1111 |
self generateCodeFrom:(aProp spec aspectSelectors) in:cls |
|
1112 |
do:[:aSel| |
|
1113 |
(aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[ |
|
1114 |
(definedMethodSelectors includes:aSel) ifFalse:[ |
|
1115 |
thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls). |
|
1116 |
codePieces add:thisCode. |
|
1117 |
definedMethodSelectors add:aSel. |
|
1118 |
Transcript showCR:'code generated for aspect: ' , aSel |
|
1119 |
] |
|
1120 |
] |
|
1121 |
]. |
|
1122 |
||
1123 |
"/ exported aspects - need setter methods |
|
3092 | 1124 |
exportSels := (treeView exportedAspects ? #()) collect:[:entry | (entry subAspect) asMutator]. |
2024 | 1125 |
self generateCodeFrom:exportSels in:cls |
1126 |
do:[:aSel| |
|
1127 |
|aspect| |
|
1128 |
||
1129 |
(aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[ |
|
1130 |
(definedMethodSelectors includes:aSel) ifFalse:[ |
|
3136 | 1131 |
aspect := (aSel copyButLast) asSymbol. |
2024 | 1132 |
thisCode := (self generateAspectSetMethodFor:aspect spec:protoSpec inClass:cls). |
1133 |
codePieces add:thisCode. |
|
1134 |
definedMethodSelectors add:aSel. |
|
1135 |
Transcript showCR:'export code generated for aspect: ' , aSel |
|
1136 |
] |
|
1137 |
] |
|
1138 |
]. |
|
1139 |
||
1140 |
self generateCodeFrom:(aProp spec actionSelectors) in:cls |
|
1141 |
do:[:aSel| |
|
1142 |
(aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[ |
|
1143 |
(definedMethodSelectors includes:aSel) ifFalse:[ |
|
1144 |
thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls). |
|
1145 |
codePieces add:thisCode. |
|
1146 |
definedMethodSelectors add:aSel. |
|
1147 |
Transcript showCR:'action generated for aspect: ' , aSel |
|
1148 |
] |
|
1149 |
] |
|
1150 |
]. |
|
1151 |
||
1152 |
self generateCodeFrom:(aProp spec valueSelectors) in:cls |
|
1153 |
do:[:aSel| |
|
1154 |
(aFilterOrEmpty isNil or:[aFilterOrEmpty includes:aSel]) ifTrue:[ |
|
1155 |
(definedMethodSelectors includes:aSel) ifFalse:[ |
|
1156 |
"/ uppercase: - assume its a globals name. |
|
1157 |
aSel isUppercaseFirst ifFalse:[ |
|
1158 |
thisCode := (self generateValueMethodFor:aSel spec:protoSpec inClass:cls). |
|
1159 |
codePieces add:thisCode. |
|
1160 |
definedMethodSelectors add:aSel. |
|
1161 |
Transcript showCR:'code generated for aspect: ' , aSel |
|
1162 |
] |
|
1163 |
] |
|
1164 |
] |
|
1165 |
]. |
|
1683
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1166 |
]. |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1167 |
|
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1168 |
AspectsAsInstances ifTrue:[ |
2024 | 1169 |
iVars := cls instVarNames asOrderedCollection. |
1170 |
definedMethodSelectors do:[:ivar | |
|
1171 |
(iVars includes:ivar) ifFalse:[ |
|
1172 |
iVars add:ivar |
|
1173 |
] |
|
1174 |
]. |
|
1175 |
iVars := iVars asArray. |
|
1176 |
t := cls shallowCopy. |
|
1177 |
t setInstanceVariableString:iVars asStringCollection asString. |
|
1178 |
codePieces addFirst:(t definition , '!!\' withCRs). |
|
1683
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1179 |
]. |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1180 |
|
1834 | 1181 |
^ String |
2024 | 1182 |
streamContents: |
1183 |
[:codeStream | |
|
1184 |
codePieces do:[:eachPiece | codeStream nextPutAll:eachPiece]. |
|
1185 |
]. |
|
1683
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1186 |
|
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1187 |
"Modified: / 29.7.1998 / 12:21:19 / cg" |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1188 |
! |
f95658463570
added selective aspect method generation.
Claus Gittinger <cg@exept.de>
parents:
1671
diff
changeset
|
1189 |
|
60 | 1190 |
generateAspectMethodFor:aspect spec:protoSpec inClass:targetClass |
2244 | 1191 |
|modelClass modelValueString modelValue modelGen codeStream| |
134 | 1192 |
|
149 | 1193 |
modelClass := protoSpec defaultModelClassFor:aspect. |
1257
acb8c0a58ef3
dataSPec defaultValue when generating aspects
Claus Gittinger <cg@exept.de>
parents:
1252
diff
changeset
|
1194 |
modelValueString := protoSpec defaultModelValueStringFor:aspect. |
acb8c0a58ef3
dataSPec defaultValue when generating aspects
Claus Gittinger <cg@exept.de>
parents:
1252
diff
changeset
|
1195 |
modelValueString notNil ifTrue:[ |
2244 | 1196 |
modelGen := modelValueString |
1257
acb8c0a58ef3
dataSPec defaultValue when generating aspects
Claus Gittinger <cg@exept.de>
parents:
1252
diff
changeset
|
1197 |
] ifFalse:[ |
2244 | 1198 |
modelValue := protoSpec defaultModelValueFor:aspect. |
1199 |
modelValue isNil ifTrue:[ |
|
1200 |
modelGen := modelClass name , ' new' |
|
1201 |
] ifFalse:[ |
|
1202 |
modelGen := modelValue storeString , ' asValue' |
|
1203 |
]. |
|
352 | 1204 |
|
1205 |
]. |
|
134 | 1206 |
|
2244 | 1207 |
codeStream := WriteStream on:(String new:100). |
1208 |
codeStream |
|
1209 |
nextPutLine:('!!' , targetClass name , ' methodsFor:''aspects''!!'); |
|
1210 |
nextPutLine:aspect; |
|
1211 |
nextPutLine:' <resource: #uiAspect>'; |
|
1212 |
cr. |
|
1213 |
||
1214 |
self class generateCommentedCode ifTrue:[ |
|
1215 |
codeStream |
|
1216 |
nextPutAll:' "automatically generated by UIPainter ..." |
|
1217 |
||
1218 |
"*** the code below creates a default model when invoked." |
|
1219 |
"*** (which may not be the one you wanted)" |
|
1220 |
"*** Please change as required and accept it in the browser." |
|
1221 |
"*** (and replace this comment by something more useful ;-)" |
|
1222 |
||
1223 |
'. |
|
1224 |
]. |
|
1474 | 1225 |
|
925
e6ddd46581c3
added option of generating aspects as instvars.
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
1226 |
AspectsAsInstances ifTrue:[ |
2244 | 1227 |
codeStream |
1228 |
nextPutLine:(' ',aspect,' isNil ifTrue:['); |
|
1229 |
nextPutLine:(' ',aspect,' := ',modelGen,'.'). |
|
1230 |
||
1231 |
modelClass ~~ TriggerValue ifTrue:[ |
|
1232 |
self class generateCommentedCode ifTrue:[ |
|
1233 |
codeStream |
|
1234 |
nextPutLine:'"/ if your app needs to be notified of changes, uncomment one of the lines below:'. |
|
1235 |
]. |
|
1236 |
codeStream |
|
1237 |
nextPutLine:'"/ ',aspect,' addDependent:self.'; |
|
1238 |
nextPutLine:'"/ ',aspect,' onChangeSend:#',aspect,'Changed to:self.'. |
|
1239 |
]. |
|
1240 |
codeStream |
|
1241 |
nextPutLine:' ].'; |
|
1242 |
nextPutLine:' ^ ',aspect,'.'. |
|
925
e6ddd46581c3
added option of generating aspects as instvars.
Claus Gittinger <cg@exept.de>
parents:
887
diff
changeset
|
1243 |
] ifFalse:[ |
2244 | 1244 |
codeStream |
580cac31c444
changed #initialize
Claus Git |