Skip to content

Commit

Permalink
Merge pull request #1548 from carolahp/selectMultipleDialog
Browse files Browse the repository at this point in the history
New dialog to select multiple items using checkboxes
  • Loading branch information
Ducasse committed Jun 13, 2024
2 parents 808f4a2 + f787b97 commit 2dc4acd
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Spec2-Dialogs/SpApplication.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ SpApplication >> newSelect [
^ SpSelectDialog newApplication: self
]

{ #category : '*Spec2-Dialogs' }
SpApplication >> newSelectMultiple [

^ SpSelectMultipleDialog newApplication: self
]

{ #category : '*Spec2-Dialogs' }
SpApplication >> notificationClass [

Expand Down
189 changes: 189 additions & 0 deletions src/Spec2-Dialogs/SpSelectMultipleDialog.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
"
A dialog that allow the users to select multiple choices from a list of `items`
"
Class {
#name : 'SpSelectMultipleDialog',
#superclass : 'SpAbstractCancelableMessageDialog',
#instVars : [
'table1',
'selectedItems',
'display',
'icon'
],
#category : 'Spec2-Dialogs',
#package : 'Spec2-Dialogs'
}

{ #category : 'accessing' }
SpSelectMultipleDialog class >> defaultExtent [

^ 450@300
]

{ #category : 'examples' }
SpSelectMultipleDialog class >> example [

| presenter |
presenter := self new.
presenter
title: 'Multiple select example';
label: 'Select multiple classes';
items: Smalltalk allClassesAndTraits;
display: [ :each | each name ];
displayIcon: [ :each | self iconNamed: each systemIconName ];
onAccept: [ :dialog |
dialog presenter inform: dialog presenter selectedItems asString ];
openDialog
]

{ #category : 'examples' }
SpSelectMultipleDialog class >> exampleModal [

| dialog selection |
dialog := self new.
selection := dialog
title: 'Select multiple modal example';
label: 'Select multiple classes';
items: Smalltalk allClassesAndTraits;
display: [ :each | each name ];
displayIcon: [ :each |
self iconNamed: each systemIconName ];
openModal.

selection ifNotNil: [ dialog inform: dialog selectedItems asString ]
]

{ #category : 'examples' }
SpSelectMultipleDialog class >> exampleMultiLineLabel [

| presenter label |

label := String streamContents: [ :s |
s nextPutAll: 'Select multiple classes';
cr;
cr;
nextPutAll: 'Something else two lines bellow with a really long long long long text that will wrap'
].

presenter := self new.

presenter
title: 'Select multiple example';
label: label;
items: Smalltalk allClassesAndTraits;
display: [ :each | each name ];
displayIcon: [ :each | self iconNamed: each systemIconName ];
onAccept: [ :dialog |
dialog presenter inform: dialog presenter selectedItem asString ];
openDialog
]

{ #category : 'accessing' }
SpSelectMultipleDialog >> columns [

| columns checkboxColumn imageColumn textColumn |
columns := OrderedCollection new.

checkboxColumn := (SpCheckBoxTableColumn
title: ' '
evaluated: [ :item |
selectedItems includes: item ])
onActivation: [ :item | selectedItems add: item ];
onDeactivation: [ :item |
selectedItems remove: item ];
width: 20;
yourself.
columns add: checkboxColumn.

icon ifNotNil: [
imageColumn := (SpImageTableColumn title: ' ' evaluated: icon)
width: 20;
yourself.
columns add: imageColumn ].

textColumn := SpStringTableColumn title: ' ' evaluated: display.
columns add: textColumn.

^ columns
]

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

^ SpBoxLayout newTopToBottom
add: label height: self calculateLabelHeight;
add: table1;
yourself
]

{ #category : 'accessing' }
SpSelectMultipleDialog >> defaultTitle [

^ 'Multiple request'
]

{ #category : 'api' }
SpSelectMultipleDialog >> display: aBlock [

display := aBlock.
self refreshTable
]

{ #category : 'api' }
SpSelectMultipleDialog >> displayIcon: aBlock [

icon := aBlock.
self refreshTable
]

{ #category : 'api' }
SpSelectMultipleDialog >> extent [

^ initialExtent ifNil: [ self class defaultExtent ]
]

{ #category : 'api' }
SpSelectMultipleDialog >> extent: aPoint [

initialExtent := aPoint
]

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

selectedItems := OrderedCollection new.
super initialize
]

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

super initializePresenters.
table1 := self newTable
beResizable;
yourself
]

{ #category : 'accessing' }
SpSelectMultipleDialog >> items [

^ table1 items
]

{ #category : 'api' }
SpSelectMultipleDialog >> items: aCollection [

table1 items: aCollection
]

{ #category : 'updating' }
SpSelectMultipleDialog >> refreshTable [

table1 columns: self columns
]

{ #category : 'accessing' }
SpSelectMultipleDialog >> selectedItems [

^ selectedItems
]

0 comments on commit 2dc4acd

Please sign in to comment.