Skip to content

Commit

Permalink
add expand/collapse keybindings (arrow left, arrow right, space) on t…
Browse files Browse the repository at this point in the history
…rees.

Incidentally, fix a bug that was happening while expanding and collapsing branches (previous selection was lost)
  • Loading branch information
estebanlm committed Nov 25, 2024
1 parent 375788d commit bb4d379
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/Spec2-Adapters-Morphic/SpMorphicTreeTableDataSource.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,16 @@ SpMorphicTreeTableDataSource >> collapsePath: aPath [

(self itemAtPath: aPath) ifNotNil:[ :aNode |
aNode collapseAll.
self tableRefresh ]
self tableRefresh.
self model selection selectPath: aPath ]
]

{ #category : 'accessing' }
SpMorphicTreeTableDataSource >> expandPath: anArray [
SpMorphicTreeTableDataSource >> expandPath: aPath [

self expandPath: anArray root: self rootItem children.
self tableRefresh
self expandPath: aPath root: self rootItem children.
self tableRefresh.
self model selection selectPath: aPath
]

{ #category : 'accessing' }
Expand Down
1 change: 1 addition & 0 deletions src/Spec2-Core/SpAbstractTreePresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ SpAbstractTreePresenter >> initialize [
verticalAlignment := SpVerticalAlignment new.

self withScrollBars.
self registerActions.
self registerEvents
]

Expand Down
2 changes: 1 addition & 1 deletion src/Spec2-Core/SpWindowPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ SpWindowPresenter >> initialize [

{ #category : 'initialization' }
SpWindowPresenter >> initializeWindow [

self presenter initializeWindow: self
]

Expand Down
15 changes: 14 additions & 1 deletion src/Spec2-ListView/SpTreeColumnViewPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SpTreeColumnViewPresenter class >> adapterName [
SpTreeColumnViewPresenter class >> example [

^ self new
application: (SpApplication new useBackend: #Gtk);
application: SpApplication new;
addColumnTitle: 'Class'
setup: [ :aPresenter | aPresenter newLabel ]
bind: [ :aPresenter :aClass | aPresenter label: aClass name ];
Expand Down Expand Up @@ -217,6 +217,19 @@ SpTreeColumnViewPresenter >> isShowingColumnHeaders [
^ showColumnHeaders
]

{ #category : 'initialization' }
SpTreeColumnViewPresenter >> registerActions [

super registerActions.
self ensureInternalActions
addShortcutWith: [ :action | action
shortcutKey: KeyboardKey right asKeyCombination | KeyboardKey space asKeyCombination;
action: [ self expandPath: self selection selectedPath ] ];
addShortcutWith: [ :action | action
shortcutKey: KeyboardKey left asKeyCombination;
action: [ self collapsePath: self selection selectedPath ] ]
]

{ #category : 'api' }
SpTreeColumnViewPresenter >> showColumnHeaders [
"Show column headers"
Expand Down
16 changes: 14 additions & 2 deletions src/Spec2-ListView/SpTreeListViewPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ SpTreeListViewPresenter class >> example [
"This example show the simples list view you can make: A list with a label"

self new
application: (SpApplication new useBackend: #Gtk);
application: SpApplication new;
items: { Object };
children: [ :aClass | aClass subclasses ];
setup: [ :aPresenter | aPresenter newLabel ];
Expand Down Expand Up @@ -235,7 +235,6 @@ SpTreeListViewPresenter >> initialize [
self beSingleSelection.
self activateOnDoubleClick.

self registerActions.
self initializeItemFactory
]

Expand All @@ -247,6 +246,19 @@ SpTreeListViewPresenter >> initializeItemFactory [
self bind: [ :aPresenter :anObject | aPresenter label: anObject asString ]
]

{ #category : 'initialization' }
SpTreeListViewPresenter >> registerActions [

super registerActions.
self ensureInternalActions
addShortcutWith: [ :action | action
shortcutKey: KeyboardKey right asKeyCombination | KeyboardKey space asKeyCombination;
action: [ self expandPath: self selection selectedPath ] ];
addShortcutWith: [ :action | action
shortcutKey: KeyboardKey left asKeyCombination;
action: [ self collapsePath: self selection selectedPath ] ]
]

{ #category : 'initialization' }
SpTreeListViewPresenter >> registerEvents [

Expand Down

0 comments on commit bb4d379

Please sign in to comment.