Skip to content
Permalink
Browse files

Merge pull request #772 from pharo-spec/add-contextMenu-to-athens-pre…

…senters

add-contextMenu-to-athens-presenters
  • Loading branch information...
estebanlm committed Sep 11, 2019
2 parents 56ae6d4 + 9d6b23d commit 78aefa5a183d81aac01927960cb92fb4007c5f9e
@@ -15,6 +15,20 @@ SpAthensAnimatedPresenterTest >> initializeTestedInstance [
presenter surfaceExtent: 800@600
]

{ #category : #tests }
SpAthensAnimatedPresenterTest >> testContextMenu [
| menu changed |

self assert: presenter contextMenu isNil.
menu := SpMenuPresenter new.
changed := false.
presenter whenMenuChangedDo: [
changed := true. ].
presenter contextMenu: menu.
self assert: presenter contextMenu equals: menu.
self assert: changed
]

{ #category : #accessing }
SpAthensAnimatedPresenterTest >> testPresentersBlockReceivesAthensCanvas [
| receivedCanvas |
@@ -28,6 +28,20 @@ SpAthensStaticPresenterTest >> initializeTestedInstance [
presenter surfaceExtent: 800@600
]

{ #category : #accessing }
SpAthensStaticPresenterTest >> testContextMenu [
| menu changed |

self assert: presenter contextMenu isNil.
menu := SpMenuPresenter new.
changed := false.
presenter whenMenuChangedDo: [
changed := true. ].
presenter contextMenu: menu.
self assert: presenter contextMenu equals: menu.
self assert: changed
]

{ #category : #accessing }
SpAthensStaticPresenterTest >> testPresentersBlockReceivesAthensCanvas [
| receivedCanvas |
@@ -1,14 +1,13 @@
Class {
#name : #SpAbstractListPresenter,
#superclass : #SpAbstractWidgetPresenter,
#traits : 'TSpHaveWrappingScrollBars',
#classTraits : 'TSpHaveWrappingScrollBars classTrait',
#traits : 'TSpHaveWrappingScrollBars + SpTContextMenu',
#classTraits : 'TSpHaveWrappingScrollBars classTrait + SpTContextMenu classTrait',
#instVars : [
'#selectionMode',
'#activationBlock',
'#activateOnSingleClick',
'#model',
'#contextMenu => SpObservableSlot',
'#itemFilter => SpObservableSlot'
],
#category : #'Spec2-Core-Widgets-Table'
@@ -64,20 +63,6 @@ SpAbstractListPresenter >> clickItem: anInteger [
self selectIndex: anInteger
]

{ #category : #api }
SpAbstractListPresenter >> contextMenu [
"Return the block used to defined the menu"

^ contextMenu
]

{ #category : #api }
SpAbstractListPresenter >> contextMenu: aValuable [
"Set the block used to defined the menu"

contextMenu := aValuable
]

{ #category : #api }
SpAbstractListPresenter >> disableFilter [
self itemFilter: nil
@@ -328,13 +313,6 @@ SpAbstractListPresenter >> whenItemFilterBlockChangedDo: aBlock [
self property: #itemFilter whenChangedDo: aBlock
]

{ #category : #'api-events' }
SpAbstractListPresenter >> whenMenuChangedDo: aBlock [
"Set a block to value when the menu block has changed"

self property: #contextMenu whenChangedDo: aBlock
]

{ #category : #'api-events' }
SpAbstractListPresenter >> whenModelChangedDo: aBlock [

@@ -1,13 +1,14 @@
Class {
#name : #SpAbstractTextPresenter,
#superclass : #SpAbstractWidgetPresenter,
#traits : 'SpTContextMenu',
#classTraits : 'SpTContextMenu classTrait',
#instVars : [
'#hasUnacceptedEdits => SpObservableSlot',
'#selection => SpObservableSlot',
'#autoAccept => SpObservableSlot',
'#wantsVisualFeedback => SpObservableSlot',
'#askBeforeDiscardingEdits => SpObservableSlot',
'#contextMenu => SpObservableSlot',
'#text => SpObservableSlot',
'#actionToPerform => SpObservableSlot',
'#readSelection => SpObservableSlot',
@@ -120,18 +121,6 @@ SpAbstractTextPresenter >> clearUndoManager [
self withAdapterDo: #clearUndoManager
]

{ #category : #api }
SpAbstractTextPresenter >> contextMenu [

^ contextMenu
]

{ #category : #api }
SpAbstractTextPresenter >> contextMenu: aValuable [

contextMenu := aValuable
]

{ #category : #api }
SpAbstractTextPresenter >> enabled: aBoolean [

@@ -409,13 +398,6 @@ SpAbstractTextPresenter >> whenAutoAcceptChangedDo: aBlock [
self property: #autoAccept whenChangedDo: aBlock
]

{ #category : #'api-events' }
SpAbstractTextPresenter >> whenMenuChangedDo: aBlock [
"Set a block to value when the menu block has changed"

self property: #contextMenu whenChangedDo: aBlock
]

{ #category : #'api-events' }
SpAbstractTextPresenter >> whenPlaceholderChangedDo: aBlock [

@@ -1,6 +1,8 @@
Class {
#name : #SpAthensStaticPresenter,
#superclass : #SpAbstractWidgetPresenter,
#traits : 'SpTContextMenu',
#classTraits : 'SpTContextMenu classTrait',
#instVars : [
'#drawBlock => SpObservableSlot',
'#surfaceExtent => SpObservableSlot'
@@ -21,11 +21,12 @@ todo
Class {
#name : #SpButtonPresenter,
#superclass : #SpAbstractWidgetPresenter,
#traits : 'SpTContextMenu',
#classTraits : 'SpTContextMenu classTrait',
#instVars : [
'#action => SpObservableSlot',
'#actionPerformed => SpObservableSlot',
'#askBeforeChanging => SpObservableSlot',
'#contextMenu => SpObservableSlot',
'#font => SpObservableSlot',
'#icon => SpObservableSlot',
'#label => SpObservableSlot',
@@ -107,16 +108,6 @@ SpButtonPresenter >> click [
^ self performAction
]

{ #category : #api }
SpButtonPresenter >> contextMenu [
^ contextMenu
]

{ #category : #api }
SpButtonPresenter >> contextMenu: aMenu [
contextMenu := aMenu
]

{ #category : #'private-focus' }
SpButtonPresenter >> ensureKeyBindingsFor: widget [

@@ -304,12 +295,6 @@ SpButtonPresenter >> whenLabelChangedDo: aBlock [
self property: #label whenChangedDo: aBlock
]

{ #category : #'api-events' }
SpButtonPresenter >> whenMenuChangedDo: aBlock [

self property: #contextMenu whenChangedDo: aBlock
]

{ #category : #'api-events' }
SpButtonPresenter >> whenStateChangedDo: aBlock [
"set a block to perform after that the button has been aclicked, and its action performed"
@@ -0,0 +1,32 @@
"
I'm a trait to add context menus capabilities to the presenter that use it.
Note that I just add some behaviour at presenter level, the right implementation needs
to be solved in the backend adaptor.
"
Trait {
#name : #SpTContextMenu,
#instVars : [
'#contextMenu => SpObservableSlot'
],
#category : #'Spec2-Core-Base'
}

{ #category : #accessing }
SpTContextMenu >> contextMenu [

^ contextMenu
]

{ #category : #accessing }
SpTContextMenu >> contextMenu: aValuable [
"Set the block used to define a context menu for the presenter"

contextMenu := aValuable
]

{ #category : #'api-events' }
SpTContextMenu >> whenMenuChangedDo: aBlock [
"Set a block to value when the menu block has changed"

self property: #contextMenu whenChangedDo: aBlock
]
@@ -14,11 +14,13 @@ Class {

{ #category : #'tick management' }
SpTimeline >> fastForward [
ticks := highestValue.

ticks := highestValue
]

{ #category : #initialization }
SpTimeline >> initialize [

self class initializeSlots: self.
super initialize.
ticks := 0.
@@ -29,11 +31,13 @@ SpTimeline >> initialize [

{ #category : #'tick management' }
SpTimeline >> rewind [
ticks := lowestValue.

ticks := lowestValue
]

{ #category : #initialization }
SpTimeline >> stepBy: aNumber [

stepBy := aNumber
]

@@ -44,17 +48,20 @@ SpTimeline >> tick [

{ #category : #accessing }
SpTimeline >> ticks [

^ ticks
]

{ #category : #accessing }
SpTimeline >> ticks: anAmount [

ticks := anAmount.
highestValue := anAmount max: highestValue .
lowestValue := anAmount min: lowestValue.
highestValue := anAmount max: highestValue.
lowestValue := anAmount min: lowestValue
]

{ #category : #initialization }
SpTimeline >> whenTickDo: aBlock [

self property: #ticks whenChangedDo: aBlock
]
@@ -9,16 +9,15 @@ self example
Class {
#name : #SpTreeTablePresenter,
#superclass : #SpAbstractWidgetPresenter,
#traits : 'TSpHaveWrappingScrollBars',
#classTraits : 'TSpHaveWrappingScrollBars classTrait',
#traits : 'TSpHaveWrappingScrollBars + SpTContextMenu',
#classTraits : 'TSpHaveWrappingScrollBars classTrait + SpTContextMenu classTrait',
#instVars : [
'#columns => SpObservableSlot',
'#showColumnHeaders => SpObservableSlot',
'#isResizable => SpObservableSlot',
'#selection => SpObservableSlot',
'#roots => SpObservableSlot',
'#childrenBlock',
'#contextMenu => SpObservableSlot',
'#activationBlock',
'#activateOnSingleClick'
],
@@ -118,18 +117,6 @@ SpTreeTablePresenter >> columns: aCollection [
columns := aCollection
]

{ #category : #api }
SpTreeTablePresenter >> contextMenu [
^ contextMenu
]

{ #category : #api }
SpTreeTablePresenter >> contextMenu: aValuable [
"Set the block used to defined the menu"

contextMenu := aValuable
]

{ #category : #simulation }
SpTreeTablePresenter >> doActivateAtPath: aPath [
"Activate only if there is an item at that position"
@@ -224,7 +211,9 @@ SpTreeTablePresenter >> itemAtPath: anArray ifAbsent: aBlock [

{ #category : #initialization }
SpTreeTablePresenter >> registerEvents [
self whenMenuChangedDo: [ self withAdapterDo: #updateMenu ]

self whenMenuChangedDo: [
self withAdapterDo: [ :anAdapter | anAdapter updateMenu ] ]
]

{ #category : #accessing }
@@ -291,13 +280,6 @@ SpTreeTablePresenter >> whenIsResizableChangedDo: aBlock [
self property: #isResizable whenChangedDo: aBlock
]

{ #category : #'api-events' }
SpTreeTablePresenter >> whenMenuChangedDo: aBlock [
"Set a block to value when the menu block has changed"

self property: #contextMenu whenChangedDo: aBlock
]

{ #category : #accessing }
SpTreeTablePresenter >> whenMultiSelectionChangedDo: aBlockClosure [

0 comments on commit 78aefa5

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