#FEATURE by cg draft
authorClaus Gittinger <cg@exept.de>
Wed, 16 Aug 2017 13:52:20 +0200
changeset 3456 4d4297bad4fa
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
--- a/Tools__ViewTreeApplication.st	Wed Aug 16 12:31:30 2017 +0200
+++ b/Tools__ViewTreeApplication.st	Wed Aug 16 13:52:20 2017 +0200
@@ -31,7 +31,7 @@
 !
 
 HierarchicalItem subclass:#ViewTreeItem
-	instanceVariableNames:'widget isDrawnShown exists xOffsetAdditionalName'
+	instanceVariableNames:'widget menuItem isDrawnShown exists xOffsetAdditionalName'
 	classVariableNames:'HandleExtent'
 	poolDictionaries:''
 	privateIn:ViewTreeInspectorApplication
@@ -751,6 +751,53 @@
       )
 !
 
+middleButtonMenuForMenuItems
+    "This resource specification was automatically generated
+     by the MenuEditor of ST/X."
+
+    "Do not manually edit this!! If it is corrupted,
+     the MenuEditor may not be able to read the specification."
+
+
+    "
+     MenuEditor new openOnClass:Tools::ViewTreeInspectorApplication andSelector:#middleButtonMenu
+     (Menu new fromLiteralArrayEncoding:(Tools::ViewTreeInspectorApplication middleButtonMenu)) startUp
+    "
+
+    <resource: #menu>
+
+    ^ 
+     #(Menu
+        (
+         (MenuItem
+            label: 'Browse Menu Item''s Class'
+            itemValue: doBrowseMenuItem:
+            argument: view
+          )
+         (MenuItem
+            label: '-'
+          )
+         (MenuItem
+            label: 'Inspect Menu Item'
+            itemValue: doInspectMenuItem:
+            argument: view
+          )
+         (MenuItem
+            label: '-'
+          )
+         (MenuItem
+            label: 'Interface'
+            submenuChannel: submenuMenuItemInterface:
+            keepLinkedMenu: true
+          )
+         )
+        nil
+        nil
+      )
+
+    "Created: / 16-08-2017 / 13:48:49 / cg"
+!
+
 toolbarMenu
     "This resource specification was automatically generated
      by the MenuEditor of ST/X."
@@ -1110,25 +1157,29 @@
         |state|
 
         view := item widget.
-
-        view id isNil ifTrue:[
-            state := 'no ID'.
-        ] ifFalse:[
-            view shown ifTrue:[
-                state := 'visible'.
+        view isNil ifTrue:[
+            info := '%1 [%2]' bindWith:(item menuItem label asString)
+                                  with:(item menuItem value asString).
+        ] ifFalse:[    
+            view id isNil ifTrue:[
+                state := 'no ID'.
             ] ifFalse:[
-                state := 'invisible'
+                view shown ifTrue:[
+                    state := 'visible'.
+                ] ifFalse:[
+                    state := 'invisible'
+                ].
             ].
-        ].
-        info := '%1 [%2] - %3' bindWith:(view class name)
-                                   with:(view name ? '') with:state allBold.
+            info := '%1 [%2] - %3' bindWith:(view class name)
+                                       with:(view name ? '') with:state allBold.
+        ]
     ] ifFalse:[
         info := ''
     ].
     hasSingleSelectionHolder value:(view notNil).
     self updateInspector
 
-    "Modified: / 30-07-2013 / 09:21:27 / cg"
+    "Modified: / 16-08-2017 / 13:44:59 / cg"
 !
 
 update:something with:someArgument from:aModel
@@ -1502,10 +1553,18 @@
     "returns the middleButton menu for the single selected item or nil"
 
     ^ [ 
-        model selectedItem notNil 
-            ifTrue:[self class middleButtonMenu]
-            ifFalse:[nil]
+        model selectedItem notNil ifTrue:[
+            model selectedItem isView ifTrue:[
+                self class middleButtonMenu
+            ] ifFalse:[
+                self class middleButtonMenuForMenuItems
+            ].    
+        ] ifFalse:[
+            nil
+        ]
       ]
+
+    "Modified: / 16-08-2017 / 13:48:31 / cg"
 !
 
 submenuApplications:aMenu
