Skip to content
Permalink
Browse files

Merge pull request #721 from juliendelplanque/720-Implement-method-to…

…-convert-spec-command-as-ButtonPresenter

720-Implement-method-to-convert-spec-command-as-ButtonPresenter
  • Loading branch information...
jecisc committed Aug 12, 2019
2 parents 152af5e + fb85041 commit dab03121fe9fa6c064b4fd837157c88e1e8505bd
Showing with 67 additions and 1 deletion.
  1. +48 −0 src/Spec2-Commander2-Tests/SpCommandTest.class.st
  2. +19 −1 src/Spec2-Commander2/SpCommand.class.st
@@ -27,6 +27,54 @@ SpCommandTest >> setUp [
command := SpCommand new
]

{ #category : #test }
SpCommandTest >> testAsButtonPresenter [
| buttonPresenter |
command := CmCommand forSpec
basicName: 'foo';
basicDescription: 'bar';
yourself.


buttonPresenter := command asButtonPresenter.

self assert: buttonPresenter label equals: 'foo'.
self assert: buttonPresenter help equals: 'bar'.
self assert: buttonPresenter icon isNil
]

{ #category : #test }
SpCommandTest >> testAsButtonPresenter2 [
| buttonPresenter |
command := CmCommand forSpec
basicName: 'foo';
basicDescription: 'bar';
iconName: #blank;
yourself.


buttonPresenter := command asButtonPresenter.

self assert: buttonPresenter label equals: 'foo'.
self assert: buttonPresenter help equals: 'bar'.
self assert: buttonPresenter icon equals: (buttonPresenter iconNamed: #blank)
]

{ #category : #test }
SpCommandTest >> testAsButtonPresenterExecutesOnClick [
| flag buttonPresenter |
flag := false.
command := CmBlockCommand new
block: [ flag := true ];
yourself.

buttonPresenter := command asSpecCommand asButtonPresenter.

buttonPresenter click.

self assert: flag equals: true
]

{ #category : #test }
SpCommandTest >> testHasIcon [
self deny: command hasIcon.
@@ -4,6 +4,9 @@ I am a command decorator adding informations useful when for usage in context of
Basically, I add:
- an #icon (#blank by default)
- a #shortcutKey (optional)
- a #displayStrategy to handle how to show the command if it is not executable on a context (default is to be disabled)
- a actionBarStrategy to handle on which side of the action bar I should be (default is left)
"
Class {
#name : #SpCommand,
@@ -12,11 +15,26 @@ Class {
'iconProvider',
'iconName',
'shortcutKey',
'displayStrategy'
'displayStrategy',
'actionBarStrategy'
],
#category : #'Spec2-Commander2-Core'
}

{ #category : #converting }
SpCommand >> asButtonPresenter [
self flag: #TODO. "Needs to use inform user display strategy when available, no other available strategy can be used in this context. See issue #705"
^ SpButtonPresenter new
label: self name;
help: self description;
in: [ :button |
self hasIcon
ifTrue: [ button iconName: self iconName ] ];
action: [ self execute ]
yourself

]

{ #category : #configuring }
SpCommand >> beDisabledWhenCantBeRun [
self displayStrategy: SpDisableWhenCantBeRun new

0 comments on commit dab0312

Please sign in to comment.
You can’t perform that action at this time.