Skip to content

Commit

Permalink
Merge pull request #670 from CafeKrem/609-Instance-of-TreeTablePresen…
Browse files Browse the repository at this point in the history
…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 9cda46c
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 60 deletions.
12 changes: 9 additions & 3 deletions src/Spec2-Adapters-Morphic/SpMorphicTreeTableAdapter.class.st
Expand Up @@ -183,6 +183,12 @@ SpMorphicTreeTableAdapter >> selectedItem [
^ (self widget dataSource elementAt: selectedIndex) data
]

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

^ self selectedPaths first
]

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

Expand All @@ -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 }
Expand Down
23 changes: 18 additions & 5 deletions src/Spec2-Core/SpAbstractTreeSingleSelectionMode.class.st
Expand Up @@ -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
]

Expand All @@ -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
Expand Down
19 changes: 0 additions & 19 deletions src/Spec2-Core/SpTreeMultipleSelectionMode.class.st
Expand Up @@ -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 [

Expand Down
12 changes: 0 additions & 12 deletions src/Spec2-Core/SpTreeSingleSelectionMode.class.st
Expand Up @@ -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."
Expand Down
72 changes: 58 additions & 14 deletions src/Spec2-Core/SpTreeTablePresenter.class.st
Expand Up @@ -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'
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 }
Expand All @@ -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
]

Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/Spec2-Deprecated/SpTreeTablePresenter.extension.st
@@ -0,0 +1,6 @@
Extension { #name : #SpTreeTablePresenter }

{ #category : #'*Spec2-Deprecated' }
SpTreeTablePresenter >> doubleClickAction: aBlockClosure [
self deprecated: 'Use #whenActivatedDo: and #activateOnDoubleClick instead.'
]
13 changes: 6 additions & 7 deletions src/Spec2-Examples/SpDemoTreeTablePresenter.class.st
Expand Up @@ -18,6 +18,7 @@ SpDemoTreeTablePresenter class >> defaultSpec [

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

Expand All @@ -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 }
Expand Down
48 changes: 48 additions & 0 deletions src/Spec2-Tests/SpTreeTablePresenterTest.class.st
Expand Up @@ -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 |
Expand Down

0 comments on commit 9cda46c

Please sign in to comment.