@@ -1817,6 +1876,23 @@
     "Modified: / 31-07-2013 / 13:09:55 / cg"
 !
 
+submenuMenuItemInterface:aMenu
+    "builds and returns the menuItem interface submenu"
+
+    |item list|
+
+    item := self selectedMenuItem.
+    item isNil ifTrue:[^ nil].
+
+    list := OrderedCollection new.
+
+    list add:(MenuDesc title:'itemValue'  value:(item itemValue)).
+
+    ^ MenuDesc buildFromList:list onGC:aMenu
+
+    "Created: / 16-08-2017 / 13:51:05 / cg"
+!
+
 submenuVisibility:aMenu
     "builds and returns the geometry submenu"
 
@@ -1955,15 +2031,17 @@
     min := 9999999.
 
     rootItem recursiveEachVisibleItemDo:[:anItem|
-        visState := (anItem widget shown).
-
-        visState ~~ anItem isDrawnShown ifTrue:[
-            anItem isDrawnShown:visState.
-            listIdx := treeView identityIndexOf:anItem.
-
-            listIdx > 0 ifTrue:[    
-                max := max max:listIdx.
-                min := min min:listIdx.
+        anItem widget notNil ifTrue:[
+            visState := (anItem widget shown).
+
+            visState ~~ anItem isDrawnShown ifTrue:[
+                anItem isDrawnShown:visState.
+                listIdx := treeView identityIndexOf:anItem.
+
+                listIdx > 0 ifTrue:[    
+                    max := max max:listIdx.
+                    min := min min:listIdx.
+                ].
             ].
         ].
     ].
@@ -1980,10 +2058,24 @@
             treeView invalidateDeviceRectangle:damage repairNow:false.
         ].
     ].
+
+    "Modified: / 16-08-2017 / 12:29:15 / cg"
 ! !
 
 !ViewTreeInspectorApplication methodsFor:'selection'!
 
+selectedMenuItem
+    "answer the selected menuItem or nil"
+
+    |item|
+
+    item := model selectedItem.
+    item notNil ifTrue:[ ^ item menuItem ].
+    ^ nil
+
+    "Created: / 16-08-2017 / 13:50:35 / cg"
+!
+
 selectedView
     "answer the selected view or nil"
 
@@ -2163,9 +2255,13 @@
 doRedraw
     "redraw the app"
 
