'From Cuis 6.0 [latest update: #5163] on 14 May 2022 at 12:33:04 pm'!

!PreferenceNG class methodsFor: 'accessing' stamp: 'hlsf 5/14/2022 11:42:57'!
allPreferences
	^ ThePreferences 
	! !

!PreferenceNG class methodsFor: 'accessing' stamp: 'hlsf 5/14/2022 12:31:28'!
at: symbolName on: aPreferencesDictionary
	^ (self instanceAt: symbolName on: aPreferencesDictionary) value! !

!PreferenceNG class methodsFor: 'accessing' stamp: 'hlsf 5/14/2022 12:31:32'!
at: symbolName put: aValue on: aPreferencesDictionary
	| myPref |
	myPref _ self instanceAt: symbolName on: aPreferencesDictionary. 
	myPref value: aValue! !

!PreferenceNG class methodsFor: 'accessing' stamp: 'hlsf 5/14/2022 12:32:08'!
instanceAt: symbolName on: aPreferencesDictionary
	^ aPreferencesDictionary at: symbolName ifAbsent: [self error: 'Unknown preference ', symbolName ]! !

!PreferenceNG class methodsFor: 'instance creation' stamp: 'hlsf 5/14/2022 11:49:09'!
name: nameSymbol category: categorySymbol value: aValue on: aPreferencesDictionary 
	self name: nameSymbol description: nil category: categorySymbol type: nil value: aValue on: aPreferencesDictionary
! !

!PreferenceNG class methodsFor: 'instance creation' stamp: 'hlsf 5/14/2022 11:43:02'!
name: nameSymbol description: aString category: categorySymbol type: aType value: aValue on: aPreferencesDictionary
	"If I exist, I am updated with the newer sent data "
	
	(nameSymbol isSymbol or: [categorySymbol isSymbol]) ifFalse: 
		[self error: 'Preference Name & Category are not valid symbol.'].
	^ aPreferencesDictionary 
		at: nameSymbol
		ifPresent: [:thePref |
			thePref 
				description: aString;
				category: categorySymbol;
				value: aValue;
				yourself]
		ifAbsent: [ | newPref |
			newPref _ self new ::
				name: nameSymbol 
				description: aString 
				category: categorySymbol 
				type: aType 
				value: aValue.
			aPreferencesDictionary at: nameSymbol put: newPref ].! !

