diff --git a/src/NewTools-SettingsBrowser/StSettingNode.class.st b/src/NewTools-SettingsBrowser/StSettingNode.class.st index 42d7abcc..870a721b 100644 --- a/src/NewTools-SettingsBrowser/StSettingNode.class.st +++ b/src/NewTools-SettingsBrowser/StSettingNode.class.st @@ -9,7 +9,8 @@ Class { 'declaration', 'pragma', 'parentName', - 'model' + 'model', + 'matchBlock' ], #category : 'NewTools-SettingsBrowser-Model', #package : 'NewTools-SettingsBrowser', @@ -103,6 +104,12 @@ StSettingNode >> hasChildren [ ^ self allChildren notEmpty ] +{ #category : 'testing' } +StSettingNode >> hasParent [ + + ^ parentName notNil +] + { #category : 'accessing' } StSettingNode >> item [ @@ -121,11 +128,30 @@ StSettingNode >> label: aString [ declaration label: aString. ] -{ #category : 'testing' } -StSettingNode >> matches: aString [ - "Answer if aString matches any of the receiver's descriptors" - - ^ self label asLowercase beginsWithAnyOf: self descriptors +{ #category : 'accessing' } +StSettingNode >> matchBlock [ + + ^ matchBlock + ifNil: [ + matchBlock := [ : node : pattern | + node label substrings anySatisfy: [ : substr | + substr asLowercase beginsWith: pattern asLowercase ] ] ] +] + +{ #category : 'enumerating' } +StSettingNode >> matches: aString [ + "Recursive search the receiver for aString in its label" + + | result | + result := OrderedCollection new. + self allChildren do: [ :node | + (self matchBlock value: node value: aString) ifTrue: [ + result add: node ]. + + node hasChildren ifTrue: [ + result addAll: (node matches: aString) ] ]. + + ^ result ] { #category : 'accessing' } diff --git a/src/NewTools-SettingsBrowser/StSettingTreeBuilder.class.st b/src/NewTools-SettingsBrowser/StSettingTreeBuilder.class.st index e8bb1449..26e67fb8 100644 --- a/src/NewTools-SettingsBrowser/StSettingTreeBuilder.class.st +++ b/src/NewTools-SettingsBrowser/StSettingTreeBuilder.class.st @@ -11,14 +11,3 @@ StSettingTreeBuilder >> nodeClass [ ^ StSettingNode ] - -{ #category : 'private - tree building' } -StSettingTreeBuilder >> nodeClass: aClass name: aSymbol [ - | node | - node := self nodeClass with: aClass new. - node item name: aSymbol. - node pragma: currentPragma. - node parentName: (currentParent ifNotNil: [currentParent name]). - self nodeList add: node. - ^ (SettingNodeBuilder new) node: node; builder: self; yourself -] diff --git a/src/NewTools-SettingsBrowser/StSettingsAbstractPresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsAbstractPresenter.class.st index 2f43f38a..acf5657c 100644 --- a/src/NewTools-SettingsBrowser/StSettingsAbstractPresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsAbstractPresenter.class.st @@ -6,6 +6,24 @@ Class { #tag : 'UI' } +{ #category : 'callbacks' } +StSettingsAbstractPresenter >> newNodePresenterFrom: aSettingNode level: anInteger [ + + | nodePresenter | + + nodePresenter := self + instantiate: aSettingNode presenterClass + on: aSettingNode. + nodePresenter sectionTitleStyle: self sectionTitleString , anInteger asString. + ^ nodePresenter +] + +{ #category : 'callbacks' } +StSettingsAbstractPresenter >> sectionTitleString [ + + ^ 'sectionTitleL' +] + { #category : 'accessing' } StSettingsAbstractPresenter >> settingsTree [ "Answer the receiver's , the settings model" diff --git a/src/NewTools-SettingsBrowser/StSettingsDetailsPresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsDetailsPresenter.class.st new file mode 100644 index 00000000..35d5fdf9 --- /dev/null +++ b/src/NewTools-SettingsBrowser/StSettingsDetailsPresenter.class.st @@ -0,0 +1,297 @@ +" +It represents a setting category page with setting sections and settings. The page was selected from `StSettingsCategoriesPresenter` and it matches a `StSettingsCategoryItemPresenter`. + +" +Class { + #name : 'StSettingsDetailsPresenter', + #superclass : 'StSettingsAbstractPresenter', + #instVars : [ + 'pageTitle', + 'settingDocPresenter', + 'settingDocLabel', + 'notebook', + 'settingTree' + ], + #category : 'NewTools-SettingsBrowser-UI', + #package : 'NewTools-SettingsBrowser', + #tag : 'UI' +} + +{ #category : 'private' } +StSettingsDetailsPresenter >> activePage [ + + | selectedPage | + + selectedPage := notebook selectedPage. + selectedPage activePresenter + ifNil: [ selectedPage retrievePresenter ]. + ^ selectedPage activePresenter +] + +{ #category : 'callbacks - tabs' } +StSettingsDetailsPresenter >> addDefaultGeneralTabFrom: aStSettingNode [ + "Private - Add General Settings default" + + | generalSettingNode | + + generalSettingNode := self newSettingNode. + generalSettingNode item name: self generalTitle. + generalSettingNode parentName: aStSettingNode name. + notebook addPage: (SpNotebookPage new + icon: (self iconNamed: #smallQuestion); + presenterProvider: [ StSettingsNotebookPageContentPresenter on: generalSettingNode ]; + title: self generalTitle; + yourself). +] + +{ #category : 'callbacks - tabs' } +StSettingsDetailsPresenter >> addHeaderForSettingsWithoutParent: aSpNotebookPage [ + "Private - We add a 'General' header (2nd level) for those nodes without parent other than the root" + + | generalSettingNode generalNodePresenter | + + generalSettingNode := self newGeneralSetting: aSpNotebookPage. + generalNodePresenter := self + newSectionNodePresenterFrom: generalSettingNode + level: 2. + self activePage + add: generalNodePresenter + expand: false +] + +{ #category : 'callbacks - tabs' } +StSettingsDetailsPresenter >> addSearchResultTabFrom: resultStSettingNodes [ + "Private - Add a tab with search results from resultStSettingNodes in the receiver's notebook" + + | rootSearchResultNode rsSettingNodes rsRootResultNode | + + notebook hasPages ifTrue: [ notebook removeAll ]. + + rsSettingNodes := resultStSettingNodes copy asOrderedCollection. + "Create a new settings tree with the results" + rsRootResultNode := StSettingsTree new nodeList: rsSettingNodes; yourself. + "Create a new parent node " + rootSearchResultNode := self newSettingNode + parentName: 'Results'; + model: rsRootResultNode; + yourself. + + "Set the model of each result node" + rsSettingNodes do: [ : snc | + snc + parentName: rootSearchResultNode name; + model: rsRootResultNode ]. + + notebook addPage: (self newResultPageOn: rootSearchResultNode). + self selectFirstPage. + + +] + +{ #category : 'callbacks - tabs' } +StSettingsDetailsPresenter >> addTabsFrom: aStSettingNode [ + + aStSettingNode allChildren do: [ :aSettingNode | + | nodePresenter | + (nodePresenter := self + instantiate: aSettingNode presenterClass + on: aSettingNode) hasChildren + ifTrue: [ + nodePresenter sectionTitleStyle: self sectionTitleString. + notebook addPage: (SpNotebookPage new + icon: (self iconNamed: #smallQuestion); + presenterProvider: [ StSettingsNotebookPageContentPresenter on: aSettingNode ]; + title: aSettingNode label; + yourself) ] ] +] + +{ #category : 'initialization' } +StSettingsDetailsPresenter >> defaultInputPort [ + + ^ SpModelPort newPresenter: self + +] + +{ #category : 'layout' } +StSettingsDetailsPresenter >> defaultLayout [ + + ^ SpBoxLayout newTopToBottom + add: pageTitle expand: false; + add: (SpPanedLayout newVertical + positionOfSlider: 0.85; + add: notebook; + add: (SpBoxLayout newTopToBottom + spacing: 5; + add: settingDocLabel expand: false; + add: settingDocPresenter; + yourself); + yourself); + yourself +] + +{ #category : 'callbacks - tabs' } +StSettingsDetailsPresenter >> generalTitle [ + + ^ 'General' +] + +{ #category : 'initialization' } +StSettingsDetailsPresenter >> initializePresenters [ + + pageTitle := self newLabel. + notebook := self newNotebook + whenSelectedPageChangedDo: [ :presenter | self updateSelectedPage: presenter ]; + yourself. + settingDocLabel := self newLabel + addStyle: 'settingDocTitle'; + yourself. + settingDocPresenter := self newText +] + +{ #category : 'callbacks - tabs' } +StSettingsDetailsPresenter >> newGeneralSetting: aSpNotebookPage [ + + | currentParent generalSettingNode | + + currentParent := aSpNotebookPage activePresenter parentNode. + generalSettingNode := StSettingNode with: PragmaSetting new. + generalSettingNode item name: self generalTitle. + generalSettingNode parentName: (currentParent ifNotNil: [ currentParent name ]). + ^ generalSettingNode +] + +{ #category : 'TOREMOVE' } +StSettingsDetailsPresenter >> newResultPageOn: aStSettingNode [ + + ^ SpNotebookPage new + icon: (self iconNamed: #smallQuestion); + presenterProvider: [ self instantiate: StSettingsNotebookPageContentPresenter on: aStSettingNode ]; + beCloseable; + title: self resultsTitle; + yourself +] + +{ #category : 'callbacks' } +StSettingsDetailsPresenter >> newSectionNodePresenterFrom: aSettingNode level: anInteger [ + "Private - This is a temporary method until finding a proper solution for 'hand-wired' sections, since some settings declarations are not grouped" + + | nodePresenter | + nodePresenter := self + instantiate: StSettingSectionPresenter + on: aSettingNode. + nodePresenter sectionTitleStyle: self sectionTitleString , anInteger asString. + ^ nodePresenter +] + +{ #category : 'callbacks - tabs' } +StSettingsDetailsPresenter >> newSettingNode [ + + ^ StSettingNode with: PragmaSetting new. +] + +{ #category : 'initialization' } +StSettingsDetailsPresenter >> notebook [ + + ^ notebook + +] + +{ #category : 'callbacks - tabs' } +StSettingsDetailsPresenter >> resultsTitle [ + + ^ 'Results' +] + +{ #category : 'callbacks' } +StSettingsDetailsPresenter >> selectFirstPage [ + + self notebook selectPageIndex: 1. + self updateSelectedPage: self notebook selectedPage. +] + +{ #category : 'accessing - model' } +StSettingsDetailsPresenter >> setModel: aNode [ + "Private - Set the receiver's content iterating recursively starting from aNode" + + settingTree := aNode model childrenOf: aNode. + pageTitle + label: aNode label; + addStyle: 'pageTitle'. + notebook removeAll. + self updatePages: aNode. + +] + +{ #category : 'callbacks - tabs' } +StSettingsDetailsPresenter >> updatePages: aStSettingNode [ + "Private - Recursively iterate aStSettingNode children using anInteger as 'level' indicator for title styling purposes" + + self addDefaultGeneralTabFrom: aStSettingNode. + self addTabsFrom: aStSettingNode. +] + +{ #category : 'callbacks' } +StSettingsDetailsPresenter >> updatePresenterGeneralNodes: aCollection [ + + | nodePresenter | + aCollection do: [ :settingNode | + nodePresenter := self newNodePresenterFrom: settingNode level: 2. + "Here the owner of each node presenter will be updated to a StSettingsNotebookPageContentPresenter" + self activePage add: nodePresenter expand: false ] +] + +{ #category : 'callbacks' } +StSettingsDetailsPresenter >> updatePresenterTree: aStSettingNode level: anInteger [ + "Private - Recursively iterate aStSettingNode children using anInteger as 'level' indicator for title styling purposes" + + aStSettingNode allChildren do: [ :aSettingNode | + | nodePresenter | + nodePresenter := self + newNodePresenterFrom: aSettingNode + level: anInteger. + "The activePage here should be a StSettingsNotebookPageContentPresenter" + self activePage add: nodePresenter expand: false. + self updatePresenterTree: aSettingNode level: anInteger + 1 ]. + + +] + +{ #category : 'callbacks - tabs' } +StSettingsDetailsPresenter >> updateSelectedPage: aSpNotebookPage [ + "Private - Update the receiver's notebook with aSpNotebookPage. The first time the notebook is opened, a #selectedPage event is triggered and aSpNotebookPage will be nil" + + aSpNotebookPage ifNotNil: [ + aSpNotebookPage activePresenter ifNotNil: [ : activePresenter | activePresenter removeAll ]. + self updateSelectedSpecialCases: aSpNotebookPage. + self updateSelectedPageTree: aSpNotebookPage ] +] + +{ #category : 'private' } +StSettingsDetailsPresenter >> updateSelectedPageTree: aSpNotebookPage [ + + | updatedPage | + + updatedPage := aSpNotebookPage activePresenter + ifNil: [ aSpNotebookPage retrievePresenter ] + ifNotNil: [ aSpNotebookPage activePresenter ]. + + self updatePresenterTree: updatedPage parentNode level: 2 +] + +{ #category : 'callbacks - tabs' } +StSettingsDetailsPresenter >> updateSelectedSpecialCases: aSpNotebookPage [ + "Do not add a 'General' header if we are already in the General tab" + + aSpNotebookPage title = self resultsTitle + ifFalse: [ + aSpNotebookPage title = self generalTitle + ifFalse: [ self addHeaderForSettingsWithoutParent: aSpNotebookPage ] + ifTrue: [ self updatePresenterGeneralNodes: (settingTree reject: [ : node | node hasChildren ]) ] ] +] + +{ #category : 'callbacks' } +StSettingsDetailsPresenter >> updateSetting: labelString helpText: settingHelpString [ + + settingDocLabel label: labelString. + settingDocPresenter text: settingHelpString. +] diff --git a/src/NewTools-SettingsBrowser/StSettingsMainPresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsMainPresenter.class.st index 76fd38db..da32e9e9 100644 --- a/src/NewTools-SettingsBrowser/StSettingsMainPresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsMainPresenter.class.st @@ -11,8 +11,7 @@ Class { #instVars : [ 'toolbarPresenter', 'detailsPresenter', - 'mainCategoriesPresenter', - 'buttonBarPresenter' + 'mainCategoriesPresenter' ], #category : 'NewTools-SettingsBrowser-UI', #package : 'NewTools-SettingsBrowser', @@ -31,6 +30,7 @@ StSettingsMainPresenter >> connectPresenters [ mainCategoriesPresenter transmitTo: detailsPresenter transform: [ : aCategoryItemPresenter | aCategoryItemPresenter node ] + postTransmission: [ : selectedPage | selectedPage selectFirstPage ] ] { #category : 'layout' } @@ -43,20 +43,17 @@ StSettingsMainPresenter >> defaultInputPort [ { #category : 'layout' } StSettingsMainPresenter >> defaultLayout [ - ^ 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 + ^ 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 ] { #category : 'ports' } @@ -65,46 +62,13 @@ StSettingsMainPresenter >> defaultOutputPort [ ^ mainCategoriesPresenter ] -{ #category : 'export' } -StSettingsMainPresenter >> exportSettings [ - | nodes actions | - - nodes := self settingsTree nodeList. - actions := nodes - collect: [ : e | e item exportSettingAction ] - thenReject: [ : e | e isNil ]. - self - exportAllSettings: actions - by: 50 - withBasename: 'exported_settings'. - - buttonBarPresenter enable -] +{ #category : 'searching' } +StSettingsMainPresenter >> followPath: aStSettingNode in: aCollection [ + + ^ aStSettingNode hasParent + ifTrue: [ (self followPath: aStSettingNode parentNode in: aCollection) ] + ifFalse: [ aCollection add: aStSettingNode ]. -{ #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' } @@ -121,8 +85,7 @@ StSettingsMainPresenter >> initializePresenters [ toolbarPresenter := self instantiate: StSettingsToolbarPresenter on: self. mainCategoriesPresenter := self instantiate: StSettingsCategoriesPresenter on: self. - detailsPresenter := self instantiate: StSettingsPagePresenter on: self. - self initializeButtonBar. + detailsPresenter := self instantiate: StSettingsDetailsPresenter on: self. self initializeFocus. ] @@ -136,10 +99,8 @@ StSettingsMainPresenter >> initializeWindow: aWindowPresenter [ centered ] -{ #category : 'menu' } -StSettingsMainPresenter >> loadSettings [ - "Load the settings from the system settings file, if exists" +{ #category : 'initialization' } +StSettingsMainPresenter >> pagePresenter [ - self settingsTree hasSettingsFile - ifTrue: [ self settingsTree updateSettingNodes ] + ^ detailsPresenter ] diff --git a/src/NewTools-SettingsBrowser/StSettingsPageNotebookPresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsNotebookPageContentPresenter.class.st similarity index 57% rename from src/NewTools-SettingsBrowser/StSettingsPageNotebookPresenter.class.st rename to src/NewTools-SettingsBrowser/StSettingsNotebookPageContentPresenter.class.st index 609e9225..53488be3 100644 --- a/src/NewTools-SettingsBrowser/StSettingsPageNotebookPresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsNotebookPageContentPresenter.class.st @@ -1,5 +1,8 @@ +" +This is the **provider** of a `SpNotebookPage` in a category of the Settings Browser. The notebook pages are contained in a `StSettingsDetailsPresenter`. +" Class { - #name : 'StSettingsPageNotebookPresenter', + #name : 'StSettingsNotebookPageContentPresenter', #superclass : 'SpPresenter', #instVars : [ 'settingsBox', @@ -11,20 +14,20 @@ Class { } { #category : 'adding' } -StSettingsPageNotebookPresenter >> add: aStSettingSectionPresenter expand: aBoolean [ - +StSettingsNotebookPageContentPresenter >> add: aStSettingSectionPresenter expand: aBoolean [ + settingsBox add: aStSettingSectionPresenter expand: aBoolean ] { #category : 'layout' } -StSettingsPageNotebookPresenter >> defaultLayout [ +StSettingsNotebookPageContentPresenter >> defaultLayout [ ^ SpScrollableLayout with: settingsBox ] { #category : 'initialization' } -StSettingsPageNotebookPresenter >> initializePresenters [ +StSettingsNotebookPageContentPresenter >> initializePresenters [ settingsBox := SpBoxLayout newTopToBottom spacing: 5; @@ -32,20 +35,20 @@ StSettingsPageNotebookPresenter >> initializePresenters [ ] { #category : 'accessing' } -StSettingsPageNotebookPresenter >> pagePresenter [ +StSettingsNotebookPageContentPresenter >> pagePresenter [ "Answer the receiver's " ^ self owner owner ] { #category : 'accessing' } -StSettingsPageNotebookPresenter >> parentNode [ +StSettingsNotebookPageContentPresenter >> parentNode [ ^ parentNode ] { #category : 'printing' } -StSettingsPageNotebookPresenter >> printOn: aStream [ +StSettingsNotebookPageContentPresenter >> printOn: aStream [ settingsBox ifNotNil: [ : sb | @@ -58,14 +61,14 @@ StSettingsPageNotebookPresenter >> printOn: aStream [ ] { #category : 'removing' } -StSettingsPageNotebookPresenter >> removeAll [ +StSettingsNotebookPageContentPresenter >> removeAll [ "Remove all presenters in the layout" settingsBox removeAll ] { #category : 'accessing - model' } -StSettingsPageNotebookPresenter >> setModelBeforeInitialization: aNode [ +StSettingsNotebookPageContentPresenter >> setModelBeforeInitialization: aNode [ parentNode := aNode ] diff --git a/src/NewTools-SettingsBrowser/StSettingsPagePresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsPagePresenter.class.st deleted file mode 100644 index ef8848f0..00000000 --- a/src/NewTools-SettingsBrowser/StSettingsPagePresenter.class.st +++ /dev/null @@ -1,214 +0,0 @@ -" -It represents a setting category page with setting sections and settings. The page was selected from `StSettingsCategoriesPresenter` and it matches a `StSettingsCategoryItemPresenter`. - -" -Class { - #name : 'StSettingsPagePresenter', - #superclass : 'StSettingsAbstractPresenter', - #instVars : [ - 'pageTitle', - 'settingDocPresenter', - 'settingDocLabel', - 'notebook', - 'settingTree' - ], - #category : 'NewTools-SettingsBrowser-UI', - #package : 'NewTools-SettingsBrowser', - #tag : 'UI' -} - -{ #category : 'private' } -StSettingsPagePresenter >> activePage [ - - ^ notebook selectedPage activePresenter -] - -{ #category : 'callbacks' } -StSettingsPagePresenter >> addDefaultGeneralTabFrom: aStSettingNode [ - "Private - Add General Settings default" - - | generalSettingNode | - - generalSettingNode := StSettingNode with: PragmaSetting new. - generalSettingNode item name: self generalTitle. - generalSettingNode parentName: aStSettingNode name. - notebook addPage: (SpNotebookPage new - icon: (self iconNamed: #smallQuestion); - presenterProvider: [ StSettingsPageNotebookPresenter on: generalSettingNode ]; - title: self generalTitle; - yourself). -] - -{ #category : 'callbacks' } -StSettingsPagePresenter >> addHeaderForSettingsWithoutParent: aSpNotebookPage [ - "Private - We add a 'General' header (2nd level) for those nodes without parent other than the root" - - | generalSettingNode generalNodePresenter | - - generalSettingNode := self newGeneralSetting: aSpNotebookPage. - generalNodePresenter := self - newSectionNodePresenterFrom: generalSettingNode - level: 2. - self activePage - add: generalNodePresenter - expand: false -] - -{ #category : 'callbacks' } -StSettingsPagePresenter >> addTabsFrom: aStSettingNode [ - - aStSettingNode allChildren do: [ :aSettingNode | - | nodePresenter | - (nodePresenter := self - instantiate: aSettingNode presenterClass - on: aSettingNode) hasChildren - ifTrue: [ - nodePresenter sectionTitleStyle: 'sectionTitleL1'. - notebook addPage: (SpNotebookPage new - icon: (self iconNamed: #smallQuestion); - presenterProvider: [ StSettingsPageNotebookPresenter on: aSettingNode ]; - title: aSettingNode label; - yourself) ] ] -] - -{ #category : 'initialization' } -StSettingsPagePresenter >> defaultInputPort [ - - ^ SpModelPort newPresenter: self - -] - -{ #category : 'layout' } -StSettingsPagePresenter >> defaultLayout [ - - ^ SpBoxLayout newTopToBottom - add: pageTitle expand: false; - add: (SpPanedLayout newVertical - positionOfSlider: 0.85; - add: notebook; - add: (SpBoxLayout newTopToBottom - spacing: 5; - add: settingDocLabel expand: false; - add: settingDocPresenter; - yourself); - yourself); - yourself -] - -{ #category : 'callbacks' } -StSettingsPagePresenter >> generalTitle [ - - ^ 'General' -] - -{ #category : 'initialization' } -StSettingsPagePresenter >> initializePresenters [ - - pageTitle := self newLabel. - notebook := self newNotebook - whenSelectedPageChangedDo: [ :presenter | self updateSelectedPage: presenter ]; - yourself. - settingDocLabel := self newLabel - addStyle: 'settingDocTitle'; - yourself. - settingDocPresenter := self newText -] - -{ #category : 'callbacks' } -StSettingsPagePresenter >> newGeneralSetting: aSpNotebookPage [ - - | currentParent generalSettingNode | - - currentParent := aSpNotebookPage activePresenter parentNode. - generalSettingNode := StSettingNode with: PragmaSetting new. - generalSettingNode item name: self generalTitle. - generalSettingNode parentName: (currentParent ifNotNil: [ currentParent name ]). - ^ generalSettingNode -] - -{ #category : 'callbacks' } -StSettingsPagePresenter >> newNodePresenterFrom: aSettingNode level: anInteger [ - - | nodePresenter | - nodePresenter := self - instantiate: aSettingNode presenterClass - on: aSettingNode. - nodePresenter sectionTitleStyle: 'sectionTitleL' , anInteger asString. - ^ nodePresenter -] - -{ #category : 'callbacks' } -StSettingsPagePresenter >> newSectionNodePresenterFrom: aSettingNode level: anInteger [ - "Private - This is a temporary method until finding a proper solution for 'hand-wired' sections, since some settings declarations are not grouped" - - | nodePresenter | - nodePresenter := self - instantiate: StSettingSectionPresenter - on: aSettingNode. - nodePresenter sectionTitleStyle: 'sectionTitleL' , anInteger asString. - ^ nodePresenter -] - -{ #category : 'accessing - model' } -StSettingsPagePresenter >> setModel: aNode [ - "Private - Set the receiver's content iterating recursively starting from aNode" - - settingTree := aNode model childrenOf: aNode. - pageTitle - label: aNode label; - addStyle: 'pageTitle'. - notebook removeAll. - self updatePages: aNode. - -] - -{ #category : 'callbacks' } -StSettingsPagePresenter >> updatePages: aStSettingNode [ - "Private - Recursively iterate aStSettingNode children using anInteger as 'level' indicator for title styling purposes" - - self addDefaultGeneralTabFrom: aStSettingNode. - self addTabsFrom: aStSettingNode. -] - -{ #category : 'callbacks' } -StSettingsPagePresenter >> updatePresenterGeneralNodes: aCollection [ - - | nodePresenter | - aCollection do: [ :settingNode | - nodePresenter := self newNodePresenterFrom: settingNode level: 2. - self activePage add: nodePresenter expand: false ] -] - -{ #category : 'callbacks' } -StSettingsPagePresenter >> updatePresenterTree: aStSettingNode level: anInteger [ - "Private - Recursively iterate aStSettingNode children using anInteger as 'level' indicator for title styling purposes" - - aStSettingNode allChildren do: [ :aSettingNode | - | nodePresenter | - nodePresenter := self - newNodePresenterFrom: aSettingNode - level: anInteger. - self activePage add: nodePresenter expand: false. - self updatePresenterTree: aSettingNode level: anInteger + 1 ] -] - -{ #category : 'callbacks' } -StSettingsPagePresenter >> updateSelectedPage: aSpNotebookPage [ - - aSpNotebookPage ifNotNil: [ - | tabNode | - aSpNotebookPage activePresenter removeAll. - "Do not add a 'General' header if we are already in the General tab" - aSpNotebookPage title = self generalTitle - ifFalse: [ self addHeaderForSettingsWithoutParent: aSpNotebookPage ] - ifTrue: [ self updatePresenterGeneralNodes: (settingTree reject: [ : node | node hasChildren ]) ]. - tabNode := aSpNotebookPage activePresenter parentNode. - self updatePresenterTree: tabNode level: 2 ] -] - -{ #category : 'callbacks' } -StSettingsPagePresenter >> updateSetting: labelString helpText: settingHelpString [ - - settingDocLabel label: labelString. - settingDocPresenter text: settingHelpString. -] diff --git a/src/NewTools-SettingsBrowser/StSettingsToolbarPresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsToolbarPresenter.class.st index 354cfc94..15b9cae2 100644 --- a/src/NewTools-SettingsBrowser/StSettingsToolbarPresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsToolbarPresenter.class.st @@ -27,32 +27,32 @@ StSettingsToolbarPresenter >> defaultLayout [ yourself ] +{ #category : 'initialization' } +StSettingsToolbarPresenter >> doSettingSearch: aString [ + "Private - Callback to search aString in the receiver's descriptions and label. For performance reasons, start to search from the third character typed " + + | colOfStSettingNode mainPresenter | + aString + ifNotEmpty: [ searchButtonPresenter enable ] + ifEmpty: [ searchButtonPresenter disable ]. + aString size >= 3 + ifFalse: [ ^ self ]. + + colOfStSettingNode := self settingsTree processSearch: aString. + mainPresenter := self owner. + mainPresenter pagePresenter addSearchResultTabFrom: colOfStSettingNode. +] + { #category : 'initialization' } StSettingsToolbarPresenter >> initializePresenters [ searchInputPresenter := self newSearchInput placeholder: 'Find in settings'; - whenTextChangedDo: [ : aString | - aString - ifNotEmpty: [ searchButtonPresenter enable ] - ifEmpty: [ searchButtonPresenter disable ]. - self updateSearch: aString ]; + whenTextChangedDo: [ : aString | self doSettingSearch: aString trimmed ]; yourself. searchButtonPresenter := self newButton iconName: #smallFind; disable; - action: [ self updateSearch: searchInputPresenter text ]; + action: [ self doSettingSearch: searchInputPresenter text trimmed ]; yourself. ] - -{ #category : 'initialization' } -StSettingsToolbarPresenter >> updateSearch: aString [ - "Private - Callback to search aString in the receiver's descriptions and label. For performance reasons, start to search from the third character typed " - - aString size >= 2 - ifFalse: [ ^ self ]. - self flag: #ToDo. - self settingsTree - processSearch: aString - on: self -] diff --git a/src/NewTools-SettingsBrowser/StSettingsTree.class.st b/src/NewTools-SettingsBrowser/StSettingsTree.class.st index 60e4da60..8b5e5002 100644 --- a/src/NewTools-SettingsBrowser/StSettingsTree.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsTree.class.st @@ -50,6 +50,13 @@ StSettingsTree >> newTreeHolder [ yourself ] +{ #category : 'accessing' } +StSettingsTree >> nodeList [ + + ^ nodeList + ifNil: [ self newSettingTreeBuilderNodes ] +] + { #category : 'accessing' } StSettingsTree >> nodeList: aCollection [ @@ -57,10 +64,12 @@ StSettingsTree >> nodeList: aCollection [ ] { #category : 'private - queries' } -StSettingsTree >> processSearch: aString on: aStSettingsToolbarPresenter [ +StSettingsTree >> processSearch: aString [ + "Recursively collect the nodes matching aString in the receiver" - ^ self treeRoots select: [ : settingNode | - settingNode matches: aString ] + ^ self treeRoots + flatCollect: [ : settingNode | settingNode matches: aString ] + as: Set ] { #category : 'instance creation' }