UIPainterTreeView.st
changeset 110 a00f1446c10b
parent 78 a0a00603a8b6
equal deleted inserted replaced
109:0b53bd128667 110:a00f1446c10b
     1 "
     1 "
     2  COPYRIGHT (c) 1995 by Claus Gittinger
     2  COPYRIGHT (c) 1995 by Claus Gittinger
     3 	      All Rights Reserved
     3               All Rights Reserved
     4 
     4 
     5  This software is furnished under a license and may be used
     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
     6  only in accordance with the terms of that license and with the
     7  inclusion of the above copyright notice.   This software may not
     7  inclusion of the above copyright notice.   This software may not
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 SelectionInListView subclass:#UIPainterTreeView
    13 
    14 	instanceVariableNames:'builderView'
    14 
       
    15 ApplicationModel subclass:#UIPainterTreeView
       
    16 	instanceVariableNames:'listHolder'
    15 	classVariableNames:''
    17 	classVariableNames:''
    16 	poolDictionaries:''
    18 	poolDictionaries:''
    17 	category:'Interface-UIPainter'
    19 	category:'Interface-UIPainter'
    18 !
    20 !
    19 
    21 
    20 !UIPainterTreeView class methodsFor:'documentation'!
    22 !UIPainterTreeView class methodsFor:'documentation'!
    21 
    23 
    22 copyright
    24 copyright
    23 "
    25 "
    24  COPYRIGHT (c) 1995 by Claus Gittinger
    26  COPYRIGHT (c) 1995 by Claus Gittinger
    25 	      All Rights Reserved
    27               All Rights Reserved
    26 
    28 
    27  This software is furnished under a license and may be used
    29  This software is furnished under a license and may be used
    28  only in accordance with the terms of that license and with the
    30  only in accordance with the terms of that license and with the
    29  inclusion of the above copyright notice.   This software may not
    31  inclusion of the above copyright notice.   This software may not
    30  be provided or otherwise made available to, or used by, any
    32  be provided or otherwise made available to, or used by, any
    31  other person.  No title to or ownership of the software is
    33  other person.  No title to or ownership of the software is
    32  hereby transferred.
    34  hereby transferred.
    33 "
    35 "
       
    36 
       
    37 
    34 !
    38 !
    35 
    39 
    36 documentation
    40 documentation
    37 "
    41 "
    38     not yet finished, not yet published, not yet released.
    42     not yet finished, not yet published, not yet released.
    39 "
    43 "
    40 ! !
       
    41 
       
    42 !UIPainterTreeView class methodsFor:'constants'!
       
    43 
       
    44 indent
       
    45     "indent for contained element
       
    46     "
       
    47     ^ 2
       
    48 
       
    49 
    44 
    50 ! !
    45 ! !
    51 
    46 
    52 !UIPainterTreeView class methodsFor:'defaults'!
    47 !UIPainterTreeView class methodsFor:'instance creation'!
    53 
    48 
    54 defaultMenuMessage   
    49 listHolder:aListHolder
    55     "This message is the default yo be sent to the menuHolder to get a menu
    50      |appl|
    56     "
       
    57     ^ #menu
       
    58 
    51 
       
    52      appl := UIPainterTreeView new.
       
    53      appl listHolder:aListHolder.
       
    54      appl openInterface:#windowSpec.
       
    55    ^ appl
    59 
    56 
    60 ! !
    57 ! !
    61 
    58 
    62 !UIPainterTreeView methodsFor:'accessing'!
    59 !UIPainterTreeView class methodsFor:'interface specs'!
    63 
    60 
    64 builderView:aBuilderView
    61 windowSpec
    65     builderView := aBuilderView.
    62     "this window spec was automatically generated by the ST/X UIPainter"
    66     self updateTree.
    63 
       
    64     "do not manually edit this - the painter/builder may not be able to
       
    65      handle the specification if its corrupted."
       
    66 
       
    67     "
       
    68      UIPainter new openOnClass:UIPainterTreeView andSelector:#windowSpec
       
    69      UIPainterTreeView new openInterface:#windowSpec
       
    70     "
       
    71 
       
    72     <resource: #canvas>
       
    73 
       
    74     ^
       
    75      
       
    76        #(#FullSpec
       
    77           #'window:' 
       
    78            #(#WindowSpec
       
    79               #'name:' 'treeView'
       
    80               #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
       
    81               #'label:' 'Tree-View'
       
    82               #'bounds:' #(#Rectangle 0 0 192 479)
       
    83           )
       
    84           #'component:' 
       
    85            #(#SpecCollection
       
    86               #'collection:' 
       
    87                #(
       
    88                  #(#SequenceViewSpec
       
    89                     #'name:' 'selectionInList'
       
    90                     #'layout:' #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
       
    91                     #'menu:' #listMenu
       
    92                     #'model:' #listHolder
       
    93                     #'callbacksSpec:' 
       
    94                      #(#UIEventCallbackSubSpec
       
    95                         #'doubleClickSelector:' #doubleClick
       
    96                     )
       
    97                     #'hasHorizontalScrollBar:' true
       
    98                     #'hasVerticalScrollBar:' true
       
    99                     #'miniScrollerHorizontal:' false
       
   100                     #'miniScrollerVertical:' false
       
   101                     #'isMultiSelect:' true
       
   102                 )
       
   103               )
       
   104           )
       
   105       )
       
   106 ! !
       
   107 
       
   108 !UIPainterTreeView methodsFor:'aspects'!
       
   109 
       
   110 doubleClick
       
   111     listHolder selectGroup
       
   112 !
       
   113 
       
   114 listHolder
       
   115     ^ listHolder
    67 
   116 
    68 !
   117 !
    69 
   118 
    70 indexOf:aString
   119 listHolder:aListHolder
    71     "returns the index of the string entry into my list
   120     listHolder := aListHolder
    72     "
       
    73     ^ list findFirst:[:aName| aName string withoutSeparators = aString ]
       
    74 
       
    75 
       
    76 ! !
       
    77 
       
    78 !UIPainterTreeView methodsFor:'event handling'!
       
    79 
       
    80 builderViewChanged:what
       
    81     "something changed in the builder view
       
    82     "
       
    83     (what == #tree or:[what == #widgetName]) ifTrue:[
       
    84         self updateTree
       
    85     ] ifFalse:[
       
    86         what ~~ #selection ifTrue:[
       
    87             ^ self
       
    88         ].
       
    89         self disableMaster:selection.
       
    90         self setSelection:nil.
       
    91     ].
       
    92 
       
    93     "update selection
       
    94     "
       
    95     builderView selectionDo:[:aView||idx|
       
    96         idx := self indexOf:(builderView uniqueNameOf:aView).
       
    97 
       
    98         idx ~~ 0 ifTrue:[
       
    99             selection isNil ifTrue:[
       
   100                 |m i|
       
   101 
       
   102                 m := list at:idx.
       
   103                 i := m indexOfNonSeparatorStartingAt:1.
       
   104                 i == 0 ifTrue:[ i := 1 ].
       
   105                 m := Text string:m.
       
   106                 m emphasizeFrom:i with:#(#bold #underline).
       
   107                 list at:idx put:m
       
   108             ].
       
   109             self addToSelection:idx
       
   110         ]
       
   111     ].
       
   112     selection isNil ifTrue:[
       
   113         self setSelection:1
       
   114     ]
       
   115 !
   121 !
   116 
   122 
   117 selectionChanged
   123 listMenu
   118     "selection has changed
   124     "returns a block which returns the menu
   119     "
   125     "
   120     |sel|
   126     ^ [listHolder painter menu]
   121 
       
   122     selection notNil ifTrue:[
       
   123         selection size == 1 ifTrue:[
       
   124             sel := (list at:(selection first)) string withoutSeparators
       
   125         ] ifFalse:[
       
   126             sel := OrderedCollection new.
       
   127             selection do:[:aNumber|
       
   128                 aNumber ~~ 1 ifTrue:[
       
   129                     sel add:((list at:aNumber) string withoutSeparators)
       
   130                 ]
       
   131             ]
       
   132         ]
       
   133     ].
       
   134     builderView selectNames:sel
       
   135 
       
   136 !
       
   137 
       
   138 selectionChangedFrom:oldSelection
       
   139     "redraw master
       
   140     "
       
   141     oldSelection ~= selection ifTrue:[
       
   142         self disableMaster:oldSelection.
       
   143         super selectionChangedFrom:oldSelection
       
   144     ]
       
   145 ! !
       
   146 
       
   147 !UIPainterTreeView methodsFor:'initialization'!
       
   148 
       
   149 initialize
       
   150     super initialize.
       
   151 
       
   152     list := OrderedCollection new.
       
   153 
       
   154     self multipleSelectOk:true.
       
   155     self action:[:aSelection| self selectionChanged ].
       
   156     self doubleClickAction:[:aSelection| builderView selectSubComponents].
       
   157 ! !
       
   158 
       
   159 !UIPainterTreeView methodsFor:'menu & actions'!
       
   160 
       
   161 inspectProps
       
   162     |view|
       
   163 
       
   164     (view := builderView singleSelection) notNil ifTrue:[
       
   165         (builderView propertyOfView:view) inspect
       
   166     ]
       
   167 !
       
   168 
       
   169 inspectSpec
       
   170     |view|
       
   171 
       
   172     (view := builderView singleSelection) notNil ifTrue:[
       
   173         (builderView fullSpecFor:view) inspect
       
   174     ]
       
   175 !
       
   176 
       
   177 inspectView
       
   178     |view|
       
   179 
       
   180     (view := builderView singleSelection) notNil ifTrue:[
       
   181         view inspect
       
   182     ]
       
   183 !
       
   184 
       
   185 menu
       
   186     |menu|
       
   187 
       
   188     (menu := builderView menu) notNil ifTrue:[
       
   189         menu addLabels:(
       
   190             resources array:#(
       
   191                                 '-'
       
   192                                 'misc'
       
   193                             )
       
   194                         )
       
   195              selectors:#(       
       
   196                                 nil
       
   197                                 #treeMisc
       
   198                         ).
       
   199 
       
   200         (builderView numberOfSelections) == 1 ifTrue:[
       
   201             menu subMenuAt:#treeMisc put:(self menuMisc)
       
   202         ] ifFalse:[
       
   203             menu disable:#treeMisc
       
   204         ]
       
   205     ].
       
   206     ^ menu
       
   207 !
       
   208 
       
   209 menuMisc
       
   210 
       
   211     |menu ispMenu|
       
   212 
       
   213     menu := PopUpMenu labels:( resources array:#('inspect' 'ordering' ) )
       
   214                    selectors:#( #inspect #ordering )
       
   215                     receiver:self.
       
   216 
       
   217     ispMenu := PopUpMenu labels:( resources array:#('view' 'spec' 'property') )
       
   218                       selectors:#( #inspectView  #inspectSpec #inspectProps  )
       
   219                        receiver:self.
       
   220 
       
   221     menu subMenuAt:#inspect put:ispMenu.
       
   222   ^ menu
       
   223 
       
   224 
       
   225 !
       
   226 
       
   227 ordering
       
   228     "change selected view to an index in its subview subviews collection
       
   229     "
       
   230     |myIdx view spView index names values|
       
   231 
       
   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 subViews do:[: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 builderViewChanged:#tree
       
   272     ]
       
   273 ! !
       
   274 
       
   275 !UIPainterTreeView methodsFor:'redrawing'!
       
   276 
       
   277 disableMaster:aLineNrOrCollection
       
   278     "find and redraw line from master as no master
       
   279     "
       
   280     |line|
       
   281 
       
   282     aLineNrOrCollection notNil ifTrue:[
       
   283         aLineNrOrCollection isCollection ifFalse:[
       
   284             (line := list at:aLineNrOrCollection) isText ifTrue:[
       
   285                 list at:aLineNrOrCollection put:(line string).
       
   286                 self redrawLine:aLineNrOrCollection.
       
   287             ]
       
   288         ] ifTrue:[
       
   289             aLineNrOrCollection do:[:aNumber|
       
   290                 (line := list at:aNumber) isText ifTrue:[
       
   291                     list at:aNumber put:(line string).
       
   292                   ^ self redrawLine:aNumber.
       
   293                 ]
       
   294             ]
       
   295         ]
       
   296     ]
       
   297 ! !
       
   298 
       
   299 !UIPainterTreeView methodsFor:'update'!
       
   300 
       
   301 updateSubTree:aView indent:anIndent
       
   302     |name indent|
       
   303 
       
   304     name := builderView uniqueNameOf:aView.
       
   305 
       
   306     anIndent ~~ 0 ifTrue:[
       
   307         name := (String new:anIndent), name
       
   308     ].
       
   309     list add:name.
       
   310 
       
   311     indent := anIndent + self class indent.
       
   312 
       
   313     builderView subviewsOf:aView do:[:subview|
       
   314         self updateSubTree:subview indent:indent
       
   315     ]
       
   316 
       
   317 
       
   318 !
       
   319 
       
   320 updateTree
       
   321 
       
   322     selection := nil.
       
   323     list      := OrderedCollection new.
       
   324     self updateSubTree:builderView indent:0.
       
   325     super list:list.
       
   326 
       
   327 ! !
   127 ! !
   328 
   128 
   329 !UIPainterTreeView class methodsFor:'documentation'!
   129 !UIPainterTreeView class methodsFor:'documentation'!
   330 
   130 
   331 version
   131 version
   332     ^ '$Header$'
   132     ^ '$Header$'
       
   133 
   333 ! !
   134 ! !