From 87d29fad87973d8b0adb064baa9625b04bd06f0c Mon Sep 17 00:00:00 2001 From: Koen De Hondt Date: Tue, 8 Oct 2024 21:26:52 +0200 Subject: [PATCH] Set enablement of button in SpCommand>>#configureAsButtonOfClass: --- .../SpCommandTest.class.st | 25 +++++++++++++++++++ src/Spec2-Commander2/SpCommand.class.st | 1 + 2 files changed, 26 insertions(+) diff --git a/src/Spec2-Commander2-Tests/SpCommandTest.class.st b/src/Spec2-Commander2-Tests/SpCommandTest.class.st index e67988d0..2b32563b 100644 --- a/src/Spec2-Commander2-Tests/SpCommandTest.class.st +++ b/src/Spec2-Commander2-Tests/SpCommandTest.class.st @@ -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 ] @@ -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. +] diff --git a/src/Spec2-Commander2/SpCommand.class.st b/src/Spec2-Commander2/SpCommand.class.st index acee0a9a..22b2c760 100644 --- a/src/Spec2-Commander2/SpCommand.class.st +++ b/src/Spec2-Commander2/SpCommand.class.st @@ -58,6 +58,7 @@ SpCommand >> configureAsButtonOfClass: aButtonClass [ specCommand hasIcon ifTrue: [ button icon: specCommand icon ] ]; action: [ specCommand execute ]; + enabled: specCommand canBeExecuted; yourself ] ]