Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set enablement of button in SpCommand>>#configureAsButtonOfClass: #1621

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/Spec2-Commander2-Tests/SpCommandTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ SpCommandTest >> testConfigureAsToolBarButton [
self assert: button label equals: command name.
self assert: button help equals: command description.
self assert: button icon isNil.
self assert: button isEnabled.
self assert: button action value equals: command execute
]

Expand Down Expand Up @@ -231,3 +232,27 @@ SpCommandTest >> testShortcutKey [

self assert: command shortcutKey equals: $a asKeyCombination
]

{ #category : 'tests' }
SpCommandTest >> testToolBarButtonEnablement [

| button context |
context := OrderedCollection new.
command := (CmBlockCommand new
name: 'foo';
description: 'bar';
canBeExecutedBlock: [:collection | collection isNotEmpty ];
context: context;
yourself) asSpecCommand.

button := command
configureAsToolbarButton;
buildPresenter.
self deny: button isEnabled.

context add: 1.
button := command
configureAsToolbarButton;
buildPresenter.
self assert: button isEnabled.
]
1 change: 1 addition & 0 deletions src/Spec2-Commander2/SpCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ SpCommand >> configureAsButtonOfClass: aButtonClass [
specCommand hasIcon
ifTrue: [ button icon: specCommand icon ] ];
action: [ specCommand execute ];
enabled: specCommand canBeExecuted;
yourself ]
]

Expand Down
Loading