Skip to content
Permalink
Browse files

Merge pull request #752 from jecisc/Add-possiblity-to-pass-action-to-…

…link-presenter

Add-possiblity-to-pass-action-to-link-presenter
  • Loading branch information...
jecisc committed Sep 4, 2019
2 parents cee71ae + 9d21c17 commit 390371739889b9a30ca2e33882a2a53def258415
@@ -10,6 +10,11 @@ Class {
#category : #'Spec2-Adapters-Morphic-Base'
}

{ #category : #accessing }
SpMorphicLinkAdapter >> action [
^ self model action
]

{ #category : #factory }
SpMorphicLinkAdapter >> buildWidget [
"Since Pharo does not yet have a real morph for URL, I create my own. Maybe later we will have real links in Morphic?"
@@ -55,12 +60,7 @@ SpMorphicLinkAdapter >> mouseLeave: anEvent from: aMorph [
{ #category : #'event handling' }
SpMorphicLinkAdapter >> mouseUp: anEvent from: aMorph [
aMorph color: self urlHoverColor.
WebBrowser openOn: self url
]

{ #category : #accessing }
SpMorphicLinkAdapter >> url [
^ self model url
self action value
]

{ #category : #'accessing colors' }
@@ -34,7 +34,7 @@ Class {
#superclass : #SpAbstractWidgetPresenter,
#instVars : [
'#label => SpObservableSlot',
'#url => SpObservableSlot'
'#action => SpObservableSlot'
],
#category : #'Spec2-Core-Widgets'
}
@@ -44,6 +44,16 @@ SpLinkPresenter class >> adapterName [
^ #LinkAdapter
]

{ #category : #api }
SpLinkPresenter >> action [
^ action
]

{ #category : #api }
SpLinkPresenter >> action: aBlock [
action := aBlock
]

{ #category : #initialization }
SpLinkPresenter >> defaultColor [
^ nil
@@ -58,7 +68,7 @@ SpLinkPresenter >> initialize [

{ #category : #api }
SpLinkPresenter >> label [
^ label ifNil: [ self url ]
^ label
]

{ #category : #api }
@@ -67,13 +77,14 @@ SpLinkPresenter >> label: aString [
]

{ #category : #api }
SpLinkPresenter >> url [
^ url
SpLinkPresenter >> url: aString [
self action: [ WebBrowser openOn: aString ].
self label ifNil: [ self label: aString ]
]

{ #category : #api }
SpLinkPresenter >> url: aString [
url := aString
{ #category : #enumerating }
SpLinkPresenter >> whenActionChangedDo: aBlock [
self property: #action whenChangedDo: aBlock
]

{ #category : #enumerating }
@@ -10,7 +10,8 @@ Class {
#instVars : [
'link1',
'link2',
'link3'
'link3',
'link4'
],
#category : #'Spec2-Examples-Demo-Other'
}
@@ -21,6 +22,7 @@ SpDemoLinksPresenter class >> defaultSpec [
add: #link1;
add: #link2;
add: #link3;
add: #link4;
yourself
]

@@ -35,6 +37,7 @@ SpDemoLinksPresenter >> initializeWidgets [
link1 := self newLink.
link2 := self newLink.
link3 := self newLink.
link4 := self newLink.

link1 url: 'https://pharo.org'.

@@ -45,20 +48,9 @@ SpDemoLinksPresenter >> initializeWidgets [
link3
url: 'https://pharo.org';
label: 'Pharo website';
color: Color purple
]

{ #category : #accessing }
SpDemoLinksPresenter >> link1 [
^ link1
]

{ #category : #accessing }
SpDemoLinksPresenter >> link2 [
^ link2
]
color: Color purple.

{ #category : #accessing }
SpDemoLinksPresenter >> link3 [
^ link3
link4
action: [ Object browse ];
label: 'Browse Object'
]
@@ -12,37 +12,35 @@ SpLinkPresenterTest >> classToTest [
{ #category : #tests }
SpLinkPresenterTest >> testLabelIsUrlByDefault [
self assert: presenter label isNil.
self assert: presenter url isNil.
presenter url: 'Test'.
self assert: presenter url equals: 'Test'.
self assert: presenter label equals: 'Test'.
presenter label: 'Label'.
self assert: presenter url equals: 'Test'.
self assert: presenter label equals: 'Label'
]

{ #category : #tests }
SpLinkPresenterTest >> testWhenLabelChangedDo [
SpLinkPresenterTest >> testWhenActionChangedDo [
| count result |
count := 0.
presenter
whenLabelChangedDo: [ :label |
whenActionChangedDo: [ :block |
count := count + 1.
result := label ].
presenter label: 'Test'.
self assert: result equals: 'Test'.
result := block ].
presenter action: [ 'Test' ].
self assert: result isBlock.
self assert: result value equals: 'Test'.
self assert: count equals: 1
]

{ #category : #tests }
SpLinkPresenterTest >> testWhenUrlChangedDo [
SpLinkPresenterTest >> testWhenLabelChangedDo [
| count result |
count := 0.
presenter
whenUrlChangedDo: [ :label |
whenLabelChangedDo: [ :label |
count := count + 1.
result := label ].
presenter url: 'Test'.
presenter label: 'Test'.
self assert: result equals: 'Test'.
self assert: count equals: 1
]

0 comments on commit 3903717

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