Tools__ViewTreeApplication.st
changeset 2455 93aaf62a6b95
parent 2454 4867f3e9dd43
child 2458 64d8f3c973b3
--- a/Tools__ViewTreeApplication.st	Fri Jan 23 17:58:19 2009 +0100
+++ b/Tools__ViewTreeApplication.st	Thu Jan 29 10:00:44 2009 +0100
@@ -4,8 +4,8 @@
 
 ApplicationModel subclass:#ViewTreeApplication
 	instanceVariableNames:'model treeView hasSingleSelectionHolder clickedItem clickedPoint
-		motionAction infoChannel testModeChannel process
-		followFocusChannel showNamesHolder'
+		motionAction infoChannel process followFocusChannel
+		showNamesHolder'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'A-Views-Support'
@@ -158,7 +158,6 @@
               hasVerticalScrollBar: true
               miniScrollerHorizontal: true
               miniScrollerVertical: false
-              backgroundColor: (Color 49.999237048905 49.999237048905 100.0)
               listModel: listOfItems
               multipleSelectOk: true
               useIndex: false
@@ -215,7 +214,7 @@
                   translateLabel: true
                 )
                (MenuItem
-                  enabled: hasPickedView
+                  enabled: hasTargetWidgetChannel
                   label: 'Release Picked View'
                   itemValue: doUnpick
                   translateLabel: true
@@ -285,12 +284,14 @@
             submenuChannel: middleButtonMenu
           )
          (MenuItem
+            enabled: hasTargetWidgetChannel
             label: 'Components'
             translateLabel: true
             startGroup: right
             submenuChannel: submenuComponents:
           )
          (MenuItem
+            enabled: hasTargetWidgetChannel
             label: 'Applications'
             translateLabel: true
             submenuChannel: submenuApplications:
@@ -489,7 +490,7 @@
             argument: application
           )
          (MenuItem
-            label: '-'
+            label: ''
           )
          (MenuItem
             enabled: hasSingleSelectionHolder
@@ -538,59 +539,69 @@
 !ViewTreeApplication methodsFor:'aspects'!
 
 followFocusChannel
-    "boolean holder, which indicates whether selection changed dependend on the focus view
-    "
+    "boolean holder, which indicates whether selection changed dependend on the focus view"
+
     ^ followFocusChannel
 !
 
 hasSingleSelectionHolder
-    "boolean holder, true if one item is selected
-    "
+    "boolean holder, true if one item is selected"
+
     ^ hasSingleSelectionHolder
 !
 
+hasTargetWidgetChannel
+    "answer the channel which is set to true if a target widget exists"
+
+    ^ model hasTargetWidgetChannel
+!
+
 infoChannel
-    "channel, which keeps a printable information
-    "
+    "channel, which keeps a printable information"
+
     ^ infoChannel
 !
 
 listOfItems
-    "returns the hierarchical list of items
-    "
+    "returns the hierarchical list of items"
+
     ^ model listOfItems
 !
 
 model
-    "returns my selection model, a ViewTreeModel
-    "
+    "returns my selection model, a ViewTreeModel"
+
     ^ model
 !
 
 selectOnClickHolder
-    "boolean holder, which indicates whether the selection will change on click
-    "
+    "boolean holder, which indicates whether the selection will change on click"
+
     ^ model selectOnClickHolder
 !
 
 showNamesHolder
     "boolean holder, which indicates whether application names or widget names
-     as additional text are shown for the items
-    "
+     as additional text are shown for the items"
+
     ^ showNamesHolder
 !
 
 testModeChannel
-    "boolean holder, which indicates whether running in test or edit mode (eat input events)
-    "
-    ^ testModeChannel
+    "answer a boolean channel which describes the behaviour how to process
+     events on the target view.
+
+     false: all input events are eaten and the selection is shown on the target view.
+     true:  no  input events are eaten and no  selection is shown on the target view."
+
+    ^ model testModeChannel
 ! !
 
 !ViewTreeApplication methodsFor:'change & update'!
 
 selectionChanged
-    "called if the selection changed
-    "
+    "called if the selection changed"
+
     |info view item|
 
     item := model selectedItem.
@@ -620,16 +631,8 @@
 update:something with:someArgument from:aModel
     |oldSelection|
 
-    oldSelection := model selectedItem.
-
-    aModel == testModeChannel ifTrue:[
-        model selectedItem:nil.
-        model testMode:(testModeChannel value).
-        model selectedItem:oldSelection.
-        ^ self
-    ].
-
     aModel == showNamesHolder ifTrue:[
+        oldSelection := model selectedItem.
         model selectedItem:nil.
         self listOfItems showWidgetNames:(aModel value).
         model selectedItem:oldSelection.
@@ -641,26 +644,35 @@
 !ViewTreeApplication methodsFor:'event processing'!
 
 processButtonMotionEvent:ev
-    "handle a button motion event
-    "
-    |click|
+    "handle a button motion event"
+
+    |click rootView|
+
+    motionAction isNil ifTrue:[^ self].
 
-    motionAction notNil ifTrue:[
-        click := ev view sensor mousePoint.
+    (rootView := model rootView) isNil ifTrue:[
+        clickedItem := motionAction := nil.
+        ^ self
+    ].
 
-        click = clickedPoint ifFalse:[
-            (clickedItem isNil or:[(click dist:clickedPoint) > 5.0]) ifTrue:[
-                motionAction value:click
-            ]
+    click := rootView device
+            translatePoint:((ev x)@ (ev y))
+            fromView:(ev view)
+            toView:rootView.
+
+    click = clickedPoint ifFalse:[
+        (clickedItem isNil or:[(click dist:clickedPoint) > 5.0]) ifTrue:[
+            motionAction value:click
         ]
     ].
 !
 
 processButtonPressEvent:ev
-    "handle a buttopn press event
-    "
-    |sensor lastRectangle|
+    "handle a buttopn press event"
 
+    |rootView sensor lastRectangle|
+
+    rootView    := model rootView.
     sensor      := model rootView sensor.
     clickedItem := model listOfItems detectItemRespondsToView:(ev view).
 
@@ -671,59 +683,65 @@
             ].
         ].
         clickedItem := motionAction := nil.
-    ] ifFalse:[
-        clickedPoint  := ev view sensor mousePoint.
-        lastRectangle := nil.
+        ^ self
+    ].
 
-        motionAction :=[:p| |rootView|
-            rootView    := model rootView device rootView.
-            clickedItem := nil.
+    clickedPoint := rootView device translatePoint:((ev x)@ (ev y))  fromView:(ev view) toView:rootView.
+    lastRectangle := nil.
 
-            rootView xoring:[
-                lastRectangle notNil ifTrue:[ rootView displayRectangle:lastRectangle ]
-                                    ifFalse:[ rootView clippedByChildren:false ].
+    motionAction :=[:p|
+        rootView    := model rootView device rootView.
+        rootView    := model rootView.
+        clickedItem := nil.
 
-                p isNil ifTrue:[
-                    rootView clippedByChildren:true.
-                    motionAction := nil.
-                ] ifFalse:[
-                    lastRectangle := Rectangle origin:(clickedPoint min:p) corner:(clickedPoint max:p).
-                    rootView displayRectangle:lastRectangle.
-                ].
-                rootView flush.
+        rootView xoring:[
+            lastRectangle notNil ifTrue:[ rootView displayRectangle:lastRectangle ]
+                                ifFalse:[ rootView clippedByChildren:false ].
+
+            p isNil ifTrue:[
+                rootView clippedByChildren:true.
+                motionAction := nil.
+            ] ifFalse:[
+                lastRectangle := Rectangle origin:(clickedPoint min:p) corner:(clickedPoint max:p).
+                rootView displayRectangle:lastRectangle.
             ].
-            lastRectangle
-        ]
-    ]
+            rootView flush.
+        ].
+        lastRectangle
+    ].
 !
 
 processButtonReleaseEvent:anEvent
-    "handle a button release event
-    "
+    "handle a button release event"
+
     |rootView rectangle newItems widget origin|
 
+    (rootView := model rootView) isNil ifTrue:[
+        clickedItem := motionAction := nil.
+        ^ self
+    ].
     motionAction isNil ifTrue:[ ^ self ].
     clickedItem notNil ifTrue:[ ^ model selectItem:clickedItem ].
 
-    (rectangle := motionAction value:nil) notNil ifTrue:[
-        rootView  := model rootView device rootView.
-        newItems := OrderedCollection new.
+    rectangle := motionAction value:nil.
+    rectangle isNil ifTrue:[^ self].
+
+    newItems := OrderedCollection new.
 
-        model rootItem recursiveDo:[:anItem|
-            widget := anItem widget.
-            origin := widget originRelativeTo:rootView.
+    model rootItem recursiveDo:[:anItem|
+        widget := anItem widget.
+        origin := widget originRelativeTo:rootView.
 
-            (rectangle containsRect:(Rectangle origin:origin extent:(widget extent))) ifTrue:[
-                newItems add:anItem.
-            ]
-        ].
-        model value:newItems.
+        (rectangle containsRect:(Rectangle origin:origin extent:(widget extent))) ifTrue:[
+            newItems add:anItem.
+        ]
     ].
+    model value:newItems.
 !
 
 processEvent:anEvent
-    "process an event
-    "
+    "process an event"
+
     |button menu|
 
     anEvent isKeyPressEvent ifTrue:[ ^ self processKeyPressEvent:anEvent ].
@@ -766,8 +784,8 @@
 !
 
 processKeyPressEvent:anEvent
-    "process an key press event
-    "
+    "process an key press event"
+
     |item prnt idx key max next|
 
     key := anEvent key.
@@ -823,8 +841,8 @@
 !
 
 processMappedView:aView
-    "process a mapped event
-    "
+    "process a mapped event"
+
     |parent anchor|
 
     parent := self listOfItems detectItemRespondsToView:aView.
@@ -846,16 +864,16 @@
 !ViewTreeApplication methodsFor:'initialization & release'!
 
 closeDownViews
-    "release the grapped application
-    "
+    "release the grapped application"
+
     process := nil.
     super closeDownViews.
     self doUnpick.
 !
 
 initialize
-    "setup my model and channels
-    "
+    "setup my model and channels"
+
     super initialize.
 
     infoChannel              := ''    asValue.
@@ -867,9 +885,6 @@
     model mappedViewAction:[:vw| self processMappedView:vw ].
     model application:self.
 
-    testModeChannel := model testMode asValue.
-    testModeChannel addDependent:self.
-
     showNamesHolder := false asValue.
     showNamesHolder addDependent:self.
 !
@@ -879,26 +894,11 @@
     treeView hasConstantHeight:true.
 ! !
 
-!ViewTreeApplication methodsFor:'menu actions'!
-
-doShowNames
-    "automatically generated by UIEditor ..."
-
-    "*** the code below performs no action"
-    "*** (except for some feedback on the Transcript)"
-    "*** Please change as required and accept in the browser."
-    "*** (and replace this comment by something more useful ;-)"
-
-    "action to be added ..."
-
-    Transcript showCR:self class name, ': action for #doShowNames ...'.
-! !
-
 !ViewTreeApplication methodsFor:'menu queries'!
 
 hasApplication
-    "returns true if the current selected view has an application
-    "
+    "returns true if the current selected view has an application"
+
     |view|
 
     view := self selectedView.
@@ -907,8 +907,8 @@
 
 hasController
     "returns true if the current selected item's view has a controller
-     other than nil or the view itself
-    "
+     other than nil or the view itself"
+
     |view controller|
 
     view := self selectedView.
@@ -921,25 +921,19 @@
 !
 
 hasModel
-    "returns true if the current selected view has a model
-    "
+    "returns true if the current selected view has a model"
+
     |view|
 
     view := self selectedView.
   ^ (view notNil and:[view model notNil])
-!
-
-hasPickedView
-    "returns true if a view is picked
-    "
-    ^ model rootItem notNil
 ! !
 
 !ViewTreeApplication methodsFor:'menu specs'!
 
 middleButtonMenu
-    "returns the middleButton menu for the single selected item or nil
-    "
+    "returns the middleButton menu for the single selected item or nil"
+
     ^ [ model selectedItem notNil ifTrue:[self class middleButtonMenu]
                                  ifFalse:[nil]
       ]
@@ -1022,8 +1016,8 @@
 !
 
 submenuGeometry:aMenu
-    "builds and returns the geometry submenu
-    "
+    "builds and returns the geometry submenu"
+
     |view point inst list x y|
 
     view := self selectedView.
@@ -1084,8 +1078,8 @@
 !
 
 submenuInspector:aMenu
-    "builds and returns the inspector submenu
-    "
+    "builds and returns the inspector submenu"
+
     |view list n names label value|
 
     view := self selectedView.
@@ -1114,8 +1108,8 @@
 !
 
 submenuInterface:aMenu
-    "builds and returns the interface submenu
-    "
+    "builds and returns the interface submenu"
+
     |view label inst value list|
 
     view := self selectedView.
@@ -1213,8 +1207,8 @@
 !
 
 submenuVisibility:aMenu
-    "builds and returns the geometry submenu
-    "
+    "builds and returns the geometry submenu"
+
     |view list value|
 
     view := self selectedView.
@@ -1286,15 +1280,16 @@
 
         process isNil ifTrue:[
             theProcess := process :=
-                Process for:[   |update|
+                Process for:[   |update testModeChannel|
 
                                 update := false.
+                                testModeChannel := model testModeChannel.
 
-                               [process == theProcess] whileTrue:[
+                                [process == theProcess] whileTrue:[
                                     Delay waitForSeconds:0.5.
 
                                     (treeView notNil and:[process == theProcess and:[treeView shown]]) ifTrue:[
-                                        (self isInTestmode and:[followFocusChannel value == true]) ifTrue:[
+                                        (testModeChannel value == true and:[followFocusChannel value == true]) ifTrue:[
                                             self selectFocusView.
                                         ].
                                         update ifTrue:[
@@ -1349,19 +1344,11 @@
     ].
 ! !
 
-!ViewTreeApplication methodsFor:'queries'!
-
-isInTestmode
-    "returns true if running in test mode - no events eaten
-    "
-    ^ testModeChannel value == true
-! !
-
 !ViewTreeApplication methodsFor:'selection'!
 
 selectedView
-    "returns the selected view or nil
-    "
+    "answer the selected view or nil"
+
     |item|
 
     item := model selectedItem.
@@ -1413,8 +1400,8 @@
 !
 
 doDestroy
-    "destroy the current selected view
-    "
+    "destroy the current selected view"
+
     |item parent|
 
     item := model selectedItem.
@@ -1449,8 +1436,8 @@
 !
 
 doFlash
-    "flash the selected view
-    "
+    "flash the selected view"
+
     |view|
 
     view := self selectedView.
@@ -1485,8 +1472,8 @@
 !
 
 doPickViews
-    "pick a window's topView
-    "
+    "pick a window's topView"
+
     |window|
 
     self doUnpick.
@@ -1557,8 +1544,8 @@
 !
 
 doUnpick
-    "release current picked window and contained subwindows
-    "
+    "release current picked window and contained subwindows"
+
     self setRootItem:nil.
 ! !