#QUALITY by mawalch
authormawalch
Wed, 24 Jan 2018 14:57:47 +0100
changeset 4056 a4fafec15105
parent 4055 92c2d38634c1
child 4057 d5c48c56f434
#QUALITY by mawalch class: MenuItem changed: #label: #label:itemValue: #label:itemValue:argument: #label:itemValue:enabled: #label:itemValue:translateLabel: #label:submenuChannel: #rawLabel: class: MenuItem class comment/format in: #documentation * Add assertions to expose usage of labels that are not strings (i.e. CharacterArray or subclass). * Add explicit hint to documentation that a label is supposed to be a string.
MenuItem.st
--- a/MenuItem.st	Fri Jan 19 10:43:24 2018 +0100
+++ b/MenuItem.st	Wed Jan 24 14:57:47 2018 +0100
@@ -58,6 +58,9 @@
     [author:]
         Claus Gittinger
 
+    [instance variables:]
+        label: MUST be a CharacterArray.
+
     [see also:]
         MenuItem
         PopUpMenu
@@ -69,7 +72,7 @@
 label:aString
     "create and return a new menuItem, given a label string"
 
-    ^ self new 
+    ^ self new
         label:aString;
         yourself
 
@@ -80,8 +83,8 @@
     "create and return a new menuItem, given its label and choice/value.
      This will create a Radio-Button-like item."
 
-    ^ (self new) 
-        label:labelString; choice:choiceAspect; choiceValue:selectorOrValue; 
+    ^ (self new)
+        label:labelString; choice:choiceAspect; choiceValue:selectorOrValue;
         yourself
 
     "Modified (format): / 26-04-2012 / 12:06:41 / cg"
@@ -90,8 +93,8 @@
 label:labelString itemValue:selectorOrValue
     "create and return a new menuItem, given its label and value"
 
-    ^ (self new) 
-        label:labelString itemValue:selectorOrValue; 
+    ^ (self new)
+        label:labelString itemValue:selectorOrValue;
         yourself
 
     "Created: / 09-09-2012 / 13:21:48 / cg"
@@ -101,8 +104,8 @@
     "create and return a new menuItem, given its label and value
      and an argument to be passed with the action"
 
-    ^ (self new) 
-        label:labelString; 
+    ^ (self new)
+        label:labelString;
         itemValue:selectorOrValue argument:messageArg;
         yourself
 
@@ -114,7 +117,7 @@
      and enabled holder, which can be a boolean, a boolean valueHolder,
      a block or a selector (to be sent to the application)"
 
-    ^ (self new) 
+    ^ (self new)
         label:labelString itemValue:selectorOrValue enabled:enabledHolder
 
     "Created: / 09-09-2012 / 13:23:05 / cg"
@@ -123,17 +126,17 @@
 label:labelString itemValue:selectorOrValue translateLabel:translateLabel
     "create and return a new menuItem, given its label, value and translateLabel flag"
 
-    ^ (self new) 
-        label:labelString 
-        itemValue:selectorOrValue 
+    ^ (self new)
+        label:labelString
+        itemValue:selectorOrValue
         translateLabel:translateLabel
 !
 
 label:labelString submenuChannel:aSymbolOrValueHolder
     "create and return a new menuItem, given its label and value"
 
-    ^ (self new) 
-        label:labelString submenuChannel:aSymbolOrValueHolder; 
+    ^ (self new)
+        label:labelString submenuChannel:aSymbolOrValueHolder;
         yourself
 !
 
@@ -150,7 +153,7 @@
     <resource: #obsolete>
     "create and return a new menuItem, given its label and value"
 
-    ^ (self new) 
+    ^ (self new)
         label:labelString; value:selectorOrValue; argument:messageArg;
         yourself
 
@@ -161,8 +164,8 @@
     <resource: #obsolete>
     "create and return a new menuItem, given its label and value"
 
-    ^ (self new) 
-        label:labelString; value:selectorOrValue; 
+    ^ (self new)
+        label:labelString; value:selectorOrValue;
         enabled:enabledHolder;
         yourself
 
@@ -198,7 +201,7 @@
 separator:sepString
     "create and return a new menuItem for a separator"
 
-    ^ self new 
+    ^ self new
         label:sepString; translateLabel:false;
         yourself
 
@@ -278,13 +281,13 @@
 
 accessCharacterPosition
     "get the index of the access character in the label text or string, or nil if none"
-    
+
     ^ accessCharacterPosition
 !
 
 accessCharacterPosition:index 
     "set the index of the access character in the label text or string, or nil if none"
-    
+
     accessCharacterPosition := index
 !
 
@@ -302,13 +305,13 @@
 
 argument
     "get argument given to the value (selector)"
-    
+
     ^ argument
 !
 
-argument:something 
+argument:something
     "set argument given to the value (selector)"
-    
+
     |arg|
 
     (arg := something) notNil ifTrue:[
@@ -327,9 +330,9 @@
     ^ auxValue
 !
 
-auxValue:something 
+auxValue:something
     "set the auxValue - an arbitrary user value"
-    
+
     auxValue := something
 !
 
@@ -353,11 +356,11 @@
 
 font
     "get the specific font for an item or nil"
-    
+
     ^ font
 !
 
-font:aFont 
+font:aFont
     "set a specific font for an item"
 
     font := aFont.
@@ -371,14 +374,14 @@
 horizontalLayout
     "by default, submenus have a vertical layout;
      if true, the submenu has a horizontal layout."
-    
+
     ^ horizontalLayout ? false
 !
 
-horizontalLayout:aBoolean 
+horizontalLayout:aBoolean
     "by default, submenus have a vertical layout;
      if true, the submenu has a horizontal layout."
-    
+
     horizontalLayout := aBoolean.
 !
 
@@ -386,17 +389,17 @@
     "if true, mnemonic (access character) in the submenus under the item are ignored;
      Set this to speedup accelerator key processing for slow dynamci menus.
      The default is set to false"
-    
+
     ^ ignoreMnemonicKeys ? false
 
     "Modified (comment): / 08-09-2011 / 04:30:19 / cg"
 !
 
-ignoreMnemonicKeys:aBoolean 
+ignoreMnemonicKeys:aBoolean
     "if true, mnemonic (access character) in the submenus under the item are ignored;
      Set this to speedup accelerator key processing for slow dynamci menus.
      the default is set to false"
-    
+
     ignoreMnemonicKeys := aBoolean.
 
     "Modified (comment): / 08-09-2011 / 04:52:23 / cg"
@@ -405,30 +408,30 @@
 ignoreShortcutKeys
     "if true, shortcutKeys (accelerators) in the submenus under the item are ignored;
      the default is set to false"
-    
+
     ^ ignoreShortcutKeys ? false
 !
 
-ignoreShortcutKeys:aBoolean 
+ignoreShortcutKeys:aBoolean
     "if true, shortcutKeys (accelerators) in the submenus under the item are ignored;
      the default is set to false"
-    
+
     ignoreShortcutKeys := aBoolean.
 !
 
 indication
     "value of the items on/off indicator (CheckToggle).
      Usually a valueHolder"
-    
+
     ^ indication
 
     "Created: 25.2.1997 / 20:59:28 / cg"
 !
 
-indication:someValueHolder 
+indication:someValueHolder
     "value of the items on/off indicator (CheckToggle).
      someValueHolder is usually a value holder"
-    
+
     indication := someValueHolder.
 
     "Created: 25.2.1997 / 20:59:28 / cg"
@@ -502,20 +505,26 @@
 !
 
 label:labelString itemValue:selectorOrBlock
+    self assert:(labelString isNil or:[labelString isString]).
+
     label := labelString.
-    itemValue := selectorOrBlock
+    itemValue := selectorOrBlock.
 
     "Created: / 09-09-2012 / 13:18:34 / cg"
+    "Modified: / 24-01-2018 / 14:33:04 / mawalch"
 !
 
 label:labelString itemValue:selectorOrBlock argument:something
     "define label, value and an argument to be passed with the action"
 
+    self assert:(labelString isNil or:[labelString isString]).
+
     label := labelString.
     itemValue := selectorOrBlock.
-    argument := something
+    argument := something.
 
     "Created: / 09-09-2012 / 13:19:36 / cg"
+    "Modified: / 24-01-2018 / 14:34:10 / mawalch"
 !
 
 label:labelString itemValue:selectorOrBlock enabled:enabledHolder
@@ -523,15 +532,23 @@
      and enabled holder, which can be a boolean, a boolean valueHolder,
      a block or a selector (to be sent to the application)"
 
+    self assert:(labelString isNil or:[labelString isString]).
+
     label := labelString.
     itemValue := selectorOrBlock.
-    enabled := enabledHolder
+    enabled := enabledHolder.
+
+    "Modified: / 24-01-2018 / 14:34:18 / mawalch"
 !
 
 label:labelString itemValue:selectorOrBlock translateLabel:translateLabelBoolean
+    self assert:(labelString isNil or:[labelString isString]).
+
     label := labelString.
     itemValue := selectorOrBlock.
-    translateLabel := translateLabelBoolean
+    translateLabel := translateLabelBoolean.
+
+    "Modified: / 24-01-2018 / 14:34:24 / mawalch"
 !
 
 labelImage
@@ -569,9 +586,12 @@
 !
 
 rawLabel:aString
+    self assert:(aString isNil or:[aString isString]).
+
     label := aString
 
-    "Created: 25.2.1997 / 19:11:02 / cg"
+    "Created: / 25-02-1997 / 19:11:02 / cg"
+    "Modified: / 24-01-2018 / 14:34:36 / mawalch"
 !
 
 resourceRetriever
@@ -590,42 +610,42 @@
 
 shortcutKey
     "get the key to press to select the menu item from the keyboard"
-    
+
     ^ shortcutKey
 !
 
-shortcutKey:something 
+shortcutKey:something
     "set the  key to press to select the menu item from the keyboard"
-    
+
     shortcutKey := something.
 !
 
 shortcutKeyCharacter
     "Backward compatibility; same as #shortcutKey.
      get the  key to press to select the menu item from the keyboard"
-    
+
     ^ self shortcutKey
 !
 
-shortcutKeyCharacter:something 
+shortcutKeyCharacter:something
     "Backward compatibility; same as #shortcutKey:.
      set the  key to press to select the menu item from the keyboard"
-    
+
     self shortcutKey:something.
 !
 
 submenu
     "get the submenu or nil"
-    
+
     ^ submenu value
 
     "Created: / 25.2.1997 / 20:59:28 / cg"
     "Modified: / 19.6.1998 / 00:33:58 / cg"
 !
 
-submenu:aMenu 
+submenu:aMenu
     "set the submenu or nil"
-    
+
     (aMenu isValueModel or:[ aMenu isBlock ]) ifTrue:[
         submenuChannel notNil ifTrue:[
             "/ programmers error ?
@@ -642,21 +662,21 @@
     "Modified: / 5.2.2000 / 16:53:28 / cg"
 !
 
-submenuProvider 
+submenuProvider
     "useful if a sub-menu is plugged in from another application (i.e. when
      a submenu is fetched via a channel AND the top-menus application cannot provide
      it"
-    
+
     ^ submenuProvider
 
     "Created: / 22-09-2010 / 13:55:55 / cg"
 !
 
-submenuProvider:something 
+submenuProvider:something
     "useful if a sub-menu is plugged in from another application (i.e. when
      a submenu is fetched via a channel AND the top-menus application cannot provide
      it"
-    
+
     submenuProvider := something.
 
     "Created: / 22-09-2010 / 13:55:40 / cg"
@@ -798,19 +818,23 @@
 !MenuItem methodsFor:'accessing-channels'!
 
 label:labelString submenuChannel:aSymbolOrValueHolder
+    self assert:(labelString isNil or:[labelString isString]).
+
     label := labelString.
-    submenuChannel := aSymbolOrValueHolder
+    submenuChannel := aSymbolOrValueHolder.
+
+    "Modified: / 24-01-2018 / 14:36:54 / mawalch"
 !
 
 submenuChannel
     "get the submenuChannel or nil"
-    
+
     ^ submenuChannel
 !
 
-submenuChannel:aMenuHolder 
+submenuChannel:aMenuHolder
     "set the submenuChannel or nil"
-    
+
     submenuChannel := aMenuHolder.
 ! !
 
@@ -842,9 +866,12 @@
 !
 
 label:aString
-    label := aString
+    self assert:(aString isNil or:[aString isString]).
 
-    "Created: 25.2.1997 / 19:55:16 / cg"
+    label := aString.
+
+    "Created: / 25-02-1997 / 19:55:16 / cg"
+    "Modified: / 24-01-2018 / 14:36:16 / mawalch"
 !
 
 startGroup
@@ -885,8 +912,8 @@
 findGuiResourcesIn:aResourceContainerOrApplication
     "resolve national language translations from aResourceContainerOrApplication"
 
-    self 
-        findGuiResourcesIn:aResourceContainerOrApplication 
+    self
+        findGuiResourcesIn:aResourceContainerOrApplication
         rememberResourcesIn:nil
 !
 
@@ -908,8 +935,8 @@
     ].
 
     (self translateLabel and:[label ~= '-']) ifTrue:[
-        label := ResourceRetriever 
-                        findResourceLabel:label 
+        label := ResourceRetriever
+                        findResourceLabel:label
                         in:aResourceContainerOrApplication
                         rememberResourcesIn:aValueHolderOrNil.
     ].
@@ -917,17 +944,17 @@
         |fetchDict|
 
         fetchDict := VirtualDictionary new.
-        fetchDict 
+        fetchDict
             fetchBlock:[:key |
                 (aResourceContainerOrApplication labelFor:key asSymbol) value
-            ].        
+            ].
         label := label bindWithArguments:fetchDict.
     ].
 
