Skip to content
Permalink
Browse files

Merge pull request #674 from tesonep/fixing-spCodePresenter-in-pharo8

Fixing sp code presenter in pharo8 & pharo7
  • Loading branch information...
tesonep committed Jul 30, 2019
2 parents 715050c + 1f168c1 commit fc5b7e8e2c6aa7a5665a056726b39644955faaae
@@ -65,6 +65,13 @@ BaselineOfSpec2 >> baseline: spec [
self parametrizedTests: spec.
self commander2: spec.

spec
baseline: 'Commander'
with: [
spec
repository: 'github://pharo-ide/Commander:v0.8.1/src';
loads: #('Commander-Spec2-Compatibility') ].

spec
package: 'Spec2-Pharo7To8Compatibility';
package: 'Spec2-Backend-Tests'
@@ -12,24 +12,11 @@ SpMorphicToolBarAdapter >> addModelTo: toolBarMorph [

toolBarMorph displayMode: self model displayMode.
toolBarMorph height: self model displayMode height.
toolBarMorph setBalloonText: self model help.

self model items
at: SpToolBarItemPosition left
ifPresent: [ :items |
items do: [ :each |
toolBarMorph addItemLeft: (self
configureItem: each
morph: each buildWithSpec
toolBar: toolBarMorph) ] ].
self model whenItemsChangeDo: [self updateItems: toolBarMorph].

self model items
at: SpToolBarItemPosition right
ifPresent: [ :items |
items do: [ :each |
toolBarMorph addItemRight: (self
configureItem: each
morph: each buildWithSpec
toolBar: toolBarMorph) ] ]
self updateItems: toolBarMorph.
]

{ #category : #factory }
@@ -55,3 +42,38 @@ SpMorphicToolBarAdapter >> configureItem: itemModel morph: itemMorph toolBar: to

^ itemMorph
]

{ #category : #testing }
SpMorphicToolBarAdapter >> hasButtonWithLabel: aString [

^ (self widget leftPanel submorphs , self widget rightPanel submorphs)
detect: [ :e | (e isKindOf: SpToolBarButtonMorph) and: [ e label = aString ] ]
ifFound: [ true ]
ifNone: [ false ]
]

{ #category : #testing }
SpMorphicToolBarAdapter >> numberOfItems [

^ self widget leftPanel submorphs size + self widget rightPanel submorphs size
]

{ #category : #factory }
SpMorphicToolBarAdapter >> updateItems: toolBarMorph [

toolBarMorph clearItems.

self model leftItems do: [ :each |
toolBarMorph addItemLeft: (self
configureItem: each
morph: each buildWithSpec
toolBar: toolBarMorph) ].

self model rightItems do: [ :each |
toolBarMorph addItemRight: (self
configureItem: each
morph: each buildWithSpec
toolBar: toolBarMorph) ]


]
@@ -0,0 +1,28 @@
Class {
#name : #SpToolBarAdapterTest,
#superclass : #SpAbstractWidgetAdapterTestCase,
#category : #'Spec2-Backend-Tests'
}

{ #category : #accessing }
SpToolBarAdapterTest >> classToTest [
^ SpToolBarPresenter
]

{ #category : #running }
SpToolBarAdapterTest >> initializeTestedInstance [
presenter

]

{ #category : #tests }
SpToolBarAdapterTest >> testAddLabelledButtonAddTheButton [
presenter addItem: (SpToolBarButton new
label: 'a label';
iconNamed: #abstract;
action: [];
yourself).

self assert: (self adapter hasButtonWithLabel: 'a label').
self assert: (self adapter numberOfItems) equals: 1
]

This file was deleted.

@@ -61,7 +61,7 @@ SpCodePresenter >> buildCodeKeyBindings [
{ #category : #private }
SpCodePresenter >> buildCodeMenu [

^ CmdContextMenuActivation buildContextMenuInContext: (SpCodeContext for: self)
^ (CmdContextMenuActivation buildMenuInContext: (SpCodeContext for: self)) asSpMenuPresenter
]

{ #category : #'api-shortcuts' }
@@ -14,8 +14,9 @@ Class {
#name : #SpToolBarPresenter,
#superclass : #SpAbstractWidgetPresenter,
#instVars : [
'displayMode',
'itemsHolder'
'#displayMode => SpObservableSlot',
'#leftItems => SpObservableSlot',
'#rightItems => SpObservableSlot'
],
#category : #'Spec2-Core-Widgets-Toolbar'
}
@@ -45,28 +46,23 @@ SpToolBarPresenter >> addItem: aToolbarItem [

{ #category : #adding }
SpToolBarPresenter >> addItem: aToolbarItem position: aPosition [
| wasEmpty |

aToolbarItem owner: self.
wasEmpty := false.
(itemsHolder
at: aPosition
ifAbsentPut: [
wasEmpty := true.
OrderedCollection new ])
add: aToolbarItem.

"Triggering add messages.
This is horrible, items holder should be a collection not a dictionary and constraints (like
group) should be handled differently"
wasEmpty ifFalse: [
itemsHolder valueChanged: aPosition ]
aPosition addItem: aToolbarItem into: self
]

{ #category : #accessing }
SpToolBarPresenter >> allItems [
{ #category : #adding }
SpToolBarPresenter >> addItemLeft: aSpToolBarItem [

^ self items values flattened
leftItems add: aSpToolBarItem.
self notifyPropertyChanged: #leftItems.
]

{ #category : #adding }
SpToolBarPresenter >> addItemRight: aSpToolBarItem [

rightItems add: aSpToolBarItem.
self notifyPropertyChanged: #rightItems.
]

{ #category : #accessing }
@@ -98,8 +94,9 @@ SpToolBarPresenter >> initialize [

super initialize.
self beBoth.
itemsHolder := Dictionary new asValueHolder.

leftItems := OrderedCollection new.
rightItems := OrderedCollection new.
]

{ #category : #testing }
@@ -129,17 +126,35 @@ SpToolBarPresenter >> isEmpty [
{ #category : #accessing }
SpToolBarPresenter >> itemNamed: aString [

^ self allItems detect: [ :e | e label = aString ]
^ self items detect: [ :e | e label = aString ]
]

{ #category : #api }
SpToolBarPresenter >> items [

^ itemsHolder value
^ leftItems , rightItems
]

{ #category : #accessing }
SpToolBarPresenter >> leftItems [
^ leftItems
]

{ #category : #testing }
SpToolBarPresenter >> notEmpty [

^ self isEmpty not
]

{ #category : #accessing }
SpToolBarPresenter >> rightItems [
^ rightItems
]

{ #category : #events }
SpToolBarPresenter >> whenItemsChangeDo: aBlockClosure [

self
property: #leftItems whenChangedDo: aBlockClosure;
property: #rightItems whenChangedDo: aBlockClosure
]
@@ -22,6 +22,11 @@ SpTransferPresenter >> from: aModel [
source := aModel
]

{ #category : #initialization }
SpTransferPresenter >> initialize [
super initialize.
]

{ #category : #accessing }
SpTransferPresenter >> passenger [
^ passenger
@@ -7,11 +7,10 @@ SpToolBarPresenterTest >> testAddItemPosition [
self assert: presenter items isEmpty.
presenter addItem: (itemLeft := self newToolbarItem) position: SpToolBarItemPosition left.
presenter addItem: (itemRight := self newToolbarItem) position: SpToolBarItemPosition right.
self
assert: presenter items
equals: (Dictionary newFromPairs: {
SpToolBarItemPosition left. { itemLeft } asOrderedCollection.
SpToolBarItemPosition right. { itemRight } asOrderedCollection })

self assertCollection: presenter leftItems hasSameElements: { itemLeft }.
self assertCollection: presenter rightItems hasSameElements: { itemRight }.

]

{ #category : #'*Spec2-PolyWidgets-Tests' }
@@ -20,7 +19,7 @@ SpToolBarPresenterTest >> testItems [

self assert: presenter items isEmpty.
presenter addItem: (item := self newToolbarItem).
self
assert: presenter items
equals: (Dictionary newFromPairs: { SpToolBarItemPosition left. { item } asOrderedCollection })

self assertCollection: presenter leftItems hasSameElements: { item }.

]
@@ -86,6 +86,13 @@ SpToolBarMorph >> addItemsFromContext: aContext [

]

{ #category : #updating }
SpToolBarMorph >> clearItems [

leftPanel removeAllMorphs.
rightPanel removeAllMorphs.
]

{ #category : #accessing }
SpToolBarMorph >> color [
^ color ifNil: [ Color transparent ]

0 comments on commit fc5b7e8

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