MenuView.st
changeset 4195 3a80e7b60d37
parent 4134 3dae6c1fce63
child 4197 196b7e1581f5
--- a/MenuView.st	Thu Nov 25 13:59:10 2010 +0100
+++ b/MenuView.st	Mon Nov 29 19:49:46 2010 +0100
@@ -16,7 +16,8 @@
 		disabledEtchedFgColor onOffFlags subMenus subMenuShown superMenu
 		checkColor lineLevel lineInset masterView needResize
 		hideOnRelease sizeFixed shortKeys maxShortKeyStringLen actions
-		checkOnImage checkOffImage blockOfSubMenuShown'
+		checkOnImage checkOffImage blockOfSubMenuShown
+		delayedSubmenuHideOrShowAction lastMousePoint'
 	classVariableNames:'DefaultCheckColor DefaultViewBackground DefaultForegroundColor
 		DefaultBackgroundColor DefaultDisabledForegroundColor
 		DefaultDisabledEtchedForegroundColor
@@ -1405,37 +1406,22 @@
 !
 
 selection:index
-    |sel line|
-
-    sel := index.
-    sel notNil ifTrue:[
-	line := self listAt:index.
-	(self isGraphicItem:line) ifTrue:[
-	    "
-	     not really selectable, but a separating line
-	    "
-	    sel := nil
-	]
-    ].
-    super selection:sel
+Transcript show:'->'; showCR:index.
+
+    super selection:(self validateSelection:index)
+
+    "Modified: / 29-11-2010 / 18:52:05 / cg"
 !
 
 setSelection:index
-    |sel line|
-
-    sel := index.
-    sel notNil ifTrue:[
-	line := self listAt:index.
-	(self isGraphicItem:line) ifTrue:[
-	    "
-	     not really selectable, but a separating line
-	    "
-	    sel := nil
-	]
+Transcript show:'=>'; showCR:index.
+    index isNil ifTrue:[
+        selection == 12 ifTrue:[self halt].
     ].
-    super setSelection:sel
-
-    "Created: 25.5.1996 / 12:27:33 / cg"
+    super setSelection:(self validateSelection:index)
+
+    "Created: / 25-05-1996 / 12:27:33 / cg"
+    "Modified: / 29-11-2010 / 18:56:26 / cg"
 !
 
 sizeFixed:aBoolean
@@ -1456,6 +1442,24 @@
      - need this to hide main menus when a submenu performed its action"
 
     superMenu := aMenu
+!
+
+validateSelection:index
+    |sel line|
+
+    sel := index.
+    sel notNil ifTrue:[
+        line := self listAt:index.
+        (self isGraphicItem:line) ifTrue:[
+            "
+             not really selectable, but a separating line
+            "
+            sel := nil
+        ]
+    ].
+    ^ sel
+
+    "Created: / 29-11-2010 / 18:51:24 / cg"
 ! !
 
 !MenuView methodsFor:'accessing-submenus'!
@@ -1788,19 +1792,23 @@
 
 buttonMotion:state x:x y:y
     (self sensor hasButtonMotionEventFor:self) ifFalse:[
-        self setSelectionForX:x y:y
+        self setSelectionForX:x y:y now:(UserPreferences current delayedMenuShowAndHide) not.
     ]
+
+    "Modified: / 29-11-2010 / 19:48:55 / cg"
 !
 
 buttonPress:button x:x y:y
-    self setSelectionForX:x y:y.
-
-    "Modified: 25.2.1997 / 22:32:22 / cg"
+    self setSelectionForX:x y:y now:true.
+
+    "Modified: / 29-11-2010 / 19:38:36 / cg"
 !
 
 buttonRelease:button x:x y:y
     |hide|
 
+    self cancelDelayedSubmenuHideOrShowAction.
+
     subMenuShown notNil ifTrue:[
         ^ self
     ].
@@ -1852,7 +1860,7 @@
 "/        superView hide
 "/    ]
 
-    "Modified: 8.3.1996 / 14:06:15 / cg"
+    "Modified: / 29-11-2010 / 19:39:42 / cg"
 !
 
 keyPress:aKey x:x y:y
@@ -1861,6 +1869,7 @@
 
     |m|
 
+    self cancelDelayedSubmenuHideOrShowAction.
     subMenuShown notNil ifTrue:[
         subMenuShown menuView keyPress:aKey x:0 y:0.
         ^ self
@@ -1913,7 +1922,7 @@
 
     super keyPress:aKey x:x y:y
 
-    "Modified: 25.2.1997 / 23:37:57 / cg"
+    "Modified: / 29-11-2010 / 19:39:31 / cg"
 !
 
 pointerLeave:state
@@ -2155,6 +2164,15 @@
 
 !MenuView methodsFor:'private'!
 
+cancelDelayedSubmenuHideOrShowAction
+    delayedSubmenuHideOrShowAction notNil ifTrue:[
+        Processor removeTimedBlock:delayedSubmenuHideOrShowAction.
+        delayedSubmenuHideOrShowAction := nil.
+    ].
+
+    "Created: / 29-11-2010 / 19:21:36 / cg"
+!
+
 hideSubmenu
     "hide the currently shown subMenu (if any)"
 
@@ -2171,10 +2189,10 @@
         ].
 
         subMenuShown := nil.
-        self setSelection:nil.
+        "/ self setSelection:nil.
     ].
 
