MultiSelectionInList.st
author Claus Gittinger <cg@exept.de>
Tue, 16 Jan 1996 03:04:32 +0100
changeset 289 82d20a3e2fe8
parent 174 d80a6cc3f9b2
child 293 ab897211c99c
permissions -rw-r--r--
dont grab if no menu pulled

"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

'From Smalltalk/X, Version:2.10.5 on 25-mar-1995 at 12:12:09 pm'!

SelectionInList subclass:#MultiSelectionInList
	 instanceVariableNames:''
	 classVariableNames:''
	 poolDictionaries:''
	 category:'Interface-Support-Models'
!

!MultiSelectionInList class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

version
    ^ '$Header'
!

documentation
"
    Like a selectionInList, but allows for multiple selected items.
    For use as a model for SelectionInListViews, with multipleSelectOk set to true.
"
! !

!MultiSelectionInList methodsFor:'initialization'!

initialize
    self listHolder:(nil asValue).      "/ could also use an empty collection here
    self selectionIndexHolder:(#() asValue).

    "Created: 26.10.1995 / 16:30:22 / cg"
! !

!MultiSelectionInList methodsFor:'accessing-values'!

selection:anObjectList 
    "set the selection to be anObjectList."

    |l indizes|

    l := self list.
    indizes := OrderedCollection new.
    anObjectList do:[:o |
	|idx|

	idx := l indexOf:o ifAbsent:0.
	idx ~~ 0 ifTrue:[
	    indizes add:idx
	].
    ].
    ^ self selectionIndex:indizes

    "Created: 26.10.1995 / 16:40:24 / cg"
!

selection
    "return the selections value (i.e. the entry in the list"

    |l|

    l := self list.
    ^ selectionIndexHolder value collect:[:index |
	l at:index
      ]

    "Created: 26.10.1995 / 16:52:27 / cg"
! !

!MultiSelectionInList methodsFor:'selections'!

selections
    |selectionIndices|

    selectionIndices := indexHolder value.
    (selectionIndices isNil 
    or:[selectionIndices isEmpty]) ifFalse:[
	^ selectionIndices collect:[:index | listHolder value at:index]
    ].
    ^ #()
! !