Skip to content

Commit

Permalink
Merge pull request #899 from hernanmd/p13-add-sb-load-export-settings…
Browse files Browse the repository at this point in the history
…-btns

Add Load/Export feature to the New Settings Browser
  • Loading branch information
Ducasse authored Nov 17, 2024
2 parents 7a23588 + caf43bc commit ebeba1a
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 15 deletions.
18 changes: 17 additions & 1 deletion src/NewTools-SettingsBrowser/StSettingNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Class {
'pragma',
'parentName',
'model',
'matchBlock'
'matchBlock',
'parentNode'
],
#category : 'NewTools-SettingsBrowser-Model',
#package : 'NewTools-SettingsBrowser',
Expand Down Expand Up @@ -241,3 +242,18 @@ StSettingNode >> settingDeclaration [

^ declaration
]

{ #category : 'printing' }
StSettingNode >> settingNodeIdentifier [
^ String streamContents: [ :aStream |
self settingNodeIdentifierOn: aStream ]
]

{ #category : 'printing' }
StSettingNode >> settingNodeIdentifierOn: aWriteStream [

parentNode
ifNotNil: [ parentName settingNodeIdentifierOn: aWriteStream ]
ifNil: [ parentName ifNotNil: [ aWriteStream print: parentName ] ].
aWriteStream print: self settingDeclaration name
]
112 changes: 112 additions & 0 deletions src/NewTools-SettingsBrowser/StSettingsExporter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
Class {
#name : 'StSettingsExporter',
#superclass : 'Object',
#instVars : [
'groupSize',
'basename'
],
#category : 'NewTools-SettingsBrowser-Model',
#package : 'NewTools-SettingsBrowser',
#tag : 'Model'
}

{ #category : 'export' }
StSettingsExporter >> application [

^ StPharoApplication current

]

{ #category : 'accessing' }
StSettingsExporter >> basename [

^ basename
]

{ #category : 'accessing' }
StSettingsExporter >> basename: anObject [

basename := anObject
]

{ #category : 'export' }
StSettingsExporter >> defaultBasename [
"Answer a <String> with the file where settings will be stored"

^ self settingsFileReference basename
]

{ #category : 'export' }
StSettingsExporter >> defaultGroupSize [

^ 50
]

{ #category : 'export' }
StSettingsExporter >> exportAllSettings: actions [
"Export all settings in files. No more than groupSize settings will be exported to the same file.
If there are more than groupSize settings, settings will be exported in multiple files
(named aString%d.st, with %d a number increasing from 1 to (actions size / groupSize)."

| index |
index := 1.
actions
groupsOf: self groupSize
atATimeDo: [ :setting |
self exportSettings: setting toFileNamed: (self settingsIndex: index fileNamed: self basename).
index := index + 1 ].
self
exportSettings: (actions last: (actions size rem: self groupSize))
toFileNamed: (self settingsIndex: index fileNamed: self basename)
]

{ #category : 'export' }
StSettingsExporter >> exportSettings: aCollection toFileNamed: filename [
StartupPreferencesLoader default addAtStartupInPreferenceVersionFolder: aCollection named: filename
]

{ #category : 'export' }
StSettingsExporter >> exportedFileFullName [
"Answer a <String> with the file where settings will be stored"

^ self settingsFileReference fullName
]

{ #category : 'export' }
StSettingsExporter >> groupSize [

^ groupSize
]

{ #category : 'accessing' }
StSettingsExporter >> groupSize: anObject [

groupSize := anObject
]

{ #category : 'initialization' }
StSettingsExporter >> initialize [

super initialize.
groupSize := self defaultGroupSize.
basename := self defaultBasename
]

{ #category : 'export' }
StSettingsExporter >> settingsFileReference [

^ self settingsTree settingsFileReference
]

{ #category : 'export' }
StSettingsExporter >> settingsIndex: index fileNamed: aString [

^ aString , index printString , '.st'
]

{ #category : 'export' }
StSettingsExporter >> settingsTree [
"Answer the receiver's <StSettingsTree>, the settings model"

^ self application propertyAt: #settingsTree.
]
113 changes: 99 additions & 14 deletions src/NewTools-SettingsBrowser/StSettingsMainPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ Class {
#instVars : [
'toolbarPresenter',
'detailsPresenter',
'mainCategoriesPresenter'
'mainCategoriesPresenter',
'buttonBarPresenter',
'exporter'
],
#category : 'NewTools-SettingsBrowser-UI',
#package : 'NewTools-SettingsBrowser',
Expand Down Expand Up @@ -108,17 +110,20 @@ StSettingsMainPresenter >> defaultInputPort [
{ #category : 'layout' }
StSettingsMainPresenter >> defaultLayout [

^ SpPanedLayout newHorizontal
positionOfSlider: 0.2;
add: (SpBoxLayout newTopToBottom
add: toolbarPresenter withConstraints: [ : constraints |
constraints
height: self class toolbarHeight + 10;
padding: 5 ];
add: mainCategoriesPresenter;
yourself);
add: detailsPresenter;
yourself
^ SpBoxLayout newTopToBottom
spacing: 5;
add: (SpPanedLayout newHorizontal
positionOfSlider: 0.2;
add: (SpBoxLayout newTopToBottom
add: toolbarPresenter withConstraints: [ :constraints |
constraints
height: self class toolbarHeight + 10;
padding: 5 ];
add: mainCategoriesPresenter;
yourself);
add: detailsPresenter);
add: buttonBarPresenter expand: false;
yourself
]

{ #category : 'ports' }
Expand All @@ -127,6 +132,26 @@ StSettingsMainPresenter >> defaultOutputPort [
^ mainCategoriesPresenter
]

{ #category : 'initialization' }
StSettingsMainPresenter >> exportSettings [
| nodes actions |

nodes := self settingsTree nodeList.
actions := nodes
collect: [ : e | e item exportSettingAction ]
thenReject: [ : e | e isNil ].

self exporter exportAllSettings: actions.
self inform: 'Settings were exported to ' , self exporter exportedFileFullName.
buttonBarPresenter enable
]

{ #category : 'accessing' }
StSettingsMainPresenter >> exporter [

^ exporter
]

{ #category : 'searching' }
StSettingsMainPresenter >> followPath: aStSettingNode in: aCollection [

Expand All @@ -142,7 +167,34 @@ StSettingsMainPresenter >> initialize [
self currentApplication
propertyAt: #settingsTree ifAbsentPut: [ StSettingsTree new ];
styleSheet: self class styleSheet.
super initialize.
super initialize.
exporter := StSettingsExporter new.
]

{ #category : 'initialization' }
StSettingsMainPresenter >> initializeButtonBar [

buttonBarPresenter := self newButtonBar
placeAtEnd;
add: (self newButton
addStyle: 'large';
icon: (self iconNamed: #openFromUrl);
label: 'Load';
help: 'Load settings from a file';
action: [ self loadSettings ];
enabled: self settingsTree hasSettingsFile;
yourself);
add: (self newButton
icon: (self application iconNamed: #save);
label: 'Export';
help: 'Save settings into a file';
action: [ self exportSettings ];
yourself);
add: (self newButton
icon: (self iconNamed: #cancel);
action: [ self delete ];
label: 'Cancel';
yourself).
]

{ #category : 'initialization' }
Expand All @@ -160,7 +212,8 @@ StSettingsMainPresenter >> initializePresenters [
toolbarPresenter := self instantiate: StSettingsToolbarPresenter on: self.
mainCategoriesPresenter := self instantiate: StSettingsCategoriesPresenter on: self.
detailsPresenter := self instantiate: StSettingsDetailsPresenter on: self.

self initializeButtonBar.

self initializeFocus.
]

Expand All @@ -173,8 +226,40 @@ StSettingsMainPresenter >> initializeWindow: aWindowPresenter [
centered
]

{ #category : 'loading' }
StSettingsMainPresenter >> loadSettings [
"Load the settings from the system settings file, if exists"

self settingsTree settingsFileDirectory
ifNotNil: [ : settingsDirectory |
settingsDirectory hasFiles
ifTrue: [ self loadSettingsFrom: (self selectDialog: settingsDirectory files) ]
ifFalse: [ self inform: 'No settings files were found in the settings directory' ] ]
]

{ #category : 'loading' }
StSettingsMainPresenter >> loadSettingsFrom: aFileReference [

self settingsTree persistence fileReference: aFileReference.
self settingsTree updateSettingNodes.
self inform: 'Settings were loaded from ' , aFileReference fullName
]

{ #category : 'initialization' }
StSettingsMainPresenter >> pagePresenter [

^ detailsPresenter
]

{ #category : 'execution' }
StSettingsMainPresenter >> selectDialog: fileReferneces [

^ SpSelectDialog new
title: 'Settings Browser Selector';
label: 'Select a Stored Settings File';
items: fileReferneces;
display: [ :each | each basename ];
displayIcon: [ :each | self iconNamed: each systemIconName ];
openModal.

]
13 changes: 13 additions & 0 deletions src/NewTools-SettingsBrowser/StSettingsTree.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ StSettingsTree >> processSearch: aString [
as: Set
]

{ #category : 'accessing' }
StSettingsTree >> settingsFileDirectory [

^ self persistence fileReference parent
]

{ #category : 'testing' }
StSettingsTree >> settingsFileReference [
"Answer a <String> with the name of the file where settings are stored"

^ self persistence fileReference
]

{ #category : 'instance creation' }
StSettingsTree >> settingsKeywords [

Expand Down

0 comments on commit ebeba1a

Please sign in to comment.