-    "Modified: 25.2.1997 / 23:38:50 / cg"
+    "Modified: / 29-11-2010 / 18:57:37 / cg"
 !
 
 isCheckItem:line
@@ -2398,7 +2416,7 @@
     "Created: 4.3.1996 / 22:10:54 / cg"
 !
 
-setSelectionForX:x y:y
+setSelectionForX:x y:y now:now
     "select whatever is under x/y coordinate - if there is
      a subMenu, show it"
 
@@ -2406,6 +2424,8 @@
 
     |newSelection subMenu|
 
+    lastMousePoint := x@y.
+
     (x < 0 
     or:[x >= width
     or:[y < 0
@@ -2413,6 +2433,8 @@
         "
          moved outside
         "
+        self cancelDelayedSubmenuHideOrShowAction.
+
         subMenuShown notNil ifTrue:[
             ^ self
         ].
@@ -2429,33 +2451,58 @@
                 newSelection := nil
             ]
         ].
-
-        subMenuShown notNil ifTrue:[
-            self hideSubmenu.
-        ].
-
+    ].
+    newSelection = selection ifTrue:[
+        now ifFalse:[
+            ^ self
+        ]
+    ].
+
+    superMenu notNil ifTrue:[
+        superMenu cancelDelayedSubmenuHideOrShowAction.
+    ].
+    self cancelDelayedSubmenuHideOrShowAction.
+    (subMenuShown isNil or:[now]) ifTrue:[
         self setSelection:newSelection.
     ].
 
-    subMenu := nil.
-    selection notNil ifTrue:[
-        subMenus notNil ifTrue:[
-            ((styleSheet at:#'menu.subMenuPopInRightHalfOnly' default:false) not
-            or:[x > (width // 2)]) ifTrue:[
-                subMenu := (subMenus at:selection)
+    now ifTrue:[
+        subMenu := nil.
+        newSelection notNil ifTrue:[
+            subMenus notNil ifTrue:[
+                ((styleSheet at:#'menu.subMenuPopInRightHalfOnly' default:false) not
+                or:[x > (width // 2)]) ifTrue:[
+                    subMenu := (subMenus at:newSelection).
+                ]
             ]
-        ]
+        ].
+
+        subMenu notNil ifTrue:[
+            subMenuShown notNil ifTrue:[
+                self hideSubmenu.
+            ].
+            subMenuShown := nil.
+            self showSubmenu:newSelection.
+        ] ifFalse:[
+            subMenuShown notNil ifTrue:[
+                self hideSubmenu.
+            ].
+            subMenuShown := nil
+        ].
+    ] ifFalse:[
+        "/ new, delayed code
+        delayedSubmenuHideOrShowAction := 
+            [
+                self setSelectionForX:lastMousePoint x y:lastMousePoint y now:true.
+            ].
+
+        Processor 
+            addTimedBlock:delayedSubmenuHideOrShowAction 
+            afterMilliseconds:100.
+
     ].
-    subMenu notNil ifTrue:[
-        self showSubmenu:selection.
-    ] ifFalse:[
-        subMenuShown notNil ifTrue:[
-            self hideSubmenu.
-        ].
-        subMenuShown := nil
-    ].
-
-    "Modified: / 29.7.1998 / 23:36:25 / cg"
+
+    "Created: / 29-11-2010 / 19:09:54 / cg"
 !
 
 showSubmenu:index
@@ -2938,9 +2985,9 @@
 !MenuView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/MenuView.st,v 1.164 2010-02-02 09:54:28 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/MenuView.st,v 1.165 2010-11-29 18:49:46 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg/MenuView.st,v 1.164 2010-02-02 09:54:28 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/MenuView.st,v 1.165 2010-11-29 18:49:46 cg Exp $'
 ! !