Skip to content

Commit

Permalink
Merge pull request #1622 from koendehondt/Pharo13
Browse files Browse the repository at this point in the history
Set enablement of button in SpCommand>>#configureAsButtonOfClass:
  • Loading branch information
estebanlm authored Oct 10, 2024
2 parents 313ea93 + 87d29fa commit 26b4503
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
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

0 comments on commit 26b4503

Please sign in to comment.