[Cuis-dev] The Preference model

Hilaire Fernandes hilaire at drgeo.eu
Sat Apr 30 06:27:59 PDT 2022


A first implementation following the ideas exchanged there.

It is a one class approach (hi Ken), with an additional type attribute 
(hi Mariano), without defaultValue attribute, it is not used in the base 
system

It is possible to reset to Cuis base preferences, or to import the 
existing Preferences from the old system, but the type is not good, so 
only for testing.

A preference is created and auto-kept when instantiating it.

Access to Preference instance as dictionary: PreferenceNG at: 
#biggerCursors. Access to preference value PreferenceNG at: 
#biggerCursors ormessage send PreferenceNG biggerCursors

Things to do, conform the value change to the type when type is not a 
class. Third party editor level right?

Each occurrence in system of Preferences biggerCursors should be 
replaced by PreferenceNG biggerCursors (to become just Preference or 
even Preference*s*). Message send goes by a DNU so may be system use 
should be PreferenceNG of: #biggerCursors

Hilaire

-- 
GNU Dr. Geo
http://drgeo.eu
http://blog.drgeo.eu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20220430/5a021e4f/attachment.htm>
-------------- next part --------------
'From Cuis 6.0 [latest update: #5113] on 30 April 2022 at 3:18:28 pm'!
!classDefinition: #PreferenceNG category: #'System-Support'!
Object subclass: #PreferenceNG
	instanceVariableNames: 'name description category value type'
	classVariableNames: 'ThePreferences'
	poolDictionaries: ''
	category: 'System-Support'!
!PreferenceNG commentStamp: 'hlsf 4/30/2022 12:47:46' prior: 0!
My instance is a Preference whose value is of a given class (type), or follow the description of the type instance

- name, category: symbol
- description: string
- type: a class (Boolean, String, Color, BlockClosure, etc.) or an instance (collection, intervale, etc.)
- value: an object whose class match type or the instance description of the type

Modus Operendi
- To create a Preference, invoke the instance creation class method (Preference name:description:category:type:value:). The new preference is automatically remembered. If a preference with same name already exist, its instance is returned.
- To access, invoke as dictionary (Preference at: #biggerCursors), a short cut exist (Preference biggerCursors)!


!PreferenceNG methodsFor: 'printing' stamp: 'hlsf 4/30/2022 14:42:44'!
printOn: aStream
	aStream nextPutAll: self class name ;
		nextPutAll: ' (';
		nextPutAll: name capitalized ;
		nextPutAll: ' = ';
		nextPutAll: type printString;
		nextPutAll: '::';
		nextPutAll: value printString;
		nextPut: $)! !


!PreferenceNG methodsFor: 'initialization' stamp: 'hlsf 4/30/2022 12:11:31'!
name: nameSymbol description: aString category: categorySymbol type: aType value: aValue
	name _ nameSymbol.
	description _ aString.
	category _ categorySymbol.
	type _ aType.
	value _ 	aValue! !


!PreferenceNG methodsFor: 'accessing' stamp: 'hlsf 4/30/2022 14:25:45'!
category
	^ category ! !

!PreferenceNG methodsFor: 'accessing' stamp: 'hlsf 4/30/2022 14:25:57'!
description
	^ description! !

!PreferenceNG methodsFor: 'accessing' stamp: 'hlsf 4/30/2022 14:26:02'!
name
	^ name! !

!PreferenceNG methodsFor: 'accessing' stamp: 'hlsf 4/30/2022 14:25:38'!
value
	^ value! !

!PreferenceNG methodsFor: 'accessing' stamp: 'hlsf 4/30/2022 15:09:58'!
value: aValue
	value _ aValue .
	self isTypeClass 
		ifTrue: [
			(aValue isKindOf: type) ifFalse: [self error: aValue printString, ' is not a ', type printString].
			value _ aValue ]
		ifFalse: [ "Should be handled somehow by the preference editor " 			].
	self class triggerEvent: #preferenceChanged with: self! !


