PullDMenu.st
changeset 542 25e48c7527f8
parent 532 689d1c622a14
child 572 121735c2aff6
--- a/PullDMenu.st	Wed Apr 17 15:22:04 1996 +0200
+++ b/PullDMenu.st	Wed Apr 17 22:20:03 1996 +0200
@@ -10,11 +10,11 @@
  hereby transferred.
 "
 
-SimpleView subclass:#PullDownMenu
+View subclass:#PullDownMenu
 	instanceVariableNames:'receiver menus titles selectors activeMenuNumber
 		showSeparatingLines topMargin fgColor bgColor activeFgColor
 		activeBgColor onLevel offLevel edgeStyle keepMenu toggleKeep
-		raiseTopWhenActivated'
+		raiseTopWhenActivated actions'
 	classVariableNames:'DefaultViewBackground DefaultForegroundColor
 		DefaultBackgroundColor DefaultHilightForegroundColor
 		DefaultHilightBackgroundColor DefaultLevel DefaultHilightLevel
@@ -395,6 +395,40 @@
 
 !PullDownMenu methodsFor:'accessing'!
 
+actionAt:stringOrNumber
+    "return the actionBlock associated with stringOrNumber; 
+     nil if there is none (but there may be still a selector there)."
+
+    |index|
+
+    actions isNil ifTrue:[^ nil].
+    index := self indexOf:stringOrNumber.
+    (index == 0) ifTrue:[^ nil].
+    ^ actions at:index ifAbsent:nil
+
+    "Modified: 24.3.1996 / 17:09:56 / cg"
+    "Created: 17.4.1996 / 20:50:45 / cg"
+!
+
+actionAt:stringOrNumber put:aBlock
+    "return the actionBlock associated with stringOrNumber; 
+     nil if there is none (but there may be still a selector there)."
+
+    |index newActions|
+
+    index := self indexOf:stringOrNumber.
+    (index == 0) ifTrue:[^ nil].
+    actions size < index ifTrue:[
+        newActions := Array new:index.
+        newActions replaceFrom:1 to:actions size with:actions.
+        actions := newActions
+    ].
+    actions at:index put:aBlock
+
+    "Modified: 24.3.1996 / 17:09:56 / cg"
+    "Created: 17.4.1996 / 20:52:13 / cg"
+!
+
 add:label selector:selector
 	"add a new title-item at the end.
 	 The corresponding label can later be set with #at:putMenu:
@@ -870,45 +904,42 @@
 
     hideMenu := false.
     (y >= height) ifTrue:[
-	"release below title-line"
-	activeLeft := activeMenu left.
-	"
-	 released in a submenu ?
-	"
-	(x between:activeLeft and:(activeMenu right)) ifTrue:[
-	    activeTop := activeMenu top.
-	    (y between:activeTop and:(activeMenu bottom)) ifTrue:[
-		"release in menu"
-		self hideActiveMenu.   
-		activeMenu buttonRelease:button
-				       x:(x - activeLeft)
-				       y:(y - activeTop).
-		^ self
-	    ]
-	].
-	hideMenu := true.
+        "release below title-line"
+        activeLeft := activeMenu left.
+        "
+         released in a submenu ?
+        "
+        (x between:activeLeft and:(activeMenu right)) ifTrue:[
+            activeTop := activeMenu top.
+            (y between:activeTop and:(activeMenu bottom)) ifTrue:[
+                "release in menu"
+                self hideActiveMenu.   
+                activeMenu buttonRelease:button
+                                       x:(x - activeLeft)
+                                       y:(y - activeTop).
+                ^ self
+            ]
+        ].
+        hideMenu := true.
     ] ifFalse:[
-	y < 0 ifTrue:[
-	    hideMenu := true
-	] ifFalse:[
-	    activeMenu isNil ifTrue:[
-		selectors notNil ifTrue:[
-		    sel := selectors at:activeMenuNumber.
-		    sel notNil ifTrue:[
-			receiver perform:sel
-		    ].
-		].
-		hideMenu := true.
-	    ] ifFalse:[
-		keepMenu ifFalse:[   
-		    hideMenu := true
-		]
-	    ]
-	]
+        y < 0 ifTrue:[
+            hideMenu := true
+        ] ifFalse:[
+            activeMenu isNil ifTrue:[
+                self performSelectedAction.
+                hideMenu := true.
+            ] ifFalse:[
+                keepMenu ifFalse:[   
+                    hideMenu := true
+                ]
+            ]
+        ]
     ].                  
     hideMenu ifTrue:[
        self hideActiveMenu.
     ]
+
+    "Modified: 17.4.1996 / 20:56:08 / cg"
 !
 
 keyPress:key x:x y:y
@@ -990,16 +1021,13 @@
         (key == #Return 
         or:[key == #MenuSelect
         or:[key == Character space]]) ifTrue:[
-            sel := selectors at:activeMenuNumber.
-            sel notNil ifTrue:[
-                receiver perform:sel
-            ]
+            self performSelectedAction.
         ].
     ] ifFalse:[
         m keyPress:key x:0 y:0.
     ].
 
-    "Modified: 22.3.1996 / 15:37:30 / cg"
+    "Modified: 17.4.1996 / 20:56:20 / cg"
 !
 
 showNoFocus:explicit
@@ -1252,6 +1280,55 @@
     ^ titles indexOf:stringOrNumber
 !
 
+performEntry:itemIndex
+    |block sel model|
+
+    actions notNil ifTrue:[
+        block := actions at:itemIndex.
+        block notNil ifTrue:[
+            block value.
+            ^ self
+        ].
+    ].
+    selectors notNil ifTrue:[
+        sel := selectors at:itemIndex.
+        sel notNil ifTrue:[
+            model notNil ifTrue:[
+                model perform:sel
+            ] ifFalse:[
+                receiver perform:sel
+            ]    
+        ].
+    ].
+
+    "Modified: 17.4.1996 / 20:55:11 / cg"
+!
+
+performSelectedAction
+    |block sel|
+
+    actions notNil ifTrue:[
+        block := actions at:activeMenuNumber.
+        block notNil ifTrue:[
+            block value.
+            ^ self
+        ].
+    ].
+    selectors notNil ifTrue:[
+        sel := selectors at:activeMenuNumber.
+        sel notNil ifTrue:[
+            model notNil ifTrue:[
+                model perform:sel
+            ] ifFalse:[
+                receiver perform:sel
+            ]    
+        ].
+    ].
+
+    "Modified: 17.4.1996 / 20:55:11 / cg"
+    "Created: 17.4.1996 / 20:55:53 / cg"
+!
+
 setMenuOrigins
     "adjust origins of menus when font changes"
 
@@ -1405,5 +1482,5 @@
 !PullDownMenu class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/Attic/PullDMenu.st,v 1.45 1996-04-12 17:08:03 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/Attic/PullDMenu.st,v 1.46 1996-04-17 20:20:03 cg Exp $'
 ! !