#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Thu, 09 Aug 2018 17:33:46 +0200
changeset 4162 26578918c9cf
parent 4161 a97047ee60f8
child 4163 54d6a48b4655
#FEATURE by cg class: MenuItem class definition added: #virtualSlotsInLiteralEncoding changed: #label:itemValue:translateLabel: #skippedInLiteralEncoding #translateLabel #translateLabel: category of: #skippedInLiteralEncoding
MenuItem.st
--- a/MenuItem.st	Thu Aug 09 17:19:34 2018 +0200
+++ b/MenuItem.st	Thu Aug 09 17:33:46 2018 +0200
@@ -16,11 +16,10 @@
 "{ NameSpace: Smalltalk }"
 
 Object subclass:#MenuItem
-	instanceVariableNames:'flags activeHelpKey enabled label itemValue nameKey
-		translateLabel startGroup isVisible indication submenu
-		submenuChannel submenuProvider shortcutKey labelImage
-		accessCharacterPosition argument choice choiceValue font auxValue
-		uuid'
+	instanceVariableNames:'flags activeHelpKey enabled label itemValue nameKey startGroup
+		isVisible indication submenu submenuChannel submenuProvider
+		shortcutKey labelImage accessCharacterPosition argument choice
+		choiceValue font auxValue uuid'
 	classVariableNames:'FLAG_FORCE_MENUINDICATOR FLAG_TRANSLATE_LABEL FLAG_ISBUTTON
 		FLAG_HIDE_ONACTIVATED FLAG_TRIGGER_ONDOWN
 		FLAG_SHOW_BUSYCURSOR_WHILE_PERFORMING FLAG_KEEP_LINKEDMENU
@@ -538,9 +537,10 @@
 
     label := labelString.
     itemValue := selectorOrBlock.
-    translateLabel := translateLabelBoolean.
+    self translateLabel:translateLabelBoolean.
 
     "Modified: / 24-01-2018 / 14:34:24 / mawalch"
+    "Modified: / 09-08-2018 / 17:27:37 / Claus Gittinger"
 !
 
 labelImage
@@ -829,13 +829,21 @@
     "returns true if the label is to be translated.
      The default is true"
 
-    ^ translateLabel ? true
+    "/ notice: here the default is true
+    ^ ((flags ? 0) bitTest:FLAG_TRANSLATE_LABEL) not "/ translateLabel ? true
+
+    "Modified (comment): / 09-08-2018 / 17:27:00 / Claus Gittinger"
 !
 
 translateLabel:aBoolean
     "sets whether label is translated"
 
-    translateLabel := aBoolean
+    "/ notice: here the default is true
+
+    "/ translateLabel := aBoolean
+    flags := (flags ? 0) changeMask:FLAG_HIDE_ONACTIVATED to:aBoolean not.
+
+    "Modified (comment): / 09-08-2018 / 17:27:20 / Claus Gittinger"
 !
 
 triggerOnDown
@@ -1133,7 +1141,33 @@
     "Modified: / 21-07-2017 / 19:48:45 / cg"
 ! !
 
-!MenuItem methodsFor:'converting'!
+!MenuItem methodsFor:'encoding & decoding'!
+
+fromLiteralArrayEncoding:aLiteralEncodedArray
+    "read my contents from a aLiteralEncodedArray"
+
+    |selector value retriever|
+
+    2 to:aLiteralEncodedArray size by:2 do:[:i |
+        selector := aLiteralEncodedArray at:i.
+        value    := (aLiteralEncodedArray at:i+1).
+        selector == #argument: ifFalse:[
+            value := value decodeAsLiteralArray
+        ].
+        self perform:selector with:value
+    ].
+    "/ kludge in case someone forgets to call findGUIResourcesIn:
+    (retriever := self resourceRetriever) notNil ifTrue:[
+        retriever labelText notNil ifTrue: [retriever labelText: label].
+    ].
+
+    "
+     #( #MenuItem #rawLabel: 'left' #nameKey: 'identifier'  #value: #left )
+         decodeAsLiteralArray
+    "
+
+    "Modified: / 4.2.2000 / 12:50:28 / cg"
+!
 
 skippedInLiteralEncoding
     "define the inst-slots which are skipped when generating a literalArrayEncoding;
@@ -1143,8 +1177,10 @@
 
     coll := super skippedInLiteralEncoding asOrderedCollection.
 
+    coll add:#flags.
+    
     label isNil ifTrue:[ coll add:#label ].
-    (translateLabel isNil or:[translateLabel == true or:[#('' '-' '=') includes:label]]) ifTrue:[ coll add:#translateLabel ].
+    (self translateLabel or:[#('' '-' '=') includes:label]) ifTrue:[ coll add:#translateLabel ].
     self isButton ifFalse:[ coll add:#isButton ].
     self triggerOnDown ifFalse:[ coll add:#triggerOnDown ].
     self hideMenuOnActivated ifTrue:[ coll add:#hideMenuOnActivated].
@@ -1178,35 +1214,21 @@
     ^ coll
 
     "Modified: / 22-08-2012 / 21:22:20 / cg"
-    "Modified (comment): / 09-08-2018 / 17:17:52 / Claus Gittinger"
-! !
-
-!MenuItem methodsFor:'encoding & decoding'!
-
-fromLiteralArrayEncoding:aLiteralEncodedArray
-    "read my contents from a aLiteralEncodedArray"
-
-    |selector value retriever|
+    "Modified: / 09-08-2018 / 17:26:11 / Claus Gittinger"
+!
 
-    2 to:aLiteralEncodedArray size by:2 do:[:i |
-        selector := aLiteralEncodedArray at:i.
-        value    := (aLiteralEncodedArray at:i+1).
-        selector == #argument: ifFalse:[
-            value := value decodeAsLiteralArray
-        ].
-        self perform:selector with:value
-    ].
-    "/ kludge in case someone forgets to call findGUIResourcesIn:
-    (retriever := self resourceRetriever) notNil ifTrue:[
-        retriever labelText notNil ifTrue: [retriever labelText: label].
-    ].
+virtualSlotsInLiteralEncoding
+    "defines additional virtual slots in the literalEncoding.
+     These are not instvars, but accessed via getters and setters during
+     store and load.
+     Use this when flags encode values which were previously encoded as boolean instvars,
+     to remain backward compatible"
 
-    "
-     #( #MenuItem #rawLabel: 'left' #nameKey: 'identifier'  #value: #left )
-         decodeAsLiteralArray
-    "
+    ^ #( ignoreMnemonicKeys ignoreShortcutKeys hideMenuOnActivated
+         keepLinkedMenu sendToOriginator showBusyCursorWhilePerforming triggerOnDown
+         hasMenuIndicator horizontalLayout isButton isMenuSlice translateLabel)
 
-    "Modified: / 4.2.2000 / 12:50:28 / cg"
+    "Created: / 09-08-2018 / 17:24:19 / Claus Gittinger"
 ! !
 
 !MenuItem methodsFor:'printing & storing'!