Tweak

Path

Actions

Session

Login

Lists


How to make a Model-View with CList:

set CList's items a CCollection

aCollection := CCollection withAll: #(1 2 3).
aList := CList new.
aList items: aCollection.
aList open.

now CList monitors changes in aCollection

aCollection addLast: 4.

How to handle Collection change events:

Collection/List change events pass the following arguments along:

onListChanged: typeOfChange from: firstIndex to: lastIndex
  "React to a change event in the list"
  <on: changed in: list>
  typeOfChange == #remove
    ifTrue:[^self copyOfList removeFrom: firstIndex to: lastIndex].
  typeOfChange == replace
    ifTrue:[^self copyOfList 
                  replaceFrom: firstIndex to: lastIndex with: 
                  (list copyFrom: firstIndex to: lastIndex)].
  typeOfChange == #insert 
    ifTrue:[^self copyOfList 
                  addAll: (list copyFrom: firstIndex to: lastIndex) 
                  at: firstIndex].

Keep in mind though that change events are coalesced so you may have to enumerate events that have happened during the current frame, so you might want to use something like:

onListChanged: change from: indexA to: indexB event: anEvent
  "Note that all arguments except event are ignored"
  <on: changed in: list>
  anEvent withDroppedEventsDo:[:evt|
    typeOfChange := evt arguments at: 1.
    firstIndex := evt arguments at: 2.
    lastIndex := evt arguments at: 3.
    "... etc ..."
 ].