-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #759 from jecisc/protocols
Add StProtocolNameChooserPresenter
- Loading branch information
Showing
12 changed files
with
257 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
src/NewTools-Core-Tests/StProtocolNameChooserPresenterTest.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
" | ||
A StProtocolNameChooserPresenterTest is a test class for testing the behavior of StProtocolNameChooserPresenter | ||
" | ||
Class { | ||
#name : 'StProtocolNameChooserPresenterTest', | ||
#superclass : 'TestCase', | ||
#instVars : [ | ||
'presenter' | ||
], | ||
#category : 'NewTools-Core-Tests-ProtocolChooser', | ||
#package : 'NewTools-Core-Tests', | ||
#tag : 'ProtocolChooser' | ||
} | ||
|
||
{ #category : 'running' } | ||
StProtocolNameChooserPresenterTest >> setUp [ | ||
super setUp. | ||
presenter := StProtocolNameChooserPresenter new | ||
] | ||
|
||
{ #category : 'tests' } | ||
StProtocolNameChooserPresenterTest >> testSmokeTest [ | ||
|
||
| window | | ||
[ self shouldnt: [ window := presenter open ] raise: Error ] ensure: [ window close ]. | ||
|
||
[ self shouldnt: [ window := presenter openDialog ] raise: Error ] ensure: [ window close ]. | ||
|
||
presenter concernedClass: self class. | ||
presenter protocolName: 'test'. | ||
|
||
[ self shouldnt: [ window := presenter open ] raise: Error ] ensure: [ window close ] | ||
] | ||
|
||
{ #category : 'tests' } | ||
StProtocolNameChooserPresenterTest >> testSuggestedProtocolsAreOrderedByPriority [ | ||
"I'm not sure how to test this without using the sae code as #protocolsToSuggest so I'm hardcoding 3 of the most used protocols in the system" | ||
|
||
self assert: ((presenter protocolsToSuggest first: 5) includesAll: #( accessing initialization testing )) | ||
] | ||
|
||
{ #category : 'tests' } | ||
StProtocolNameChooserPresenterTest >> testSuggestedProtocolsDependOnInstanceOrClassSide [ | ||
|
||
| protocolName classProtocolName | | ||
protocolName := UUID new asString36. | ||
classProtocolName := UUID new asString36. | ||
|
||
[ | ||
self class addProtocol: protocolName. | ||
self class class addProtocol: classProtocolName. | ||
|
||
presenter concernedClass: self class. | ||
self assert: (presenter protocolsToSuggest includes: protocolName). | ||
self deny: (presenter protocolsToSuggest includes: classProtocolName). | ||
|
||
presenter concernedClass: self class class. | ||
self deny: (presenter protocolsToSuggest includes: protocolName). | ||
self assert: (presenter protocolsToSuggest includes: classProtocolName) ] ensure: [ | ||
self class removeProtocol: protocolName. | ||
self class class removeProtocol: classProtocolName ] | ||
] | ||
|
||
{ #category : 'tests' } | ||
StProtocolNameChooserPresenterTest >> testSuggestedProtocolsIncludesProtocolsOfTheImage [ | ||
|
||
| protocolName | | ||
protocolName := UUID new asString36. | ||
|
||
self deny: (presenter protocolsToSuggest includes: protocolName). | ||
[ | ||
self class addProtocol: protocolName. | ||
|
||
self assert: (presenter protocolsToSuggest includes: protocolName) ] ensure: [ self class removeProtocol: protocolName ] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Package { #name : 'NewTools-Core-Tests' } |
165 changes: 165 additions & 0 deletions
165
src/NewTools-Core/StProtocolNameChooserPresenter.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
" | ||
I am a little interface to let the user choose the name of a protocol. | ||
This interface will suggest the name of the protocol as the user types the beginning of the name. | ||
I can be configured with a concerned class to refine the UI such as proposing instance or class side protocols in the suggestion list. | ||
See my class side for an example of usage and some helpers. | ||
Idea of improvements for the future: | ||
- Suggest protocols from super classes first? | ||
- Add tests | ||
" | ||
Class { | ||
#name : 'StProtocolNameChooserPresenter', | ||
#superclass : 'StPresenter', | ||
#instVars : [ | ||
'suggestionList', | ||
'protocolNameField', | ||
'concernedClass' | ||
], | ||
#category : 'NewTools-Core-ProtocolChooser', | ||
#package : 'NewTools-Core', | ||
#tag : 'ProtocolChooser' | ||
} | ||
|
||
{ #category : 'examples' } | ||
StProtocolNameChooserPresenter class >> exampleConfiguringPresenter [ | ||
|
||
<example> | ||
self requestProtocolNameConfiguring: [ :presenter :dialog | | ||
presenter | ||
concernedClass: self class; "Giving the concerned class can allow some customizations such as knowing if we should suggest instance or class side protocols" | ||
protocolName: 'ac'. | ||
dialog title: 'Updated title' ] | ||
] | ||
|
||
{ #category : 'instance creation' } | ||
StProtocolNameChooserPresenter class >> open [ | ||
|
||
<script> | ||
self new open | ||
] | ||
|
||
{ #category : 'instance creation' } | ||
StProtocolNameChooserPresenter class >> requestProtocolName [ | ||
"See comment of StProtocolNameChooser class>>#requestProtocolNameConfiguring:" | ||
|
||
<script> | ||
^ self requestProtocolNameConfiguring: [ :presenter :dialog | ] | ||
] | ||
|
||
{ #category : 'instance creation' } | ||
StProtocolNameChooserPresenter class >> requestProtocolNameConfiguring: aBlock [ | ||
"I request a protocol name through a dialog and signal a CmdCommandAborted in case the provided protocol is empty or an extension name. | ||
I allow the user to configure the presenter or the dialog via a configuration block." | ||
|
||
<script> | ||
| protocolName presenter dialog | | ||
dialog := (presenter := self new) asBlockedDialogWindow. | ||
|
||
aBlock cull: presenter cull: dialog. | ||
|
||
dialog open. | ||
|
||
protocolName := presenter protocolName. | ||
|
||
protocolName isEmptyOrNil ifTrue: [ CmdCommandAborted signal ]. | ||
(protocolName beginsWith: '*') ifTrue: [ | ||
self inform: 'Star is forbidden for protocol name since this is used for method extensions.'. | ||
^ CmdCommandAborted signal ]. | ||
^ protocolName | ||
] | ||
|
||
{ #category : 'accessing' } | ||
StProtocolNameChooserPresenter >> concernedClass [ | ||
"Giving the concerned class can allow some customizations such as knowing if we should suggest instance or class side protocols" | ||
|
||
^ concernedClass | ||
] | ||
|
||
{ #category : 'accessing' } | ||
StProtocolNameChooserPresenter >> concernedClass: anObject [ | ||
|
||
concernedClass := anObject | ||
] | ||
|
||
{ #category : 'initialization' } | ||
StProtocolNameChooserPresenter >> connectPresenters [ | ||
|
||
super connectPresenters. | ||
|
||
protocolNameField whenTextChangedDo: [ self updatePresenter ] | ||
] | ||
|
||
{ #category : 'layout' } | ||
StProtocolNameChooserPresenter >> defaultLayout [ | ||
|
||
^ SpBoxLayout newTopToBottom | ||
add: suggestionList; | ||
add: protocolNameField expand: false; | ||
yourself | ||
] | ||
|
||
{ #category : 'initialization' } | ||
StProtocolNameChooserPresenter >> initializeDialogWindow: aDialogWindowPresenter [ | ||
|
||
super initializeDialogWindow: aDialogWindowPresenter. | ||
protocolNameField whenSubmitDo: [ :protocolName | aDialogWindowPresenter triggerOkAction ]. | ||
suggestionList whenSelectedDo: [ :protocolName | self protocolName: protocolName ] | ||
] | ||
|
||
{ #category : 'initialization' } | ||
StProtocolNameChooserPresenter >> initializePresenters [ | ||
|
||
super initializePresenters. | ||
|
||
suggestionList := self newList. | ||
|
||
protocolNameField := self newTextInput. | ||
protocolNameField placeholder: 'Protocol name (e.g. accessing)' | ||
] | ||
|
||
{ #category : 'initialization' } | ||
StProtocolNameChooserPresenter >> initializeWindow: aWindowPresenter [ | ||
|
||
super initializeWindow: aWindowPresenter. | ||
aWindowPresenter title: 'New protocol name'. | ||
|
||
aWindowPresenter whenOpenedDo: [ protocolNameField takeKeyboardFocus ] | ||
] | ||
|
||
{ #category : 'accessing - defaults' } | ||
StProtocolNameChooserPresenter >> protocolName [ | ||
^ protocolNameField text asSymbol | ||
] | ||
|
||
{ #category : 'accessing' } | ||
StProtocolNameChooserPresenter >> protocolName: aString [ | ||
"I allow to set a default protocol name to the list." | ||
|
||
protocolNameField text: aString. | ||
self updatePresenter | ||
] | ||
|
||
{ #category : 'initialization' } | ||
StProtocolNameChooserPresenter >> protocolsToSuggest [ | ||
|
||
| suggestedProtocols | | ||
suggestedProtocols := concernedClass environment allClasses flatCollect: [ :class | | ||
(concernedClass isNil or: [ concernedClass isInstanceSide ]) | ||
ifTrue: [ class protocols ] | ||
ifFalse: [ class class protocols ] ]. | ||
suggestedProtocols := suggestedProtocols reject: [ :protocol | protocol isExtensionProtocol ]. | ||
suggestedProtocols := suggestedProtocols collect: [ :protocol | protocol name ] as: Bag. | ||
suggestedProtocols := suggestedProtocols sortedCounts collect: [ :association | association value ]. | ||
suggestedProtocols := suggestedProtocols select: [ :protocolName | protocolName includesSubstring: self protocolName ]. | ||
^ suggestedProtocols | ||
] | ||
|
||
{ #category : 'initialization' } | ||
StProtocolNameChooserPresenter >> updatePresenter [ | ||
|
||
suggestionList items: self protocolsToSuggest | ||
] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/NewTools-Fuel/Object.extension.st → src/NewTools-Utils/Object.extension.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...Compression-Utils/ZipArchive.extension.st → src/NewTools-Utils/ZipArchive.extension.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Package { #name : 'NewTools-Utils' } |