-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1611 from koendehondt/gh1601-pharo12-fillWith
Add SpMenuPresenter>>#fillWith: that applies for SpMenuBarPresenter as well, and add tests and example
- Loading branch information
Showing
8 changed files
with
238 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Extension { #name : 'SpMenuBarPresenter' } | ||
|
||
{ #category : '*Spec2-Commander2' } | ||
SpMenuBarPresenter >> presenterBuilderClass [ | ||
|
||
^ SpMenuBarPresenterBuilder | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Extension { #name : 'SpMenuPresenter' } | ||
|
||
{ #category : '*Spec2-Commander2' } | ||
SpMenuPresenter >> fillWith: aCommandGroup [ | ||
|
||
self removeAllItems. | ||
self presenterBuilderClass new | ||
menuPresenter: self; | ||
visit: aCommandGroup | ||
] | ||
|
||
{ #category : '*Spec2-Commander2' } | ||
SpMenuPresenter >> presenterBuilderClass [ | ||
|
||
^ SpMenuPresenterBuilder | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
" | ||
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', | ||
'list' | ||
], | ||
#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); | ||
register: (self buildListMenuWith: presenter) | ||
] | ||
|
||
{ #category : 'commands' } | ||
SpCommandGroupExample class >> buildListMenuWith: presenter [ | ||
|
||
^ (CmCommandGroup named: 'List') asSpecGroup | ||
beRoot; | ||
register: (SpExampleNewCommand forSpec context: presenter); | ||
yourself | ||
] | ||
|
||
{ #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 | ||
add: list; | ||
yourself | ||
] | ||
|
||
{ #category : 'initialization' } | ||
SpCommandGroupExample >> initializeList [ | ||
|
||
| contextMenu | | ||
list := self newList. | ||
contextMenu := self newMenu. | ||
contextMenu fillWith: self rootCommandsGroup / 'List'. | ||
list contextMenu: contextMenu | ||
] | ||
|
||
{ #category : 'initialization' } | ||
SpCommandGroupExample >> initializeMenuBar [ | ||
|
||
menuBar := self newMenuBar. | ||
menuBar fillWith: self rootCommandsGroup / 'MenuBar' | ||
] | ||
|
||
{ #category : 'initialization' } | ||
SpCommandGroupExample >> initializePresenters [ | ||
|
||
super initializePresenters. | ||
self initializeList. | ||
self initializeMenuBar. | ||
self initializeToolBar | ||
] | ||
|
||
{ #category : 'initialization' } | ||
SpCommandGroupExample >> initializeToolBar [ | ||
|
||
toolBar := self newToolbar. | ||
toolBar fillWith: self rootCommandsGroup / 'ToolBar' | ||
] | ||
|
||
{ #category : 'initialization' } | ||
SpCommandGroupExample >> initializeWindow: aWindowPresenter [ | ||
|
||
super initializeWindow: aWindowPresenter. | ||
aWindowPresenter | ||
title: 'Example with context menu, menubar and toolbar based on commands'; | ||
initialExtent: 600@300; | ||
menu: menuBar; | ||
toolbar: toolBar | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters