ColorMenu.st
changeset 3997 35c107962304
parent 3996 4ef9b35afcdc
child 3998 b0ef8a3d446c
equal deleted inserted replaced
3996:4ef9b35afcdc 3997:35c107962304
    12 "{ Package: 'stx:libwidg2' }"
    12 "{ Package: 'stx:libwidg2' }"
    13 
    13 
    14 MenuPanel subclass:#ColorMenu
    14 MenuPanel subclass:#ColorMenu
    15 	instanceVariableNames:'overwriteDefaultToggleChannel enabledChannel labelsAreColored
    15 	instanceVariableNames:'overwriteDefaultToggleChannel enabledChannel labelsAreColored
    16 		color colorName allowSymbolicColors showDefaultToggle
    16 		color colorName allowSymbolicColors showDefaultToggle
    17 		acceptAction useDefaultColorToggleVisibleHolder'
    17 		acceptAction useDefaultColorToggleVisibleHolder allowNilColor
       
    18 		haveMenu hasNilColorHolder'
    18 	classVariableNames:'ColorMenuSpec RecentlyUsedColors'
    19 	classVariableNames:'ColorMenuSpec RecentlyUsedColors'
    19 	poolDictionaries:''
    20 	poolDictionaries:''
    20 	category:'Interface-UIPainter'
    21 	category:'Interface-UIPainter'
    21 !
    22 !
    22 
    23 
   409 chooseColor:aColor
   410 chooseColor:aColor
   410     "accept the current selected item"
   411     "accept the current selected item"
   411 
   412 
   412     (model notNil 
   413     (model notNil 
   413     and:[ model isSymbol not]) ifTrue:[
   414     and:[ model isSymbol not]) ifTrue:[
   414         model value:aColor.
   415         model value:(self hasNilColorHolder value ifTrue:[nil] ifFalse:[aColor]).
   415     ].
   416     ].
   416     color := aColor.
   417     color := aColor.
       
   418 
       
   419     "Modified: / 24-01-2011 / 10:27:57 / cg"
   417 ! !
   420 ! !
   418 
   421 
   419 !ColorMenu methodsFor:'accessing'!
   422 !ColorMenu methodsFor:'accessing'!
   420 
   423 
   421 acceptAction:something
   424 acceptAction:something
   422     acceptAction := something.
   425     acceptAction := something.
   423 !
   426 !
   424 
   427 
       
   428 allowNilColor
       
   429     ^ allowNilColor
       
   430 
       
   431     "Created: / 24-01-2011 / 10:01:55 / cg"
       
   432 !
       
   433 
       
   434 allowNilColor:aBoolean
       
   435     allowNilColor ~~ aBoolean ifTrue:[
       
   436         allowNilColor := aBoolean.
       
   437         haveMenu ifTrue:[
       
   438             self setupMenu.
       
   439         ].
       
   440     ].
       
   441 
       
   442     "Created: / 24-01-2011 / 10:02:25 / cg"
       
   443 !
       
   444 
   425 allowSymbolicColors
   445 allowSymbolicColors
   426     ^ allowSymbolicColors
   446     ^ allowSymbolicColors
   427 !
   447 !
   428 
   448 
   429 allowSymbolicColors:aBoolean
   449 allowSymbolicColors:aBoolean
   431 !
   451 !
   432 
   452 
   433 color
   453 color
   434     "get current color"
   454     "get current color"
   435 
   455 
   436     ^ color
   456     ^ (self hasNilColorHolder value ifTrue:[nil] ifFalse:[color])
       
   457 
       
   458     "Modified: / 24-01-2011 / 10:28:13 / cg"
   437 !
   459 !
   438 
   460 
   439 color:aColor
   461 color:aColor
   440     "set current color"
   462     "set current color"
   441 
   463 
   473 !
   495 !
   474 
   496 
   475 colorHolder
   497 colorHolder
   476     "returns the item which keeps the selected color in its label"
   498     "returns the item which keeps the selected color in its label"
   477 
   499 
       
   500     haveMenu ifFalse:[
       
   501         self setupMenu
       
   502     ].
   478     ^ self itemAt:#selection
   503     ^ self itemAt:#selection
       
   504 
       
   505     "Modified: / 24-01-2011 / 10:10:55 / cg"
   479 !
   506 !
   480 
   507 
   481 contents
   508 contents
   482     ^ self color
   509     ^ self color
   483 !
   510 !
   494 "/    ^ enabledChannel
   521 "/    ^ enabledChannel
   495 
   522 
   496     "Modified: / 23-01-2011 / 16:24:12 / cg"
   523     "Modified: / 23-01-2011 / 16:24:12 / cg"
   497 !
   524 !
   498 
   525 
       
   526 hasNilColorHolder
       
   527     hasNilColorHolder isNil ifTrue:[
       
   528         hasNilColorHolder := false asValue.
       
   529         hasNilColorHolder onChangeSend:#hasNilColorHolderChanged to:self.
       
   530     ].
       
   531     ^ hasNilColorHolder
       
   532 
       
   533     "Created: / 24-01-2011 / 10:21:52 / cg"
       
   534 !
       
   535 
   499 labelsAreColored
   536 labelsAreColored
   500     "controls if labels or their backgrounds will be colored"
   537     "controls if labels or their backgrounds will be colored"
   501 
   538 
   502     ^ labelsAreColored
   539     ^ labelsAreColored
   503 !
   540 !
   509 
   546 
   510     bool := aBoolean ? false.
   547     bool := aBoolean ? false.
   511 
   548 
   512     labelsAreColored ~~ bool ifTrue:[
   549     labelsAreColored ~~ bool ifTrue:[
   513         labelsAreColored := bool.
   550         labelsAreColored := bool.
   514         self setupMenu
   551         haveMenu ifTrue:[
   515     ].
   552             self setupMenu.
       
   553         ].
       
   554     ].
       
   555 
       
   556     "Modified: / 24-01-2011 / 10:08:59 / cg"
   516 !
   557 !
   517 
   558 
   518 overwriteDefaultToggleChannel
   559 overwriteDefaultToggleChannel
   519     overwriteDefaultToggleChannel isNil ifTrue:[
   560     overwriteDefaultToggleChannel isNil ifTrue:[
   520         overwriteDefaultToggleChannel := false asValue.
   561         overwriteDefaultToggleChannel := false asValue.
   544     ]
   585     ]
   545 ! !
   586 ! !
   546 
   587 
   547 !ColorMenu methodsFor:'change & update'!
   588 !ColorMenu methodsFor:'change & update'!
   548 
   589 
       
   590 hasNilColorHolderChanged
       
   591     overwriteDefaultToggleChannel value:(hasNilColorHolder value)
       
   592 
       
   593     "Created: / 24-01-2011 / 10:35:57 / cg"
       
   594 !
       
   595 
   549 updateFromModel
   596 updateFromModel
   550     self color:(model value)
   597     |clr|
       
   598 
       
   599     self color:(clr := model value).
       
   600     self hasNilColorHolder value:clr isNil.
       
   601 
       
   602     "Modified: / 24-01-2011 / 10:26:20 / cg"
   551 ! !
   603 ! !
   552 
   604 
   553 !ColorMenu methodsFor:'help'!
   605 !ColorMenu methodsFor:'help'!
   554 
   606 
   555 flyByHelpSpec
   607 flyByHelpSpec
   628 initialize
   680 initialize
   629     super initialize.
   681     super initialize.
   630     labelsAreColored    := false.
   682     labelsAreColored    := false.
   631     verticalLayout      := false.
   683     verticalLayout      := false.
   632     allowSymbolicColors := false.
   684     allowSymbolicColors := false.
       
   685     allowNilColor       := false.
   633 
   686 
   634     self fitFirstPanel:false.
   687     self fitFirstPanel:false.
   635     "/ enabledChannel := ValueHolder with:false.
   688     "/ enabledChannel := ValueHolder with:false.
   636     self setupMenu.
   689     "/ self setupMenu.
   637 
   690 
   638     "Modified: / 23-01-2011 / 16:05:31 / cg"
   691     "Modified: / 24-01-2011 / 10:07:25 / cg"
       
   692 !
       
   693 
       
   694 menu:aMenu
       
   695     haveMenu := true.
       
   696     super menu:aMenu
       
   697 
       
   698     "Created: / 24-01-2011 / 10:07:47 / cg"
       
   699 !
       
   700 
       
   701 realized
       
   702     super realized.
       
   703     haveMenu ifFalse:[
       
   704         self setupMenu.
       
   705     ].
       
   706 
       
   707     "Created: / 24-01-2011 / 10:06:37 / cg"
   639 !
   708 !
   640 
   709 
   641 setupMenu
   710 setupMenu
   642     |menu toggleItem|
   711     |menu toggleItem|
   643 
   712 
   681         toggleItem activeHelpKey:#useDefaultColorToggle.    
   750         toggleItem activeHelpKey:#useDefaultColorToggle.    
   682         toggleItem isVisible:(self useDefaultColorToggleVisibleHolder).    
   751         toggleItem isVisible:(self useDefaultColorToggleVisibleHolder).    
   683         menu addItem:toggleItem beforeIndex:1.
   752         menu addItem:toggleItem beforeIndex:1.
   684 "/    ].
   753 "/    ].
   685 
   754 
       
   755     allowNilColor ifTrue:[
       
   756         toggleItem := MenuItem labeled:'No Color'.
       
   757         toggleItem value:#noColor.
       
   758         toggleItem isButton:false.
       
   759         toggleItem activeHelpKey:#noColor.    
       
   760         toggleItem indication:self hasNilColorHolder.
       
   761         menu addItem:toggleItem.
       
   762     ].
       
   763 
   686     self menu:menu.
   764     self menu:menu.
   687 
       
   688     self updateEnableChannel
   765     self updateEnableChannel
   689 
   766 
   690     "Modified: / 23-01-2011 / 16:08:18 / cg"
   767     "Modified: / 24-01-2011 / 10:31:08 / cg"
   691 !
   768 !
   692 
   769 
   693 updateEnableChannel
   770 updateEnableChannel
   694     self do:[:anItem|
   771     self do:[:anItem|
   695         anItem value == #selection ifTrue:[
   772         anItem value == #selection ifTrue:[
   696             anItem indication:self overwriteDefaultToggleChannel.
   773             anItem indication:self overwriteDefaultToggleChannel.
   697             "/ anItem enabled:enabledChannel.
   774             "/ anItem enabled:enabledChannel.
   698         ] ifFalse:[
   775         ] ifFalse:[
   699             anItem enabled:self overwriteDefaultToggleChannel.
   776             anItem value == #noColor ifTrue:[
       
   777             ] ifFalse:[
       
   778                 anItem enabled:self overwriteDefaultToggleChannel.
       
   779             ]
   700         ]
   780         ]
   701     ]
   781     ]
   702 
   782 
   703     "Created: / 23-01-2011 / 16:08:06 / cg"
   783     "Created: / 23-01-2011 / 16:08:06 / cg"
       
   784     "Modified: / 24-01-2011 / 10:30:03 / cg"
   704 ! !
   785 ! !
   705 
   786 
   706 !ColorMenu methodsFor:'user actions'!
   787 !ColorMenu methodsFor:'user actions'!
   707 
   788 
   708 keepColorHolderIndicationAlwaysEnabled
   789 keepColorHolderIndicationAlwaysEnabled
   730 ! !
   811 ! !
   731 
   812 
   732 !ColorMenu class methodsFor:'documentation'!
   813 !ColorMenu class methodsFor:'documentation'!
   733 
   814 
   734 version
   815 version
   735     ^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.67 2011-01-23 19:35:29 cg Exp $'
   816     ^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.68 2011-01-24 10:25:37 cg Exp $'
   736 !
   817 !
   737 
   818 
   738 version_CVS
   819 version_CVS
   739     ^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.67 2011-01-23 19:35:29 cg Exp $'
   820     ^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.68 2011-01-24 10:25:37 cg Exp $'
   740 ! !
   821 ! !