Use `MenuItem`'s receiver (if specified) to resolve aspects jv
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 05 Feb 2018 12:44:06 +0000
branchjv
changeset 5710 936667f9bf00
parent 5696 d43a504f6ec3
child 5724 ba5f99908093
Use `MenuItem`'s receiver (if specified) to resolve aspects ...and as receiver of "action" methods. This is useful when one assembles menu from different sources, like part of the list menu is item-defined and part of the menu is application-specific).
MenuPanel.st
--- a/MenuPanel.st	Sat Jan 27 08:59:02 2018 +0000
+++ b/MenuPanel.st	Mon Feb 05 12:44:06 2018 +0000
@@ -1147,7 +1147,7 @@
             self error:'no originating widget (no target for message)' mayProceed:true.
         ].
     ] ifFalse:[
-        rec := aReceiver
+        rec := anItem receiver ? aReceiver
     ].
 
     rec isNil ifTrue:[
@@ -1219,6 +1219,7 @@
     ^ self "/ ^ selectorOrBlock
 
     "Modified: / 06-03-2012 / 14:49:00 / cg"
+    "Modified: / 05-02-2018 / 12:30:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 acceptItem:anItemOrNil inMenu:aMenu
@@ -1464,7 +1465,9 @@
     (receiver isNil and:[superMenu notNil]) ifTrue:[
         ^ superMenu receiver
     ].
-  ^ receiver
+    ^ receiver
+
+    "Modified (format): / 05-02-2018 / 10:28:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 receiver:anObject
@@ -6371,6 +6374,19 @@
     ^ subMenu isNil or:[subMenu shown not]
 !
 
+receiver
+    "Return an object used to resolve 'aspects' and used
+     as a rever if 'action' messages."
+
+    | receiver |
+
+    receiver := menuItem receiver.
+    receiver notNil ifTrue:[ ^ receiver ].
+    ^  menuPanel receiver
+
+    "Created: / 05-02-2018 / 12:00:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 toggleIndication
     "toggle indication or choice"
 
@@ -6942,7 +6958,7 @@
     "/ would require to fork stx:libtool2 which I'd like to avoid for now.
     "/ If more fixes would go to stx:libtool2 then I will fork, and
     "/ remove this code.
-    (menuPanel receiver isNil
+    (self receiver isNil
     and:[ app notNil
     and:[ (app askFor:#isUIPainter) or:[app isKindOf: (Smalltalk at:#UISelectionPanel)]]])
     ifTrue:[
@@ -6950,7 +6966,7 @@
     ].
     Logger info: aMessage
 
-    "Modified: / 15-04-2016 / 18:29:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 05-02-2018 / 12:06:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 indication
@@ -7510,7 +7526,7 @@
 
     |appl value|
 
-    appl := menuPanel receiver.
+    appl := self receiver.
     (appl isValueModel) ifTrue:[
         ^ appl value:aKey
     ].
@@ -7542,7 +7558,7 @@
     ^ value
 
     "Modified: / 02-08-2013 / 16:44:28 / cg"
-    "Modified: / 15-04-2016 / 18:29:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 05-02-2018 / 12:06:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !MenuPanel::Item methodsFor:'change & update'!
@@ -8521,37 +8537,39 @@
     indication isNil ifTrue:[^ nil].       "no indication specified"
 
     indication isSymbol ifFalse:[
-	^ indication value == true          "block or model"
+        ^ indication value == true          "block or model"
     ].
 
     numArgs := indication numArgs.
     numArgs == 2 ifTrue:[
-	recv := menuPanel receiver ? menuPanel application.
-	(recv notNil and:[recv isValueModel not]) ifTrue:[
-	    sel := indication copyFrom:1 to:(indication indexOf:$:).
-	    sel := sel asSymbol.
-
-	    MessageNotUnderstood handle:[:ex|
-		ex selector ~~ sel ifTrue:[
-		    ex reject.
-		].
-	    ] do:[
-		sel := recv perform:sel with:(menuItem argument).
-	    ]
-	].
+        recv := self receiver ? menuPanel application.
+        (recv notNil and:[recv isValueModel not]) ifTrue:[
+            sel := indication copyFrom:1 to:(indication indexOf:$:).
+            sel := sel asSymbol.
+
+            MessageNotUnderstood handle:[:ex|
+                ex selector ~~ sel ifTrue:[
+                    ex reject.
+                ].
+            ] do:[
+                sel := recv perform:sel with:(menuItem argument).
+            ]
+        ].
     ] ifFalse:[
-	numArgs == 0 ifTrue:[
-	    sel := indication
-	] ifFalse:[
-	    sel := (indication copyButLast:1) asSymbol.
-	].
-	sel := self aspectAt:sel.
-	sel isValueModel ifTrue:[
-	    indication := sel.
-	    indication addDependent:self.
-	].
+        numArgs == 0 ifTrue:[
+            sel := indication
+        ] ifFalse:[
+            sel := (indication copyButLast:1) asSymbol.
+        ].
+        sel := self aspectAt:sel.
+        sel isValueModel ifTrue:[
+            indication := sel.
+            indication addDependent:self.
+        ].
     ].
     ^ sel value == true
+
+    "Modified: / 05-02-2018 / 12:06:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 indicationValue:aValue
@@ -8570,7 +8588,7 @@
         ^ self
     ].
 
-    recv := menuPanel receiver.
+    recv := self receiver.
     recv isValueModel ifTrue:[^ self].
 
     recv isNil ifTrue:[
@@ -8595,7 +8613,7 @@
     ].
 
     "Modified (format): / 02-08-2013 / 16:42:20 / cg"
-    "Modified: / 15-04-2016 / 18:28:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 05-02-2018 / 12:06:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 isEntered