Skip to content

Commit

Permalink
add dynamic group first iteration (working, in morphic... not yet in …
Browse files Browse the repository at this point in the history
…gtk)
  • Loading branch information
estebanlm committed Oct 10, 2024
1 parent 09fa345 commit ed331f8
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 20 deletions.
15 changes: 15 additions & 0 deletions src/Spec2-Commander2/SpActionMenuPresenterBuilder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,18 @@ SpActionMenuPresenterBuilder >> visitCommand: aCmCommand [
aCmCommand isVisible ifFalse: [ ^ self ].
super visitCommand: aCmCommand
]

{ #category : 'visiting' }
SpActionMenuPresenterBuilder >> visitCommandDynamicGroup: aDynamicGroup [

aDynamicGroup
displayIn: stack top
do: [ :specGroupOrSubMenu |
| group |
stack push: specGroupOrSubMenu.
group := SpActionGroup new.
aDynamicGroup dynamicBuilder value: group.
group entries do: [ :each |
each acceptVisitor: self ].
stack pop ]
]
8 changes: 4 additions & 4 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 information useful in the context of a Spec application.
I am a command group decorator adding informations useful when for usage in context of a Spec application.
Basically, I add:
- an #icon (#blank by default)
- the strategy to display command groups in a `SpMenuPresenter`, `SpMenuBarPresenter`, or `SpToolbarPresenter`
- the strategy to display commands group in a MenuPresenter
"
Class {
#name : 'SpCommandGroup',
Expand Down Expand Up @@ -35,8 +35,8 @@ SpCommandGroup >> asMenuBarPresenter [

{ #category : 'converting' }
SpCommandGroup >> asMenuBarPresenterWith: aBlock [

| builder |

builder := SpMenuBarPresenterBuilder new.
aBlock value: builder menuPresenter.
^ builder
Expand All @@ -54,8 +54,8 @@ SpCommandGroup >> asMenuPresenter [

{ #category : 'converting' }
SpCommandGroup >> asMenuPresenterWith: aBlock [

| builder |

builder := SpMenuPresenterBuilder new.
aBlock value: builder menuPresenter.
^ builder
Expand Down
85 changes: 85 additions & 0 deletions src/Spec2-Commander2/SpDynamicActionGroup.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"
An action group is a spec command group (`SpCommandGroup`) that will be used for dynamic context menus in the presenters that implement `SpTActionContainer`
"
Class {
#name : 'SpDynamicActionGroup',
#superclass : 'SpCommandGroup',
#instVars : [
'id',
'dynamicBuilder'
],
#category : 'Spec2-Commander2-Action',
#package : 'Spec2-Commander2',
#tag : 'Action'
}

{ #category : 'instance creation' }
SpDynamicActionGroup class >> newName: aName [

^ self new
name: aName;
yourself
]

{ #category : 'instance creation' }
SpDynamicActionGroup class >> newName: aName with: aBlock [

^ (self newName: aName)
in: [ :this | aBlock value: this ];
yourself
]

{ #category : 'comparing' }
SpDynamicActionGroup >> = anObject [
"Answer whether the receiver and anObject represent the same object."

self == anObject ifTrue: [ ^ true ].
self class = anObject class ifFalse: [ ^ false ].
^ self id = anObject id
]

{ #category : 'visiting' }
SpDynamicActionGroup >> acceptVisitor: aVisitor [

^ aVisitor visitCommandDynamicGroup: self
]

{ #category : 'converting' }
SpDynamicActionGroup >> asMenuPresenter [

^ SpActionMenuPresenterBuilder new
visit: self;
menuPresenter
]

{ #category : 'private' }
SpDynamicActionGroup >> dynamicBuilder [

^ dynamicBuilder
]

{ #category : 'comparing' }
SpDynamicActionGroup >> hash [
"Answer an integer value that is related to the identity of the receiver."

^ self id hash
]

{ #category : 'accessing' }
SpDynamicActionGroup >> id [

^ id ifNil: [ id := super id ]
]

{ #category : 'initialization' }
SpDynamicActionGroup >> initialize [

decoratedGroup := SpBaseActionGroup new.
super initialize
]

{ #category : 'accessing' }
SpDynamicActionGroup >> with: aBlock [

dynamicBuilder := aBlock
]
11 changes: 1 addition & 10 deletions src/Spec2-Commander2/SpMenuPresenter.extension.st
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
Extension { #name : 'SpMenuPresenter' }

{ #category : '*Spec2-Commander2' }
SpMenuPresenter >> fillWith: aCommandGroup [

self removeAllItems.
self presenterBuilderClass new
menuPresenter: self;
visit: aCommandGroup
]

{ #category : '*Spec2-Commander2' }
SpMenuPresenter >> presenterBuilderClass [

^ SpMenuPresenterBuilder
^ SpActionMenuPresenterBuilder
]
11 changes: 5 additions & 6 deletions src/Spec2-Commander2/SpMenuPresenterBuilder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ SpMenuPresenterBuilder >> fillItem: aMenuItem with: aCommand [
SpMenuPresenterBuilder >> initialize [

super initialize.
self menuPresenter: self class menuPresenterClass new
self menuPresenter: self class menuPresenterClass new.
stack := Stack new
push: self menuPresenter;
yourself
]

{ #category : 'accessing' }
Expand All @@ -47,11 +50,7 @@ SpMenuPresenterBuilder >> menuPresenter [

{ #category : 'accessing' }
SpMenuPresenterBuilder >> menuPresenter: anObject [

menuPresenter := anObject.
stack := Stack new
push: self menuPresenter;
yourself
menuPresenter := anObject
]

{ #category : 'visiting' }
Expand Down

0 comments on commit ed331f8

Please sign in to comment.