Skip to content
Permalink
Browse files

Merge pull request #670 from CafeKrem/609-Instance-of-TreeTablePresen…

…ter-did-not-understand-activatesOnDoubleClick

609-Instance-of-TreeTablePresenter-did-not-understand-activatesOnDoubleClick
  • Loading branch information...
jecisc committed Aug 5, 2019
2 parents a8dd99f + 5c2a9c8 commit 9cda46c5c878d83b433f65a06cab945edfc1e27d
@@ -183,6 +183,12 @@ SpMorphicTreeTableAdapter >> selectedItem [
^ (self widget dataSource elementAt: selectedIndex) data
]

{ #category : #accessing }
SpMorphicTreeTableAdapter >> selectedPath [

^ self selectedPaths first
]

{ #category : #accessing }
SpMorphicTreeTableAdapter >> selectedPaths [

@@ -198,9 +204,9 @@ SpMorphicTreeTableAdapter >> selectionChanged: ann [

{ #category : #factory }
SpMorphicTreeTableAdapter >> strongSelectionChanged: aFTStrongSelectionChanged [

self presenter activatesOnDoubleClick ifFalse: [ ^ self ].
self presenter doubleClickAtIndex: aFTStrongSelectionChanged selectedIndex
self presenter activatesOnDoubleClick
ifFalse: [ ^ self ].
self presenter doubleClickAtPath: self selectedPath
]

{ #category : #factory }
@@ -38,15 +38,18 @@ SpAbstractTreeSingleSelectionMode >> isEmpty [
^ selection isEmpty
]

{ #category : #selection }
SpAbstractTreeSingleSelectionMode >> replaceOtherSelectionMode: anotherSelection [
{ #category : #accessing }
SpAbstractTreeSingleSelectionMode >> isMultipleSelection [
^ false
]

self subclassResponsibility
{ #category : #accesing }
SpAbstractTreeSingleSelectionMode >> presenter: aPresenter [
presenter := aPresenter
]

{ #category : #selection }
SpAbstractTreeSingleSelectionMode >> selectPath: aPath [

self subclassResponsibility
]

@@ -55,13 +58,23 @@ SpAbstractTreeSingleSelectionMode >> selectPaths: pathArray [
self subclassResponsibility
]

{ #category : #accessing }
SpAbstractTreeSingleSelectionMode >> selectedItem [
^ self subclassResponsibility
]

{ #category : #accessing }
SpAbstractTreeSingleSelectionMode >> selectedPaths [
^ self subclassResponsibility
]

{ #category : #selecting }
SpAbstractTreeSingleSelectionMode >> unselectAll [

self clearSelection
]

{ #category : #'API - events' }
{ #category : #'api - events' }
SpAbstractTreeSingleSelectionMode >> whenChangedDo: aBlockClosure [

self property: #selection whenChangedDo: aBlockClosure
@@ -10,25 +10,6 @@ SpTreeMultipleSelectionMode >> isMultipleSelection [
^ true
]

{ #category : #accessing }
SpTreeMultipleSelectionMode >> presenter: aTreeTablePresenter [

presenter := aTreeTablePresenter
]

{ #category : #selection }
SpTreeMultipleSelectionMode >> replaceOtherSelectionMode: anotherSelectionMode [

| originalValueHolder |

selection := anotherSelectionMode selectedPath.
originalValueHolder := anotherSelectionMode observablePropertyNamed: #selection.

originalValueHolder announcer subscriptions subscriptions do: [
self halt.
]
]

{ #category : #selection }
SpTreeMultipleSelectionMode >> selectPath: aPath [

@@ -4,18 +4,6 @@ Class {
#category : #'Spec2-Core-Widgets-Tree'
}

{ #category : #accessing }
SpTreeSingleSelectionMode >> isMultipleSelection [

^ false
]

{ #category : #accessing }
SpTreeSingleSelectionMode >> presenter: aTreeTablePresenter [

presenter := aTreeTablePresenter
]

{ #category : #accessing }
SpTreeSingleSelectionMode >> selectPath: aPath [
"If the path is out of range, keep the selection."
@@ -16,10 +16,11 @@ Class {
'#showColumnHeaders => SpObservableSlot',
'#isResizable => SpObservableSlot',
'#selection => SpObservableSlot',
'#doubleClickAction => SpObservableSlot',
'#roots => SpObservableSlot',
'#childrenBlock',
'#contextMenu => SpObservableSlot'
'#contextMenu => SpObservableSlot',
'#activationBlock',
'#activateOnSingleClick'
],
#category : #'Spec2-Core-Widgets-Tree'
}
@@ -30,6 +31,30 @@ SpTreeTablePresenter class >> adapterName [
^ #TreeTableAdapter
]

{ #category : #api }
SpTreeTablePresenter >> activateOnDoubleClick [

activateOnSingleClick := false
]

{ #category : #api }
SpTreeTablePresenter >> activateOnSingleClick [

activateOnSingleClick := true
]

{ #category : #testing }
SpTreeTablePresenter >> activatesOnDoubleClick [

^ activateOnSingleClick not
]

{ #category : #testing }
SpTreeTablePresenter >> activatesOnSingleClick [

^ activateOnSingleClick
]

{ #category : #api }
SpTreeTablePresenter >> addColumn: aColumn [
columns := self columns copyWith: aColumn
@@ -74,6 +99,15 @@ SpTreeTablePresenter >> childrenFor: anObject [
^ self children value: anObject
]

{ #category : #simulation }
SpTreeTablePresenter >> clickAtPath: aPath [

self selectPath: aPath.

activateOnSingleClick ifFalse: [ ^ self ].
self doActivateAtPath: aPath
]

{ #category : #accessing }
SpTreeTablePresenter >> columns [
^ columns
@@ -96,23 +130,24 @@ SpTreeTablePresenter >> contextMenu: aValuable [
contextMenu := aValuable
]

{ #category : #private }
SpTreeTablePresenter >> doubleClickAction [

^ doubleClickAction
]
{ #category : #simulation }
SpTreeTablePresenter >> doActivateAtPath: aPath [
"Activate only if there is an item at that position"

{ #category : #'api-events' }
SpTreeTablePresenter >> doubleClickAction: aBlockClosure [

doubleClickAction := aBlockClosure
self itemAtPath: aPath ifAbsent: [ ^ self ].
activationBlock
cull:
((SpTreeSingleSelectionMode on: self)
selectPath: aPath;
yourself)
]

{ #category : #simulation }
SpTreeTablePresenter >> doubleClickAtIndex: anInteger [
SpTreeTablePresenter >> doubleClickAtPath: aPath [
self selectPath: aPath.

self selectedIndex: anInteger.
doubleClickAction cull: anInteger
activateOnSingleClick ifTrue: [ ^ self ].
self doActivateAtPath: aPath
]

{ #category : #api }
@@ -126,12 +161,16 @@ SpTreeTablePresenter >> initialize [
super initialize.

self withScrollBars.

activationBlock := [ ].

showColumnHeaders := true.
columns := #().
isResizable := false.
selection := SpTreeSingleSelectionMode on: self.
childrenBlock := [ :item | #() ].
roots := #().
self activateOnDoubleClick.
self registerEvents
]

@@ -236,6 +275,11 @@ SpTreeTablePresenter >> unselectAll [
self selection unselectAll
]

{ #category : #'api-events' }
SpTreeTablePresenter >> whenActivatedDo: aBlockClosure [
activationBlock := aBlockClosure
]

{ #category : #'api-events' }
SpTreeTablePresenter >> whenColumnsChangedDo: aBlockClosure [
self property: #columns whenChangedDo: aBlockClosure
@@ -0,0 +1,6 @@
Extension { #name : #SpTreeTablePresenter }

{ #category : #'*Spec2-Deprecated' }
SpTreeTablePresenter >> doubleClickAction: aBlockClosure [
self deprecated: 'Use #whenActivatedDo: and #activateOnDoubleClick instead.'
]
@@ -18,6 +18,7 @@ SpDemoTreeTablePresenter class >> defaultSpec [

^ SpBoxLayout newVertical
add: #table1;
add: 'Double click to browse.' height: self labelHeight;
yourself
]

@@ -30,21 +31,19 @@ SpDemoTreeTablePresenter >> initializeWidgets [
(SpCompositeTableColumn new
title: 'Classes';
addColumn:
(SpImageTableColumn new
((SpImageTableColumn evaluated: #systemIcon)
width: 20;
evaluated: #systemIcon;
yourself);
addColumn:
(SpStringTableColumn new
evaluated: #name;
yourself);
addColumn: (SpStringTableColumn evaluated: #name);
yourself);
addColumn: (SpStringTableColumn title: 'Number of subclasses' evaluated: [ :class | class subclasses size asString ]);
addColumn: (SpStringTableColumn title: 'Number of methods' evaluated: [ :class | class methods size asString ]);
roots: {Object};
children: [ :aClass | aClass subclasses ];
beResizable;
contextMenu: self menu
contextMenu: self menu;
activateOnDoubleClick;
whenActivatedDo: [ :selection | selection selectedItem browse ]
]

{ #category : #accessing }
@@ -23,6 +23,54 @@ SpTreeTablePresenterTest >> setUp [

]

{ #category : #tests }
SpTreeTablePresenterTest >> testActivationOnDoubleClickShouldActivateOnDoubleClick [
| activatedItem |
presenter
activateOnDoubleClick;
whenActivatedDo: [ :selection | activatedItem := selection selectedItem ].

presenter doubleClickAtPath: #(1 2 1).

self assert: activatedItem equals: 110
]

{ #category : #tests }
SpTreeTablePresenterTest >> testActivationOnDoubleClickShouldNotActivateOnClick [
| activatedItem |
presenter
activateOnDoubleClick;
whenActivatedDo: [ :selection | activatedItem := selection selectedItem ].

presenter clickAtPath: #(1).

self assert: activatedItem isNil
]

{ #category : #tests }
SpTreeTablePresenterTest >> testActivationOnSingleClickShouldActivateOnClick [
| activatedItem |
presenter
activateOnSingleClick;
whenActivatedDo: [ :selection | activatedItem := selection selectedItem ].

presenter clickAtPath: #(1).

self assert: activatedItem equals: 1
]

{ #category : #tests }
SpTreeTablePresenterTest >> testActivationOnSingleClickShouldNotActivateOnClickOutside [
| activatedItem |
presenter
activateOnSingleClick;
whenActivatedDo: [ :selection | activatedItem := selection selectedItem ].

presenter clickAtPath: #(4).

self assert: activatedItem isNil
]

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

0 comments on commit 9cda46c

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