UIPainterView.st
changeset 698 5bf234e0e451
parent 662 28d6cac7968b
child 708 b5f3169a0ba7
equal deleted inserted replaced
697:ca492fc8390a 698:5bf234e0e451
    11 "
    11 "
    12 
    12 
    13 UIObjectView subclass:#UIPainterView
    13 UIObjectView subclass:#UIPainterView
    14 	instanceVariableNames:'treeView listHolder superclassName className methodName
    14 	instanceVariableNames:'treeView listHolder superclassName className methodName
    15 		categoryName'
    15 		categoryName'
    16 	classVariableNames:'HandCursor'
    16 	classVariableNames:'HandCursor RedefineMethods'
    17 	poolDictionaries:''
    17 	poolDictionaries:''
    18 	category:'Interface-UIPainter'
    18 	category:'Interface-UIPainter'
    19 !
    19 !
    20 
    20 
    21 Object subclass:#ViewProperty
    21 Object subclass:#ViewProperty
    54         Claus Gittinger
    54         Claus Gittinger
    55         Claus Atzkern
    55         Claus Atzkern
    56 "
    56 "
    57 ! !
    57 ! !
    58 
    58 
       
    59 !UIPainterView class methodsFor:'code generation mode'!
       
    60 
       
    61 redefineMethods
       
    62     "redefine methods yes or no. If a method is defined in super class
       
    63      should the message be reinstalled ?
       
    64     "
       
    65     ^ RedefineMethods ? false
       
    66 
       
    67 !
       
    68 
       
    69 redefineMethods:aBool
       
    70     "redefine methods yes or no. If a method is defined in super class
       
    71      should the message be reinstalled ?
       
    72     "
       
    73     RedefineMethods := aBool
       
    74 
       
    75 
       
    76 ! !
       
    77 
    59 !UIPainterView class methodsFor:'defaults'!
    78 !UIPainterView class methodsFor:'defaults'!
    60 
    79 
    61 defaultMenuMessage   
    80 defaultMenuMessage   
    62     "This message is the default yo be sent to the menuHolder to get a menu
    81     "This message is the default yo be sent to the menuHolder to get a menu
    63     "
    82     "
   158 !UIPainterView methodsFor:'copy & cut & paste'!
   177 !UIPainterView methodsFor:'copy & cut & paste'!
   159 
   178 
   160 copySelection
   179 copySelection
   161     "copy the selection into the cut&paste-buffer
   180     "copy the selection into the cut&paste-buffer
   162     "
   181     "
   163     |specs coll|
   182     |specs coll sel|
       
   183 
       
   184     sel := treeView selection.
   164 
   185 
   165     coll := self minSetOfSuperViews:(self selection).
   186     coll := self minSetOfSuperViews:(self selection).
   166 
   187 
   167     coll notNil ifTrue:[
   188     coll notNil ifTrue:[
   168         self select:nil.
   189         self select:nil.
   169         specs := coll collect:[:aView| self fullSpecFor:aView ].
   190         specs := coll collect:[:aView| self fullSpecFor:aView ].
   170         self setSelection:specs
   191         self setSelection:specs.
   171     ].
   192         treeView selection: sel
   172 
   193     ].
   173 
   194 
   174 !
   195 
   175 
   196 !
   176 deleteSelection
   197 
   177     "delete the selection; copy the selection into the cut&paste-buffer
   198 cutSelection
       
   199     "cut the selection into the cut&paste-buffer
   178      and open a transaction
   200      and open a transaction
   179     "
   201     "
   180     |specs coll|
   202     |specs coll|
   181 
   203 
   182     coll := self minSetOfSuperViews:(self selection).
   204     coll := self minSetOfSuperViews:(self selection).
   191                     self createUndoRemove:aView.
   213                     self createUndoRemove:aView.
   192                     self remove:aView
   214                     self remove:aView
   193                 ]
   215                 ]
   194             ].
   216             ].
   195             self setSelection:specs.
   217             self setSelection:specs.
       
   218             treeView selection: (Array with: 1)
       
   219         ]
       
   220     ]
       
   221 !
       
   222 
       
   223 deleteSelection
       
   224     "delete the selection; copy the selection into the cut&paste-buffer
       
   225      and open a transaction
       
   226     "
       
   227     |specs coll|
       
   228 
       
   229     coll := self minSetOfSuperViews:(self selection).
       
   230 
       
   231     coll notNil ifTrue:[
       
   232         treeView cvsEventsDisabledDo:[
       
   233             self select:nil.
       
   234             specs := coll collect:[:aView| self fullSpecFor:aView ].
       
   235 
       
   236             self withinTransaction:#cut objects:coll do:[
       
   237                 coll reverseDo:[:aView|
       
   238                     self remove:aView
       
   239                 ]
       
   240             ].
       
   241             treeView selection: (Array with: 1)
   196         ]
   242         ]
   197     ]
   243     ]
   198 !
   244 !
   199 
   245 
   200 pasteBuffer
   246 pasteBuffer
   320 
   366 
   321 !UIPainterView methodsFor:'drag & drop'!
   367 !UIPainterView methodsFor:'drag & drop'!
   322 
   368 
   323 canDrop:something
   369 canDrop:something
   324     "returns true if something can be droped
   370     "returns true if something can be droped
   325     "
   371     "      
   326     (something size == 1 and:[self enabled and:[self numberOfSelections <= 1]]) ifTrue:[
   372     (something size == 1 and:[self enabled and:[self numberOfSelections <= 1]]) ifTrue:[
   327       ^ something first theObject isKindOf:UISpecification
   373       ^ something first theObject isKindOf:UISpecification
   328     ].
   374     ].
   329     ^ false
   375     ^ false
   330 !
   376 !
   353 
   399 
   354     size == 1 ifTrue:[
   400     size == 1 ifTrue:[
   355         ^ self canPasteInto:(self singleSelection)
   401         ^ self canPasteInto:(self singleSelection)
   356     ].
   402     ].
   357   ^ true
   403   ^ true
   358 
       
   359 !
   404 !
   360 
   405 
   361 canPasteInto:aView
   406 canPasteInto:aView
   362     "can paste into a view
   407     "can paste into a view
   363     "
   408     "
   604     |cls code skip menuSelector protoSpec thisCode|
   649     |cls code skip menuSelector protoSpec thisCode|
   605 
   650 
   606     code := ''.
   651     code := ''.
   607 
   652 
   608     className isNil ifTrue:[
   653     className isNil ifTrue:[
   609         self warn:'set the class first'.
   654         self warn:'Set first the class!!'.
   610         ^ code
   655         ^ code
   611     ].
   656     ].
   612     cls := self resolveName:className.
   657 
       
   658     (cls := self resolveName:className) isNil ifTrue:[
       
   659         self warn:'Class ', className asString, ' does not exist!!'.
       
   660         ^ code
       
   661     ].
   613 
   662 
   614     treeView propertiesDo:[:aProp|
   663     treeView propertiesDo:[:aProp|
   615         |modelSelector menuSelector|
   664         |modelSelector menuSelector|
   616 
   665 
   617         protoSpec := aProp spec.
   666         protoSpec := aProp spec.
   618 
   667 
   619         (modelSelector := aProp model) notNil ifTrue:[
   668         (modelSelector := aProp model) notNil ifTrue:[
   620             (modelSelector isArray not) ifTrue:[
   669             self generateCodeFrom:(Array with:modelSelector) in:cls
   621                 (cls implements:modelSelector asSymbol) ifFalse:[
   670                 do:[:aSel|
   622                     skip := false.
   671                     skip := false.
       
   672 
   623                     (cls isSubclassOf:SimpleDialog) ifTrue:[
   673                     (cls isSubclassOf:SimpleDialog) ifTrue:[
   624                         skip := SimpleDialog implements:modelSelector asSymbol
   674                         skip := SimpleDialog implements:aSel asSymbol
   625                     ].
   675                     ].
       
   676 
   626                     skip ifFalse:[
   677                     skip ifFalse:[
   627                         "/ kludge ..
   678                         "/ kludge ..
   628                         (protoSpec isKindOf:ActionButtonSpec) ifTrue:[
   679                         (protoSpec isKindOf:ActionButtonSpec) ifTrue:[
   629                             thisCode := (self generateActionMethodFor:modelSelector spec:protoSpec inClass:cls).
   680                             thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls).
   630                         ] ifFalse:[
   681                         ] ifFalse:[
   631                             thisCode := (self generateAspectMethodFor:modelSelector spec:protoSpec inClass:cls).
   682                             thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls).
   632                         ].
   683                         ].
   633                         code := code , thisCode
   684                         code := code, thisCode
   634                     ].
   685                     ]
   635                 ].
   686                 ]
   636             ].
   687         ].
   637         ].
   688 
   638 
   689         self generateCodeFrom:(aProp spec aspectSelectors) in:cls
   639         aProp spec aspectSelectors do:[:aSel|
   690                 do:[:aSel|
   640             (aSel isArray not) ifTrue:[
       
   641                 (cls implements:aSel asSymbol) ifFalse:[
       
   642                     thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls).
   691                     thisCode := (self generateAspectMethodFor:aSel spec:protoSpec inClass:cls).
   643                     code := code , thisCode
   692                     code := code , thisCode
   644                 ]
   693                 ].
   645             ]
   694 
   646         ].
   695         self generateCodeFrom:(aProp spec actionSelectors) in:cls
   647         aProp spec actionSelectors do:[:aSel|
   696                 do:[:aSel|
   648             (aSel isArray not) ifTrue:[
       
   649                 (cls implements:aSel asSymbol) ifFalse:[
       
   650                     thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls).
   697                     thisCode := (self generateActionMethodFor:aSel spec:protoSpec inClass:cls).
   651                     code := code , thisCode
   698                     code := code , thisCode
   652                 ]
   699                 ].
   653             ]
   700 
   654         ].
   701         self generateCodeFrom:(aProp spec valueSelectors) in:cls
   655         aProp spec valueSelectors do:[:aSel|
   702                 do:[:aSel|
   656             (aSel isArray not) ifTrue:[
   703                  "/ uppercase: - assume its a globals name.
   657                 "/ uppercase: - assume its a globals name.
   704                     aSel first isUppercase ifFalse:[
   658                 aSel first isUppercase ifFalse:[
       
   659                     (cls implements:aSel asSymbol) ifFalse:[
       
   660                         thisCode := (self generateValueMethodFor:aSel spec:protoSpec inClass:cls).
   705                         thisCode := (self generateValueMethodFor:aSel spec:protoSpec inClass:cls).
   661                         code := code , thisCode
   706                         code := code , thisCode
   662                     ]
   707                     ]
   663                 ]
   708                 ].
       
   709     ].
       
   710 
       
   711     ^ code
       
   712 
       
   713 !
       
   714 
       
   715 generateCodeFrom:aListOfSelectors in:aClass do:aBlock
       
   716 
       
   717     self class redefineMethods ifTrue:[
       
   718         aListOfSelectors do:[:aSelector|
       
   719             (aSelector isArray or:[aClass implements:aSelector]) ifFalse:[
       
   720                 aBlock value:aSelector
   664             ]
   721             ]
   665         ]
   722         ]
   666     ].
   723     ] ifFalse:[
   667 
   724         aListOfSelectors do:[:aSelector|
   668     ^ code
   725             (aSelector isArray or:[aClass canUnderstand:aSelector]) ifFalse:[
       
   726                 aBlock value:aSelector
       
   727             ]
       
   728         ]
       
   729     ]
       
   730 
       
   731 
   669 !
   732 !
   670 
   733 
   671 generateHookMethodFor:selectorSpec comment:commentWhen note:noteOrNil defaultCode:defaultCode inClass:targetClass
   734 generateHookMethodFor:selectorSpec comment:commentWhen note:noteOrNil defaultCode:defaultCode inClass:targetClass
   672     ^ ('!!' , targetClass name , ' methodsFor:''hooks''!!\\' ,
   735     ^ ('!!' , targetClass name , ' methodsFor:''hooks''!!\\' ,
   673       selectorSpec , '\' ,
   736       selectorSpec , '\' ,
   839     className      := 'NewApplication'.
   902     className      := 'NewApplication'.
   840     methodName     := 'windowSpec'.
   903     methodName     := 'windowSpec'.
   841     categoryName   := 'Applications'.
   904     categoryName   := 'Applications'.
   842     HandCursor     := Cursor leftHand.
   905     HandCursor     := Cursor leftHand.
   843 
   906 
       
   907     self backgroundColor: self class defaultViewBackgroundColor
   844 !
   908 !
   845 
   909 
   846 setupFromSpec:specOrSpecArray
   910 setupFromSpec:specOrSpecArray
   847     |spec builder|
   911     |spec builder|
   848 
   912 
  1247     "update current selected view from specification
  1311     "update current selected view from specification
  1248     "
  1312     "
  1249     |props name builder|
  1313     |props name builder|
  1250 
  1314 
  1251     aSpec class == WindowSpec ifTrue:[
  1315     aSpec class == WindowSpec ifTrue:[
  1252         ^ treeView canvasSpec:aSpec
  1316          ^ treeView canvasSpec:aSpec
  1253     ].
  1317     ].
  1254 
  1318 
  1255     self singleSelection notNil ifTrue:[
  1319     self singleSelection notNil ifTrue:[
  1256         self withSelectionHiddenDo:[
  1320         self withSelectionHiddenDo:[
  1257             self transaction:#specification selectionDo:[:aView|
  1321             self transaction:#specification selectionDo:[:aView|