From d2fb3cf4906651c95e70a5e8f9e8b07ce35c8c53 Mon Sep 17 00:00:00 2001 From: Hernan Morales Durand <4825959+hernanmd@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:31:09 +0200 Subject: [PATCH 1/7] Working in the search feature (WiP) --- .../StSettingNode.class.st | 35 +++++++++++++++---- .../StSettingsMainPresenter.class.st | 28 +++++++++++++++ .../StSettingsToolbarPresenter.class.st | 34 +++++++++--------- .../StSettingsTree.class.st | 6 ++-- 4 files changed, 76 insertions(+), 27 deletions(-) diff --git a/src/NewTools-SettingsBrowser/StSettingNode.class.st b/src/NewTools-SettingsBrowser/StSettingNode.class.st index 42d7abcc..f2e11238 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,27 @@ 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 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/StSettingsMainPresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsMainPresenter.class.st index a6193670..db3b33a0 100644 --- a/src/NewTools-SettingsBrowser/StSettingsMainPresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsMainPresenter.class.st @@ -18,6 +18,25 @@ Class { #tag : 'UI' } +{ #category : 'adding' } +StSettingsMainPresenter >> addSearchResults: aCollection [ + "Process the search results in aCollection. + If there is only a single item as result, we follow the path to that node. + Otherwise, we present a new tab with the results" + + | results | + + results := OrderedCollection new. + aCollection size = 1 + ifTrue: [ + | singleResult | + singleResult := aCollection anyOne. + results add: singleResult. + self followPath: singleResult in: results ] + ifFalse: [ self halt ]. + self halt. +] + { #category : 'initialization' } StSettingsMainPresenter >> browserTitle [ @@ -61,6 +80,15 @@ StSettingsMainPresenter >> defaultOutputPort [ ^ mainCategoriesPresenter ] +{ #category : 'searching' } +StSettingsMainPresenter >> followPath: aStSettingNode in: aCollection [ + + ^ aStSettingNode hasParent + ifTrue: [ (self followPath: aStSettingNode parentNode in: aCollection) ] + ifFalse: [ aCollection add: aStSettingNode ]. + +] + { #category : 'initialization' } StSettingsMainPresenter >> initializeFocus [ diff --git a/src/NewTools-SettingsBrowser/StSettingsToolbarPresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsToolbarPresenter.class.st index 354cfc94..1d59e96e 100644 --- a/src/NewTools-SettingsBrowser/StSettingsToolbarPresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsToolbarPresenter.class.st @@ -27,32 +27,30 @@ 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 " + + aString + ifNotEmpty: [ searchButtonPresenter enable ] + ifEmpty: [ searchButtonPresenter disable ]. + aString size >= 3 + ifFalse: [ ^ self ]. + + self owner addSearchResults: (self settingsTree processSearch: aString) + +] + { #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 899d7767..37e38452 100644 --- a/src/NewTools-SettingsBrowser/StSettingsTree.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsTree.class.st @@ -50,10 +50,10 @@ 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 ] ] { #category : 'instance creation' } From ffd57faa2476e67668d599e8b2e0ff3399b6a278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hern=C3=A1n=20Morales=20Durand?= Date: Sun, 20 Oct 2024 14:05:04 +0200 Subject: [PATCH 2/7] WiP - Adding search feature to settings browser --- .../StSettingsAbstractPresenter.class.st | 11 +++++ .../StSettingsMainPresenter.class.st | 33 +++++++++++-- .../StSettingsPageNotebookPresenter.class.st | 18 ++++++- .../StSettingsPagePresenter.class.st | 49 ++++++++++++------- .../StSettingsToolbarPresenter.class.st | 8 ++- .../StSettingsTree.class.st | 4 +- 6 files changed, 97 insertions(+), 26 deletions(-) diff --git a/src/NewTools-SettingsBrowser/StSettingsAbstractPresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsAbstractPresenter.class.st index 2f43f38a..088a4036 100644 --- a/src/NewTools-SettingsBrowser/StSettingsAbstractPresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsAbstractPresenter.class.st @@ -6,6 +6,17 @@ Class { #tag : 'UI' } +{ #category : 'callbacks' } +StSettingsAbstractPresenter >> newNodePresenterFrom: aSettingNode level: anInteger [ + + | nodePresenter | + nodePresenter := self + instantiate: aSettingNode presenterClass + on: aSettingNode. + nodePresenter sectionTitleStyle: 'sectionTitleL' , anInteger asString. + ^ nodePresenter +] + { #category : 'accessing' } StSettingsAbstractPresenter >> settingsTree [ "Answer the receiver's , the settings model" diff --git a/src/NewTools-SettingsBrowser/StSettingsMainPresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsMainPresenter.class.st index db3b33a0..b3abf15a 100644 --- a/src/NewTools-SettingsBrowser/StSettingsMainPresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsMainPresenter.class.st @@ -27,14 +27,33 @@ StSettingsMainPresenter >> addSearchResults: aCollection [ | results | results := OrderedCollection new. - aCollection size = 1 + ^ aCollection size = 1 ifTrue: [ | singleResult | singleResult := aCollection anyOne. results add: singleResult. - self followPath: singleResult in: results ] - ifFalse: [ self halt ]. - self halt. + self followPath: singleResult in: results. + results ] + ifFalse: [ self addTab: aCollection ]. +] + +{ #category : 'adding' } +StSettingsMainPresenter >> addTab: aCollection [ + + | newPage | + newPage := SpNotebookPage new + icon: (self iconNamed: #smallQuestion); + presenterProvider: [ StSettingsPageNotebookPresenter on: + ((StSettingNode with: PragmaSetting new) item name: 'temp') ]; + title: 'Search Results'; + yourself. + + aCollection do: [ :aStSettingNode | + | nodePresenter | + + nodePresenter := self newNodePresenterFrom: aStSettingNode level: 2. + newPage presenterProvider value add: nodePresenter expand: false ]. + ] { #category : 'initialization' } @@ -116,3 +135,9 @@ StSettingsMainPresenter >> initializeWindow: aWindowPresenter [ initialExtent: 1200 @ 700; centered ] + +{ #category : 'initialization' } +StSettingsMainPresenter >> pagePresenter [ + + ^ detailsPresenter +] diff --git a/src/NewTools-SettingsBrowser/StSettingsPageNotebookPresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsPageNotebookPresenter.class.st index 609e9225..814ce26c 100644 --- a/src/NewTools-SettingsBrowser/StSettingsPageNotebookPresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsPageNotebookPresenter.class.st @@ -10,9 +10,18 @@ Class { #tag : 'UI' } +{ #category : 'instance creation' } +StSettingsPageNotebookPresenter class >> onResults: aCollection [ + + ^ self new + initializeWithResults: aCollection; + yourself + +] + { #category : 'adding' } StSettingsPageNotebookPresenter >> add: aStSettingSectionPresenter expand: aBoolean [ - + settingsBox add: aStSettingSectionPresenter expand: aBoolean ] @@ -31,6 +40,13 @@ StSettingsPageNotebookPresenter >> initializePresenters [ yourself ] +{ #category : 'initialization' } +StSettingsPageNotebookPresenter >> initializeWithResults: aCollection [ + + aCollection do: [ : aStSettingNode | + self add: aStSettingNode expand: true ] +] + { #category : 'accessing' } StSettingsPageNotebookPresenter >> pagePresenter [ "Answer the receiver's " diff --git a/src/NewTools-SettingsBrowser/StSettingsPagePresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsPagePresenter.class.st index ef8848f0..a5a08189 100644 --- a/src/NewTools-SettingsBrowser/StSettingsPagePresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsPagePresenter.class.st @@ -23,7 +23,7 @@ StSettingsPagePresenter >> activePage [ ^ notebook selectedPage activePresenter ] -{ #category : 'callbacks' } +{ #category : 'callbacks - tabs' } StSettingsPagePresenter >> addDefaultGeneralTabFrom: aStSettingNode [ "Private - Add General Settings default" @@ -39,7 +39,7 @@ StSettingsPagePresenter >> addDefaultGeneralTabFrom: aStSettingNode [ yourself). ] -{ #category : 'callbacks' } +{ #category : 'callbacks - tabs' } StSettingsPagePresenter >> addHeaderForSettingsWithoutParent: aSpNotebookPage [ "Private - We add a 'General' header (2nd level) for those nodes without parent other than the root" @@ -54,7 +54,31 @@ StSettingsPagePresenter >> addHeaderForSettingsWithoutParent: aSpNotebookPage [ expand: false ] -{ #category : 'callbacks' } +{ #category : 'callbacks - tabs' } +StSettingsPagePresenter >> addSearchResultTabFrom: resultStSettingNodes [ + "Private - Add General Settings default" + + | searchResultSettingNode presenterNodes title | + + title := 'Search Results'. + presenterNodes := resultStSettingNodes collect: [ :aSettingNode | + | nodePresenter | + (nodePresenter := self + instantiate: aSettingNode presenterClass + on: aSettingNode) hasChildren + ifTrue: [ nodePresenter sectionTitleStyle: 'sectionTitleL1' ] ]. + + + searchResultSettingNode := StSettingNode with: PragmaSetting new. + searchResultSettingNode item name: title. + notebook addPage: (SpNotebookPage new + icon: (self iconNamed: #smallQuestion); + presenterProvider: [ StSettingsPageNotebookPresenter onResults: presenterNodes ]; + title: title; + yourself). +] + +{ #category : 'callbacks - tabs' } StSettingsPagePresenter >> addTabsFrom: aStSettingNode [ aStSettingNode allChildren do: [ :aSettingNode | @@ -95,7 +119,7 @@ StSettingsPagePresenter >> defaultLayout [ yourself ] -{ #category : 'callbacks' } +{ #category : 'callbacks - tabs' } StSettingsPagePresenter >> generalTitle [ ^ 'General' @@ -114,7 +138,7 @@ StSettingsPagePresenter >> initializePresenters [ settingDocPresenter := self newText ] -{ #category : 'callbacks' } +{ #category : 'callbacks - tabs' } StSettingsPagePresenter >> newGeneralSetting: aSpNotebookPage [ | currentParent generalSettingNode | @@ -126,17 +150,6 @@ StSettingsPagePresenter >> newGeneralSetting: aSpNotebookPage [ ^ 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" @@ -162,7 +175,7 @@ StSettingsPagePresenter >> setModel: aNode [ ] -{ #category : 'callbacks' } +{ #category : 'callbacks - tabs' } StSettingsPagePresenter >> updatePages: aStSettingNode [ "Private - Recursively iterate aStSettingNode children using anInteger as 'level' indicator for title styling purposes" @@ -192,7 +205,7 @@ StSettingsPagePresenter >> updatePresenterTree: aStSettingNode level: anInteger self updatePresenterTree: aSettingNode level: anInteger + 1 ] ] -{ #category : 'callbacks' } +{ #category : 'callbacks - tabs' } StSettingsPagePresenter >> updateSelectedPage: aSpNotebookPage [ aSpNotebookPage ifNotNil: [ diff --git a/src/NewTools-SettingsBrowser/StSettingsToolbarPresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsToolbarPresenter.class.st index 1d59e96e..49b9abbc 100644 --- a/src/NewTools-SettingsBrowser/StSettingsToolbarPresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsToolbarPresenter.class.st @@ -31,14 +31,18 @@ StSettingsToolbarPresenter >> defaultLayout [ 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 ]. - self owner addSearchResults: (self settingsTree processSearch: aString) - + self halt. + colOfStSettingNode := self settingsTree processSearch: aString. + "self owner addTab: (self owner addSearchResults:)." + mainPresenter := self owner. + mainPresenter pagePresenter addSearchResultTabFrom: colOfStSettingNode. ] { #category : 'initialization' } diff --git a/src/NewTools-SettingsBrowser/StSettingsTree.class.st b/src/NewTools-SettingsBrowser/StSettingsTree.class.st index 37e38452..22673440 100644 --- a/src/NewTools-SettingsBrowser/StSettingsTree.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsTree.class.st @@ -53,7 +53,9 @@ StSettingsTree >> nodeList: aCollection [ StSettingsTree >> processSearch: aString [ "Recursively collect the nodes matching aString in the receiver" - ^ self treeRoots flatCollect: [ : settingNode | settingNode matches: aString ] + ^ self treeRoots + flatCollect: [ : settingNode | settingNode matches: aString ] + as: Set ] { #category : 'instance creation' } From 3bfc3bed308db0edbdbc52f3c0f8c2e71599fb82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hern=C3=A1n=20Morales=20Durand?= Date: Mon, 21 Oct 2024 22:47:42 +0200 Subject: [PATCH 3/7] First implementation of search feature in new settings browser Auto-select first tab on setting category selection --- .../SpNotebookPresenter.extension.st | 22 +++ .../StSettingNode.class.st | 5 +- .../StSettingsAbstractPresenter.class.st | 8 +- .../StSettingsMainPresenter.class.st | 39 +----- ... StSettingsNotebookPagePresenter.class.st} | 22 +-- .../StSettingsPagePresenter.class.st | 125 +++++++++++++----- .../StSettingsToolbarPresenter.class.st | 2 - 7 files changed, 137 insertions(+), 86 deletions(-) create mode 100644 src/NewTools-SettingsBrowser/SpNotebookPresenter.extension.st rename src/NewTools-SettingsBrowser/{StSettingsPageNotebookPresenter.class.st => StSettingsNotebookPagePresenter.class.st} (67%) diff --git a/src/NewTools-SettingsBrowser/SpNotebookPresenter.extension.st b/src/NewTools-SettingsBrowser/SpNotebookPresenter.extension.st new file mode 100644 index 00000000..dcc1f5d1 --- /dev/null +++ b/src/NewTools-SettingsBrowser/SpNotebookPresenter.extension.st @@ -0,0 +1,22 @@ +Extension { #name : 'SpNotebookPresenter' } + +{ #category : '*NewTools-SettingsBrowser' } +SpNotebookPresenter >> addPageFirst: aPage [ + "Add a page (an instance of `SpNotebookPage`) to the notebook." + + aPage owner: self. + pagesHolder addFirst: aPage. + ^ aPage +] + +{ #category : '*NewTools-SettingsBrowser' } +SpNotebookPresenter >> hasPageNamed: aTitle [ + + ^ self pages anySatisfy: [ : page | page title = aTitle ] +] + +{ #category : '*NewTools-SettingsBrowser' } +SpNotebookPresenter >> pageNamed: aTitle [ + + ^ self pages detect: [ : page | page title = aTitle ] +] diff --git a/src/NewTools-SettingsBrowser/StSettingNode.class.st b/src/NewTools-SettingsBrowser/StSettingNode.class.st index f2e11238..870a721b 100644 --- a/src/NewTools-SettingsBrowser/StSettingNode.class.st +++ b/src/NewTools-SettingsBrowser/StSettingNode.class.st @@ -132,7 +132,10 @@ StSettingNode >> label: aString [ StSettingNode >> matchBlock [ ^ matchBlock - ifNil: [ matchBlock := [ : node : pattern | node label asLowercase beginsWith: pattern asLowercase ] ] + ifNil: [ + matchBlock := [ : node : pattern | + node label substrings anySatisfy: [ : substr | + substr asLowercase beginsWith: pattern asLowercase ] ] ] ] { #category : 'enumerating' } diff --git a/src/NewTools-SettingsBrowser/StSettingsAbstractPresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsAbstractPresenter.class.st index 088a4036..430955cf 100644 --- a/src/NewTools-SettingsBrowser/StSettingsAbstractPresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsAbstractPresenter.class.st @@ -13,10 +13,16 @@ StSettingsAbstractPresenter >> newNodePresenterFrom: aSettingNode level: anInteg nodePresenter := self instantiate: aSettingNode presenterClass on: aSettingNode. - nodePresenter sectionTitleStyle: 'sectionTitleL' , anInteger asString. + 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/StSettingsMainPresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsMainPresenter.class.st index b3abf15a..56957abb 100644 --- a/src/NewTools-SettingsBrowser/StSettingsMainPresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsMainPresenter.class.st @@ -18,44 +18,6 @@ Class { #tag : 'UI' } -{ #category : 'adding' } -StSettingsMainPresenter >> addSearchResults: aCollection [ - "Process the search results in aCollection. - If there is only a single item as result, we follow the path to that node. - Otherwise, we present a new tab with the results" - - | results | - - results := OrderedCollection new. - ^ aCollection size = 1 - ifTrue: [ - | singleResult | - singleResult := aCollection anyOne. - results add: singleResult. - self followPath: singleResult in: results. - results ] - ifFalse: [ self addTab: aCollection ]. -] - -{ #category : 'adding' } -StSettingsMainPresenter >> addTab: aCollection [ - - | newPage | - newPage := SpNotebookPage new - icon: (self iconNamed: #smallQuestion); - presenterProvider: [ StSettingsPageNotebookPresenter on: - ((StSettingNode with: PragmaSetting new) item name: 'temp') ]; - title: 'Search Results'; - yourself. - - aCollection do: [ :aStSettingNode | - | nodePresenter | - - nodePresenter := self newNodePresenterFrom: aStSettingNode level: 2. - newPage presenterProvider value add: nodePresenter expand: false ]. - -] - { #category : 'initialization' } StSettingsMainPresenter >> browserTitle [ @@ -68,6 +30,7 @@ StSettingsMainPresenter >> connectPresenters [ mainCategoriesPresenter transmitTo: detailsPresenter transform: [ : aCategoryItemPresenter | aCategoryItemPresenter node ] + postTransmission: [ : selectedPage | selectedPage selectFirstPage ] ] { #category : 'layout' } diff --git a/src/NewTools-SettingsBrowser/StSettingsPageNotebookPresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsNotebookPagePresenter.class.st similarity index 67% rename from src/NewTools-SettingsBrowser/StSettingsPageNotebookPresenter.class.st rename to src/NewTools-SettingsBrowser/StSettingsNotebookPagePresenter.class.st index 814ce26c..7879ca56 100644 --- a/src/NewTools-SettingsBrowser/StSettingsPageNotebookPresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsNotebookPagePresenter.class.st @@ -1,5 +1,5 @@ Class { - #name : 'StSettingsPageNotebookPresenter', + #name : 'StSettingsNotebookPagePresenter', #superclass : 'SpPresenter', #instVars : [ 'settingsBox', @@ -11,7 +11,7 @@ Class { } { #category : 'instance creation' } -StSettingsPageNotebookPresenter class >> onResults: aCollection [ +StSettingsNotebookPagePresenter class >> onResults: aCollection [ ^ self new initializeWithResults: aCollection; @@ -20,20 +20,20 @@ StSettingsPageNotebookPresenter class >> onResults: aCollection [ ] { #category : 'adding' } -StSettingsPageNotebookPresenter >> add: aStSettingSectionPresenter expand: aBoolean [ +StSettingsNotebookPagePresenter >> add: aStSettingSectionPresenter expand: aBoolean [ settingsBox add: aStSettingSectionPresenter expand: aBoolean ] { #category : 'layout' } -StSettingsPageNotebookPresenter >> defaultLayout [ +StSettingsNotebookPagePresenter >> defaultLayout [ ^ SpScrollableLayout with: settingsBox ] { #category : 'initialization' } -StSettingsPageNotebookPresenter >> initializePresenters [ +StSettingsNotebookPagePresenter >> initializePresenters [ settingsBox := SpBoxLayout newTopToBottom spacing: 5; @@ -41,27 +41,27 @@ StSettingsPageNotebookPresenter >> initializePresenters [ ] { #category : 'initialization' } -StSettingsPageNotebookPresenter >> initializeWithResults: aCollection [ +StSettingsNotebookPagePresenter >> initializeWithResults: aCollection [ aCollection do: [ : aStSettingNode | self add: aStSettingNode expand: true ] ] { #category : 'accessing' } -StSettingsPageNotebookPresenter >> pagePresenter [ +StSettingsNotebookPagePresenter >> pagePresenter [ "Answer the receiver's " ^ self owner owner ] { #category : 'accessing' } -StSettingsPageNotebookPresenter >> parentNode [ +StSettingsNotebookPagePresenter >> parentNode [ ^ parentNode ] { #category : 'printing' } -StSettingsPageNotebookPresenter >> printOn: aStream [ +StSettingsNotebookPagePresenter >> printOn: aStream [ settingsBox ifNotNil: [ : sb | @@ -74,14 +74,14 @@ StSettingsPageNotebookPresenter >> printOn: aStream [ ] { #category : 'removing' } -StSettingsPageNotebookPresenter >> removeAll [ +StSettingsNotebookPagePresenter >> removeAll [ "Remove all presenters in the layout" settingsBox removeAll ] { #category : 'accessing - model' } -StSettingsPageNotebookPresenter >> setModelBeforeInitialization: aNode [ +StSettingsNotebookPagePresenter >> setModelBeforeInitialization: aNode [ parentNode := aNode ] diff --git a/src/NewTools-SettingsBrowser/StSettingsPagePresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsPagePresenter.class.st index a5a08189..a22067eb 100644 --- a/src/NewTools-SettingsBrowser/StSettingsPagePresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsPagePresenter.class.st @@ -20,7 +20,12 @@ Class { { #category : 'private' } StSettingsPagePresenter >> activePage [ - ^ notebook selectedPage activePresenter + | selectedPage | + + selectedPage := notebook selectedPage. + selectedPage activePresenter + ifNil: [ selectedPage retrievePresenter ]. + ^ selectedPage activePresenter ] { #category : 'callbacks - tabs' } @@ -34,7 +39,7 @@ StSettingsPagePresenter >> addDefaultGeneralTabFrom: aStSettingNode [ generalSettingNode parentName: aStSettingNode name. notebook addPage: (SpNotebookPage new icon: (self iconNamed: #smallQuestion); - presenterProvider: [ StSettingsPageNotebookPresenter on: generalSettingNode ]; + presenterProvider: [ StSettingsNotebookPagePresenter on: generalSettingNode ]; title: self generalTitle; yourself). ] @@ -56,26 +61,17 @@ StSettingsPagePresenter >> addHeaderForSettingsWithoutParent: aSpNotebookPage [ { #category : 'callbacks - tabs' } StSettingsPagePresenter >> addSearchResultTabFrom: resultStSettingNodes [ - "Private - Add General Settings default" + "Private - Add a tab with search results from resultStSettingNodes in the receiver's notebook" - | searchResultSettingNode presenterNodes title | + | resultSearchNodes searchResultPage | - title := 'Search Results'. - presenterNodes := resultStSettingNodes collect: [ :aSettingNode | - | nodePresenter | - (nodePresenter := self - instantiate: aSettingNode presenterClass - on: aSettingNode) hasChildren - ifTrue: [ nodePresenter sectionTitleStyle: 'sectionTitleL1' ] ]. - - - searchResultSettingNode := StSettingNode with: PragmaSetting new. - searchResultSettingNode item name: title. - notebook addPage: (SpNotebookPage new - icon: (self iconNamed: #smallQuestion); - presenterProvider: [ StSettingsPageNotebookPresenter onResults: presenterNodes ]; - title: title; - yourself). + resultSearchNodes := self collectResultNodes: resultStSettingNodes. + searchResultPage := (notebook hasPageNamed: self resultsTitle) + ifFalse: [ notebook addPageFirst: (self newResultPageOn: resultSearchNodes) ] + ifTrue: [ (notebook pageNamed: self resultsTitle) presenterProvider: [ StSettingsNotebookPagePresenter onResults: resultSearchNodes ] ]. + notebook selectPage: searchResultPage. + self notebook selectedPage resetContent. + ] { #category : 'callbacks - tabs' } @@ -87,14 +83,28 @@ StSettingsPagePresenter >> addTabsFrom: aStSettingNode [ instantiate: aSettingNode presenterClass on: aSettingNode) hasChildren ifTrue: [ - nodePresenter sectionTitleStyle: 'sectionTitleL1'. + nodePresenter sectionTitleStyle: self sectionTitleString. notebook addPage: (SpNotebookPage new - icon: (self iconNamed: #smallQuestion); - presenterProvider: [ StSettingsPageNotebookPresenter on: aSettingNode ]; + icon: (self iconNamed: #smallQuestion); + presenterProvider: [ StSettingsNotebookPagePresenter on: aSettingNode ]; title: aSettingNode label; yourself) ] ] ] +{ #category : 'private' } +StSettingsPagePresenter >> collectResultNodes: aCollection [ + "Private - Select and answer those nodes that do not represent section titles" + + | nodePresenters | + nodePresenters := aCollection collect: [ :aSettingNode | + self + instantiate: aSettingNode presenterClass + on: aSettingNode ]. + ^ nodePresenters + reject: [ :nodePresenter | nodePresenter hasChildren ] + +] + { #category : 'initialization' } StSettingsPagePresenter >> defaultInputPort [ @@ -150,6 +160,17 @@ StSettingsPagePresenter >> newGeneralSetting: aSpNotebookPage [ ^ generalSettingNode ] +{ #category : 'instance creation' } +StSettingsPagePresenter >> newResultPageOn: aCollection [ + + ^ SpNotebookPage new + icon: (self iconNamed: #smallQuestion); + presenterProvider: [ StSettingsNotebookPagePresenter onResults: aCollection ]; + beCloseable; + title: self resultsTitle; + yourself +] + { #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" @@ -158,10 +179,30 @@ StSettingsPagePresenter >> newSectionNodePresenterFrom: aSettingNode level: anIn nodePresenter := self instantiate: StSettingSectionPresenter on: aSettingNode. - nodePresenter sectionTitleStyle: 'sectionTitleL' , anInteger asString. + nodePresenter sectionTitleStyle: self sectionTitleString , anInteger asString. ^ nodePresenter ] +{ #category : 'initialization' } +StSettingsPagePresenter >> notebook [ + + ^ notebook + +] + +{ #category : 'callbacks - tabs' } +StSettingsPagePresenter >> resultsTitle [ + + ^ 'Results' +] + +{ #category : 'callbacks' } +StSettingsPagePresenter >> selectFirstPage [ + + self notebook selectPageIndex: 1. + self updateSelectedPage: self notebook selectedPage. +] + { #category : 'accessing - model' } StSettingsPagePresenter >> setModel: aNode [ "Private - Set the receiver's content iterating recursively starting from aNode" @@ -207,16 +248,34 @@ StSettingsPagePresenter >> updatePresenterTree: aStSettingNode level: anInteger { #category : 'callbacks - tabs' } StSettingsPagePresenter >> 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: [ - | 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 ] + aSpNotebookPage activePresenter ifNotNil: [ : activePresenter | activePresenter removeAll ]. + self updateSelectedSpecialCases: aSpNotebookPage. + self updateSelectedPageTree: aSpNotebookPage ] +] + +{ #category : 'private' } +StSettingsPagePresenter >> updateSelectedPageTree: aSpNotebookPage [ + + aSpNotebookPage activePresenter + ifNil: [ aSpNotebookPage retrievePresenter ] + ifNotNil: [ : activePresenter | + activePresenter parentNode + ifNotNil: [ : tabNode | self updatePresenterTree: tabNode level: 2 ] + ifNil: [ self updatePresenterTree: aSpNotebookPage activePresenter level: 2 ] ] +] + +{ #category : 'callbacks - tabs' } +StSettingsPagePresenter >> 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' } diff --git a/src/NewTools-SettingsBrowser/StSettingsToolbarPresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsToolbarPresenter.class.st index 49b9abbc..15b9cae2 100644 --- a/src/NewTools-SettingsBrowser/StSettingsToolbarPresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsToolbarPresenter.class.st @@ -38,9 +38,7 @@ StSettingsToolbarPresenter >> doSettingSearch: aString [ aString size >= 3 ifFalse: [ ^ self ]. - self halt. colOfStSettingNode := self settingsTree processSearch: aString. - "self owner addTab: (self owner addSearchResults:)." mainPresenter := self owner. mainPresenter pagePresenter addSearchResultTabFrom: colOfStSettingNode. ] From eefcf202b5fe013665a9cf5715b37eddc2bffde3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hern=C3=A1n=20Morales=20Durand?= Date: Wed, 23 Oct 2024 22:37:38 +0200 Subject: [PATCH 4/7] Setting Browser search updates --- .../SpNotebookPresenter.extension.st | 11 +-- .../StSettingTreeBuilder.class.st | 11 --- ...st => StSettingsDetailsPresenter.class.st} | 94 +++++++++++-------- .../StSettingsMainPresenter.class.st | 81 +++------------- ...ingsNotebookPageContentPresenter.class.st} | 34 +++---- 5 files changed, 84 insertions(+), 147 deletions(-) rename src/NewTools-SettingsBrowser/{StSettingsPagePresenter.class.st => StSettingsDetailsPresenter.class.st} (70%) rename src/NewTools-SettingsBrowser/{StSettingsNotebookPagePresenter.class.st => StSettingsNotebookPageContentPresenter.class.st} (56%) diff --git a/src/NewTools-SettingsBrowser/SpNotebookPresenter.extension.st b/src/NewTools-SettingsBrowser/SpNotebookPresenter.extension.st index dcc1f5d1..b8e9d597 100644 --- a/src/NewTools-SettingsBrowser/SpNotebookPresenter.extension.st +++ b/src/NewTools-SettingsBrowser/SpNotebookPresenter.extension.st @@ -1,18 +1,15 @@ Extension { #name : 'SpNotebookPresenter' } { #category : '*NewTools-SettingsBrowser' } -SpNotebookPresenter >> addPageFirst: aPage [ - "Add a page (an instance of `SpNotebookPage`) to the notebook." +SpNotebookPresenter >> hasPageNamed: aTitle [ - aPage owner: self. - pagesHolder addFirst: aPage. - ^ aPage + ^ self pages anySatisfy: [ : page | page title = aTitle ] ] { #category : '*NewTools-SettingsBrowser' } -SpNotebookPresenter >> hasPageNamed: aTitle [ +SpNotebookPresenter >> hasPages [ - ^ self pages anySatisfy: [ : page | page title = aTitle ] + ^ self pages isNotEmpty ] { #category : '*NewTools-SettingsBrowser' } 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/StSettingsPagePresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsDetailsPresenter.class.st similarity index 70% rename from src/NewTools-SettingsBrowser/StSettingsPagePresenter.class.st rename to src/NewTools-SettingsBrowser/StSettingsDetailsPresenter.class.st index a22067eb..ab07acbe 100644 --- a/src/NewTools-SettingsBrowser/StSettingsPagePresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsDetailsPresenter.class.st @@ -3,7 +3,7 @@ It represents a setting category page with setting sections and settings. The pa " Class { - #name : 'StSettingsPagePresenter', + #name : 'StSettingsDetailsPresenter', #superclass : 'StSettingsAbstractPresenter', #instVars : [ 'pageTitle', @@ -18,7 +18,7 @@ Class { } { #category : 'private' } -StSettingsPagePresenter >> activePage [ +StSettingsDetailsPresenter >> activePage [ | selectedPage | @@ -29,7 +29,7 @@ StSettingsPagePresenter >> activePage [ ] { #category : 'callbacks - tabs' } -StSettingsPagePresenter >> addDefaultGeneralTabFrom: aStSettingNode [ +StSettingsDetailsPresenter >> addDefaultGeneralTabFrom: aStSettingNode [ "Private - Add General Settings default" | generalSettingNode | @@ -39,13 +39,13 @@ StSettingsPagePresenter >> addDefaultGeneralTabFrom: aStSettingNode [ generalSettingNode parentName: aStSettingNode name. notebook addPage: (SpNotebookPage new icon: (self iconNamed: #smallQuestion); - presenterProvider: [ StSettingsNotebookPagePresenter on: generalSettingNode ]; + presenterProvider: [ StSettingsNotebookPageContentPresenter on: generalSettingNode ]; title: self generalTitle; yourself). ] { #category : 'callbacks - tabs' } -StSettingsPagePresenter >> addHeaderForSettingsWithoutParent: aSpNotebookPage [ +StSettingsDetailsPresenter >> addHeaderForSettingsWithoutParent: aSpNotebookPage [ "Private - We add a 'General' header (2nd level) for those nodes without parent other than the root" | generalSettingNode generalNodePresenter | @@ -60,22 +60,27 @@ StSettingsPagePresenter >> addHeaderForSettingsWithoutParent: aSpNotebookPage [ ] { #category : 'callbacks - tabs' } -StSettingsPagePresenter >> addSearchResultTabFrom: resultStSettingNodes [ +StSettingsDetailsPresenter >> addSearchResultTabFrom: resultStSettingNodes [ "Private - Add a tab with search results from resultStSettingNodes in the receiver's notebook" - | resultSearchNodes searchResultPage | + | newResultPage rootSearchResultNode | - resultSearchNodes := self collectResultNodes: resultStSettingNodes. - searchResultPage := (notebook hasPageNamed: self resultsTitle) - ifFalse: [ notebook addPageFirst: (self newResultPageOn: resultSearchNodes) ] - ifTrue: [ (notebook pageNamed: self resultsTitle) presenterProvider: [ StSettingsNotebookPagePresenter onResults: resultSearchNodes ] ]. - notebook selectPage: searchResultPage. + notebook hasPages ifTrue: [ notebook removeAll ]. + "resultSearchNodes := self collectResultNodes: resultStSettingNodes." + rootSearchResultNode := StSettingNode new + parentName: #Root; + declaration: SettingDeclaration new; + model: (StSettingsTree new nodeList: resultStSettingNodes; yourself) + yourself. + newResultPage := self newResultPageOn: rootSearchResultNode. + notebook addPage: newResultPage. + notebook selectPage: newResultPage. self notebook selectedPage resetContent. ] { #category : 'callbacks - tabs' } -StSettingsPagePresenter >> addTabsFrom: aStSettingNode [ +StSettingsDetailsPresenter >> addTabsFrom: aStSettingNode [ aStSettingNode allChildren do: [ :aSettingNode | | nodePresenter | @@ -86,13 +91,13 @@ StSettingsPagePresenter >> addTabsFrom: aStSettingNode [ nodePresenter sectionTitleStyle: self sectionTitleString. notebook addPage: (SpNotebookPage new icon: (self iconNamed: #smallQuestion); - presenterProvider: [ StSettingsNotebookPagePresenter on: aSettingNode ]; + presenterProvider: [ StSettingsNotebookPageContentPresenter on: aSettingNode ]; title: aSettingNode label; yourself) ] ] ] -{ #category : 'private' } -StSettingsPagePresenter >> collectResultNodes: aCollection [ +{ #category : 'TOREMOVE' } +StSettingsDetailsPresenter >> collectResultNodes: aCollection [ "Private - Select and answer those nodes that do not represent section titles" | nodePresenters | @@ -106,14 +111,14 @@ StSettingsPagePresenter >> collectResultNodes: aCollection [ ] { #category : 'initialization' } -StSettingsPagePresenter >> defaultInputPort [ +StSettingsDetailsPresenter >> defaultInputPort [ ^ SpModelPort newPresenter: self ] { #category : 'layout' } -StSettingsPagePresenter >> defaultLayout [ +StSettingsDetailsPresenter >> defaultLayout [ ^ SpBoxLayout newTopToBottom add: pageTitle expand: false; @@ -130,13 +135,13 @@ StSettingsPagePresenter >> defaultLayout [ ] { #category : 'callbacks - tabs' } -StSettingsPagePresenter >> generalTitle [ +StSettingsDetailsPresenter >> generalTitle [ ^ 'General' ] { #category : 'initialization' } -StSettingsPagePresenter >> initializePresenters [ +StSettingsDetailsPresenter >> initializePresenters [ pageTitle := self newLabel. notebook := self newNotebook @@ -149,7 +154,7 @@ StSettingsPagePresenter >> initializePresenters [ ] { #category : 'callbacks - tabs' } -StSettingsPagePresenter >> newGeneralSetting: aSpNotebookPage [ +StSettingsDetailsPresenter >> newGeneralSetting: aSpNotebookPage [ | currentParent generalSettingNode | @@ -160,19 +165,19 @@ StSettingsPagePresenter >> newGeneralSetting: aSpNotebookPage [ ^ generalSettingNode ] -{ #category : 'instance creation' } -StSettingsPagePresenter >> newResultPageOn: aCollection [ +{ #category : 'TOREMOVE' } +StSettingsDetailsPresenter >> newResultPageOn: aStSettingNode [ ^ SpNotebookPage new icon: (self iconNamed: #smallQuestion); - presenterProvider: [ StSettingsNotebookPagePresenter onResults: aCollection ]; + presenterProvider: [ StSettingsNotebookPageContentPresenter on: aStSettingNode ]; beCloseable; title: self resultsTitle; yourself ] { #category : 'callbacks' } -StSettingsPagePresenter >> newSectionNodePresenterFrom: aSettingNode level: anInteger [ +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 | @@ -184,27 +189,27 @@ StSettingsPagePresenter >> newSectionNodePresenterFrom: aSettingNode level: anIn ] { #category : 'initialization' } -StSettingsPagePresenter >> notebook [ +StSettingsDetailsPresenter >> notebook [ ^ notebook ] { #category : 'callbacks - tabs' } -StSettingsPagePresenter >> resultsTitle [ +StSettingsDetailsPresenter >> resultsTitle [ ^ 'Results' ] { #category : 'callbacks' } -StSettingsPagePresenter >> selectFirstPage [ +StSettingsDetailsPresenter >> selectFirstPage [ self notebook selectPageIndex: 1. self updateSelectedPage: self notebook selectedPage. ] { #category : 'accessing - model' } -StSettingsPagePresenter >> setModel: aNode [ +StSettingsDetailsPresenter >> setModel: aNode [ "Private - Set the receiver's content iterating recursively starting from aNode" settingTree := aNode model childrenOf: aNode. @@ -217,7 +222,7 @@ StSettingsPagePresenter >> setModel: aNode [ ] { #category : 'callbacks - tabs' } -StSettingsPagePresenter >> updatePages: aStSettingNode [ +StSettingsDetailsPresenter >> updatePages: aStSettingNode [ "Private - Recursively iterate aStSettingNode children using anInteger as 'level' indicator for title styling purposes" self addDefaultGeneralTabFrom: aStSettingNode. @@ -225,7 +230,7 @@ StSettingsPagePresenter >> updatePages: aStSettingNode [ ] { #category : 'callbacks' } -StSettingsPagePresenter >> updatePresenterGeneralNodes: aCollection [ +StSettingsDetailsPresenter >> updatePresenterGeneralNodes: aCollection [ | nodePresenter | aCollection do: [ :settingNode | @@ -234,9 +239,10 @@ StSettingsPagePresenter >> updatePresenterGeneralNodes: aCollection [ ] { #category : 'callbacks' } -StSettingsPagePresenter >> updatePresenterTree: aStSettingNode level: anInteger [ +StSettingsDetailsPresenter >> updatePresenterTree: aStSettingNode level: anInteger [ "Private - Recursively iterate aStSettingNode children using anInteger as 'level' indicator for title styling purposes" + "self haltIf: [ (aStSettingNode respondsTo: #allChildren) or: [ aStSettingNode canUnderstand: #allChildren ] ]." aStSettingNode allChildren do: [ :aSettingNode | | nodePresenter | nodePresenter := self @@ -247,7 +253,7 @@ StSettingsPagePresenter >> updatePresenterTree: aStSettingNode level: anInteger ] { #category : 'callbacks - tabs' } -StSettingsPagePresenter >> updateSelectedPage: aSpNotebookPage [ +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: [ @@ -257,18 +263,21 @@ StSettingsPagePresenter >> updateSelectedPage: aSpNotebookPage [ ] { #category : 'private' } -StSettingsPagePresenter >> updateSelectedPageTree: aSpNotebookPage [ +StSettingsDetailsPresenter >> updateSelectedPageTree: aSpNotebookPage [ - aSpNotebookPage activePresenter + | updatedPage | + + updatedPage := aSpNotebookPage activePresenter ifNil: [ aSpNotebookPage retrievePresenter ] - ifNotNil: [ : activePresenter | - activePresenter parentNode - ifNotNil: [ : tabNode | self updatePresenterTree: tabNode level: 2 ] - ifNil: [ self updatePresenterTree: aSpNotebookPage activePresenter level: 2 ] ] + ifNotNil: [ aSpNotebookPage activePresenter ]. + + updatedPage parentNode + ifNotNil: [ : tabNode | self updatePresenterTree: tabNode level: 2 ] + ifNil: [ self updatePresenterTree: updatedPage level: 2 ] ] { #category : 'callbacks - tabs' } -StSettingsPagePresenter >> updateSelectedSpecialCases: aSpNotebookPage [ +StSettingsDetailsPresenter >> updateSelectedSpecialCases: aSpNotebookPage [ "Do not add a 'General' header if we are already in the General tab" aSpNotebookPage title = self resultsTitle @@ -276,10 +285,13 @@ StSettingsPagePresenter >> updateSelectedSpecialCases: aSpNotebookPage [ aSpNotebookPage title = self generalTitle ifFalse: [ self addHeaderForSettingsWithoutParent: aSpNotebookPage ] ifTrue: [ self updatePresenterGeneralNodes: (settingTree reject: [ : node | node hasChildren ]) ] ] + ifTrue: [ + aSpNotebookPage activePresenter + ifNotNil: [ self halt. ] ] ] { #category : 'callbacks' } -StSettingsPagePresenter >> updateSetting: labelString helpText: settingHelpString [ +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 3ef0a133..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', @@ -44,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' } @@ -75,48 +71,6 @@ StSettingsMainPresenter >> followPath: aStSettingNode in: aCollection [ ] -{ #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 : '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 [ @@ -131,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. ] @@ -151,11 +104,3 @@ StSettingsMainPresenter >> pagePresenter [ ^ detailsPresenter ] - -{ #category : 'menu' } -StSettingsMainPresenter >> loadSettings [ - "Load the settings from the system settings file, if exists" - - self settingsTree hasSettingsFile - ifTrue: [ self settingsTree updateSettingNodes ] -] diff --git a/src/NewTools-SettingsBrowser/StSettingsNotebookPagePresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsNotebookPageContentPresenter.class.st similarity index 56% rename from src/NewTools-SettingsBrowser/StSettingsNotebookPagePresenter.class.st rename to src/NewTools-SettingsBrowser/StSettingsNotebookPageContentPresenter.class.st index 7879ca56..695ca4f2 100644 --- a/src/NewTools-SettingsBrowser/StSettingsNotebookPagePresenter.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 : 'StSettingsNotebookPagePresenter', + #name : 'StSettingsNotebookPageContentPresenter', #superclass : 'SpPresenter', #instVars : [ 'settingsBox', @@ -10,58 +13,49 @@ Class { #tag : 'UI' } -{ #category : 'instance creation' } -StSettingsNotebookPagePresenter class >> onResults: aCollection [ - - ^ self new - initializeWithResults: aCollection; - yourself - -] - { #category : 'adding' } -StSettingsNotebookPagePresenter >> add: aStSettingSectionPresenter expand: aBoolean [ +StSettingsNotebookPageContentPresenter >> add: aStSettingSectionPresenter expand: aBoolean [ settingsBox add: aStSettingSectionPresenter expand: aBoolean ] { #category : 'layout' } -StSettingsNotebookPagePresenter >> defaultLayout [ +StSettingsNotebookPageContentPresenter >> defaultLayout [ ^ SpScrollableLayout with: settingsBox ] { #category : 'initialization' } -StSettingsNotebookPagePresenter >> initializePresenters [ +StSettingsNotebookPageContentPresenter >> initializePresenters [ settingsBox := SpBoxLayout newTopToBottom spacing: 5; yourself ] -{ #category : 'initialization' } -StSettingsNotebookPagePresenter >> initializeWithResults: aCollection [ +{ #category : 'TOREMOVE' } +StSettingsNotebookPageContentPresenter >> initializeWithResults: aCollection [ aCollection do: [ : aStSettingNode | self add: aStSettingNode expand: true ] ] { #category : 'accessing' } -StSettingsNotebookPagePresenter >> pagePresenter [ +StSettingsNotebookPageContentPresenter >> pagePresenter [ "Answer the receiver's " ^ self owner owner ] { #category : 'accessing' } -StSettingsNotebookPagePresenter >> parentNode [ +StSettingsNotebookPageContentPresenter >> parentNode [ ^ parentNode ] { #category : 'printing' } -StSettingsNotebookPagePresenter >> printOn: aStream [ +StSettingsNotebookPageContentPresenter >> printOn: aStream [ settingsBox ifNotNil: [ : sb | @@ -74,14 +68,14 @@ StSettingsNotebookPagePresenter >> printOn: aStream [ ] { #category : 'removing' } -StSettingsNotebookPagePresenter >> removeAll [ +StSettingsNotebookPageContentPresenter >> removeAll [ "Remove all presenters in the layout" settingsBox removeAll ] { #category : 'accessing - model' } -StSettingsNotebookPagePresenter >> setModelBeforeInitialization: aNode [ +StSettingsNotebookPageContentPresenter >> setModelBeforeInitialization: aNode [ parentNode := aNode ] From 40317af44bc25019da82377e3879483b8695a92d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hern=C3=A1n=20Morales=20Durand?= Date: Thu, 24 Oct 2024 14:04:51 +0200 Subject: [PATCH 5/7] Refactoring Configure results tree --- .../StSettingsAbstractPresenter.class.st | 1 + .../StSettingsDetailsPresenter.class.st | 49 ++++++++++--------- .../StSettingsTree.class.st | 7 +++ 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/NewTools-SettingsBrowser/StSettingsAbstractPresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsAbstractPresenter.class.st index 430955cf..acf5657c 100644 --- a/src/NewTools-SettingsBrowser/StSettingsAbstractPresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsAbstractPresenter.class.st @@ -10,6 +10,7 @@ Class { StSettingsAbstractPresenter >> newNodePresenterFrom: aSettingNode level: anInteger [ | nodePresenter | + nodePresenter := self instantiate: aSettingNode presenterClass on: aSettingNode. diff --git a/src/NewTools-SettingsBrowser/StSettingsDetailsPresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsDetailsPresenter.class.st index ab07acbe..e2b35e85 100644 --- a/src/NewTools-SettingsBrowser/StSettingsDetailsPresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsDetailsPresenter.class.st @@ -34,7 +34,7 @@ StSettingsDetailsPresenter >> addDefaultGeneralTabFrom: aStSettingNode [ | generalSettingNode | - generalSettingNode := StSettingNode with: PragmaSetting new. + generalSettingNode := self newSettingNode. generalSettingNode item name: self generalTitle. generalSettingNode parentName: aStSettingNode name. notebook addPage: (SpNotebookPage new @@ -63,16 +63,28 @@ StSettingsDetailsPresenter >> addHeaderForSettingsWithoutParent: aSpNotebookPage StSettingsDetailsPresenter >> addSearchResultTabFrom: resultStSettingNodes [ "Private - Add a tab with search results from resultStSettingNodes in the receiver's notebook" - | newResultPage rootSearchResultNode | + | newResultPage rootSearchResultNode rsSettingNodes rsRootResultNode | notebook hasPages ifTrue: [ notebook removeAll ]. - "resultSearchNodes := self collectResultNodes: resultStSettingNodes." - rootSearchResultNode := StSettingNode new - parentName: #Root; - declaration: SettingDeclaration new; - model: (StSettingsTree new nodeList: resultStSettingNodes; yourself) + + self halt. + 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 ]. + newResultPage := self newResultPageOn: rootSearchResultNode. + newResultPage retrievePresenter. notebook addPage: newResultPage. notebook selectPage: newResultPage. self notebook selectedPage resetContent. @@ -96,20 +108,6 @@ StSettingsDetailsPresenter >> addTabsFrom: aStSettingNode [ yourself) ] ] ] -{ #category : 'TOREMOVE' } -StSettingsDetailsPresenter >> collectResultNodes: aCollection [ - "Private - Select and answer those nodes that do not represent section titles" - - | nodePresenters | - nodePresenters := aCollection collect: [ :aSettingNode | - self - instantiate: aSettingNode presenterClass - on: aSettingNode ]. - ^ nodePresenters - reject: [ :nodePresenter | nodePresenter hasChildren ] - -] - { #category : 'initialization' } StSettingsDetailsPresenter >> defaultInputPort [ @@ -188,6 +186,12 @@ StSettingsDetailsPresenter >> newSectionNodePresenterFrom: aSettingNode level: a ^ nodePresenter ] +{ #category : 'callbacks - tabs' } +StSettingsDetailsPresenter >> newSettingNode [ + + ^ StSettingNode with: PragmaSetting new. +] + { #category : 'initialization' } StSettingsDetailsPresenter >> notebook [ @@ -285,9 +289,6 @@ StSettingsDetailsPresenter >> updateSelectedSpecialCases: aSpNotebookPage [ aSpNotebookPage title = self generalTitle ifFalse: [ self addHeaderForSettingsWithoutParent: aSpNotebookPage ] ifTrue: [ self updatePresenterGeneralNodes: (settingTree reject: [ : node | node hasChildren ]) ] ] - ifTrue: [ - aSpNotebookPage activePresenter - ifNotNil: [ self halt. ] ] ] { #category : 'callbacks' } diff --git a/src/NewTools-SettingsBrowser/StSettingsTree.class.st b/src/NewTools-SettingsBrowser/StSettingsTree.class.st index 89dcae8b..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 [ From 1c55bda93825632ca990d576587351fbcf02c4df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hern=C3=A1n=20Morales=20Durand?= Date: Thu, 24 Oct 2024 15:38:49 +0200 Subject: [PATCH 6/7] Live update results tab Remove unnecessary code --- .../StSettingsDetailsPresenter.class.st | 24 +++++++++---------- ...tingsNotebookPageContentPresenter.class.st | 7 ------ 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/NewTools-SettingsBrowser/StSettingsDetailsPresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsDetailsPresenter.class.st index e2b35e85..35d5fdf9 100644 --- a/src/NewTools-SettingsBrowser/StSettingsDetailsPresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsDetailsPresenter.class.st @@ -63,11 +63,10 @@ StSettingsDetailsPresenter >> addHeaderForSettingsWithoutParent: aSpNotebookPage StSettingsDetailsPresenter >> addSearchResultTabFrom: resultStSettingNodes [ "Private - Add a tab with search results from resultStSettingNodes in the receiver's notebook" - | newResultPage rootSearchResultNode rsSettingNodes rsRootResultNode | + | rootSearchResultNode rsSettingNodes rsRootResultNode | notebook hasPages ifTrue: [ notebook removeAll ]. - self halt. rsSettingNodes := resultStSettingNodes copy asOrderedCollection. "Create a new settings tree with the results" rsRootResultNode := StSettingsTree new nodeList: rsSettingNodes; yourself. @@ -83,11 +82,9 @@ StSettingsDetailsPresenter >> addSearchResultTabFrom: resultStSettingNodes [ parentName: rootSearchResultNode name; model: rsRootResultNode ]. - newResultPage := self newResultPageOn: rootSearchResultNode. - newResultPage retrievePresenter. - notebook addPage: newResultPage. - notebook selectPage: newResultPage. - self notebook selectedPage resetContent. + notebook addPage: (self newResultPageOn: rootSearchResultNode). + self selectFirstPage. + ] @@ -168,7 +165,7 @@ StSettingsDetailsPresenter >> newResultPageOn: aStSettingNode [ ^ SpNotebookPage new icon: (self iconNamed: #smallQuestion); - presenterProvider: [ StSettingsNotebookPageContentPresenter on: aStSettingNode ]; + presenterProvider: [ self instantiate: StSettingsNotebookPageContentPresenter on: aStSettingNode ]; beCloseable; title: self resultsTitle; yourself @@ -239,6 +236,7 @@ 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 ] ] @@ -246,14 +244,16 @@ StSettingsDetailsPresenter >> updatePresenterGeneralNodes: aCollection [ StSettingsDetailsPresenter >> updatePresenterTree: aStSettingNode level: anInteger [ "Private - Recursively iterate aStSettingNode children using anInteger as 'level' indicator for title styling purposes" - "self haltIf: [ (aStSettingNode respondsTo: #allChildren) or: [ aStSettingNode canUnderstand: #allChildren ] ]." 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 ] + self updatePresenterTree: aSettingNode level: anInteger + 1 ]. + + ] { #category : 'callbacks - tabs' } @@ -275,9 +275,7 @@ StSettingsDetailsPresenter >> updateSelectedPageTree: aSpNotebookPage [ ifNil: [ aSpNotebookPage retrievePresenter ] ifNotNil: [ aSpNotebookPage activePresenter ]. - updatedPage parentNode - ifNotNil: [ : tabNode | self updatePresenterTree: tabNode level: 2 ] - ifNil: [ self updatePresenterTree: updatedPage level: 2 ] + self updatePresenterTree: updatedPage parentNode level: 2 ] { #category : 'callbacks - tabs' } diff --git a/src/NewTools-SettingsBrowser/StSettingsNotebookPageContentPresenter.class.st b/src/NewTools-SettingsBrowser/StSettingsNotebookPageContentPresenter.class.st index 695ca4f2..53488be3 100644 --- a/src/NewTools-SettingsBrowser/StSettingsNotebookPageContentPresenter.class.st +++ b/src/NewTools-SettingsBrowser/StSettingsNotebookPageContentPresenter.class.st @@ -34,13 +34,6 @@ StSettingsNotebookPageContentPresenter >> initializePresenters [ yourself ] -{ #category : 'TOREMOVE' } -StSettingsNotebookPageContentPresenter >> initializeWithResults: aCollection [ - - aCollection do: [ : aStSettingNode | - self add: aStSettingNode expand: true ] -] - { #category : 'accessing' } StSettingsNotebookPageContentPresenter >> pagePresenter [ "Answer the receiver's " From b2e57fa4b7469aaef8bc4a7929f2721797f002e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hern=C3=A1n=20Morales=20Durand?= Date: Mon, 28 Oct 2024 21:05:00 +0100 Subject: [PATCH 7/7] Moved Notebook presenter methods to Spec --- .../SpNotebookPresenter.extension.st | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 src/NewTools-SettingsBrowser/SpNotebookPresenter.extension.st diff --git a/src/NewTools-SettingsBrowser/SpNotebookPresenter.extension.st b/src/NewTools-SettingsBrowser/SpNotebookPresenter.extension.st deleted file mode 100644 index b8e9d597..00000000 --- a/src/NewTools-SettingsBrowser/SpNotebookPresenter.extension.st +++ /dev/null @@ -1,19 +0,0 @@ -Extension { #name : 'SpNotebookPresenter' } - -{ #category : '*NewTools-SettingsBrowser' } -SpNotebookPresenter >> hasPageNamed: aTitle [ - - ^ self pages anySatisfy: [ : page | page title = aTitle ] -] - -{ #category : '*NewTools-SettingsBrowser' } -SpNotebookPresenter >> hasPages [ - - ^ self pages isNotEmpty -] - -{ #category : '*NewTools-SettingsBrowser' } -SpNotebookPresenter >> pageNamed: aTitle [ - - ^ self pages detect: [ : page | page title = aTitle ] -]