Skip to content

Commit

Permalink
search on easy list views (not con column views or trees yet) working
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanlm committed Nov 15, 2024
1 parent 4c5d9b5 commit 7cc74d1
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 16 deletions.
5 changes: 4 additions & 1 deletion src/Spec2-Adapters-Morphic/SpStyle.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ SpStyle class >> defaultStyleSheetData [
.progressBar:label [ Draw { #color : EnvironmentColor(#selectionText) } ],
.progressBar:bar [
Draw { #color: EnvironmentColor(#selection) },
Geometry { #height: 5 } ]
Geometry { #height: 5 } ] ,
.searchBox [
Geometry { #width: 150 }
]
]
'
]
Expand Down
7 changes: 7 additions & 0 deletions src/Spec2-Core/SpAbstractListPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ SpAbstractListPresenter >> initialize [

super initialize.
self initializeTHaveWrappingScrollBars.
self initializeTSearchable.

activationBlock := [ ].
verticalAlignment := SpVerticalAlignment new.
Expand Down Expand Up @@ -259,6 +260,12 @@ SpAbstractListPresenter >> registerEvents [
self withAdapterDo: [ :anAdapter | anAdapter updateMenu ] ]
]

{ #category : 'private' }
SpAbstractListPresenter >> searchValueOf: item [

^ item asString
]

{ #category : 'api' }
SpAbstractListPresenter >> sortingBlock [
"Answer the sorting block defined to sort the model list.
Expand Down
1 change: 0 additions & 1 deletion src/Spec2-Core/SpListPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ SpListPresenter >> iconFor: anItem [
SpListPresenter >> initialize [

super initialize.
self initializeTSearchable.
autoDeselect := true.
allowToSelect := true.
display := [ :object | object asStringOrText ]
Expand Down
9 changes: 0 additions & 9 deletions src/Spec2-Core/SpTablePresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ A table has columns with a type (See column types section).
Class {
#name : 'SpTablePresenter',
#superclass : 'SpAbstractListPresenter',
#traits : 'SpTSearchable',
#classTraits : 'SpTSearchable classTrait',
#instVars : [
'#columns => ObservableSlot',
'#showColumnHeaders => ObservableSlot',
Expand Down Expand Up @@ -110,7 +108,6 @@ SpTablePresenter >> hideColumnHeaders [
SpTablePresenter >> initialize [

super initialize.
self initializeTSearchable.
showColumnHeaders := true.
columns := #().
isResizable := false
Expand Down Expand Up @@ -142,12 +139,6 @@ SpTablePresenter >> removeColumn: aColumn [
columns := columns copyWithout: aColumn
]

{ #category : 'private' }
SpTablePresenter >> searchValueOf: anObject [

^ anObject asString
]

{ #category : 'api' }
SpTablePresenter >> showColumnHeaders [
"Show column headers"
Expand Down
4 changes: 3 additions & 1 deletion src/Spec2-ListView/SpAbstractEasyListViewPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SpAbstractEasyListViewPresenter >> findFirst: aString [
items isEmptyOrNil ifTrue: [ ^ 0 ].

(contentView selection selectedIndex max: 1) to: items size do: [ :index |
(self
(contentView
performSearch: (items at: index)
matching: aString)
ifTrue: [ ^ index ] ].
Expand Down Expand Up @@ -75,6 +75,8 @@ SpAbstractEasyListViewPresenter >> selectFirst [
SpAbstractEasyListViewPresenter >> selectFirst: aString [
| index |

self isSearchEnabled ifFalse: [ ^ self ].

index := self findFirst: aString.
index = 0 ifTrue: [ ^ self ].

Expand Down
10 changes: 8 additions & 2 deletions src/Spec2-ListView/SpAbstractEasyPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ SpAbstractEasyPresenter >> activateSearchWith: aString [

self isSearchEnabled ifFalse: [ ^ self ].

"keep last in case we need to go back there (if user cancels)"
lastSelectedRow := contentView selectedItem.

searchBox show.
searchBox text: aString.
searchBox takeKeyboardFocus.
searchBox unselectAll.
searchBox cursorPositionIndex: aString size
searchBox cursorPositionIndex: aString size + 1
]

{ #category : 'api' }
Expand Down Expand Up @@ -206,7 +207,12 @@ SpAbstractEasyPresenter >> maybeActivateSearchOn: event [
(event anyModifierKeyPressed
or: [ (event keyValue between: 32 and: 127) not ])
ifTrue: [ ^ self ].
self activateSearchWith: event keyCharacter asString

event wasHandled: true.
"I need to defer it beacuse in morphic this causes the event to
be passed to the box (no idea why)."
self application defer: [
self activateSearchWith: event keyCharacter asString ]
]

{ #category : 'transmission' }
Expand Down
2 changes: 1 addition & 1 deletion src/Spec2-ListView/SpEasySearchBoxPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ SpEasySearchBoxPresenter >> defaultLayout [
{ #category : 'initialization' }
SpEasySearchBoxPresenter >> initializePresenters [

self addStyle: 'stSearchbar'.
self addStyle: 'searchBox'.

textInput := self newSearchInput.
closeButton := self newButton
Expand Down
1 change: 0 additions & 1 deletion src/Spec2-ListView/SpListViewPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ SpListViewPresenter >> headerTitle: aString [
SpListViewPresenter >> initialize [

super initialize.
self initializeTSearchable.
self initializeItemFactory
]

Expand Down

0 comments on commit 7cc74d1

Please sign in to comment.