!PreferenceNG class methodsFor: 'class initialization' stamp: 'hlsf 5/14/2022 12:31:53'!
installDefault: anArray in: category on: aPreferencesDictionary
	"Description of preference in Array: name - value - type (optional) - event handler (optional) "
	| myPref |

	myPref _ PreferenceNG name: anArray first 				description: '' category: category 
		type: (anArray at: 3 ifAbsent: [self detectType: anArray second]) value: anArray second
		on: aPreferencesDictionary.
	anArray size = 4 ifTrue: [ "fourth record is an event listener hooked to Preference"
		myPref when: #preferenceChanged send: anArray fourth to: PreferenceNG.
		myPref triggerEvent: #preferenceChanged with: myPref]! !

!PreferenceNG class methodsFor: 'class initialization' stamp: 'hlsf 5/14/2022 12:31:58'!
installHaloPreferencesWith: anArray on: aPreferencesDictionary
	| aColor |
	^ PreferenceNG 
		name: #haloSpecifications 
		description: 'Halo specifications describing which halos are to be used, what they should look like, and where they should be situated'
		category: #gui
		type: Array
		value: (anArray collect: [ :each |
			aColor _ Color.
			each fourth do: [ :sel | aColor _ aColor perform: sel].
			HaloSpec new 
				horizontalPlacement: each second
				verticalPlacement: each third 
				color: aColor
				iconSymbol: each fifth
				addHandleSelector: each first
				hoverHelp: each sixth])
		on: aPreferencesDictionary! !

!PreferenceNG class methodsFor: 'class initialization' stamp: 'hlsf 5/14/2022 12:32:02'!
installMiscPreferencesOn: aPreferencesDictionary
" Preference value defined with closure. We could insert in a dynamic array...
  Preference with event handler "
	PreferenceNG 
		name: #haloHandleSize category: #gui 
		value: [(aPreferencesDictionary at: #standardListFont) value pointSize * 5 // 3 max: 16]
		on: aPreferencesDictionary.
	PreferenceNG
		name: #roundedButtonRadius 	category: #gui 
		value: [(aPreferencesDictionary at: #standardListFont) value pointSize * 8 // 14]
		on: aPreferencesDictionary.
	PreferenceNG
		name: #roundedWindowRadius 	category: #gui
		value: [(aPreferencesDictionary at: #standardListFont) value pointSize]
		on: aPreferencesDictionary.
	PreferenceNG
		name: #scrollbarThickness category: #gui 	
		value: [(aPreferencesDictionary at: #windowTitleFont) value pointSize + 2]
		on: aPreferencesDictionary.
	PreferenceNG
		name: #classFinder category: #programming
		value: [ BrowserWindow findClass ]
		on: aPreferencesDictionary.
	PreferenceNG
		name: #defaultAuthorName category: #programming
		value: [Utilities authorName]
		on: aPreferencesDictionary.! !

!PreferenceNG class methodsFor: 'event handlers' stamp: 'hlsf 5/14/2022 12:31:38'!
defaultFontSize: guiElementSizePref on: aPreferencesDictionary
" #guiElementSize changed "
	| font titleFont pointSize |
	pointSize _ self fontSizes at: guiElementSizePref value.
	font _ FontFamily familyName: FontFamily defaultFamilyName pointSize: pointSize.
	PreferenceNG name: #standardListFont category: #font value: font on: aPreferencesDictionary.
	PreferenceNG name: #standardMenuFont category: #font value: font on: aPreferencesDictionary.
	PreferenceNG name: #standardCodeFont category: #font value: font on: aPreferencesDictionary.
	PreferenceNG name: #standardButtonFont category: #font value: font on: aPreferencesDictionary.
	FontFamily defaultFamilyName: font familyName defaultPointSize: pointSize.	
	titleFont _ FontFamily familyName: FontFamily defaultFamilyName pointSize: pointSize * 12//10.
	PreferenceNG name: #windowTitleFont category: #font value: titleFont on: aPreferencesDictionary.
	PreferenceNG at: #biggerCursors put: (pointSize > 14) on: aPreferencesDictionary.
	^font! !

!PreferenceNG class methodsFor: 'fonts' stamp: 'hlsf 5/14/2022 12:32:24'!
setDefaultFont: aFontName on: aPreferencesDictionary
	"Change the font on the whole system without changing point sizes."
	FontFamily defaultFamilyName: aFontName.
	PreferenceNG
			setDefaultFont: FontFamily defaultFamilyName
			spec: {
				{#standardListFont. (PreferenceNG at: #standardListFont on: aPreferencesDictionary) pointSize.}.
				{#standardMenuFont. (PreferenceNG at: #standardMenuFont on: aPreferencesDictionary) pointSize.}.
				{#windowTitleFont. (PreferenceNG at: #windowTitleFont on: aPreferencesDictionary) pointSize.}.
				{#standardCodeFont. (PreferenceNG at: #standardCodeFont on: aPreferencesDictionary) pointSize.}.
				{#standardButtonFont. (PreferenceNG at: #standardButtonFont on: aPreferencesDictionary) pointSize.}
				}
			on: aPreferencesDictionary.
	MorphicCanvas allSubclassesDo: [ :c| c guiSizePreferenceChanged ].
	UISupervisor ui ifNotNil: [ :w | w fontPreferenceChanged ].! !

!PreferenceNG class methodsFor: 'fonts' stamp: 'hlsf 5/14/2022 12:32:28'!
setDefaultFont: fontFamilyName spec: defaultFontsSpec on: aPreferencesDictionary
	| font |
	defaultFontsSpec do: [ :triplet |
		font _ FontFamily familyName: fontFamilyName pointSize: triplet second.
		font ifNil: [ font _ FontFamily defaultFamilyAndPointSize ]. 
		triplet size > 2 ifTrue: [			font _ font emphasized: triplet third ].
		PreferenceNG at: triplet first put: font on: aPreferencesDictionary ].
	MorphicCanvas allSubclassesDo: [ :c| c guiSizePreferenceChanged ].
	UISupervisor ui ifNotNil: [ :w | w fontPreferenceChanged ].! !


!PreferenceNG class methodsFor: 'accessing' stamp: 'hlsf 5/14/2022 12:32:05'!
instanceAt: symbolName
	^ self instanceAt: symbolName on: ThePreferences! !

!PreferenceNG class methodsFor: 'instance creation' stamp: 'hlsf 5/14/2022 11:45:41'!
name: nameSymbol category: categorySymbol value: aValue
	self name: nameSymbol description: nil category: categorySymbol type: nil value: aValue on: ThePreferences
! !

!PreferenceNG class methodsFor: 'class initialization' stamp: 'hlsf 5/14/2022 12:33:00'!
initialize
	| newPreferences |
	newPreferences _ Dictionary new.
	#(gui font programming system) do: [: category | 
		(self perform: (#pref, category capitalized) asSymbol) do: [:aPrefArray |
			self installDefault: aPrefArray in: category on: newPreferences ] ].
	self installHaloPreferencesWith: self iconicHaloSpecifications on: newPreferences.
	self installMiscPreferencesOn: newPreferences.
	self defaultFontSize: #standardFonts on: newPreferences.
	self setDefaultFont: FontFamily defaultFamilyName on: newPreferences.
	ThePreferences _ newPreferences.
	MorphicCanvas allSubclassesDo: [ :c| c guiSizePreferenceChanged ].
	UISupervisor ui ifNotNil: [ :w | w fontPreferenceChanged ].! !

!PreferenceNG class methodsFor: 'fileIn/Out' stamp: 'hlsf 5/14/2022 11:43:35'!
loadFrom: aFileEntry
" Load all preferences from file, update the existing preferences with the data from file "
	(SmartRefStream restoreFromFile: aFileEntry) do: [:aPref | 
		PreferenceNG 
			name: aPref name 
			description: aPref description 
			category: aPref category 
			type: aPref type 
			value: (aPref instVarNamed: #value)	 " We want the raw value "
			on: ThePreferences ]! !

!PreferenceNG class methodsFor: 'fileIn/Out' stamp: 'hlsf 5/14/2022 11:43:05'!
saveCategory: categorySymbol to: aFileEntry
	| myPref |
	myPref _ ThePreferences values select: [:aPreference | aPreference category == categorySymbol ].
	SmartRefStream 
		dumpOnFile: aFileEntry 
		object: 	(myPref collect: [:aPref | aPref name -> aPref ]) asDictionary! !

!PreferenceNG class methodsFor: 'event handlers' stamp: 'hlsf 5/14/2022 12:31:35'!
defaultFontSize: guiElementSizePref
" #guiElementSize changed "
	| font pointSize |
	pointSize _ self fontSizes at: guiElementSizePref value.
	font _ self defaultFontSize: guiElementSizePref on: ThePreferences.
	MorphicCanvas allSubclassesDo: [ :c| c guiSizePreferenceChanged ].
	UISupervisor ui ifNotNil: [ :w | w fontPreferenceChanged ].
	PreferenceNG at: #biggerCursors put: (pointSize > 14).
	Cursor defaultCursor activateCursor.
	^font! !

!PreferenceNG class methodsFor: 'fonts' stamp: 'hlsf 5/14/2022 12:32:21'!
setDefaultFont: aFontName
	"Change the font on the whole system without changing point sizes."
	self setDefaultFont: aFontName on: ThePreferences.
	MorphicCanvas allSubclassesDo: [ :c| c guiSizePreferenceChanged ].
	UISupervisor ui ifNotNil: [ :w | w fontPreferenceChanged ].! !

!methodRemoval: PreferenceNG class #installDefault:in: stamp: 'jmv 5/14/2022 11:55:42'!
PreferenceNG class removeSelector: #installDefault:in:!
!methodRemoval: PreferenceNG class #installHaloPreferencesWith: stamp: 'jmv 5/14/2022 11:55:42'!
PreferenceNG class removeSelector: #installHaloPreferencesWith:!
!methodRemoval: PreferenceNG class #name:description:category:type:value: stamp: 'jmv 5/14/2022 11:55:42'!
PreferenceNG class removeSelector: #name:description:category:type:value:!
!methodRemoval: PreferenceNG class #select: stamp: 'jmv 5/14/2022 11:55:42'!
PreferenceNG class removeSelector: #select:!
!methodRemoval: PreferenceNG class #all stamp: 'jmv 5/14/2022 11:55:42'!
PreferenceNG class removeSelector: #all!
!methodRemoval: PreferenceNG class #installMiscPreferences stamp: 'jmv 5/14/2022 11:55:42'!
PreferenceNG class removeSelector: #installMiscPreferences!
!methodRemoval: PreferenceNG class #setDefaultFont:spec: stamp: 'jmv 5/14/2022 12:17:27'!
PreferenceNG class removeSelector: #setDefaultFont:spec:!
PreferenceNG initialize!
