Skip to content

Commit

Permalink
add settings presenter
Browse files Browse the repository at this point in the history
  • Loading branch information
demarey committed Jul 4, 2024
1 parent 81fd0e8 commit 79fe5b4
Show file tree
Hide file tree
Showing 7 changed files with 676 additions and 0 deletions.
151 changes: 151 additions & 0 deletions src/PharoLauncher-Core/PharoLauncherSettings.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
"
I manage Pharo Launcher settings.
I reuse settings pragma already defined and provide a nice API to set settings.
I'm used by the Pharo Launcher settings presenter.
"
Class {
#name : 'PharoLauncherSettings',
#superclass : 'Object',
#category : 'PharoLauncher-Core-Settings',
#package : 'PharoLauncher-Core',
#tag : 'Settings'
}

{ #category : 'accessing' }
PharoLauncherSettings >> checkTemplateSourcesUpdate: aBoolean [

self setValueOfDeclarationNamed: #shouldCheckTemplateSourcesUpdate with: aBoolean
]

{ #category : 'accessing' }
PharoLauncherSettings >> clearTemplatesAtStartup: aBoolean [

self setValueOfDeclarationNamed: #templatesClearedOnStartup with: aBoolean
]

{ #category : 'private' }
PharoLauncherSettings >> declarationNamed: aSettingIdentifier [

^ (self settingNodeNamed: aSettingIdentifier) declaration
]

{ #category : 'accessing' }
PharoLauncherSettings >> enableDevelopmentEnvironment: aBoolean [

self setValueOfDeclarationNamed: #developmentEnvironmentEnabled with: aBoolean
]

{ #category : 'resetting' }
PharoLauncherSettings >> hardResetPersistanceState [

PharoLauncherApplication hardResetPersistanceState: true
]

{ #category : 'accessing' }
PharoLauncherSettings >> imagesLocation: aString [

self setValueOfDeclarationNamed: #locationString with: aString
]

{ #category : 'accessing' }
PharoLauncherSettings >> initializationScriptsLocation: aFileReference [

self setValueOfDeclarationNamed: #initializationScriptsLocation with: aFileReference
]

{ #category : 'accessing' }
PharoLauncherSettings >> launchInALoginShell: aBoolean [

self setValueOfDeclarationNamed: #launchInALoginShell with: aBoolean
]

{ #category : 'building' }
PharoLauncherSettings >> newCheckBoxFor: aSettingIdentifier presenter: aPresenter [
| declaration |

declaration := self declarationNamed: aSettingIdentifier.
^ aPresenter newCheckBox
help: declaration description;
state: (self valueOfDeclarationNamed: aSettingIdentifier);
whenChangedDo: [ :state | self setValueOfDeclarationNamed: aSettingIdentifier with: state ]

]

{ #category : 'instance creation' }
PharoLauncherSettings >> newTextInputFor: aSettingIdentifier presenter: aPresenter [
| declaration |

declaration := self declarationNamed: aSettingIdentifier.
^ aPresenter newTextInput
help: declaration description;
text: (self valueOfDeclarationNamed: aSettingIdentifier);
whenChangedDo: [ :text | self setValueOfDeclarationNamed: aSettingIdentifier with: text ]
]

{ #category : 'accessing' }
PharoLauncherSettings >> quitOnLaunch: aBoolean [

self setValueOfDeclarationNamed: #quitOnLaunch with: aBoolean
]

{ #category : 'private' }
PharoLauncherSettings >> setValueOfDeclarationNamed: aName with: anArgument [
| declaration |

declaration := self declarationNamed: aName.
declaration settingReceiver perform: declaration setSelector with: anArgument.

]

{ #category : 'private' }
PharoLauncherSettings >> settingNodeNamed: aSettingIdentifier [

^ self settingNodes detect: [ :node | node declaration name = aSettingIdentifier ]
]

{ #category : 'private' }
PharoLauncherSettings >> settingNodes [
^ StSettingsTree new
acceptableKeywords: { #pharoLauncherSettings };
newSettingTreeBuilderNodes
]

{ #category : 'accessing' }
PharoLauncherSettings >> sourcesFileLocation: aString [

self setValueOfDeclarationNamed: #launcherCoreDirString with: aString
]

{ #category : 'accessing' }
PharoLauncherSettings >> sourcesUrl: aString [

self setValueOfDeclarationNamed: #sourcesUrl with: aString
]

{ #category : 'ston persistence' }
PharoLauncherSettings >> stonOn: stonWriter [

^ (StoredSettingsFactory new fromSettingNodes: self settingNodes) asArray
stonOn: stonWriter
]

{ #category : 'private' }
PharoLauncherSettings >> valueOfDeclarationNamed: aName [
| declaration |

declaration := self declarationNamed: aName.
^ declaration settingReceiver perform: declaration getSelector

]

{ #category : 'accessing' }
PharoLauncherSettings >> vmsLocation: aFileReference [

self setValueOfDeclarationNamed: #vmStoreString with: aFileReference
]

{ #category : 'accessing' }
PharoLauncherSettings >> warnOnArchMismatch: aBoolean [

self setValueOfDeclarationNamed: #warnOnArchMismatch with: aBoolean
]
40 changes: 40 additions & 0 deletions src/PharoLauncher-Spec2/PhLAppearanceSettingsPresenter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Class {
#name : 'PhLAppearanceSettingsPresenter',
#superclass : 'SpPresenter',
#instVars : [
'lightThemePresenter',
'darkThemePresenter'
],
#category : 'PharoLauncher-Spec2',
#package : 'PharoLauncher-Spec2'
}

{ #category : 'instance creation' }
PhLAppearanceSettingsPresenter class >> open [

<script>

^ self new open
]

{ #category : 'layout' }
PhLAppearanceSettingsPresenter >> defaultLayout [

^ SpBoxLayout newTopToBottom
add: (SpBoxLayout newLeftToRight
spacing: 10;
add: lightThemePresenter;
add: darkThemePresenter;
yourself)
expand: false;
vAlignCenter
]

{ #category : 'layout' }
PhLAppearanceSettingsPresenter >> initializePresenters [
| welcomePresenter |

welcomePresenter := StWelcomeSetupPresenter new.
lightThemePresenter := welcomePresenter newThemePresenter: StWelcomeTheme light.
darkThemePresenter := welcomePresenter newThemePresenter: StWelcomeTheme dark.
]
152 changes: 152 additions & 0 deletions src/PharoLauncher-Spec2/PhLGeneralSettingsPresenter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
Class {
#name : 'PhLGeneralSettingsPresenter',
#superclass : 'SpPresenterWithModel',
#traits : 'TPhLInteractionTrait',
#classTraits : 'TPhLInteractionTrait classTrait',
#instVars : [
'clearTemplatesSwitch',
'quitOnLaunchSwitch',
'launchFromALoginShellSwitch',
'warnOnImageArchMisMatchSwitch',
'checkForTemplateSourcesUpdateSwitch',
'enableDevEnvironmentSwitch',
'hardResetPersistentStateButton',
'templateSourcesUrlInput',
'sourcesFileLocationInput',
'imagesLocationInput',
'imagesInitScriptsLocationInput',
'vmsLocationInput',
'sourcesFileLocationButton',
'imagesLocationButton',
'imagesInitScriptsLocationButton',
'vmsLocationButton'
],
#category : 'PharoLauncher-Spec2',
#package : 'PharoLauncher-Spec2'
}

{ #category : 'instance creation' }
PhLGeneralSettingsPresenter class >> open [
<script>

^ (self on: PharoLauncherSettings new) open
]

{ #category : 'initialization' }
PhLGeneralSettingsPresenter >> chooseDirectoryFor: anInputTextPresenter [

| directory |
directory := self newFileRequest
currentFolder: FileLocator launcherUserFilesLocation;
chooseDirectory.
directory ifNil: [ ^ self ].

anInputTextPresenter text: directory asFileReference fullName
]

{ #category : 'layout' }
PhLGeneralSettingsPresenter >> defaultLayout [

^ SpBoxLayout newTopToBottom
spacing: 15;
add: (SpBoxLayout newLeftToRight
add: 'Check for template sources update?';
add: checkForTemplateSourcesUpdateSwitch;
yourself) expand: false;
add: (SpBoxLayout newLeftToRight
add: 'Templates cleared at startup';
add: clearTemplatesSwitch;
yourself) expand: false;
add: (SpBoxLayout newLeftToRight
add: 'Quit On Launch';
add: quitOnLaunchSwitch;
yourself) expand: false;
add: (SpBoxLayout newLeftToRight
add: 'Launch image from a login shell';
add: launchFromALoginShellSwitch;
yourself) expand: false;
add: (SpBoxLayout newLeftToRight
add: 'Warn on image architecture mismatch?';
add: warnOnImageArchMisMatchSwitch;
yourself) expand: false;
add: (SpBoxLayout newLeftToRight
add: 'Enable development environment';
add: enableDevEnvironmentSwitch;
yourself) expand: false;

add: 'Template sources Url' expand: false;
add: (SpBoxLayout newLeftToRight
add: templateSourcesUrlInput;
yourself) expand: false;
add: 'Location of template sources file' expand: false;
add: (SpBoxLayout newLeftToRight
spacing: 5;
add: sourcesFileLocationInput;
add: sourcesFileLocationButton expand: false;
yourself) expand: false;
add: 'Location of your images' expand: false;
add: (SpBoxLayout newLeftToRight
spacing: 5;
add: imagesLocationInput;
add: imagesLocationButton expand: false;
yourself) expand: false;
add: 'Location of your image initialization scripts' expand: false;
add: (SpBoxLayout newLeftToRight
spacing: 5;
add: imagesInitScriptsLocationInput;
add: imagesInitScriptsLocationButton expand: false;
yourself) expand: false;
add: 'VMs Directory' expand: false;
add: (SpBoxLayout newLeftToRight
spacing: 5;
add: vmsLocationInput;
add: vmsLocationButton expand: false;
yourself) expand: false;
add: hardResetPersistentStateButton expand: false;
yourself
]

{ #category : 'initialization' }
PhLGeneralSettingsPresenter >> initializePresenters [

clearTemplatesSwitch := self settings newCheckBoxFor: #templatesClearedOnStartup presenter: self.
quitOnLaunchSwitch := self settings newCheckBoxFor: #quitOnLaunch presenter: self.
launchFromALoginShellSwitch := self settings newCheckBoxFor: #launchInALoginShell presenter: self.
warnOnImageArchMisMatchSwitch := self settings newCheckBoxFor: #warnOnArchMismatch presenter: self.
checkForTemplateSourcesUpdateSwitch := self settings newCheckBoxFor: #shouldCheckTemplateSourcesUpdate presenter: self.
enableDevEnvironmentSwitch := self settings newCheckBoxFor: #developmentEnvironmentEnabled presenter: self.

templateSourcesUrlInput := self settings newTextInputFor: #sourcesUrl presenter: self.
sourcesFileLocationInput := (self settings newTextInputFor: #launcherCoreDirString presenter: self)
beNotEditable;
yourself.
sourcesFileLocationButton := self newButton
icon: (self iconNamed: #open);
action: [ self chooseDirectoryFor: sourcesFileLocationInput ];
yourself.
imagesLocationInput := self settings newTextInputFor: #locationString presenter: self.
imagesLocationButton := self newButton
icon: (self iconNamed: #open);
action: [ self chooseDirectoryFor: imagesLocationInput ];
yourself.
imagesInitScriptsLocationInput := self settings newTextInputFor: #initializationScriptsLocation presenter: self..
imagesInitScriptsLocationButton := self newButton
icon: (self iconNamed: #open);
action: [ self chooseDirectoryFor: imagesInitScriptsLocationInput ];
yourself.
vmsLocationInput := self settings newTextInputFor: #vmStoreString presenter: self.
vmsLocationButton := self newButton
icon: (self iconNamed: #open);
action: [ self chooseDirectoryFor: vmsLocationInput ];
yourself.

hardResetPersistentStateButton := self newButton
label: 'Hard reset persistent state'.

]

{ #category : 'accessing' }
PhLGeneralSettingsPresenter >> settings [

^ self model
]
Loading

0 comments on commit 79fe5b4

Please sign in to comment.