From ed331f8b6094c3b73519d9ec296f221dd7452c79 Mon Sep 17 00:00:00 2001 From: Esteban Lorenzano Date: Thu, 10 Oct 2024 12:20:51 +0200 Subject: [PATCH] add dynamic group first iteration (working, in morphic... not yet in gtk) --- .../SpActionMenuPresenterBuilder.class.st | 15 ++++ src/Spec2-Commander2/SpCommandGroup.class.st | 8 +- .../SpDynamicActionGroup.class.st | 85 +++++++++++++++++++ .../SpMenuPresenter.extension.st | 11 +-- .../SpMenuPresenterBuilder.class.st | 11 ++- 5 files changed, 110 insertions(+), 20 deletions(-) create mode 100644 src/Spec2-Commander2/SpDynamicActionGroup.class.st diff --git a/src/Spec2-Commander2/SpActionMenuPresenterBuilder.class.st b/src/Spec2-Commander2/SpActionMenuPresenterBuilder.class.st index ffd31e53..94c24a7f 100644 --- a/src/Spec2-Commander2/SpActionMenuPresenterBuilder.class.st +++ b/src/Spec2-Commander2/SpActionMenuPresenterBuilder.class.st @@ -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 ] +] diff --git a/src/Spec2-Commander2/SpCommandGroup.class.st b/src/Spec2-Commander2/SpCommandGroup.class.st index d5ff072b..93e2b3ba 100644 --- a/src/Spec2-Commander2/SpCommandGroup.class.st +++ b/src/Spec2-Commander2/SpCommandGroup.class.st @@ -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', @@ -35,8 +35,8 @@ SpCommandGroup >> asMenuBarPresenter [ { #category : 'converting' } SpCommandGroup >> asMenuBarPresenterWith: aBlock [ - | builder | + builder := SpMenuBarPresenterBuilder new. aBlock value: builder menuPresenter. ^ builder @@ -54,8 +54,8 @@ SpCommandGroup >> asMenuPresenter [ { #category : 'converting' } SpCommandGroup >> asMenuPresenterWith: aBlock [ - | builder | + builder := SpMenuPresenterBuilder new. aBlock value: builder menuPresenter. ^ builder diff --git a/src/Spec2-Commander2/SpDynamicActionGroup.class.st b/src/Spec2-Commander2/SpDynamicActionGroup.class.st new file mode 100644 index 00000000..d67ee11e --- /dev/null +++ b/src/Spec2-Commander2/SpDynamicActionGroup.class.st @@ -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 +] diff --git a/src/Spec2-Commander2/SpMenuPresenter.extension.st b/src/Spec2-Commander2/SpMenuPresenter.extension.st index dd080430..6bb7f71a 100644 --- a/src/Spec2-Commander2/SpMenuPresenter.extension.st +++ b/src/Spec2-Commander2/SpMenuPresenter.extension.st @@ -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 ] diff --git a/src/Spec2-Commander2/SpMenuPresenterBuilder.class.st b/src/Spec2-Commander2/SpMenuPresenterBuilder.class.st index 610a92ad..fcc37cb7 100644 --- a/src/Spec2-Commander2/SpMenuPresenterBuilder.class.st +++ b/src/Spec2-Commander2/SpMenuPresenterBuilder.class.st @@ -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' } @@ -47,11 +50,7 @@ SpMenuPresenterBuilder >> menuPresenter [ { #category : 'accessing' } SpMenuPresenterBuilder >> menuPresenter: anObject [ - - menuPresenter := anObject. - stack := Stack new - push: self menuPresenter; - yourself + menuPresenter := anObject ] { #category : 'visiting' }