!PreferenceNG methodsFor: 'testing' stamp: 'hlsf 4/30/2022 15:01:36'!
isTypeClass
	^ type class class == Metaclass ! !

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

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

!PreferenceNG class methodsFor: 'accessing' stamp: 'hlsf 4/30/2022 15:14:39'!
at: symbolName
	^ ThePreferences at: symbolName ifAbsent: [self error: 'Unknown preference ', symbolName ]! !

!PreferenceNG class methodsFor: 'accessing' stamp: 'hlsf 4/30/2022 14:28:57'!
categories
	| categories |
	categories _ Set new.
	ThePreferences values do: [:aPreference | categories add: aPreference category].
	^ categories sorted! !

!PreferenceNG class methodsFor: 'accessing' stamp: 'hlsf 4/30/2022 12:23:31'!
cuisDefaults
	^ #( 
		#(#drawKeyboardFocusIndicator true )
		#(#balloonHelpEnabled true )
		#(#biggerCursors false )
		#(#browseWithPrettyPrint false )
		#(#caseSensitiveFinds false )
		#(#checkForSlips true )
		#(#cmdDotEnabled true )
		#(#diffsInChangeList true )
		#(#diffsWithPrettyPrint false )
		#(#menuKeyboardControl true )
		#(#optionalButtons true )
		#(#extraDebuggerButtons true )
		#(#subPixelRenderFonts true )
		#(#thoroughSenders true )
		#(#cheapWindowReframe false )
		#(#syntaxHighlightingAsYouType true )
		#(#tapAndHoldEmulatesButton2 true )
		#(#clickGrabsMorphs false )
		#(#syntaxHighlightingAsYouTypeAnsiAssignment false )
		#(#syntaxHighlightingAsYouTypeLeftArrowAssignment false )
		#(#wantsMenuIcons true )
	)! !

!PreferenceNG class methodsFor: 'accessing' stamp: 'hlsf 4/30/2022 15:13:29'!
of: symbolName
	^ (self at: symbolName) value! !

!PreferenceNG class methodsFor: 'accessing' stamp: 'hlsf 4/30/2022 14:29:56'!
select: aCategory
" I select the preferences of the given category "
	^ ThePreferences values select: [:aPreference | aPreference category == aCategory ]! !


!PreferenceNG class methodsFor: 'instance creation' stamp: 'hlsf 4/30/2022 14:39:32'!
import
"Import the preferences from the old system"
	Preferences preferencesDictionary valuesDo: [:oldPref |
		PreferenceNG 
			name: oldPref name 
			description: (oldPref instVarNamed: #helpString)
			category: (oldPref instVarNamed: #categoryList) first
			type: Object
			value: oldPref preferenceValue 
		]! !

!PreferenceNG class methodsFor: 'instance creation' stamp: 'hlsf 4/30/2022 12:17:04'!
name: nameSymbol description: aString category: categorySymbol type: aType value: aValue
	(nameSymbol isSymbol or: [categorySymbol isSymbol]) ifFalse: 
		[self error: 'Preference Name & Category are not valid symbol.'].
	^ ThePreferences 
		at: nameSymbol
		ifAbsentPut: [ 
			self new ::
				name: nameSymbol 
				description: aString 
				category: categorySymbol 
				type: aType 
				value: aValue].
	! !

!PreferenceNG class methodsFor: 'instance creation' stamp: 'hlsf 4/30/2022 12:28:57'!
reset
	ThePreferences _ Dictionary new.
	self cuisDefaults do: [:anArray |
		self name: anArray first description: '' category: #system type: Boolean value: anArray second]
		! !


!PreferenceNG class methodsFor: 'error handling' stamp: 'hlsf 4/30/2022 15:15:57'!
doesNotUnderstand: aMessage
	aMessage hasArguments ifTrue: [^ super doesNotUnderstand: aMessage].
	^ self of: aMessage selector! !


More information about the Cuis-dev mailing list