UIPainterTreeView.st
changeset 58 668eb9eae2ac
parent 54 d0b5a33e6df0
child 60 7542ab7fbbfe
equal deleted inserted replaced
57:5af567f52811 58:668eb9eae2ac
    52 !UIPainterTreeView class methodsFor:'defaults'!
    52 !UIPainterTreeView class methodsFor:'defaults'!
    53 
    53 
    54 defaultMenuMessage   
    54 defaultMenuMessage   
    55     "This message is the default yo be sent to the menuHolder to get a menu
    55     "This message is the default yo be sent to the menuHolder to get a menu
    56     "
    56     "
    57     ^ #editMenu
    57     ^ #menu
    58 
    58 
    59 
    59 
    60 ! !
    60 ! !
    61 
    61 
    62 !UIPainterTreeView methodsFor:'accessing'!
    62 !UIPainterTreeView methodsFor:'accessing'!
    68 !
    68 !
    69 
    69 
    70 indexOf:aString
    70 indexOf:aString
    71     "returns the index of the string entry into my list
    71     "returns the index of the string entry into my list
    72     "
    72     "
    73     ^ list findFirst:[:aName| aName withoutSeparators = aString ]
    73     ^ list findFirst:[:aName| aName string withoutSeparators = aString ]
    74 
    74 
    75 
    75 
    76 ! !
    76 ! !
    77 
    77 
    78 !UIPainterTreeView methodsFor:'event handling'!
    78 !UIPainterTreeView methodsFor:'event handling'!
    82     "
    82     "
    83     |sel|
    83     |sel|
    84 
    84 
    85     selection notNil ifTrue:[
    85     selection notNil ifTrue:[
    86         selection size == 1 ifTrue:[
    86         selection size == 1 ifTrue:[
    87             sel := (list at:(selection first)) withoutSeparators
    87             sel := (list at:(selection first)) string withoutSeparators
    88         ] ifFalse:[
    88         ] ifFalse:[
    89             sel := OrderedCollection new.
    89             sel := OrderedCollection new.
    90             selection do:[:aNumber|
    90             selection do:[:aNumber|
    91                 aNumber ~~ 1 ifTrue:[
    91                 aNumber ~~ 1 ifTrue:[
    92                     sel add:((list at:aNumber) withoutSeparators)
    92                     sel add:((list at:aNumber) string withoutSeparators)
    93                 ]
    93                 ]
    94             ]
    94             ]
    95         ]
    95         ]
    96     ].
    96     ].
    97     builderView selectNames:sel
    97     builderView selectNames:sel
    98 
    98 
    99 !
    99 !
   100 
   100 
       
   101 selectionChangedFrom:oldSelection
       
   102     "redraw master
       
   103     "
       
   104     self disableMaster:oldSelection.
       
   105     super selectionChangedFrom:oldSelection
       
   106 
       
   107 !
       
   108 
   101 update:something
   109 update:something
   102 
   110 
   103     (something == #tree or:[something == #widgetName]) ifTrue:[
   111     (something == #tree or:[something == #widgetName]) ifTrue:[
   104         self updateTree
   112         self updateTree
   105     ] ifFalse:[
   113     ] ifFalse:[
   106         something == #selection ifFalse:[
   114         something ~~ #selection ifTrue:[
   107             ^ self
   115             ^ self
   108         ].
   116         ].
       
   117         self disableMaster:selection.
   109         self setSelection:nil.
   118         self setSelection:nil.
   110     ].
   119     ].
   111 
   120 
   112     "update selection
   121     "update selection
   113     "
   122     "
   114     builderView selectionDo:[:aView||idx|
   123     builderView selectionDo:[:aView||idx|
   115         idx := self indexOf:(builderView variableNameOf:aView).
   124         idx := self indexOf:(builderView variableNameOf:aView).
   116 
   125 
   117         idx ~~ 0 ifTrue:[
   126         idx ~~ 0 ifTrue:[
       
   127             selection isNil ifTrue:[
       
   128                 |m i|
       
   129 
       
   130                 m := list at:idx.
       
   131                 i := m indexOfNonSeparatorStartingAt:1.
       
   132                 i == 0 ifTrue:[ i := 1 ].
       
   133                 m := Text string:m.
       
   134                 m emphasizeFrom:i with:#(#bold #underline).
       
   135                 list at:idx put:m
       
   136             ].
   118             self addToSelection:idx
   137             self addToSelection:idx
   119         ]
   138         ]
   120     ].
   139     ].
   121     selection isNil ifTrue:[
   140     selection isNil ifTrue:[
   122         self setSelection:1
   141         self setSelection:1
   136 
   155 
   137 ! !
   156 ! !
   138 
   157 
   139 !UIPainterTreeView methodsFor:'menu & actions'!
   158 !UIPainterTreeView methodsFor:'menu & actions'!
   140 
   159 
   141 editMenu
   160 inspectProps
       
   161     builderView inspectAttributes
       
   162 !
       
   163 
       
   164 inspectSpec
       
   165     builderView inspectSpec
       
   166 !
       
   167 
       
   168 inspectView
       
   169     builderView inspectSelection
       
   170 !
       
   171 
       
   172 menu
       
   173     |menu noSel|
       
   174 
       
   175     noSel := builderView numberOfSelections.
       
   176 
       
   177     menu := PopUpMenu labels:(
       
   178               resources array:#(
       
   179                                 'cut'
       
   180                                 'undo'
       
   181                                 '-'
       
   182                                 'misc'
       
   183                                )
       
   184                              )
       
   185                   selectors:#(
       
   186                                 #cut
       
   187                                 #undo
       
   188                                 nil
       
   189                                 #misc
       
   190                              )
       
   191                     receiver:self.
       
   192 
       
   193     noSel == 1 ifTrue:[ menu subMenuAt:#misc put:(self menuMisc)]
       
   194               ifFalse:[ menu disable:#misc].
       
   195 
       
   196     noSel == 0 ifTrue:[ menu disable:#cut]
       
   197               ifFalse:[ menu actionAt:#cut put:[builderView deleteSelection]].
       
   198 
       
   199     builderView hasUndos ifFalse:[ menu disable:#undo]
       
   200                           ifTrue:[ menu actionAt:#undo put:[builderView undoLast]].
       
   201 
       
   202 
       
   203 
       
   204   ^ menu
       
   205 
       
   206 
       
   207 !
       
   208 
       
   209 menuMisc
       
   210 
   142     |menu ispMenu|
   211     |menu ispMenu|
   143 
   212 
   144     menu := PopUpMenu labels:( resources array:#('inspect') )
   213     menu := PopUpMenu labels:( resources array:#('inspect' 'ordering' 'remove layout' ) )
   145                    selectors:#( #inspect  )
   214                    selectors:#( #inspect #ordering #removeLayout )
   146                     receiver:self.
   215                     receiver:self.
   147 
   216 
   148     ispMenu := PopUpMenu labels:( resources array:#('view' 'property') )
   217     ispMenu := PopUpMenu labels:( resources array:#('view' 'spec' 'property') )
   149                       selectors:#( #inspectView  #inspectProps  )
   218                       selectors:#( #inspectView  #inspectSpec #inspectProps  )
   150                        receiver:self.
   219                        receiver:self.
   151 
   220 
   152     menu subMenuAt:#inspect put:ispMenu.
   221     menu subMenuAt:#inspect put:ispMenu.
   153   ^ menu
   222   ^ menu
   154 
   223 
   155 
   224 
   156 !
   225 !
   157 
   226 
   158 inspectProps
   227 ordering
   159     builderView inspectAttributes
   228     "change selected view to an index in its subview subviews collection
   160 !
   229     "
   161 
   230     |myIdx view spView index names values|
   162 inspectView
   231 
   163     builderView inspectSelection
   232     view := builderView singleSelection.
       
   233     view isNil ifTrue:[^ self].
       
   234 
       
   235     spView := view superView.
       
   236     names  := OrderedCollection new.
       
   237     values := OrderedCollection new.
       
   238     index  := 1.
       
   239 
       
   240     spView allSubViewsDo:[:aView||props|
       
   241         aView ~~ view ifTrue:[
       
   242             props := builderView propertyOfView:aView.
       
   243 
       
   244             props notNil ifTrue:[
       
   245                 names  add:(props name).
       
   246                 values add:index
       
   247             ]
       
   248         ] ifFalse:[
       
   249             myIdx := index
       
   250         ].
       
   251         index := index + 1
       
   252     ].
       
   253 
       
   254     names isEmpty ifTrue:[
       
   255         ^ self
       
   256     ].
       
   257 
       
   258     index := Dialog choose:'before name:' 
       
   259                   fromList:names
       
   260                     values:values
       
   261                      lines:20
       
   262                     cancel:[nil].
       
   263 
       
   264     index isNil ifTrue:[
       
   265         ^ self
       
   266     ].
       
   267     myIdx < index ifTrue:[
       
   268         index := index - 1
       
   269     ].
       
   270     (spView changeSequenceOrderFor:view to:index) ifTrue:[
       
   271         self update:#tree
       
   272     ]
       
   273 !
       
   274 
       
   275 removeLayout
       
   276     builderView selectionHiddenDo:[
       
   277         builderView selectionDo:[:aView|
       
   278             aView geometryLayout:nil.
       
   279             aView superView sizeChanged:nil
       
   280         ]
       
   281     ].
       
   282 ! !
       
   283 
       
   284 !UIPainterTreeView methodsFor:'redrawing'!
       
   285 
       
   286 disableMaster:aLineNrOrCollection
       
   287     "find and redraw line from master as no master
       
   288     "
       
   289     |line|
       
   290 
       
   291     aLineNrOrCollection notNil ifTrue:[
       
   292         aLineNrOrCollection isCollection ifFalse:[
       
   293             (line := list at:aLineNrOrCollection) isText ifTrue:[
       
   294                 list at:aLineNrOrCollection put:(line string).
       
   295                 self redrawLine:aLineNrOrCollection.
       
   296             ]
       
   297         ] ifTrue:[
       
   298             aLineNrOrCollection do:[:aNumber|
       
   299                 (line := list at:aNumber) isText ifTrue:[
       
   300                     list at:aNumber put:(line string).
       
   301                   ^ self redrawLine:aNumber.
       
   302                 ]
       
   303             ]
       
   304         ]
       
   305     ]
   164 ! !
   306 ! !
   165 
   307 
   166 !UIPainterTreeView methodsFor:'update'!
   308 !UIPainterTreeView methodsFor:'update'!
   167 
   309 
   168 updateSubTree:aView indent:anIndent
   310 updateSubTree:aView indent:anIndent