diff --git a/src/Spec2-Commander2/SpCommandGroup.class.st b/src/Spec2-Commander2/SpCommandGroup.class.st index c0bd1c40..671725ec 100644 --- a/src/Spec2-Commander2/SpCommandGroup.class.st +++ b/src/Spec2-Commander2/SpCommandGroup.class.st @@ -1,9 +1,9 @@ " -I am a command group decorator adding informations useful when for usage in context of a Spec application. +I am a command group decorator adding information useful in the context of a Spec application. Basically, I add: - an #icon (#blank by default) -- the strategy to display commands group in a MenuPresenter +- the strategy to display command groups in a `SpMenuPresenter`, `SpMenuBarPresenter`, or `SpToolbarPresenter` " Class { #name : 'SpCommandGroup', @@ -63,6 +63,25 @@ SpCommandGroup >> asMenuPresenterWith: aBlock [ menuPresenter ] +{ #category : 'converting' } +SpCommandGroup >> asToolbarPresenter [ + + ^ SpToolbarPresenterBuilder new + visit: self; + toolbarPresenter +] + +{ #category : 'converting' } +SpCommandGroup >> asToolbarPresenterWith: aBlock [ + + | builder | + builder := SpToolbarPresenterBuilder new. + aBlock value: builder toolbarPresenter. + ^ builder + visit: self; + toolbarPresenter +] + { #category : 'configuring' } SpCommandGroup >> beToolbarGroup [ diff --git a/src/Spec2-Examples/SpCommandGroupExample.class.st b/src/Spec2-Examples/SpCommandGroupExample.class.st new file mode 100644 index 00000000..cbde920e --- /dev/null +++ b/src/Spec2-Examples/SpCommandGroupExample.class.st @@ -0,0 +1,92 @@ +" +I am an example presenter to show how commands can be used as the basis for adding a menubar and a toolbar. +" +Class { + #name : 'SpCommandGroupExample', + #superclass : 'SpPresenter', + #instVars : [ + 'menuBar', + 'toolBar' + ], + #category : 'Spec2-Examples-Demo-CommandGroup', + #package : 'Spec2-Examples', + #tag : 'Demo-CommandGroup' +} + +{ #category : 'commands' } +SpCommandGroupExample class >> buildCommandsGroupWith: presenter forRoot: rootCommandGroup [ + + rootCommandGroup + register: (self buildMenuBarGroupWith: presenter); + register: (self buildToolBarGroupWith: presenter) +] + +{ #category : 'commands' } +SpCommandGroupExample class >> buildMenuBarGroupWith: presenter [ + + ^ (CmCommandGroup named: 'MenuBar') asSpecGroup + beRoot; + register: (self buildMenuWith: presenter); + yourself +] + +{ #category : 'commands' } +SpCommandGroupExample class >> buildMenuWith: presenter [ + + ^ (CmCommandGroup named: 'Menu') asSpecGroup + register: (SpExampleNewCommand forSpec context: presenter); + yourself +] + +{ #category : 'commands' } +SpCommandGroupExample class >> buildToolBarGroupWith: presenter [ + + ^ (CmCommandGroup named: 'ToolBar') asSpecGroup + beRoot; + register: (SpExampleNewCommand forSpec context: presenter); + yourself +] + +{ #category : 'examples' } +SpCommandGroupExample class >> example [ + "This example opens a presenter with a menubar and a toolbar created from commands." + + ^ self new open +] + +{ #category : 'layout' } +SpCommandGroupExample >> defaultLayout [ + + ^ SpBoxLayout newTopToBottom +] + +{ #category : 'initialization' } +SpCommandGroupExample >> initializeMenuBar [ + + menuBar := (self rootCommandsGroup / 'MenuBar') asMenuBarPresenter +] + +{ #category : 'initialization' } +SpCommandGroupExample >> initializePresenters [ + + super initializePresenters. + self initializeMenuBar. + self initializeToolBar +] + +{ #category : 'initialization' } +SpCommandGroupExample >> initializeToolBar [ + + toolBar := (self rootCommandsGroup / 'ToolBar') asToolbarPresenter +] + +{ #category : 'initialization' } +SpCommandGroupExample >> initializeWindow: aWindowPresenter [ + + super initializeWindow: aWindowPresenter. + aWindowPresenter + title: 'Example with menubar and toolbar based on commands'; + initialExtent: 500@200; + menu: menuBar; + toolbar: toolBar +] diff --git a/src/Spec2-Examples/SpExampleNewCommand.class.st b/src/Spec2-Examples/SpExampleNewCommand.class.st new file mode 100644 index 00000000..341226f1 --- /dev/null +++ b/src/Spec2-Examples/SpExampleNewCommand.class.st @@ -0,0 +1,34 @@ +" +I am an example command to create a new thing. +" +Class { + #name : 'SpExampleNewCommand', + #superclass : 'CmCommand', + #category : 'Spec2-Examples-Demo-CommandGroup', + #package : 'Spec2-Examples', + #tag : 'Demo-CommandGroup' +} + +{ #category : 'converting' } +SpExampleNewCommand >> asSpecCommand [ + + ^ super asSpecCommand + iconName: #smallNew; + shortcutKey: $n meta; + yourself +] + +{ #category : 'executing' } +SpExampleNewCommand >> execute [ + + self inform: 'This command is not implemented yet.' +] + +{ #category : 'initialization' } +SpExampleNewCommand >> initialize [ + + super initialize. + self + name: 'New'; + description: 'Create a new thing' +]