Skip to content
Permalink
Browse files

Merge pull request #700 from juliendelplanque/692-Commander2-layer-sh…

…ould-set-the-presenter-as-context-of-commands-when-not-done

692 commander2 layer should set the presenter as context of commands when not done
  • Loading branch information...
juliendelplanque committed Aug 10, 2019
2 parents 5ca15b3 + 1fce30a commit d0f288989f6b551556b85f5c91a65565d04f665d
@@ -1,14 +1,14 @@
Extension { #name : #SpContactBookPresenter }

{ #category : #'*Spec2-Commander2-ContactBook-Extensions' }
SpContactBookPresenter classSide >> changePhoneCommandWith: presenter forRootGroup: aCmCommandsGroup [
SpContactBookPresenter class >> changePhoneCommandWith: presenter forRootGroup: aCmCommandsGroup [
<extensionCommands>
(aCmCommandsGroup / 'Context Menu' / 'Edition') "Inject an additional command in 'Edition' group."
register: (SpChangePhoneCommand forSpec context: presenter)
register: SpChangePhoneCommand forSpec
]

{ #category : #'*Spec2-Commander2-ContactBook-Extensions' }
SpContactBookPresenter classSide >> extraCommandsWith: presenter forRootGroup: aCmCommandsGroup [
SpContactBookPresenter class >> extraCommandsWith: presenter forRootGroup: aCmCommandsGroup [
<extensionCommands>
aCmCommandsGroup / 'Context Menu'
register: ((CmCommandGroup named: 'Extra') asSpecGroup
@@ -20,7 +20,7 @@ Class {
SpContactBookPresenter class >> buildAddingGroupWith: presenterIntance [
^ (CmCommandGroup named: 'Adding') asSpecGroup
basicDescription: 'Commands related to contact addition.';
register: (SpAddContactCommand forSpec context: presenterIntance);
register: SpAddContactCommand forSpec;
beDisplayedAsGroup;
yourself
]
@@ -45,23 +45,23 @@ SpContactBookPresenter class >> buildContextualMenuGroupWith: presenterIntance [
SpContactBookPresenter class >> buildEditionGroupWith: presenterIntance [
^ (CmCommandGroup named: 'Edition') asSpecGroup
basicDescription: 'Commands related to contact edition.';
register: (SpRenameContactCommand forSpec context: presenterIntance);
register: SpRenameContactCommand forSpec;
beDisplayedAsGroup;
yourself
]

{ #category : #commands }
SpContactBookPresenter class >> buildMenuBarGroupWith: presenterIntance [
^ (CmCommandGroup named: 'MenuBar') asSpecGroup
register: (SpPrintContactBookInTranscript forSpec context: presenterIntance);
register: SpPrintContactBookInTranscript forSpec;
yourself
]

{ #category : #commands }
SpContactBookPresenter class >> buildRemovingGroupWith: presenterIntance [
^ (CmCommandGroup named: 'Removing') asSpecGroup
basicDescription: 'Command related to contact removal.';
register: (SpRemoveContactCommand forSpec context: presenterIntance);
register: SpRemoveContactCommand forSpec;
beDisplayedAsGroup;
yourself
]
@@ -0,0 +1,46 @@
"
A SpRecursiveContextSetterTest is a test class for testing the behavior of SpRecursiveContextSetter
"
Class {
#name : #SpRecursiveContextSetterTest,
#superclass : #TestCase,
#category : #'Spec2-Commander2-Tests'
}

{ #category : #test }
SpRecursiveContextSetterTest >> testVisitCommand [
| commandsGroup |
commandsGroup := (CmCommandGroup named: 'root') asSpecGroup beRoot
register: (CmBlockCommand new
basicName: 'c1';
block: [ ];
context: 42;
yourself) asSpecCommand;
register: ((CmCommandGroup named: 'sub1') asSpecGroup
register: (CmBlockCommand new
basicName: 'c2';
block: [ ];
context: 42;
yourself) asSpecCommand;
register: (CmBlockCommand new
basicName: 'c3';
block: [ ];
yourself) asSpecCommand);
register: (CmBlockCommand new
basicName: 'c4';
block: [ ];
yourself) asSpecCommand;
yourself.

self assert: (commandsGroup / 'c1') context equals: 42.
self assert: (commandsGroup / 'sub1' / 'c2') context equals: 42.
self assert: (commandsGroup / 'sub1' / 'c3') context isNil.
self assert: (commandsGroup / 'c4') context isNil.

SpRecursiveContextSetter visit: commandsGroup toSetContext: 43.

self assert: (commandsGroup / 'c1') context equals: 42.
self assert: (commandsGroup / 'sub1' / 'c2') context equals: 42.
self assert: (commandsGroup / 'sub1' / 'c3') context equals: 43.
self assert: (commandsGroup / 'c4') context equals: 43
]
@@ -27,5 +27,5 @@ SpPresenter class >> buildRootCommandsGroupFor: presenterInstance [

{ #category : #'*Spec2-Commander2' }
SpPresenter >> rootCommandsGroup [
^ self class buildRootCommandsGroupFor: self
^ SpRecursiveContextSetter visit: (self class buildRootCommandsGroupFor: self) toSetContext: self
]
@@ -0,0 +1,45 @@
"
Visit recursively the tree of commands groups to set the context stored in my #context inst. var. to all CmCommands located at the leaves of the tree.
"
Class {
#name : #SpRecursiveContextSetter,
#superclass : #CmVisitor,
#instVars : [
'context'
],
#category : #'Spec2-Commander2-Visitors'
}

{ #category : #'instance creation' }
SpRecursiveContextSetter class >> context: context [
^ self new
context: context;
yourself
]

{ #category : #helper }
SpRecursiveContextSetter class >> visit: aCommandOrGroup toSetContext: anObject [
aCommandOrGroup
acceptVisitor: (self context: anObject).

^ aCommandOrGroup
]

{ #category : #accessing }
SpRecursiveContextSetter >> context [
^ context
]

{ #category : #accessing }
SpRecursiveContextSetter >> context: anObject [
context := anObject
]

{ #category : #visiting }
SpRecursiveContextSetter >> visitCommand: aCmCommand [
aCmCommand context
ifNotNil: [ ^ self ].

aCmCommand
context: self context
]

0 comments on commit d0f2889

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