#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Wed, 16 Aug 2017 13:52:20 +0200
changeset 34564d4297bad4fa
parent 3455 4ba13182f80f
child 3457 3f3ea99e8af5
#FEATURE by cg
class: Tools::ViewTreeInspectorApplication
also show menus

added:
#selectedMenuItem
#submenuMenuItemInterface:
comment/format in: #selectionChanged
changed:
#doRedraw
#middleButtonMenu
#updateShownStatus

class: Tools::ViewTreeInspectorApplication class
added: #middleButtonMenuForMenuItems

class: Tools::ViewTreeInspectorApplication::ViewTreeItem
class definition
added:
#forMenuItem:
#menuItem
#parent:
comment/format in:
#icon
#specClass
changed:
#displayOn:x:y:h:isHighlightedAsSelected:
#exists
#handlesDo:
#hasChildren
#string

class: Tools::ViewTreeInspectorApplication::ViewTreeItem class
added:
#buildMenuItemsFrom:
#forMenuItem:
comment/format in: #forView:
changed: #buildViewsFrom:

class: Tools::ViewTreeInspectorApplication::ViewTreeModel
changed: #path

class: Tools::ViewTreeInspectorApplication::ViewTreeModel::ItemList
changed: #additionalLabelForItem:
Tools__ViewTreeApplication.st
     1.1 --- a/Tools__ViewTreeApplication.st	Wed Aug 16 12:31:30 2017 +0200
     1.2 +++ b/Tools__ViewTreeApplication.st	Wed Aug 16 13:52:20 2017 +0200
     1.3 @@ -31,7 +31,7 @@
     1.4  !
     1.5  
     1.6  HierarchicalItem subclass:#ViewTreeItem
     1.7 -	instanceVariableNames:'widget isDrawnShown exists xOffsetAdditionalName'
     1.8 +	instanceVariableNames:'widget menuItem isDrawnShown exists xOffsetAdditionalName'
     1.9  	classVariableNames:'HandleExtent'
    1.10  	poolDictionaries:''
    1.11  	privateIn:ViewTreeInspectorApplication
    1.12 @@ -751,6 +751,53 @@
    1.13        )
    1.14  !
    1.15  
    1.16 +middleButtonMenuForMenuItems
    1.17 +    "This resource specification was automatically generated
    1.18 +     by the MenuEditor of ST/X."
    1.19 +
    1.20 +    "Do not manually edit this!! If it is corrupted,
    1.21 +     the MenuEditor may not be able to read the specification."
    1.22 +
    1.23 +
    1.24 +    "
    1.25 +     MenuEditor new openOnClass:Tools::ViewTreeInspectorApplication andSelector:#middleButtonMenu
    1.26 +     (Menu new fromLiteralArrayEncoding:(Tools::ViewTreeInspectorApplication middleButtonMenu)) startUp
    1.27 +    "
    1.28 +
    1.29 +    <resource: #menu>
    1.30 +
    1.31 +    ^ 
    1.32 +     #(Menu
    1.33 +        (
    1.34 +         (MenuItem
    1.35 +            label: 'Browse Menu Item''s Class'
    1.36 +            itemValue: doBrowseMenuItem:
    1.37 +            argument: view
    1.38 +          )
    1.39 +         (MenuItem
    1.40 +            label: '-'
    1.41 +          )
    1.42 +         (MenuItem
    1.43 +            label: 'Inspect Menu Item'
    1.44 +            itemValue: doInspectMenuItem:
    1.45 +            argument: view
    1.46 +          )
    1.47 +         (MenuItem
    1.48 +            label: '-'
    1.49 +          )
    1.50 +         (MenuItem
    1.51 +            label: 'Interface'
    1.52 +            submenuChannel: submenuMenuItemInterface:
    1.53 +            keepLinkedMenu: true
    1.54 +          )
    1.55 +         )
    1.56 +        nil
    1.57 +        nil
    1.58 +      )
    1.59 +
    1.60 +    "Created: / 16-08-2017 / 13:48:49 / cg"
    1.61 +!
    1.62 +
    1.63  toolbarMenu
    1.64      "This resource specification was automatically generated
    1.65       by the MenuEditor of ST/X."
    1.66 @@ -1110,25 +1157,29 @@
    1.67          |state|
    1.68  
    1.69          view := item widget.
    1.70 -
    1.71 -        view id isNil ifTrue:[
    1.72 -            state := 'no ID'.
    1.73 -        ] ifFalse:[
    1.74 -            view shown ifTrue:[
    1.75 -                state := 'visible'.
    1.76 +        view isNil ifTrue:[
    1.77 +            info := '%1 [%2]' bindWith:(item menuItem label asString)
    1.78 +                                  with:(item menuItem value asString).
    1.79 +        ] ifFalse:[    
    1.80 +            view id isNil ifTrue:[
    1.81 +                state := 'no ID'.
    1.82              ] ifFalse:[
    1.83 -                state := 'invisible'
    1.84 +                view shown ifTrue:[
    1.85 +                    state := 'visible'.
    1.86 +                ] ifFalse:[
    1.87 +                    state := 'invisible'
    1.88 +                ].
    1.89              ].
    1.90 -        ].
    1.91 -        info := '%1 [%2] - %3' bindWith:(view class name)
    1.92 -                                   with:(view name ? '') with:state allBold.
    1.93 +            info := '%1 [%2] - %3' bindWith:(view class name)
    1.94 +                                       with:(view name ? '') with:state allBold.
    1.95 +        ]
    1.96      ] ifFalse:[
    1.97          info := ''
    1.98      ].
    1.99      hasSingleSelectionHolder value:(view notNil).
   1.100      self updateInspector
   1.101  
   1.102 -    "Modified: / 30-07-2013 / 09:21:27 / cg"
   1.103 +    "Modified: / 16-08-2017 / 13:44:59 / cg"
   1.104  !
   1.105  
   1.106  update:something with:someArgument from:aModel
   1.107 @@ -1502,10 +1553,18 @@
   1.108      "returns the middleButton menu for the single selected item or nil"
   1.109  
   1.110      ^ [ 
   1.111 -        model selectedItem notNil 
   1.112 -            ifTrue:[self class middleButtonMenu]
   1.113 -            ifFalse:[nil]
   1.114 +        model selectedItem notNil ifTrue:[
   1.115 +            model selectedItem isView ifTrue:[
   1.116 +                self class middleButtonMenu
   1.117 +            ] ifFalse:[
   1.118 +                self class middleButtonMenuForMenuItems
   1.119 +            ].    
   1.120 +        ] ifFalse:[
   1.121 +            nil
   1.122 +        ]
   1.123        ]
   1.124 +
   1.125 +    "Modified: / 16-08-2017 / 13:48:31 / cg"
   1.126  !
   1.127  
   1.128  submenuApplications:aMenu
   1.129 @@ -1817,6 +1876,23 @@
   1.130      "Modified: / 31-07-2013 / 13:09:55 / cg"
   1.131  !
   1.132  
   1.133 +submenuMenuItemInterface:aMenu
   1.134 +    "builds and returns the menuItem interface submenu"
   1.135 +
   1.136 +    |item list|
   1.137 +
   1.138 +    item := self selectedMenuItem.
   1.139 +    item isNil ifTrue:[^ nil].
   1.140 +
   1.141 +    list := OrderedCollection new.
   1.142 +
   1.143 +    list add:(MenuDesc title:'itemValue'  value:(item itemValue)).
   1.144 +
   1.145 +    ^ MenuDesc buildFromList:list onGC:aMenu
   1.146 +
   1.147 +    "Created: / 16-08-2017 / 13:51:05 / cg"
   1.148 +!
   1.149 +
   1.150  submenuVisibility:aMenu
   1.151      "builds and returns the geometry submenu"
   1.152  
   1.153 @@ -1955,15 +2031,17 @@
   1.154      min := 9999999.
   1.155  
   1.156      rootItem recursiveEachVisibleItemDo:[:anItem|
   1.157 -        visState := (anItem widget shown).
   1.158 -
   1.159 -        visState ~~ anItem isDrawnShown ifTrue:[
   1.160 -            anItem isDrawnShown:visState.
   1.161 -            listIdx := treeView identityIndexOf:anItem.
   1.162 -
   1.163 -            listIdx > 0 ifTrue:[    
   1.164 -                max := max max:listIdx.
   1.165 -                min := min min:listIdx.
   1.166 +        anItem widget notNil ifTrue:[
   1.167 +            visState := (anItem widget shown).
   1.168 +
   1.169 +            visState ~~ anItem isDrawnShown ifTrue:[
   1.170 +                anItem isDrawnShown:visState.
   1.171 +                listIdx := treeView identityIndexOf:anItem.
   1.172 +
   1.173 +                listIdx > 0 ifTrue:[    
   1.174 +                    max := max max:listIdx.
   1.175 +                    min := min min:listIdx.
   1.176 +                ].
   1.177              ].
   1.178          ].
   1.179      ].
   1.180 @@ -1980,10 +2058,24 @@
   1.181              treeView invalidateDeviceRectangle:damage repairNow:false.
   1.182          ].
   1.183      ].
   1.184 +
   1.185 +    "Modified: / 16-08-2017 / 12:29:15 / cg"
   1.186  ! !
   1.187  
   1.188  !ViewTreeInspectorApplication methodsFor:'selection'!
   1.189  
   1.190 +selectedMenuItem
   1.191 +    "answer the selected menuItem or nil"
   1.192 +
   1.193 +    |item|
   1.194 +
   1.195 +    item := model selectedItem.
   1.196 +    item notNil ifTrue:[ ^ item menuItem ].
   1.197 +    ^ nil
   1.198 +
   1.199 +    "Created: / 16-08-2017 / 13:50:35 / cg"
   1.200 +!
   1.201 +
   1.202  selectedView
   1.203      "answer the selected view or nil"
   1.204  
   1.205 @@ -2163,9 +2255,13 @@
   1.206  doRedraw
   1.207      "redraw the app"
   1.208  
   1.209 -    model rootView notNil ifTrue:[
   1.210 -        model rootView withAllSubViewsDo:[:v | v "redraw; "invalidate].
   1.211 +    |rootView|
   1.212 +    
   1.213 +    (rootView := model rootView) notNil ifTrue:[
   1.214 +        rootView withAllSubViewsDo:[:v | v "redraw; "invalidate].
   1.215      ]
   1.216 +
   1.217 +    "Modified: / 16-08-2017 / 12:02:11 / cg"
   1.218  !
   1.219  
   1.220  doSelectNextElementStartingIn:anItem forWhich:aBlock
   1.221 @@ -2359,9 +2455,30 @@
   1.222  
   1.223  !ViewTreeInspectorApplication::ViewTreeItem class methodsFor:'building'!
   1.224  
   1.225 +buildMenuItemsFrom:aMenuItem
   1.226 +    "build the items starting from a source menu item;
   1.227 +     returns the anchor.
   1.228 +    "
   1.229 +    |item subMenu subItems|
   1.230 +
   1.231 +    aMenuItem isNil ifTrue:[^ nil].
   1.232 +
   1.233 +    item     := self forMenuItem:aMenuItem.
   1.234 +    subItems := OrderedCollection new.
   1.235 +    (subMenu := aMenuItem submenuOrNil) notNil ifTrue:[
   1.236 +        subMenu items do:[:eachMenuItem |
   1.237 +            subItems add:(self buildMenuItemsFrom:eachMenuItem)
   1.238 +        ].    
   1.239 +    ].
   1.240 +    item children:subItems.
   1.241 +    ^ item
   1.242 +
   1.243 +    "Created: / 16-08-2017 / 12:23:02 / cg"
   1.244 +!
   1.245 +
   1.246  buildViewsFrom:aView
   1.247      "build the items starting from a source view;
   1.248 -     returns the anhor.
   1.249 +     returns the anchor.
   1.250      "
   1.251      |item subViews subItems|
   1.252  
   1.253 @@ -2369,15 +2486,24 @@
   1.254  
   1.255      item     := self forView:aView.
   1.256      subViews := aView subViews.
   1.257 +    subItems := OrderedCollection new.
   1.258  
   1.259      subViews notEmptyOrNil ifTrue:[
   1.260 -        subItems := OrderedCollection new.
   1.261          subViews do:[:aSubView|
   1.262              subItems add:(self buildViewsFrom:aSubView).
   1.263          ].
   1.264 -        item children:subItems.
   1.265      ].
   1.266 +
   1.267 +    (aView isKindOf:MenuPanel) ifTrue:[
   1.268 +        (aView items ? #()) do:[:eachMenuItem |
   1.269 +            subItems add:(self buildMenuItemsFrom:eachMenuItem)
   1.270 +        ].    
   1.271 +    ].    
   1.272 +    item children:subItems.
   1.273 +    
   1.274      ^ item
   1.275 +
   1.276 +    "Modified: / 16-08-2017 / 12:43:35 / cg"
   1.277  ! !
   1.278  
   1.279  !ViewTreeInspectorApplication::ViewTreeItem class methodsFor:'documentation'!
   1.280 @@ -2418,12 +2544,24 @@
   1.281  
   1.282  !ViewTreeInspectorApplication::ViewTreeItem class methodsFor:'instance creation'!
   1.283  
   1.284 +forMenuItem:aMenuItem
   1.285 +    |item|
   1.286 +
   1.287 +    item := self basicNew initialize.
   1.288 +    item forMenuItem:aMenuItem.
   1.289 +    ^ item
   1.290 +
   1.291 +    "Created: / 16-08-2017 / 12:07:55 / cg"
   1.292 +!
   1.293 +
   1.294  forView:aView
   1.295      |item|
   1.296  
   1.297      item := self basicNew initialize.
   1.298      item forView:aView.
   1.299 -  ^ item
   1.300 +    ^ item
   1.301 +
   1.302 +    "Modified (format): / 16-08-2017 / 12:07:40 / cg"
   1.303  !
   1.304  
   1.305  new
   1.306 @@ -2461,6 +2599,16 @@
   1.307      isDrawnShown := aBoolean.
   1.308  !
   1.309  
   1.310 +menuItem
   1.311 +    ^ menuItem
   1.312 +!
   1.313 +
   1.314 +parent:aParent
   1.315 +    super parent:aParent.
   1.316 +
   1.317 +    "Created: / 16-08-2017 / 12:40:26 / cg"
   1.318 +!
   1.319 +
   1.320  rootView
   1.321      "returns the widget assigned to the root or nil
   1.322      "
   1.323 @@ -2472,7 +2620,12 @@
   1.324  specClass
   1.325      "returns the spec-class assigned to the item
   1.326      "
   1.327 +    widget isNil ifTrue:[
   1.328 +        ^ MenuPanelSpec 
   1.329 +    ].
   1.330      ^ widget specClass
   1.331 +
   1.332 +    "Modified (format): / 16-08-2017 / 12:31:36 / cg"
   1.333  !
   1.334  
   1.335  treeModel
   1.336 @@ -2555,25 +2708,41 @@
   1.337  !
   1.338  
   1.339  hasChildren
   1.340 -    |subViews list item|
   1.341 -
   1.342 -    children size ~~ 0 ifTrue:[
   1.343 -        ^ true
   1.344 +    "not only a query; also builds"
   1.345 +
   1.346 +    |subViews list item subMenu|
   1.347 +
   1.348 +    children isNil ifTrue:[
   1.349 +        isExpanded := false.
   1.350 +
   1.351 +        list := OrderedCollection new.
   1.352 +
   1.353 +        "/ it's either a widget or a menuItem
   1.354 +        widget notNil ifTrue:[
   1.355 +            subViews := widget subViews.
   1.356 +            subViews notEmptyOrNil ifTrue:[
   1.357 +                subViews do:[:aSubView|
   1.358 +                    item := self class buildViewsFrom:aSubView.
   1.359 +                    item parent:self.
   1.360 +                    list add:item.
   1.361 +                ].
   1.362 +            ].
   1.363 +        ].
   1.364 +
   1.365 +        menuItem notNil ifTrue:[ 
   1.366 +            (subMenu := menuItem submenuOrNil) notNil ifTrue:[
   1.367 +                subMenu items do:[:aSubItem|
   1.368 +                    item := self class buildMenuItemsFrom:aSubItem.
   1.369 +                    item parent:self.
   1.370 +                    list add:item.
   1.371 +                ].
   1.372 +            ].
   1.373 +        ].
   1.374 +        children := list.
   1.375      ].
   1.376 -    isExpanded := false.
   1.377 -    subViews   := widget subViews.
   1.378 -
   1.379 -    subViews size == 0 ifTrue:[^ false].
   1.380 -
   1.381 -    list := OrderedCollection new.
   1.382 -
   1.383 -    subViews do:[:aSubView|
   1.384 -        item := self class buildViewsFrom:aSubView.
   1.385 -        item parent:self.
   1.386 -        list add:item.
   1.387 -    ].
   1.388 -    children := list.
   1.389 -    ^ true
   1.390 +    ^ children notEmpty
   1.391 +
   1.392 +    "Modified: / 16-08-2017 / 12:27:23 / cg"
   1.393  !
   1.394  
   1.395  size
   1.396 @@ -2621,16 +2790,21 @@
   1.397      label := self label.
   1.398      label isEmptyOrNil ifTrue:[^ self].
   1.399  
   1.400 -    widget id isNil ifTrue:[
   1.401 -        isDrawnShown := false.
   1.402 -
   1.403 -        self exists ifFalse:[
   1.404 -            xOffsetAdditionalName := nil.
   1.405 +    widget isNil ifTrue:[
   1.406 +        isValidAndShown := true.
   1.407 +    ] ifFalse:[
   1.408 +        widget id isNil ifTrue:[
   1.409 +            isDrawnShown := false.
   1.410 +
   1.411 +            self exists ifFalse:[
   1.412 +                xOffsetAdditionalName := nil.
   1.413 +            ].
   1.414 +            isValidAndShown := false.
   1.415 +        ] ifFalse:[
   1.416 +            isValidAndShown := widget shown.
   1.417          ].
   1.418 -        isValidAndShown := false.
   1.419 -    ] ifFalse:[
   1.420 -        isValidAndShown := widget shown.
   1.421      ].
   1.422 +    
   1.423      isValidAndShown ifFalse:[
   1.424          label := Text string:label emphasis:#italic.
   1.425          label colorizeAllWith:Color gray.
   1.426 @@ -2645,13 +2819,14 @@
   1.427          additionalName notNil ifTrue:[
   1.428              self displayLabel:additionalName
   1.429                              h:labelHeight on:aGC
   1.430 -                            x:(x + xOffsetAdditionalName)
   1.431 -                            y:y
   1.432 +                            x:(x + xOffsetAdditionalName) y:y
   1.433                              h:h.
   1.434          ] ifFalse:[
   1.435              xOffsetAdditionalName := nil.
   1.436          ].
   1.437      ].
   1.438 +
   1.439 +    "Modified (format): / 16-08-2017 / 12:57:39 / cg"
   1.440  !
   1.441  
   1.442  recursiveAdditionalNameBehaviourChanged
   1.443 @@ -2715,6 +2890,8 @@
   1.444      rootView := self rootView.
   1.445      rootView isNil ifTrue:[^ self ].
   1.446  
   1.447 +    widget isNil ifTrue:[^ self].
   1.448 +
   1.449      relOrg   := widget originRelativeTo:rootView.
   1.450      relOrg isNil ifTrue:[ ^ self ].    "/ widget destroyed
   1.451  
   1.452 @@ -2757,6 +2934,8 @@
   1.453        ^ self
   1.454      ].
   1.455      aTwoArgAction value:(Rectangle left:xR top:yB width:w height:h) value:nil.
   1.456 +
   1.457 +    "Modified: / 16-08-2017 / 13:04:27 / cg"
   1.458  !
   1.459  
   1.460  recursiveEachVisibleItemDo:anOneArgBlock
   1.461 @@ -2784,6 +2963,12 @@
   1.462  
   1.463  !ViewTreeInspectorApplication::ViewTreeItem methodsFor:'initialization'!
   1.464  
   1.465 +forMenuItem:aMenuItem
   1.466 +    menuItem := aMenuItem.
   1.467 +
   1.468 +    "Created: / 16-08-2017 / 12:08:50 / cg"
   1.469 +!
   1.470 +
   1.471  forView:aView
   1.472      widget := aView.
   1.473  !
   1.474 @@ -3018,19 +3203,26 @@
   1.475  !ViewTreeInspectorApplication::ViewTreeItem methodsFor:'printing & storing'!
   1.476  
   1.477  icon
   1.478 -    "get the icon used for presentation
   1.479 -    "
   1.480 +    "get the icon used for presentation"
   1.481 +
   1.482      |specClass model|
   1.483  
   1.484 +    menuItem notNil ifTrue:[
   1.485 +        menuItem label isImage ifTrue:[
   1.486 +            ^ menuItem label magnifiedTo:20@20.
   1.487 +        ].    
   1.488 +    ].
   1.489 +    
   1.490      specClass := self specClass.
   1.491      specClass isNil ifTrue:[^ nil].
   1.492  
   1.493      model := self treeModel.
   1.494 -
   1.495      model notNil ifTrue:[
   1.496          ^ model iconAt:specClass ifNonePut:[specClass icon]
   1.497      ].
   1.498      ^ specClass icon
   1.499 +
   1.500 +    "Modified: / 16-08-2017 / 13:00:35 / cg"
   1.501  !
   1.502  
   1.503  label
   1.504 @@ -3048,7 +3240,12 @@
   1.505  string
   1.506      "get the string
   1.507      "
   1.508 +    widget isNil ifTrue:[
   1.509 +        ^ menuItem class name    
   1.510 +    ].    
   1.511      ^ widget class name.
   1.512 +
   1.513 +    "Modified: / 16-08-2017 / 13:45:39 / cg"
   1.514  ! !
   1.515  
   1.516  !ViewTreeInspectorApplication::ViewTreeItem methodsFor:'queries'!
   1.517 @@ -3074,6 +3271,7 @@
   1.518  !
   1.519  
   1.520  exists
   1.521 +    widget isNil ifTrue:[^ menuItem notNil].
   1.522      widget id notNil ifTrue:[^ true ].
   1.523  
   1.524      exists ~~ false ifTrue:[
   1.525 @@ -3086,6 +3284,8 @@
   1.526          ].
   1.527      ].
   1.528      ^ exists
   1.529 +
   1.530 +    "Modified: / 16-08-2017 / 12:47:50 / cg"
   1.531  !
   1.532  
   1.533  isApplicationClass
   1.534 @@ -3307,6 +3507,8 @@
   1.535      ] ifFalse:[ 
   1.536          view := selection widget.
   1.537      ].
   1.538 +    view isNil ifTrue:[^ nil].
   1.539 +    
   1.540      views := OrderedCollection new.
   1.541      [ view notNil ] whileTrue:[ 
   1.542          views add: view.
   1.543 @@ -3321,6 +3523,7 @@
   1.544      ]
   1.545  
   1.546      "Created: / 19-05-2014 / 18:15:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   1.547 +    "Modified: / 16-08-2017 / 13:03:47 / cg"
   1.548  !
   1.549  
   1.550  rootItem
   1.551 @@ -4464,11 +4667,13 @@
   1.552  
   1.553      |widget l applClass applClassName key|
   1.554  
   1.555 -    widget := anItem widget.
   1.556 -
   1.557      l := nil.
   1.558      showWidgetNames == true ifTrue:[
   1.559 -        l := '"', widget name, '"'
   1.560 +        (widget := anItem widget) notNil ifTrue:[
   1.561 +            l := '"', widget name, '"'
   1.562 +        ] ifFalse:[
   1.563 +            l := '"', anItem menuItem label asString, '"'
   1.564 +        ].    
   1.565      ].
   1.566  
   1.567      anItem isApplicationClass ifTrue:[
   1.568 @@ -4487,6 +4692,8 @@
   1.569      ].
   1.570  
   1.571      ^ l
   1.572 +
   1.573 +    "Modified: / 16-08-2017 / 12:47:12 / cg"
   1.574  !
   1.575  
   1.576  showWidgetNames