Skip to content
Permalink
Browse files

Merge pull request #722 from juliendelplanque/714-Create-builder-for-…

…SpActionBarPresenter

714-Create-builder-for-SpActionBarPresenter
  • Loading branch information...
jecisc committed Aug 13, 2019
2 parents 7b7d4b5 + 7eec209 commit c5f1e59434563c904cc84805757d3b1ab97da1bf
@@ -0,0 +1,41 @@
"
A SpSetButtonLeftStrategyTest is a test class for testing the behavior of SpSetButtonLeftStrategy
"
Class {
#name : #SpLeftPositionStrategyTest,
#superclass : #TestCase,
#category : #'Spec2-Commander2-Tests'
}

{ #category : #test }
SpLeftPositionStrategyTest >> testAddButtonToActionBar [
| actionBar button |
actionBar := SpActionBarPresenter new.
button := SpButtonPresenter new.

self assertEmpty: actionBar items.

SpLeftPositionStrategy new
addButton: button toActionBar: actionBar.

self assert: actionBar items size equals: 1.
self assert: (actionBar items includesKey: #start).
self assert: (actionBar items at: #start) size equals: 1.
self assert: (actionBar items at: #start) anyOne equals: button
]

{ #category : #test }
SpLeftPositionStrategyTest >> testAddButtonToToolbar [
| toolbar button |
toolbar := SpToolBarPresenter new.
button := SpToolBarButton new.

self assertEmpty: toolbar items.

SpLeftPositionStrategy new
addButton: button toToolbar: toolbar.

self assert: toolbar leftItems size equals: 1.
self assert: toolbar leftItems anyOne equals: button.
self assertEmpty: toolbar rightItems
]
@@ -0,0 +1,41 @@
"
A SpSetButtonRightStrategyTest is a test class for testing the behavior of SpSetButtonRightStrategy
"
Class {
#name : #SpRightPositionStrategyTest,
#superclass : #TestCase,
#category : #'Spec2-Commander2-Tests'
}

{ #category : #test }
SpRightPositionStrategyTest >> testAddButtonToActionBar [
| actionBar button |
actionBar := SpActionBarPresenter new.
button := SpButtonPresenter new.

self assertEmpty: actionBar items.

SpRightPositionStrategy new
addButton: button toActionBar: actionBar.

self assert: actionBar items size equals: 1.
self assert: (actionBar items includesKey: #end).
self assert: (actionBar items at: #end) size equals: 1.
self assert: (actionBar items at: #end) anyOne equals: button
]

{ #category : #test }
SpRightPositionStrategyTest >> testAddButtonToToolbar [
| toolbar button |
toolbar := SpToolBarPresenter new.
button := SpToolBarButton new.

self assertEmpty: toolbar items.

SpRightPositionStrategy new
addButton: button toToolbar: toolbar.

self assert: toolbar rightItems size equals: 1.
self assert: toolbar rightItems anyOne equals: button.
self assertEmpty: toolbar leftItems
]
@@ -0,0 +1,36 @@
"
I build a ActionBarPresenter from a group of commands.
To do that, I visit recursively groups of command breadth first and simple add each command encountered to the action bar.
"
Class {
#name : #SpActionBarPresenterBuilder,
#superclass : #CmVisitor,
#instVars : [
'actionBarPresenter'
],
#category : #'Spec2-Commander2-Visitors'
}

{ #category : #accessing }
SpActionBarPresenterBuilder >> actionBarPresenter [
^ actionBarPresenter
]

{ #category : #accessing }
SpActionBarPresenterBuilder >> actionBarPresenter: anObject [
actionBarPresenter := anObject
]

{ #category : #initialization }
SpActionBarPresenterBuilder >> initialize [
super initialize.
self actionBarPresenter: SpActionBarPresenter new.
]

{ #category : #visiting }
SpActionBarPresenterBuilder >> visitCommand: aCmCommandEntry [
aCmCommandEntry positionStrategy
addButton: aCmCommandEntry asButtonPresenter
toActionBar: self actionBarPresenter
]
@@ -5,7 +5,7 @@ Basically, I add:
- an #icon (#blank by default)
- a #shortcutKey (optional)
- a #displayStrategy to handle how to show the command if it is not executable on a context (default is to be disabled)
- a actionBarStrategy to handle on which side of the action bar I should be (default is left)
- a #positionStrategy to handle on which side presenter with left and right side I should be (default is left)
"
Class {
@@ -16,7 +16,7 @@ Class {
'iconName',
'shortcutKey',
'displayStrategy',
'actionBarStrategy'
'positionStrategy'
],
#category : #'Spec2-Commander2-Core'
}
@@ -40,6 +40,16 @@ SpCommand >> beDisabledWhenCantBeRun [
self displayStrategy: SpDisableWhenCantBeRun new
]

{ #category : #configuring }
SpCommand >> beDisplayedOnLeftSide [
positionStrategy := SpLeftPositionStrategy new
]

{ #category : #configuring }
SpCommand >> beDisplayedOnRightSide [
positionStrategy := SpRightPositionStrategy new
]

{ #category : #configuring }
SpCommand >> beHiddenWhenCantBeRun [
self displayStrategy: SpHideWhenCantBeRun new
@@ -121,7 +131,13 @@ SpCommand >> iconProvider: anObject [
SpCommand >> initialize [

super initialize.
self beDisabledWhenCantBeRun
self beDisabledWhenCantBeRun.
self beDisplayedOnLeftSide
]

{ #category : #accessing }
SpCommand >> positionStrategy [
^ positionStrategy
]

{ #category : #accessing }
@@ -4,7 +4,7 @@ I allow to configure how a spec group display itself when shown in UI.
Class {
#name : #SpCommandDisplayStrategy,
#superclass : #Object,
#category : #'Spec2-Commander2-Core'
#category : #'Spec2-Commander2-Strategies'
}

{ #category : #displaying }
@@ -4,7 +4,7 @@ I allow to configure how a spec command group display when shown in UI.
Class {
#name : #SpCommandGroupDisplayStrategy,
#superclass : #Object,
#category : #'Spec2-Commander2-Core'
#category : #'Spec2-Commander2-Strategies'
}

{ #category : #displaying }
@@ -4,7 +4,7 @@ I implement the fact that the button corresponding to a command is disabled when
Class {
#name : #SpDisableWhenCantBeRun,
#superclass : #SpCommandDisplayStrategy,
#category : #'Spec2-Commander2-Core'
#category : #'Spec2-Commander2-Strategies'
}

{ #category : #displaying }
@@ -4,7 +4,7 @@ I display a command group as a group in the MenuPresenter.
Class {
#name : #SpDisplayAsGroup,
#superclass : #SpCommandGroupDisplayStrategy,
#category : #'Spec2-Commander2-Core'
#category : #'Spec2-Commander2-Strategies'
}

{ #category : #displaying }
@@ -4,7 +4,7 @@ I display a command group as a submenu in the MenuPresenter.
Class {
#name : #SpDisplayAsSubMenu,
#superclass : #SpCommandGroupDisplayStrategy,
#category : #'Spec2-Commander2-Core'
#category : #'Spec2-Commander2-Strategies'
}

{ #category : #displaying }
@@ -4,7 +4,7 @@ I implement the fact that the button corresponding to a command is hidden when i
Class {
#name : #SpHideWhenCantBeRun,
#superclass : #SpCommandDisplayStrategy,
#category : #'Spec2-Commander2-Core'
#category : #'Spec2-Commander2-Strategies'
}

{ #category : #displaying }
@@ -0,0 +1,18 @@
"
I set the button generated from a command on the left side a presenter.
"
Class {
#name : #SpLeftPositionStrategy,
#superclass : #SpPositionStrategy,
#category : #'Spec2-Commander2-Strategies'
}

{ #category : #adding }
SpLeftPositionStrategy >> addButton: aButtonPresenter toActionBar: anActionBarPresenter [
anActionBarPresenter add: aButtonPresenter
]

{ #category : #adding }
SpLeftPositionStrategy >> addButton: aButtonPresenter toToolbar: aToolbarPresenter [
aToolbarPresenter addItemLeft: aButtonPresenter
]
@@ -0,0 +1,18 @@
"
I model a strategy to add a command in a presenter for which it can be either left or right.
"
Class {
#name : #SpPositionStrategy,
#superclass : #Object,
#category : #'Spec2-Commander2-Strategies'
}

{ #category : #adding }
SpPositionStrategy >> addButton: aButtonPresenter toActionBar: anActionBarPresenter [
self subclassResponsibility
]

{ #category : #adding }
SpPositionStrategy >> addButton: aButtonPresenter toToolbar: aToolbarPresenter [
self subclassResponsibility
]
@@ -0,0 +1,18 @@
"
I set the button generated from a command on the left side a presenter.
"
Class {
#name : #SpRightPositionStrategy,
#superclass : #SpPositionStrategy,
#category : #'Spec2-Commander2-Strategies'
}

{ #category : #adding }
SpRightPositionStrategy >> addButton: aButtonPresenter toActionBar: anActionBarPresenter [
anActionBarPresenter addLast: aButtonPresenter
]

{ #category : #adding }
SpRightPositionStrategy >> addButton: aButtonPresenter toToolbar: aToolbarPresenter [
aToolbarPresenter addItemRight: aButtonPresenter
]
@@ -30,11 +30,12 @@ SpToolBarPresenterBuilder >> toolbarPresenter: anObject [

{ #category : #visiting }
SpToolBarPresenterBuilder >> visitCommand: aCmCommandEntry [
self toolbarPresenter
addItem: (SpToolBarButton new
aCmCommandEntry positionStrategy
addButton: (SpToolBarButton new
label: aCmCommandEntry name;
help: aCmCommandEntry description;
icon: aCmCommandEntry icon;
action: [ aCmCommandEntry execute ];
yourself)
toToolbar: self toolbarPresenter
]

0 comments on commit c5f1e59

Please sign in to comment.
You can’t perform that action at this time.