ColorMenu.st
changeset 3998 b0ef8a3d446c
parent 3997 35c107962304
child 4003 ed34e80d3840
--- a/ColorMenu.st	Mon Jan 24 11:25:37 2011 +0100
+++ b/ColorMenu.st	Mon Jan 24 20:35:06 2011 +0100
@@ -15,7 +15,7 @@
 	instanceVariableNames:'overwriteDefaultToggleChannel enabledChannel labelsAreColored
 		color colorName allowSymbolicColors showDefaultToggle
 		acceptAction useDefaultColorToggleVisibleHolder allowNilColor
-		haveMenu hasNilColorHolder'
+		hasNilColorHolder'
 	classVariableNames:'ColorMenuSpec RecentlyUsedColors'
 	poolDictionaries:''
 	category:'Interface-UIPainter'
@@ -394,17 +394,23 @@
                 holder label:(Text string:'   ').
             ].
         ] ifFalse:[  
-            color := item argument.
-            holder label:(Text string:'   ' emphasis:(#backgroundColor->color)).
+            item value == #hasNilColorHolder: ifTrue:[
+                self overwriteDefaultToggleChannel value ifFalse:[
+                    model value:nil withoutNotifying:self
+                ].
+            ] ifFalse:[
+                color := item argument.
+                holder label:(Text string:'   ' emphasis:(#backgroundColor->color)).
+                self chooseColor:color.
+            ].
         ].
-        self chooseColor:color.
         self class rememberRecentlyUsedColor:color.
         acceptAction notNil ifTrue:[
             acceptAction value:color
         ].
     ]
 
-    "Modified: / 23-01-2011 / 16:22:36 / cg"
+    "Modified: / 24-01-2011 / 20:22:07 / cg"
 !
 
 chooseColor:aColor
@@ -412,11 +418,9 @@
 
     (model notNil 
     and:[ model isSymbol not]) ifTrue:[
-        model value:(self hasNilColorHolder value ifTrue:[nil] ifFalse:[aColor]).
+        model value:aColor.
     ].
     color := aColor.
-
-    "Modified: / 24-01-2011 / 10:27:57 / cg"
 ! !
 
 !ColorMenu methodsFor:'accessing'!
@@ -427,19 +431,20 @@
 
 allowNilColor
     ^ allowNilColor
-
-    "Created: / 24-01-2011 / 10:01:55 / cg"
 !
 
 allowNilColor:aBoolean
     allowNilColor ~~ aBoolean ifTrue:[
         allowNilColor := aBoolean.
-        haveMenu ifTrue:[
-            self setupMenu.
+        allowNilColor ifTrue:[      
+            self overwriteDefaultToggleChannel value:true.
+            self hasNilColorHolder value:(color notNil).
         ].
+        self setupMenu.
     ].
 
     "Created: / 24-01-2011 / 10:02:25 / cg"
+    "Modified: / 24-01-2011 / 20:06:28 / cg"
 !
 
 allowSymbolicColors
@@ -453,9 +458,10 @@
 color
     "get current color"
 
-    ^ (self hasNilColorHolder value ifTrue:[nil] ifFalse:[color])
+    self overwriteDefaultToggleChannel value ifFalse:[^ nil].
+    ^ color
 
-    "Modified: / 24-01-2011 / 10:28:13 / cg"
+    "Modified: / 24-01-2011 / 20:14:27 / cg"
 !
 
 color:aColor
@@ -463,9 +469,14 @@
 
     |label newColor|
 
+    self hasNilColorHolder setValue:aColor isNil.
+
     (aColor isColor or:[aColor isSymbol]) ifFalse:[
         self overwriteDefaultToggleChannel value:false.
         self colorHolder label:'   '.
+        (aColor isNil and:[allowNilColor]) ifTrue:[
+            self chooseColor:aColor
+        ]
     ] ifTrue:[
         newColor := aColor.
         aColor isSymbol ifTrue:[
@@ -491,18 +502,13 @@
         ]
     ]
 
-    "Modified: / 23-01-2011 / 16:23:13 / cg"
+    "Modified: / 24-01-2011 / 20:09:39 / cg"
 !
 
 colorHolder
     "returns the item which keeps the selected color in its label"
 
-    haveMenu ifFalse:[
-        self setupMenu
-    ].
     ^ self itemAt:#selection
-
-    "Modified: / 24-01-2011 / 10:10:55 / cg"
 !
 
 contents
@@ -530,7 +536,7 @@
     ].
     ^ hasNilColorHolder
 
-    "Created: / 24-01-2011 / 10:21:52 / cg"
+    "Created: / 24-01-2011 / 19:22:49 / cg"
 !
 
 labelsAreColored
@@ -548,12 +554,8 @@
 
     labelsAreColored ~~ bool ifTrue:[
         labelsAreColored := bool.
-        haveMenu ifTrue:[
-            self setupMenu.
-        ].
+        self setupMenu
     ].
-
-    "Modified: / 24-01-2011 / 10:08:59 / cg"
 !
 
 overwriteDefaultToggleChannel
@@ -588,18 +590,16 @@
 !ColorMenu methodsFor:'change & update'!
 
 hasNilColorHolderChanged
-    overwriteDefaultToggleChannel value:(hasNilColorHolder value)
+    self overwriteDefaultToggleChannel value:(self hasNilColorHolder value not).
+"/    self hasNilColorHolder value ifTrue:[
+"/        self color:nil
+"/    ].
 
-    "Created: / 24-01-2011 / 10:35:57 / cg"
+    "Modified: / 24-01-2011 / 20:14:01 / cg"
 !
 
 updateFromModel
-    |clr|
-
-    self color:(clr := model value).
-    self hasNilColorHolder value:clr isNil.
-
-    "Modified: / 24-01-2011 / 10:26:20 / cg"
+    self color:(model value)
 ! !
 
 !ColorMenu methodsFor:'help'!
@@ -686,25 +686,9 @@
 
     self fitFirstPanel:false.
     "/ enabledChannel := ValueHolder with:false.
-    "/ self setupMenu.
-
-    "Modified: / 24-01-2011 / 10:07:25 / cg"
-!
-
-menu:aMenu
-    haveMenu := true.
-    super menu:aMenu
+    self setupMenu.
 
-    "Created: / 24-01-2011 / 10:07:47 / cg"
-!
-
-realized
-    super realized.
-    haveMenu ifFalse:[
-        self setupMenu.
-    ].
-
-    "Created: / 24-01-2011 / 10:06:37 / cg"
+    "Modified: / 24-01-2011 / 19:20:55 / cg"
 !
 
 setupMenu
@@ -754,17 +738,17 @@
 
     allowNilColor ifTrue:[
         toggleItem := MenuItem labeled:'No Color'.
-        toggleItem value:#noColor.
         toggleItem isButton:false.
         toggleItem activeHelpKey:#noColor.    
         toggleItem indication:self hasNilColorHolder.
+        toggleItem value:#'hasNilColorHolder:'.
         menu addItem:toggleItem.
     ].
 
     self menu:menu.
     self updateEnableChannel
 
-    "Modified: / 24-01-2011 / 10:31:08 / cg"
+    "Modified: / 24-01-2011 / 19:35:23 / cg"
 !
 
 updateEnableChannel
@@ -773,7 +757,7 @@
             anItem indication:self overwriteDefaultToggleChannel.
             "/ anItem enabled:enabledChannel.
         ] ifFalse:[
-            anItem value == #noColor ifTrue:[
+            anItem value == #hasNilColorHolder: ifTrue:[
             ] ifFalse:[
                 anItem enabled:self overwriteDefaultToggleChannel.
             ]
@@ -781,7 +765,7 @@
     ]
 
     "Created: / 23-01-2011 / 16:08:06 / cg"
-    "Modified: / 24-01-2011 / 10:30:03 / cg"
+    "Modified: / 24-01-2011 / 19:35:52 / cg"
 ! !
 
 !ColorMenu methodsFor:'user actions'!
@@ -813,9 +797,9 @@
 !ColorMenu class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.68 2011-01-24 10:25:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.69 2011-01-24 19:35:06 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.68 2011-01-24 10:25:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.69 2011-01-24 19:35:06 cg Exp $'
 ! !