Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Load/Export feature to the New Settings Browser #899

Open
wants to merge 4 commits into
base: Pharo13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/NewTools-SettingsBrowser/SettingDeclaration.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ SettingDeclaration >> asSettingPresenter [
"Answer an appropriate <SpPresenter> container for the receiver's value"

^ self precondition value
ifTrue: [ self default asSettingPresenter: self ]
ifTrue: [
self hasValue
ifTrue: [ self realValue asSettingPresenter: self ]
ifFalse: [ self default asSettingPresenter: self ] ]
ifFalse: [ SpNullPresenter new ]
]

Expand Down
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
]
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ StSettingsAbstractPresenter class >> appearanceIconContents [
^ 'iVBORw0KGgoAAAANS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BHhjJ9RqLJalEgSi1LGYMXSvj1T5200vptIuTx4/iyOEJlGcX6MUSZC1JoO0BURYwSQbzeXz50RlaHiLFBuISWDM3RreNtL3xzNbVR2IMVSLNalimJ8UAyQMxJiltAsnJnJQdWzFvbiYe3cnGZFtxR1tvDog+sVSqIZ/vw6m3XjfuX5mMXQjwnYFvRU59FplGmWoU/J5N8N1+6DBAtVoT1Wb+2Td/dki8Rzqs9IRsNmu8+nwuJaqgfV5YOy4KT35E//2zZvrpyEWUix+gUV3E7Tt3+XLD1Fnpy7aCxIAxiOj2fF8fvZA3vSXP+8FmxxViIl08ECtQ2odupShDIPUvLjWJyNC0FMS7V39K9yvPzuGv23fZDX1zJ7w8caBtQFcC8urmu8MI0ieM5iC9xSSibTtMKteQWB0yucIrnh7YuWOUwEP4feompqZvYby4E3m2+Ih/nQRonRV5eDp0HJXNr/DdnN1R8d3AW0a6pwdjxV0kIyDriUFMxlRYELIduxgs9JtSjnWsEQIDQeAok+LQBAAWXSgjmzkgSptM4uUY6/lnk2OL6vjYThR3befZ+K6hqV08kFTB+s9MT8OqVqFTLhq7x6GZ0bVazdS2YlNal5CBEM41G5uUplyAIp0hkFke0FRueR7yX1yAdfUaJwPM/nIF4ego5mbnMTs/37W3y/EOIbhccuNjRfN+0LUTdjskyUgUYPcI8E8Fikpi4TXNlipWmVB0HO6ciCRktCze3wqKeID1lGRkjnKvgEcE9944DnvvY+P6sLfXJKVcsR4vrWQ9d0J2zkgVtbDMN7FpnnYNM4v/BtJA8Rax5clsczD/3hlDRou14gG+1w0MDppPJ8TaM6KULyeSgx4xDbYTKX1DmPXn+7OC3kqOWJUkA0ex9+Jv4WYm1wZbc1VrRzCVbV03qTh16+/Tlua/56z2FQzW1POfFg177Qr43vHRK/8CwASYO3ntL1AAAAAASUVORK5CYII='
]

{ #category : 'accessing' }
StSettingsAbstractPresenter class >> application [

^ StPharoApplication current

]

{ #category : 'accessing - icons' }
StSettingsAbstractPresenter class >> codeBrowsingIcon [
"Private - Generated method"
Expand Down Expand Up @@ -184,7 +191,7 @@ StSettingsAbstractPresenter class >> toolsIconContents [
{ #category : 'accessing' }
StSettingsAbstractPresenter >> application [

^ StPharoApplication current
^ self class application
]

{ #category : 'accessing' }
Expand Down
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.
]
135 changes: 107 additions & 28 deletions src/NewTools-SettingsBrowser/StSettingsMainPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,21 @@ Class {
#instVars : [
'toolbarPresenter',
'detailsPresenter',
'mainCategoriesPresenter'
'mainCategoriesPresenter',
'buttonBarPresenter',
'exporter'
],
#category : 'NewTools-SettingsBrowser-UI',
#package : 'NewTools-SettingsBrowser',
#tag : 'UI'
}

{ #category : 'accessing' }
StSettingsMainPresenter class >> application [

^ StPharoApplication current

]

{ #category : 'adding' }
StSettingsMainPresenter class >> descriptionBackgroundColor [

^ Smalltalk ui theme lightBackgroundColor asHexString
]

{ #category : 'class initialization' }
StSettingsMainPresenter class >> initialize [

self application
propertyAt: #settingsTree put: StSettingsTree new;
styleSheet: self styleSheet
]

{ #category : 'world menu' }
StSettingsMainPresenter class >> menuSettingsBrowserCommandOn: aBuilder [
<worldMenu>
Expand Down Expand Up @@ -123,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 @@ -142,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 @@ -151,6 +161,42 @@ StSettingsMainPresenter >> followPath: aStSettingNode in: aCollection [

]

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

super initialize.
self application
propertyAt: #settingsTree ifAbsentPut: StSettingsTree new;
styleSheet: self class styleSheet.
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' }
StSettingsMainPresenter >> initializeFocus [

Expand All @@ -166,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 @@ -179,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 : 'as yet unclassified' }
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
Loading