Skip to content

Commit

Permalink
Add SpSearchInputFieldOptionsPresenter
Browse files Browse the repository at this point in the history
  • Loading branch information
Hernán Morales Durand committed Sep 20, 2024
1 parent 5b6ba6a commit b015861
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Spec2-Core/SpAbstractFormButtonPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ SpAbstractFormButtonPresenter >> initialize [
self whenLabelClickableChangedDo: [ :aBoolean | self changed: {#labelClickable: . aBoolean} ]
]

{ #category : 'testing' }
SpAbstractFormButtonPresenter >> isActive [
"Answer <true> if the receiver is selected"

^ self state
]

{ #category : 'api' }
SpAbstractFormButtonPresenter >> label [
"Answers the label to be shown by the button"
Expand Down
110 changes: 110 additions & 0 deletions src/Spec2-Core/SpSearchInputFieldOptionsPresenter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
"
Provides a presenter to allow the user to configure the type of search.
A radio button group is used for the main search type:
- Substring search
- Regular expression search
- Exact matching
A separate checkboxes is used for case sensitive search. It's important to note that exact matching cannot be combined with substring or regex searches, as they are fundamentally different approaches.
"
Class {
#name : 'SpSearchInputFieldOptionsPresenter',
#superclass : 'SpPresenter',
#instVars : [
'caseCheckBox',
'regexpOptionButton',
'exactOptionButton',
'substringOptionButton'
],
#category : 'Spec2-Core-Widgets',
#package : 'Spec2-Core',
#tag : 'Widgets'
}

{ #category : 'instance creation' }
SpSearchInputFieldOptionsPresenter class >> open [
<script>

^ self new open
]

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

^ SpBoxLayout newLeftToRight
spacing: 2;
add: substringOptionButton width: 95;
add: regexpOptionButton width: 70;
add: exactOptionButton width: 70;
add: caseCheckBox width: 70;
yourself
]

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

super initializePresenters.
self initializeSearchTypePresenters.
]

{ #category : 'initialization' }
SpSearchInputFieldOptionsPresenter >> initializeSearchTypePresenters [

regexpOptionButton := self newRadioButton
label: 'Regexp';
state: false;
help: 'Use regular expression';
yourself.

exactOptionButton := self newRadioButton
label: 'Exact';
state: false;
help: 'Use exact match';
yourself.

substringOptionButton := self newRadioButton
label: 'Substring';
help: 'Use substring search';
yourself.

substringOptionButton associatedRadioButtons: { exactOptionButton. regexpOptionButton }.

caseCheckBox := self newCheckBox
label: 'Case';
state: false;
help: 'Use match case';
yourself.
]

{ #category : 'updating' }
SpSearchInputFieldOptionsPresenter >> selectBlock [
"Answer a <BlockClosure> with the matching strategy depending of the active searching options in the receiver"

(regexpOptionButton isActive and: [ caseCheckBox isActive not ])
ifTrue: [ ^ [ : item : regex | regex asRegexIgnoringCase search: item ] ].

(regexpOptionButton isActive and: [ caseCheckBox isActive ])
ifTrue: [ ^ [ : item : regex | regex search: item ] ].

(exactOptionButton isActive and: [ caseCheckBox isActive and: [ regexpOptionButton isActive not ]])
ifTrue: [ ^ [ : item : pattern | item = pattern ] ].

(exactOptionButton isActive and: [ caseCheckBox isActive not and: [ regexpOptionButton isActive not ] ])
ifTrue: [ ^ [ : item : pattern | item asLowercase = pattern asLowercase ] ].

(exactOptionButton isActive not and: [ caseCheckBox isActive and: [ regexpOptionButton isActive not ] ])
ifTrue: [ ^ [ : item : pattern | item includesSubstring: pattern caseSensitive: true ] ].

(exactOptionButton isActive not and: [ caseCheckBox isActive not and: [ regexpOptionButton isActive not ] ])
ifTrue: [ ^ [ : item : pattern | item includesSubstring: pattern caseSensitive: false ] ].


]

{ #category : 'accessing' }
SpSearchInputFieldOptionsPresenter >> substringBox [
^ substringOptionButton
]

0 comments on commit b015861

Please sign in to comment.