'From Cuis 6.0 [latest update: #5116] on 28 April 2022 at 12:21:28 pm'!
!classDefinition: #MyPref category: #'System-Support'!
Object subclass: #MyPref
	instanceVariableNames: 'name description value setter'
	classVariableNames: 'PrefDict'
	poolDictionaries: ''
	category: 'System-Support'!
!MyPref commentStamp: '<historical>' prior: 0!
I describe and hold a Preference.

name: a Symbol
description: a String
setter: a two-argument closure, 	
	e.g.  [ :pref :newValue | 
		  (newValue isKindOf: Boolean)
			ifTrue: [ prev value: newValue
			ifFalse: [ self inform: pref name , 'needs a Boolean value']. ]

E.g. 
  (MyPref name: #DoYouLikeMe description: 'Like me? true or false') inspect.
In inspector, try 
  self setter value: self value: 3.
	!


!MyPref methodsFor: 'accessing' stamp: 'KenD 4/28/2022 07:47:46'!
name
	
	^ name! !

!MyPref methodsFor: 'accessing' stamp: 'KenD 4/28/2022 07:44:02'!
setter
	
	^ setter ! !

!MyPref methodsFor: 'accessing' stamp: 'KenD 4/28/2022 07:44:24'!
value
	
	^ value ! !


!MyPref methodsFor: 'initialization' stamp: 'KenD 4/28/2022 12:20:36'!
name: aSymbol description: aString value: initialValue setter: twoArgProc

	(twoArgProc isKindOf: BlockClosure)
		ifFalse:  [ self error: 'Expected a closure for setting ', twoArgProc printString ].
	(twoArgProc numArgs = 2)
		ifFalse: [ self error:
					'Expected setter closure w 2 args [ :property :newValue | ..] ', 
					twoArgProc printString ].
				
	name := aSymbol asSymbol. "allow a string"
	description := aString.
	value := initialValue.
	setter := twoArgProc.
	
	self class preferencesDictionary at: name asSymbol put: self.
	! !


!MyPref methodsFor: 'private' stamp: 'KenD 4/28/2022 12:16:16'!
value: newValue
	
	"Note Bene: unchecked.  Use my setter!!"
	value := newValue.
	self class triggerEvent: #preferenceChanged with: self! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

!classDefinition: 'MyPref class' category: #'System-Support'!
MyPref class
	instanceVariableNames: ''!

!MyPref class methodsFor: 'instance creation' stamp: 'KenD 4/28/2022 12:20:14'!
name: aSymbol description: aString 

	^ self new 
		name: aSymbol 
		description: aString value: true 
		setter:  [ :pref :newValue | 
		  		(newValue isKindOf: Boolean)
					ifTrue: [ pref value: newValue ]
					ifFalse: [ pref inform: pref name , ' needs a Boolean value']
		]
! !

!MyPref class methodsFor: 'instance creation' stamp: 'KenD 4/28/2022 12:13:21'!
name: aSymbol description: aString value: initialValue setter: twoArgProc

	^ self new 
		name: aSymbol 
		description: aString 
		value: initialValue 
		setter: twoArgProc 
! !


!MyPref class methodsFor: 'accessing' stamp: 'KenD 4/28/2022 12:14:38'!
at: prefSymbol
	
	^ self preferencesDictionary at: prefSymbol! !

!MyPref class methodsFor: 'accessing' stamp: 'KenD 4/28/2022 07:27:21'!
preferencesDictionary

 	PrefDict ifNil: [ PrefDict := Dictionary new ].
	
	^ PrefDict! !
