From 7cc74d128935882826341922034dd7d2cb9ecb64 Mon Sep 17 00:00:00 2001 From: Esteban Lorenzano Date: Fri, 15 Nov 2024 14:15:37 +0100 Subject: [PATCH] search on easy list views (not con column views or trees yet) working --- src/Spec2-Adapters-Morphic/SpStyle.class.st | 5 ++++- src/Spec2-Core/SpAbstractListPresenter.class.st | 7 +++++++ src/Spec2-Core/SpListPresenter.class.st | 1 - src/Spec2-Core/SpTablePresenter.class.st | 9 --------- .../SpAbstractEasyListViewPresenter.class.st | 4 +++- src/Spec2-ListView/SpAbstractEasyPresenter.class.st | 10 ++++++++-- src/Spec2-ListView/SpEasySearchBoxPresenter.class.st | 2 +- src/Spec2-ListView/SpListViewPresenter.class.st | 1 - 8 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/Spec2-Adapters-Morphic/SpStyle.class.st b/src/Spec2-Adapters-Morphic/SpStyle.class.st index 1bd40a3d..31a2691b 100644 --- a/src/Spec2-Adapters-Morphic/SpStyle.class.st +++ b/src/Spec2-Adapters-Morphic/SpStyle.class.st @@ -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 } + ] ] ' ] diff --git a/src/Spec2-Core/SpAbstractListPresenter.class.st b/src/Spec2-Core/SpAbstractListPresenter.class.st index 94c603bf..b4bed1cf 100644 --- a/src/Spec2-Core/SpAbstractListPresenter.class.st +++ b/src/Spec2-Core/SpAbstractListPresenter.class.st @@ -125,6 +125,7 @@ SpAbstractListPresenter >> initialize [ super initialize. self initializeTHaveWrappingScrollBars. + self initializeTSearchable. activationBlock := [ ]. verticalAlignment := SpVerticalAlignment new. @@ -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. diff --git a/src/Spec2-Core/SpListPresenter.class.st b/src/Spec2-Core/SpListPresenter.class.st index 50f5cfa9..0e6f1d85 100644 --- a/src/Spec2-Core/SpListPresenter.class.st +++ b/src/Spec2-Core/SpListPresenter.class.st @@ -150,7 +150,6 @@ SpListPresenter >> iconFor: anItem [ SpListPresenter >> initialize [ super initialize. - self initializeTSearchable. autoDeselect := true. allowToSelect := true. display := [ :object | object asStringOrText ] diff --git a/src/Spec2-Core/SpTablePresenter.class.st b/src/Spec2-Core/SpTablePresenter.class.st index 75a04a8a..ba9716fc 100644 --- a/src/Spec2-Core/SpTablePresenter.class.st +++ b/src/Spec2-Core/SpTablePresenter.class.st @@ -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', @@ -110,7 +108,6 @@ SpTablePresenter >> hideColumnHeaders [ SpTablePresenter >> initialize [ super initialize. - self initializeTSearchable. showColumnHeaders := true. columns := #(). isResizable := false @@ -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" diff --git a/src/Spec2-ListView/SpAbstractEasyListViewPresenter.class.st b/src/Spec2-ListView/SpAbstractEasyListViewPresenter.class.st index eb6fab7b..3c581376 100644 --- a/src/Spec2-ListView/SpAbstractEasyListViewPresenter.class.st +++ b/src/Spec2-ListView/SpAbstractEasyListViewPresenter.class.st @@ -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 ] ]. @@ -75,6 +75,8 @@ SpAbstractEasyListViewPresenter >> selectFirst [ SpAbstractEasyListViewPresenter >> selectFirst: aString [ | index | + self isSearchEnabled ifFalse: [ ^ self ]. + index := self findFirst: aString. index = 0 ifTrue: [ ^ self ]. diff --git a/src/Spec2-ListView/SpAbstractEasyPresenter.class.st b/src/Spec2-ListView/SpAbstractEasyPresenter.class.st index aba69398..df93b687 100644 --- a/src/Spec2-ListView/SpAbstractEasyPresenter.class.st +++ b/src/Spec2-ListView/SpAbstractEasyPresenter.class.st @@ -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' } @@ -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' } diff --git a/src/Spec2-ListView/SpEasySearchBoxPresenter.class.st b/src/Spec2-ListView/SpEasySearchBoxPresenter.class.st index 422d81ad..eb25cc79 100644 --- a/src/Spec2-ListView/SpEasySearchBoxPresenter.class.st +++ b/src/Spec2-ListView/SpEasySearchBoxPresenter.class.st @@ -57,7 +57,7 @@ SpEasySearchBoxPresenter >> defaultLayout [ { #category : 'initialization' } SpEasySearchBoxPresenter >> initializePresenters [ - self addStyle: 'stSearchbar'. + self addStyle: 'searchBox'. textInput := self newSearchInput. closeButton := self newButton diff --git a/src/Spec2-ListView/SpListViewPresenter.class.st b/src/Spec2-ListView/SpListViewPresenter.class.st index c10af143..4d4a4787 100644 --- a/src/Spec2-ListView/SpListViewPresenter.class.st +++ b/src/Spec2-ListView/SpListViewPresenter.class.st @@ -269,7 +269,6 @@ SpListViewPresenter >> headerTitle: aString [ SpListViewPresenter >> initialize [ super initialize. - self initializeTSearchable. self initializeItemFactory ]