Skip to content

Commit

Permalink
Introduce SpCommandGroup>>#asToolbarPresenter and SpCommandGroup>>#as…
Browse files Browse the repository at this point in the history
…ToolbarPresenterWith:

Also add an example and improve the SpCommandGroup class comment.
  • Loading branch information
koendehondt committed Sep 15, 2024
1 parent cc2b5c8 commit 8f3c737
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/Spec2-Commander2/SpCommandGroup.class.st
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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 [

Expand Down
92 changes: 92 additions & 0 deletions src/Spec2-Examples/SpCommandGroupExample.class.st
Original file line number Diff line number Diff line change
@@ -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
]
34 changes: 34 additions & 0 deletions src/Spec2-Examples/SpExampleNewCommand.class.st
Original file line number Diff line number Diff line change
@@ -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'
]

0 comments on commit 8f3c737

Please sign in to comment.