-    model rootView notNil ifTrue:[
-        model rootView withAllSubViewsDo:[:v | v "redraw; "invalidate].
+    |rootView|
+    
+    (rootView := model rootView) notNil ifTrue:[
+        rootView withAllSubViewsDo:[:v | v "redraw; "invalidate].
     ]
+
+    "Modified: / 16-08-2017 / 12:02:11 / cg"
 !
 
 doSelectNextElementStartingIn:anItem forWhich:aBlock
@@ -2359,9 +2455,30 @@
 
 !ViewTreeInspectorApplication::ViewTreeItem class methodsFor:'building'!
 
+buildMenuItemsFrom:aMenuItem
+    "build the items starting from a source menu item;
+     returns the anchor.
+    "
+    |item subMenu subItems|
+
+    aMenuItem isNil ifTrue:[^ nil].
+
+    item     := self forMenuItem:aMenuItem.
+    subItems := OrderedCollection new.
+    (subMenu := aMenuItem submenuOrNil) notNil ifTrue:[
+        subMenu items do:[:eachMenuItem |
+            subItems add:(self buildMenuItemsFrom:eachMenuItem)
+        ].    
+    ].
+    item children:subItems.
+    ^ item
+
+    "Created: / 16-08-2017 / 12:23:02 / cg"
+!
+
 buildViewsFrom:aView
     "build the items starting from a source view;
-     returns the anhor.
+     returns the anchor.
     "
     |item subViews subItems|
 
@@ -2369,15 +2486,24 @@
 
     item     := self forView:aView.
     subViews := aView subViews.
+    subItems := OrderedCollection new.
 
     subViews notEmptyOrNil ifTrue:[
-        subItems := OrderedCollection new.
         subViews do:[:aSubView|
             subItems add:(self buildViewsFrom:aSubView).
         ].
-        item children:subItems.
     ].
+
+    (aView isKindOf:MenuPanel) ifTrue:[
+        (aView items ? #()) do:[:eachMenuItem |
+            subItems add:(self buildMenuItemsFrom:eachMenuItem)
+        ].    
+    ].    
+    item children:subItems.
+    
     ^ item
+
+    "Modified: / 16-08-2017 / 12:43:35 / cg"
 ! !
 
 !ViewTreeInspectorApplication::ViewTreeItem class methodsFor:'documentation'!
@@ -2418,12 +2544,24 @@
 
 !ViewTreeInspectorApplication::ViewTreeItem class methodsFor:'instance creation'!
 
+forMenuItem:aMenuItem
+    |item|
+
+    item := self basicNew initialize.
+    item forMenuItem:aMenuItem.
+    ^ item
+
+    "Created: / 16-08-2017 / 12:07:55 / cg"
+!
+
 forView:aView
     |item|
 
     item := self basicNew initialize.
     item forView:aView.
-  ^ item
+    ^ item
+
+    "Modified (format): / 16-08-2017 / 12:07:40 / cg"
 !
 
 new
@@ -2461,6 +2599,16 @@
     isDrawnShown := aBoolean.
 !
 
+menuItem
+    ^ menuItem
+!
+
+parent:aParent
+    super parent:aParent.
+
+    "Created: / 16-08-2017 / 12:40:26 / cg"
+!
+
 rootView
     "returns the widget assigned to the root or nil
     "
@@ -2472,7 +2620,12 @@
 specClass
     "returns the spec-class assigned to the item
     "
+    widget isNil ifTrue:[
+        ^ MenuPanelSpec 
+    ].
     ^ widget specClass
+
+    "Modified (format): / 16-08-2017 / 12:31:36 / cg"
 !
 
 treeModel
@@ -2555,25 +2708,41 @@
 !
 
 hasChildren
-    |subViews list item|
-
-    children size ~~ 0 ifTrue:[
-        ^ true
+    "not only a query; also builds"
+
+    |subViews list item subMenu|
+
+    children isNil ifTrue:[
+        isExpanded := false.
+
+        list := OrderedCollection new.
+
+        "/ it's either a widget or a menuItem
+        widget notNil ifTrue:[
+            subViews := widget subViews.
+            subViews notEmptyOrNil ifTrue:[
+                subViews do:[:aSubView|
+                    item := self class buildViewsFrom:aSubView.
+                    item parent:self.
+                    list add:item.
+                ].
+            ].
+        ].
+
+        menuItem notNil ifTrue:[ 
+            (subMenu := menuItem submenuOrNil) notNil ifTrue:[
+                subMenu items do:[:aSubItem|
+                    item := self class buildMenuItemsFrom:aSubItem.
+                    item parent:self.
+                    list add:item.
+                ].
+            ].
+        ].
+        children := list.
     ].
-    isExpanded := false.
-    subViews   := widget subViews.
-
-    subViews size == 0 ifTrue:[^ false].
-
-    list := OrderedCollection new.
-
-    subViews do:[:aSubView|
-        item := self class buildViewsFrom:aSubView.
-        item parent:self.
-        list add:item.
-    ].
-    children := list.
-    ^ true
+    ^ children notEmpty
+
+    "Modified: / 16-08-2017 / 12:27:23 / cg"
 !
 
 size
@@ -2621,16 +2790,21 @@
     label := self label.
     label isEmptyOrNil ifTrue:[^ self].
 
-    widget id isNil ifTrue:[
-        isDrawnShown := false.
-
-        self exists ifFalse:[
-            xOffsetAdditionalName := nil.
+    widget isNil ifTrue:[
+        isValidAndShown := true.
+    ] ifFalse:[
+        widget id isNil ifTrue:[
+            isDrawnShown := false.
+
+            self exists ifFalse:[
+                xOffsetAdditionalName := nil.
+            ].
+            isValidAndShown := false.
+        ] ifFalse:[
+            isValidAndShown := widget shown.
         ].
-        isValidAndShown := false.
-    ] ifFalse:[
-        isValidAndShown := widget shown.
     ].
+    
     isValidAndShown ifFalse:[
         label := Text string:label emphasis:#italic.
         label colorizeAllWith:Color gray.
@@ -2645,13 +2819,14 @@
         additionalName notNil ifTrue:[
             self displayLabel:additionalName
                             h:labelHeight on:aGC
-                            x:(x + xOffsetAdditionalName)
-                            y:y
+                            x:(x + xOffsetAdditionalName) y:y
                             h:h.
         ] ifFalse:[
             xOffsetAdditionalName := nil.
         ].
     ].
+
+    "Modified (format): / 16-08-2017 / 12:57:39 / cg"
 !
 
 recursiveAdditionalNameBehaviourChanged
@@ -2715,6 +2890,8 @@
     rootView := self rootView.
     rootView isNil ifTrue:[^ self ].
 
+    widget isNil ifTrue:[^ self].
+
     relOrg   := widget originRelativeTo:rootView.
     relOrg isNil ifTrue:[ ^ self ].    "/ widget destroyed
 
@@ -2757,6 +2934,8 @@
       ^ self
     ].
     aTwoArgAction value:(Rectangle left:xR top:yB width:w height:h) value:nil.
+
+    "Modified: / 16-08-2017 / 13:04:27 / cg"
 !
 
 recursiveEachVisibleItemDo:anOneArgBlock
@@ -2784,6 +2963,12 @@
 
 !ViewTreeInspectorApplication::ViewTreeItem methodsFor:'initialization'!
 
+forMenuItem:aMenuItem
+    menuItem := aMenuItem.
+
+    "Created: / 16-08-2017 / 12:08:50 / cg"
+!
+
 forView:aView
     widget := aView.
 !
@@ -3018,19 +3203,26 @@
 !ViewTreeInspectorApplication::ViewTreeItem methodsFor:'printing & storing'!
 
 icon
-    "get the icon used for presentation
-    "
+    "get the icon used for presentation"
+
     |specClass model|
 
+    menuItem notNil ifTrue:[
+        menuItem label isImage ifTrue:[
+            ^ menuItem label magnifiedTo:20@20.
+        ].    
+    ].
+    
     specClass := self specClass.
     specClass isNil ifTrue:[^ nil].
 
     model := self treeModel.
-
     model notNil ifTrue:[
         ^ model iconAt:specClass ifNonePut:[specClass icon]
     ].
     ^ specClass icon
+
+    "Modified: / 16-08-2017 / 13:00:35 / cg"
 !
 
 label
@@ -3048,7 +3240,12 @@
 string
     "get the string
     "
+    widget isNil ifTrue:[
+        ^ menuItem class name    
+    ].    
     ^ widget class name.
+
+    "Modified: / 16-08-2017 / 13:45:39 / cg"
 ! !
 
 !ViewTreeInspectorApplication::ViewTreeItem methodsFor:'queries'!
@@ -3074,6 +3271,7 @@
 !
 
 exists
+    widget isNil ifTrue:[^ menuItem notNil].
     widget id notNil ifTrue:[^ true ].
 
     exists ~~ false ifTrue:[
@@ -3086,6 +3284,8 @@
         ].
     ].
     ^ exists
+
+    "Modified: / 16-08-2017 / 12:47:50 / cg"
 !
 
 isApplicationClass
@@ -3307,6 +3507,8 @@
     ] ifFalse:[ 
         view := selection widget.
     ].
+    view isNil ifTrue:[^ nil].
+    
     views := OrderedCollection new.
     [ view notNil ] whileTrue:[ 
         views add: view.
@@ -3321,6 +3523,7 @@
     ]
 
     "Created: / 19-05-2014 / 18:15:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 16-08-2017 / 13:03:47 / cg"
 !
 
 rootItem
@@ -4464,11 +4667,13 @@
 
     |widget l applClass applClassName key|
 
-    widget := anItem widget.
-
     l := nil.
     showWidgetNames == true ifTrue:[
-        l := '"', widget name, '"'
+        (widget := anItem widget) notNil ifTrue:[
+            l := '"', widget name, '"'
+        ] ifFalse:[
+            l := '"', anItem menuItem label asString, '"'
+        ].    
     ].
 
     anItem isApplicationClass ifTrue:[
@@ -4487,6 +4692,8 @@
     ].
 
     ^ l
+
+    "Modified: / 16-08-2017 / 12:47:12 / cg"
 !
 
 showWidgetNames