-    (retriever := self resourceRetriever) notNil ifTrue:[ 
+    (retriever := self resourceRetriever) notNil ifTrue:[
         retriever findGuiResourcesIn:aResourceContainerOrApplication.
         retriever labelText notNil ifTrue: [retriever labelText:label].
-    ].   
+    ].
     (m := self submenu) notNil ifTrue:[
         m := m value.
         m notNil ifTrue:[
@@ -971,10 +998,10 @@
     aReceiver isNil ifTrue:[
         ^ nil
     ].
-    menu := self 
+    menu := self
                 receiver:aReceiver perform:submenuChannel with:argument
-                ifNone:[ 
-                    self 
+                ifNone:[
+                    self
                         receiver:(aReceiver class) perform:submenuChannel with:argument 
                         ifNone:[
                             "/ ('MenuItem [info]: no aspect for slice ',submenuChannel) infoPrintCR.
@@ -1060,9 +1087,9 @@
         self perform:selector with:value
     ].
     "/ kludge in case someone forgets to call findGUIResourcesIn:
-    (retriever := self resourceRetriever) notNil ifTrue:[ 
+    (retriever := self resourceRetriever) notNil ifTrue:[
         retriever labelText notNil ifTrue: [retriever labelText: label].
-    ].   
+    ].
 
     "
      #( #MenuItem #rawLabel: 'left' #nameKey: 'identifier'  #value: #left )