Skip to content

Commit

Permalink
ToAlbumEditsFeedbackLayer: + ToAlbumEditsFeedbackElement and ToAlbumE…
Browse files Browse the repository at this point in the history
…ditsFeedbackElementSkin

+ example_ListWithSelectionTrace to illustrate the use of a specific list primary selection element skin (example from Thales)
  • Loading branch information
plantec committed Sep 23, 2024
1 parent 41cd4fd commit 0d0ca33
Show file tree
Hide file tree
Showing 15 changed files with 380 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
I'm part of a larger example. I'm not expected to be used as a standalone.
"
Class {
#name : #ToListSelectionHistoryEventHandlerExamplePart,
#name : #ToListSelectionHistoryExampleEventHandler,
#superclass : #BlCustomEventHandler,
#instVars : [
'historyList',
Expand All @@ -12,15 +12,15 @@ Class {
}

{ #category : #'event handling' }
ToListSelectionHistoryEventHandlerExamplePart >> addIndexesSelectionCommand: aCommand [
ToListSelectionHistoryExampleEventHandler >> addIndexesSelectionCommand: aCommand [

aCommand operation deselectAllBefore ifTrue: [
historyList data removeAll ].
historyList data add: (currentTarget data at: aCommand indexes last)
]

{ #category : #'event handling' }
ToListSelectionHistoryEventHandlerExamplePart >> addIntervalSelectionCommand: aCommand [
ToListSelectionHistoryExampleEventHandler >> addIntervalSelectionCommand: aCommand [

| s |
aCommand operation deselectAllBefore ifTrue: [
Expand All @@ -32,33 +32,33 @@ ToListSelectionHistoryEventHandlerExamplePart >> addIntervalSelectionCommand: aC
]

{ #category : #'event handling' }
ToListSelectionHistoryEventHandlerExamplePart >> addWholeSelectionCommand: aCommand [
ToListSelectionHistoryExampleEventHandler >> addWholeSelectionCommand: aCommand [

(historyList dataAccessor includes: currentTarget dataAccessor last)
ifTrue: [ ^ self ].
historyList dataAccessor add: currentTarget dataAccessor last
]

{ #category : #'api - accessing' }
ToListSelectionHistoryEventHandlerExamplePart >> eventsToHandle [
ToListSelectionHistoryExampleEventHandler >> eventsToHandle [

^ { ToListSelectionCommandAppliedEvent }
]

{ #category : #accessing }
ToListSelectionHistoryEventHandlerExamplePart >> historyList [
{ #category : #'as yet unclassified' }
ToListSelectionHistoryExampleEventHandler >> historyList [

^ historyList
]

{ #category : #accessing }
ToListSelectionHistoryEventHandlerExamplePart >> historyList: aList [
{ #category : #'as yet unclassified' }
ToListSelectionHistoryExampleEventHandler >> historyList: aList [

historyList := aList
]

{ #category : #'event handling' }
ToListSelectionHistoryEventHandlerExamplePart >> listSelectionCommandAppliedEvent: aCommandAppliedEvent [
ToListSelectionHistoryExampleEventHandler >> listSelectionCommandAppliedEvent: aCommandAppliedEvent [

currentTarget := aCommandAppliedEvent currentTarget.
" check that the command is applied on the primary selection model "
Expand All @@ -69,13 +69,13 @@ ToListSelectionHistoryEventHandlerExamplePart >> listSelectionCommandAppliedEven
]

{ #category : #'event handling' }
ToListSelectionHistoryEventHandlerExamplePart >> removeIndexesSelectionCommand: aCommand [
ToListSelectionHistoryExampleEventHandler >> removeIndexesSelectionCommand: aCommand [


]

{ #category : #'event handling' }
ToListSelectionHistoryEventHandlerExamplePart >> removeIntervalSelectionCommand: aCommand [
ToListSelectionHistoryExampleEventHandler >> removeIntervalSelectionCommand: aCommand [

(historyList dataAccessor includes:
(currentTarget dataAccessor at: aCommand to)) ifFalse: [ ^ self ].
Expand All @@ -84,7 +84,7 @@ ToListSelectionHistoryEventHandlerExamplePart >> removeIntervalSelectionCommand:
]

{ #category : #'event handling' }
ToListSelectionHistoryEventHandlerExamplePart >> removeWholeSelectionCommand: aCommand [
ToListSelectionHistoryExampleEventHandler >> removeWholeSelectionCommand: aCommand [

historyList dataAccessor removeAll
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"
I'm part of a larger example. I'm not expected to be used as a standalone.
"
Class {
#name : #ToListSelectionTraceExampleEventHandler,
#superclass : #BlCustomEventHandler,
#instVars : [
'currentTarget',
'traceSelectionModel'
],
#category : #'Toplo-Examples-Parts'
}

{ #category : #'event handling' }
ToListSelectionTraceExampleEventHandler >> addIndexesSelectionCommand: aCommand [


aCommand operation deselectAllBefore ifTrue: [
traceSelectionModel deselectAll ].
traceSelectionModel selectIndexes: aCommand indexes.
traceSelectionModel deselectIndex: aCommand indexes last
]

{ #category : #'event handling' }
ToListSelectionTraceExampleEventHandler >> addIntervalSelectionCommand: aCommand [
aCommand operation deselectAllBefore ifTrue: [
traceSelectionModel deselectAll ].
traceSelectionModel selectIndexes: currentTarget selectionModel selectedIndexes.
traceSelectionModel deselectIndex: aCommand to
]

{ #category : #'event handling' }
ToListSelectionTraceExampleEventHandler >> addWholeSelectionCommand: aCommand [

traceSelectionModel
selectIndex: 1
to: currentTarget selectionModel itemCount - 1
]

{ #category : #'api - accessing' }
ToListSelectionTraceExampleEventHandler >> eventsToHandle [

^ { ToListSelectionCommandAppliedEvent }
]

{ #category : #'event handling' }
ToListSelectionTraceExampleEventHandler >> listSelectionCommandAppliedEvent: aCommandAppliedEvent [

currentTarget := aCommandAppliedEvent currentTarget.

" check that the command is applied on the primary selection model "
aCommandAppliedEvent selectionModel = currentTarget selectionModel
ifFalse: [ ^ self ].

traceSelectionModel := currentTarget userData at: #traceSelectionModel.

aCommandAppliedEvent command applyWithOperator: self.

currentTarget := nil.
traceSelectionModel := nil
]

{ #category : #'event handling' }
ToListSelectionTraceExampleEventHandler >> removeIndexesSelectionCommand: aCommand [

traceSelectionModel deselectIndex: aCommand indexes
]

{ #category : #'event handling' }
ToListSelectionTraceExampleEventHandler >> removeIntervalSelectionCommand: aCommand [

traceSelectionModel deselectIndex: aCommand from to: aCommand to
]

{ #category : #'event handling' }
ToListSelectionTraceExampleEventHandler >> removeWholeSelectionCommand: aCommand [

traceSelectionModel deselectAll
]
145 changes: 83 additions & 62 deletions src/Toplo-Examples/ToSandBox.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1109,66 +1109,6 @@ ToSandBox class >> example_LabeledIconlWithIconAndText_vertical_interspace [
^ but
]

{ #category : #list }
ToSandBox class >> example_List2WithAllClassesMono [

| l |
l := ToListElement new.
l primarySelectionMode beSingleSelection.
l dataAccessor addAll:
(Smalltalk globals allClasses collect: [ :cls | cls name ]).
l openInSpace
]

{ #category : #list }
ToSandBox class >> example_List2WithAllClassesMulti [

| l |
l := ToListElement new.
l withRowNumbers.
"l selectionModel inspect."
l dataAccessor addAll:
(Smalltalk globals allClasses collect: [ :cls | cls name ]).
l openInSpace
]

{ #category : #list }
ToSandBox class >> example_List2WithAllClassesNone [

| l |
l := ToListElement new.
l primarySelectionMode disable.
l dataAccessor addAll:
(Smalltalk globals allClasses collect: [ :cls | cls name ]).
l openInSpace
]

{ #category : #list }
ToSandBox class >> example_List2WithSelectionHistory [

| statesList historyList pane |
pane := ToPane horizontal.
statesList := ToListElement new matchParent.

historyList := ToListElement new matchParent.
statesList dataAccessor addAll: self statesOfAmerica.
pane addChildren: {
statesList.
historyList }.

statesList addEventHandler:
(ToListSelectionHistoryEventHandlerExamplePart new historyList:
historyList).
statesList addEventHandler: (BlEventHandler
on: ToListSelectionCommandAppliedEvent
do: [ :event | event traceCr ]).

pane
matchParent;
addDividers.
pane openInInnerWindow
]

{ #category : #list }
ToSandBox class >> example_ListOneClass [

Expand Down Expand Up @@ -1302,14 +1242,47 @@ ToSandBox class >> example_ListWithAllClassesAsToggleButton [
ifTrue: [
holder listElement selecter deselectIndex: holder position ]
ifFalse: [
holder listElement selecter selectIndex: holder position ].
event traceCr ].
holder listElement selecter selectIndex: holder position ] ].
node addChild: toggle ].
l dataAccessor addAll: Smalltalk globals allClasses.
l primarySelectionMode option masked: true.
l openInSpace
]

{ #category : #list }
ToSandBox class >> example_ListWithAllClassesMono [

| l |
l := ToListElement new.
l primarySelectionMode beSingleSelection.
l dataAccessor addAll:
(Smalltalk globals allClasses collect: [ :cls | cls name ]).
l openInSpace
]

{ #category : #list }
ToSandBox class >> example_ListWithAllClassesMulti [

| l |
l := ToListElement new.
l withRowNumbers.
"l selectionModel inspect."
l dataAccessor addAll:
(Smalltalk globals allClasses collect: [ :cls | cls name ]).
l openInSpace
]

{ #category : #list }
ToSandBox class >> example_ListWithAllClassesNone [

| l |
l := ToListElement new.
l primarySelectionMode disable.
l dataAccessor addAll:
(Smalltalk globals allClasses collect: [ :cls | cls name ]).
l openInSpace
]

{ #category : #list }
ToSandBox class >> example_ListWithAllMethods [

Expand Down Expand Up @@ -1395,6 +1368,54 @@ ToSandBox class >> example_ListWithPanes [
list openInSpace
]

{ #category : #list }
ToSandBox class >> example_ListWithSelectionHistory [

| statesList historyList pane |
pane := ToPane horizontal.
statesList := ToListElement new matchParent.

historyList := ToListElement new matchParent.
statesList dataAccessor addAll: self statesOfAmerica.
pane addChildren: {
statesList.
historyList }.

statesList addEventHandler:
(ToListSelectionHistoryExampleEventHandler new historyList:
historyList).
statesList addEventHandler: (BlEventHandler
on: ToListSelectionCommandAppliedEvent
do: [ :event | event traceCr ]).

pane
matchParent;
addDividers.
pane openInInnerWindow
]

{ #category : #list }
ToSandBox class >> example_ListWithSelectionTrace [

| statesList |
statesList := ToListElement new matchParent.
statesList withRowNumbers.
statesList dataAccessor addAll: self statesOfAmerica.
statesList addEventHandler:
ToListSelectionTraceExampleEventHandler new.
" use of userData is ok here for the example but a subclass of ToListElement
would be preferable to store the traceSelectionModel as an instance variable"
statesList userData
at: #traceSelectionModel
put: statesList newSelectionModel.
" mandatory option here: the selection are separate (one selection element for each selected node)"
statesList primarySelectionMode option grouped: false.
statesList primarySelectionMode option elementFactory: [
ToListBasicSelectionElement new defaultSkin:
ToTraceListPrimarySelectionElementSkin new ].
statesList openInSpace
]

{ #category : #list }
ToSandBox class >> example_NodeContainerWithStatesOfAmerica [

Expand Down
24 changes: 24 additions & 0 deletions src/Toplo-Examples/ToTraceListPrimarySelectionElementSkin.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Class {
#name : #ToTraceListPrimarySelectionElementSkin,
#superclass : #ToListBasicSelectionElementSkin,
#category : #'Toplo-Examples-Parts'
}

{ #category : #'event handling' }
ToTraceListPrimarySelectionElementSkin >> installSkinEvent: anEvent [

super installSkinEvent: anEvent.
anEvent elementDo: [ :e |
| color traceSelectionModel |
e geometry: (BlRoundedRectangleGeometry cornerRadius:
(e valueOfTokenNamed: #'border-radius-SM')).
e border: BlBorder empty.
traceSelectionModel := e listElement userData at:
#traceSelectionModel.
" since the selection option is separate, e nodes size is always 1 "
(traceSelectionModel containsIndex: e nodes anyOne holder position)
ifTrue: [ color := Color red ]
ifFalse: [
color := e valueOfTokenNamed: #'color-primary-selection-focused' ].
e background: color ]
]
21 changes: 21 additions & 0 deletions src/Toplo-Widget-Album/ToAlbumEditsFeedbackElement.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Class {
#name : #ToAlbumEditsFeedbackElement,
#superclass : #ToElement,
#category : #'Toplo-Widget-Album-TextPane'
}

{ #category : #initialization }
ToAlbumEditsFeedbackElement >> initialize [

super initialize.
self size: 25 @ 25.
self constraintsDo: [ :c |
c frame horizontal alignRight.
c frame vertical alignTop ]
]

{ #category : #'instance creation' }
ToAlbumEditsFeedbackElement >> newRawSkin [

^ ToAlbumEditsFeedbackElementSkin new
]
Loading

0 comments on commit 0d0ca33

Please sign in to comment.