From 6cbe943274404b3833c2bbcf01f42c6189f63f5b Mon Sep 17 00:00:00 2001 From: Esteban Lorenzano Date: Mon, 18 Dec 2023 13:16:47 +0100 Subject: [PATCH] move examples to listview presenter package to fix dependency --- .../SpDropDownPresenter.extension.st | 56 ------ .../SpListViewPresenter.extension.st | 162 ------------------ .../SpDropDownPresenter.class.st | 55 ++++++ .../SpListViewPresenter.class.st | 161 +++++++++++++++++ 4 files changed, 216 insertions(+), 218 deletions(-) delete mode 100644 src/Spec2-Examples/SpDropDownPresenter.extension.st delete mode 100644 src/Spec2-Examples/SpListViewPresenter.extension.st diff --git a/src/Spec2-Examples/SpDropDownPresenter.extension.st b/src/Spec2-Examples/SpDropDownPresenter.extension.st deleted file mode 100644 index 9f4b300c..00000000 --- a/src/Spec2-Examples/SpDropDownPresenter.extension.st +++ /dev/null @@ -1,56 +0,0 @@ -Extension { #name : 'SpDropDownPresenter' } - -{ #category : '*Spec2-Examples' } -SpDropDownPresenter class >> example [ - "This example show the simples list view you can make: A list with a label" - - self new - application: (SpApplication new useBackend: #Gtk); - items: self environment allClasses; - setup: [ :aPresenter | aPresenter newLabel ]; - bind: [ :aPresenter :aClass | aPresenter label: aClass name ]; - display: [ :aClass | aClass name ]; - open -] - -{ #category : '*Spec2-Examples' } -SpDropDownPresenter class >> exampleWithIcons [ - "This example shows how to construct a list with icons. - It shows also the fact you can put any presenter inside, giving a huge power - to your lists." - - ^ self new - application: (SpApplication new useBackend: #Gtk); - items: self environment allClasses; - setup: [ :aPresenter | - | presenter | - (presenter := aPresenter newPresenter) - layout: (SpBoxLayout newHorizontal - "spacing: 5;" - add: presenter newImage expand: false; - add: presenter newLabel; - yourself); - yourself ]; - bind: [ :aPresenter :aClass | | icon image label | - icon := Smalltalk ui icons iconNamed: aClass systemIconName. - image := aPresenter layout children first. - image image: icon. - label := aPresenter layout children second. - label label: aClass name ]; - open -] - -{ #category : '*Spec2-Examples' } -SpDropDownPresenter class >> exampleWithSelectedItem [ - "This example show the simples list view you can make: A list with a label" - - self new - application: (SpApplication new useBackend: #Gtk); - items: self environment allClassesAndTraits; - setup: [ :aPresenter | aPresenter newLabel ]; - bind: [ :aPresenter :aClass | aPresenter label: aClass name ]; - display: [ :aClass | aClass name ]; - selectItem: Object; - whenSelectionChangedDo: [ :aSelection | aSelection selectedItem crTrace ]; - open -] diff --git a/src/Spec2-Examples/SpListViewPresenter.extension.st b/src/Spec2-Examples/SpListViewPresenter.extension.st deleted file mode 100644 index 527c77aa..00000000 --- a/src/Spec2-Examples/SpListViewPresenter.extension.st +++ /dev/null @@ -1,162 +0,0 @@ -Extension { #name : 'SpListViewPresenter' } - -{ #category : '*Spec2-Examples' } -SpListViewPresenter class >> example [ - "This example show the simples list view you can make: A list with a label" - - self new - application: (SpApplication new useBackend: #Gtk); - items: self environment allClasses; - setup: [ :aPresenter | aPresenter newLabel ]; - bind: [ :aPresenter :aClass | aPresenter label: aClass name ]; - open -] - -{ #category : '*Spec2-Examples' } -SpListViewPresenter class >> exampleReplaceItems [ - "This example shows how to replace dynamically the list of elements." - | presenter listView button items | - - items := #(). - - presenter := SpPresenter newApplication: (SpApplication new "useBackend: #Gtk"). - presenter layout: (SpBoxLayout newVertical - add: (listView := presenter newListView); - add: (button := presenter newButton) expand: false; - yourself). - - listView - items: #(); - setup: [ :aPresenter | aPresenter newLabel ]; - bind: [ :aPresenter :aClass | aPresenter label: aClass name ]. - - button - label: 'Add'; - action: [ listView items: (items := items copyWith: self environment allClasses atRandom) ]. - - ^ presenter open -] - -{ #category : '*Spec2-Examples' } -SpListViewPresenter class >> exampleWithActions [ - "This example show the simples list view you can make: A list with a label" - - self new - application: (SpApplication new useBackend: #Gtk); - items: self environment allClasses; - setup: [ :aPresenter | aPresenter newLabel ]; - bind: [ :aPresenter :aClass | aPresenter label: aClass name ]; - actionsWith: [ :rootGroup | rootGroup - addGroupWith: [ :aGroup | aGroup - name: 'Group 1'; - beDisplayedAsGroup; - addActionWith: [ :act | act - name: 'Test 1'; - shortcut: $a ctrl; - action: [ 'Test 1.1' crTrace ] ]; - addActionWith: [ :act | act - name: 'Test 2'; - action: [ 'Test 1.2' crTrace ] ] ]; - addGroupWith: [ :subGroup1 | subGroup1 - name: 'Group 2'; - addActionWith: [ :act | act - name: 'Test 1'; - shortcut: $y ctrl; - action: [ 'Test 2.1' crTrace ]; - actionEnabled: [ false ] ]; - addActionWith: [ :act | act - name: 'Test 2'; - action: [ 'Test 2.2' crTrace ] ] ]; - addActionWith: [ :act | act - name: 'Test 3'; - shortcut: $a ctrl; - action: [ 'Test 3' crTrace ] ]; - addActionWith: [ :act | act - name: 'Test 4'; - shortcut: Character escape asKeyCombination; - action: [ 'Test 4' crTrace ] ] ]; - open -] - -{ #category : '*Spec2-Examples' } -SpListViewPresenter class >> exampleWithIcons [ - "This example shows how to construct a list with icons. - It shows also the fact you can put any presenter inside, giving a huge power - to your lists." - - ^ self new - "application: (SpApplication new useBackend: #Gtk);" - items: self environment allClasses; - setup: [ :aPresenter | - | presenter | - (presenter := aPresenter newPresenter) - layout: (SpBoxLayout newHorizontal - spacing: 5; - add: presenter newImage expand: false; - add: presenter newLabel; - yourself); - yourself ]; - bind: [ :aPresenter :aClass | | icon image label | - icon := Smalltalk ui icons iconNamed: aClass systemIconName. - image := aPresenter layout children first. - image image: icon. - label := aPresenter layout children second. - label label: aClass name ]; - open -] - -{ #category : '*Spec2-Examples' } -SpListViewPresenter class >> exampleWithIconsAndSelectedItem [ - "This example shows how to construct a list with icons. - It shows also the fact you can put any presenter inside, giving a huge power - to your lists." - - ^ self new - "application: (SpApplication new useBackend: #Gtk);" - items: self environment allClasses; - selectItem: Object scrollToSelection: true; - setup: [ :aPresenter | - | presenter | - (presenter := aPresenter newPresenter) - layout: (SpBoxLayout newHorizontal - spacing: 5; - add: presenter newImage expand: false; - add: presenter newLabel; - yourself); - yourself ]; - bind: [ :aPresenter :aClass | | icon image label | - icon := Smalltalk ui icons iconNamed: aClass systemIconName. - image := aPresenter layout children first. - image image: icon. - label := aPresenter layout children second. - label label: aClass name ]; - open -] - -{ #category : '*Spec2-Examples' } -SpListViewPresenter class >> exampleWithIconsMultipleSelection [ - "This example shows how to construct a list with multiple selection available. - It shows also the fact you can put any presenter inside, giving a huge power - to your lists." - - ^ self new - "application: (SpApplication new useBackend: #Gtk);" - beMultipleSelection; - items: self environment allClasses; - setup: [ :aPresenter | - | presenter | - (presenter := aPresenter newPresenter) - layout: (SpBoxLayout newHorizontal - spacing: 5; - add: presenter newImage expand: false; - add: presenter newLabel; - yourself); - yourself ]; - bind: [ :aPresenter :aClass | | icon image label | - icon := Smalltalk ui icons iconNamed: aClass systemIconName. - image := aPresenter layout children first. - image image: icon. - label := aPresenter layout children second. - label label: aClass name ]; - open -] diff --git a/src/Spec2-ListView/SpDropDownPresenter.class.st b/src/Spec2-ListView/SpDropDownPresenter.class.st index b4f9346d..f212fbde 100644 --- a/src/Spec2-ListView/SpDropDownPresenter.class.st +++ b/src/Spec2-ListView/SpDropDownPresenter.class.st @@ -18,6 +18,61 @@ SpDropDownPresenter class >> adapterName [ ^ #DropDownAdapter ] +{ #category : 'examples' } +SpDropDownPresenter class >> example [ + "This example show the simples list view you can make: A list with a label" + + self new + application: (SpApplication new useBackend: #Gtk); + items: self environment allClasses; + setup: [ :aPresenter | aPresenter newLabel ]; + bind: [ :aPresenter :aClass | aPresenter label: aClass name ]; + display: [ :aClass | aClass name ]; + open +] + +{ #category : 'examples' } +SpDropDownPresenter class >> exampleWithIcons [ + "This example shows how to construct a list with icons. + It shows also the fact you can put any presenter inside, giving a huge power + to your lists." + + ^ self new + application: (SpApplication new useBackend: #Gtk); + items: self environment allClasses; + setup: [ :aPresenter | + | presenter | + (presenter := aPresenter newPresenter) + layout: (SpBoxLayout newHorizontal + "spacing: 5;" + add: presenter newImage expand: false; + add: presenter newLabel; + yourself); + yourself ]; + bind: [ :aPresenter :aClass | | icon image label | + icon := Smalltalk ui icons iconNamed: aClass systemIconName. + image := aPresenter layout children first. + image image: icon. + label := aPresenter layout children second. + label label: aClass name ]; + open +] + +{ #category : 'examples' } +SpDropDownPresenter class >> exampleWithSelectedItem [ + "This example show the simples list view you can make: A list with a label" + + self new + application: (SpApplication new useBackend: #Gtk); + items: self environment allClassesAndTraits; + setup: [ :aPresenter | aPresenter newLabel ]; + bind: [ :aPresenter :aClass | aPresenter label: aClass name ]; + display: [ :aClass | aClass name ]; + selectItem: Object; + whenSelectionChangedDo: [ :aSelection | aSelection selectedItem crTrace ]; + open +] + { #category : 'api' } SpDropDownPresenter >> bind: aBlock [ diff --git a/src/Spec2-ListView/SpListViewPresenter.class.st b/src/Spec2-ListView/SpListViewPresenter.class.st index 24da7809..77a2ed22 100644 --- a/src/Spec2-ListView/SpListViewPresenter.class.st +++ b/src/Spec2-ListView/SpListViewPresenter.class.st @@ -17,6 +17,167 @@ SpListViewPresenter class >> adapterName [ ^ #ListViewAdapter ] +{ #category : 'examples' } +SpListViewPresenter class >> example [ + "This example show the simples list view you can make: A list with a label" + + self new + application: (SpApplication new useBackend: #Gtk); + items: self environment allClasses; + setup: [ :aPresenter | aPresenter newLabel ]; + bind: [ :aPresenter :aClass | aPresenter label: aClass name ]; + open +] + +{ #category : 'examples' } +SpListViewPresenter class >> exampleReplaceItems [ + "This example shows how to replace dynamically the list of elements." + | presenter listView button items | + + items := #(). + + presenter := SpPresenter newApplication: (SpApplication new "useBackend: #Gtk"). + presenter layout: (SpBoxLayout newVertical + add: (listView := presenter newListView); + add: (button := presenter newButton) expand: false; + yourself). + + listView + items: #(); + setup: [ :aPresenter | aPresenter newLabel ]; + bind: [ :aPresenter :aClass | aPresenter label: aClass name ]. + + button + label: 'Add'; + action: [ listView items: (items := items copyWith: self environment allClasses atRandom) ]. + + ^ presenter open +] + +{ #category : 'examples' } +SpListViewPresenter class >> exampleWithActions [ + "This example show the simples list view you can make: A list with a label" + + self new + application: (SpApplication new useBackend: #Gtk); + items: self environment allClasses; + setup: [ :aPresenter | aPresenter newLabel ]; + bind: [ :aPresenter :aClass | aPresenter label: aClass name ]; + actionsWith: [ :rootGroup | rootGroup + addGroupWith: [ :aGroup | aGroup + name: 'Group 1'; + beDisplayedAsGroup; + addActionWith: [ :act | act + name: 'Test 1'; + shortcut: $a ctrl; + action: [ 'Test 1.1' crTrace ] ]; + addActionWith: [ :act | act + name: 'Test 2'; + action: [ 'Test 1.2' crTrace ] ] ]; + addGroupWith: [ :subGroup1 | subGroup1 + name: 'Group 2'; + addActionWith: [ :act | act + name: 'Test 1'; + shortcut: $y ctrl; + action: [ 'Test 2.1' crTrace ]; + actionEnabled: [ false ] ]; + addActionWith: [ :act | act + name: 'Test 2'; + action: [ 'Test 2.2' crTrace ] ] ]; + addActionWith: [ :act | act + name: 'Test 3'; + shortcut: $a ctrl; + action: [ 'Test 3' crTrace ] ]; + addActionWith: [ :act | act + name: 'Test 4'; + shortcut: Character escape asKeyCombination; + action: [ 'Test 4' crTrace ] ] ]; + open +] + +{ #category : 'examples' } +SpListViewPresenter class >> exampleWithIcons [ + "This example shows how to construct a list with icons. + It shows also the fact you can put any presenter inside, giving a huge power + to your lists." + + ^ self new + "application: (SpApplication new useBackend: #Gtk);" + items: self environment allClasses; + setup: [ :aPresenter | + | presenter | + (presenter := aPresenter newPresenter) + layout: (SpBoxLayout newHorizontal + spacing: 5; + add: presenter newImage expand: false; + add: presenter newLabel; + yourself); + yourself ]; + bind: [ :aPresenter :aClass | | icon image label | + icon := Smalltalk ui icons iconNamed: aClass systemIconName. + image := aPresenter layout children first. + image image: icon. + label := aPresenter layout children second. + label label: aClass name ]; + open +] + +{ #category : 'examples' } +SpListViewPresenter class >> exampleWithIconsAndSelectedItem [ + "This example shows how to construct a list with icons. + It shows also the fact you can put any presenter inside, giving a huge power + to your lists." + + ^ self new + "application: (SpApplication new useBackend: #Gtk);" + items: self environment allClasses; + selectItem: Object scrollToSelection: true; + setup: [ :aPresenter | + | presenter | + (presenter := aPresenter newPresenter) + layout: (SpBoxLayout newHorizontal + spacing: 5; + add: presenter newImage expand: false; + add: presenter newLabel; + yourself); + yourself ]; + bind: [ :aPresenter :aClass | | icon image label | + icon := Smalltalk ui icons iconNamed: aClass systemIconName. + image := aPresenter layout children first. + image image: icon. + label := aPresenter layout children second. + label label: aClass name ]; + open +] + +{ #category : 'examples' } +SpListViewPresenter class >> exampleWithIconsMultipleSelection [ + "This example shows how to construct a list with multiple selection available. + It shows also the fact you can put any presenter inside, giving a huge power + to your lists." + + ^ self new + "application: (SpApplication new useBackend: #Gtk);" + beMultipleSelection; + items: self environment allClasses; + setup: [ :aPresenter | + | presenter | + (presenter := aPresenter newPresenter) + layout: (SpBoxLayout newHorizontal + spacing: 5; + add: presenter newImage expand: false; + add: presenter newLabel; + yourself); + yourself ]; + bind: [ :aPresenter :aClass | | icon image label | + icon := Smalltalk ui icons iconNamed: aClass systemIconName. + image := aPresenter layout children first. + image image: icon. + label := aPresenter layout children second. + label label: aClass name ]; + open +] + { #category : 'api' } SpListViewPresenter >> bind: aBlock [