SelectionInList.st
author Claus Gittinger <cg@exept.de>
Mon, 04 Feb 2008 10:33:20 +0100
changeset 3541 73dd9da193e7
parent 2748 c1efcd93841b
child 4442 7c67a011c29b
permissions -rw-r--r--
care for List objects in list:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
133
claus
parents: 129
diff changeset
     1
"
claus
parents: 129
diff changeset
     2
 COPYRIGHT (c) 1994 by Claus Gittinger
claus
parents: 129
diff changeset
     3
	      All Rights Reserved
claus
parents: 129
diff changeset
     4
claus
parents: 129
diff changeset
     5
 This software is furnished under a license and may be used
claus
parents: 129
diff changeset
     6
 only in accordance with the terms of that license and with the
claus
parents: 129
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
claus
parents: 129
diff changeset
     8
 be provided or otherwise made available to, or used by, any
claus
parents: 129
diff changeset
     9
 other person.  No title to or ownership of the software is
claus
parents: 129
diff changeset
    10
 hereby transferred.
claus
parents: 129
diff changeset
    11
"
2251
419939054e77 category change
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
    12
"{ Package: 'stx:libwidg' }"
419939054e77 category change
Claus Gittinger <cg@exept.de>
parents: 1541
diff changeset
    13
129
claus
parents: 114
diff changeset
    14
ValueHolder subclass:#SelectionInList
359
dec35d4fbc35 dont initialize twice
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    15
	instanceVariableNames:'listHolder selectionIndexHolder'
dec35d4fbc35 dont initialize twice
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    16
	classVariableNames:''
dec35d4fbc35 dont initialize twice
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    17
	poolDictionaries:''
dec35d4fbc35 dont initialize twice
Claus Gittinger <cg@exept.de>
parents: 204
diff changeset
    18
	category:'Interface-Support-Models'
114
5d736ee65276 Initial revision
claus
parents:
diff changeset
    19
!
5d736ee65276 Initial revision
claus
parents:
diff changeset
    20
133
claus
parents: 129
diff changeset
    21
!SelectionInList class methodsFor:'documentation'!
claus
parents: 129
diff changeset
    22
claus
parents: 129
diff changeset
    23
copyright
claus
parents: 129
diff changeset
    24
"
claus
parents: 129
diff changeset
    25
 COPYRIGHT (c) 1994 by Claus Gittinger
claus
parents: 129
diff changeset
    26
	      All Rights Reserved
claus
parents: 129
diff changeset
    27
claus
parents: 129
diff changeset
    28
 This software is furnished under a license and may be used
claus
parents: 129
diff changeset
    29
 only in accordance with the terms of that license and with the
claus
parents: 129
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
claus
parents: 129
diff changeset
    31
 be provided or otherwise made available to, or used by, any
claus
parents: 129
diff changeset
    32
 other person.  No title to or ownership of the software is
claus
parents: 129
diff changeset
    33
 hereby transferred.
claus
parents: 129
diff changeset
    34
"
claus
parents: 129
diff changeset
    35
!
claus
parents: 129
diff changeset
    36
claus
parents: 129
diff changeset
    37
documentation
claus
parents: 129
diff changeset
    38
"
claus
parents: 129
diff changeset
    39
    Instances of SelectionInList can be used as model for
claus
parents: 129
diff changeset
    40
    a SelectionInListView or a PopUpList. 
claus
parents: 129
diff changeset
    41
    They keep two values: a list value and a selection value; 
claus
parents: 129
diff changeset
    42
    both are referred to via valueHolders.
claus
parents: 129
diff changeset
    43
577
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
    44
    If any of those two changes, the selectionInList notifies its 
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
    45
    dependents via a change notification, 
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
    46
    using #list or #selectionIndex as update aspect respectively.
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
    47
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
    48
    A popupList also knows how to deal with a selectionInList model;
133
claus
parents: 129
diff changeset
    49
    this makes it possible to have popupLists be somewhat exchangable
claus
parents: 129
diff changeset
    50
    with selectionInListViews.
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    51
577
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
    52
    SelectionInLists only support a single selection within the list;
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
    53
    use MultiSelectionInList, if multiple selections are needed.
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
    54
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
    55
    [instance variables:]
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
    56
        listHolder              <ValueHolder>           holds the list
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
    57
        selectionIndexHolder    <ValueHolder>           holdes the selectionIndex
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
    58
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
    59
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    60
    [see also:]
577
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
    61
        SelectionInListView PopUpList
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
    62
        MultiSelectionInList Model ValueHolder
583
2ec13b7ceba5 documentation
Claus Gittinger <cg@exept.de>
parents: 577
diff changeset
    63
2ec13b7ceba5 documentation
Claus Gittinger <cg@exept.de>
parents: 577
diff changeset
    64
    [author:]
2ec13b7ceba5 documentation
Claus Gittinger <cg@exept.de>
parents: 577
diff changeset
    65
        Claus Gittinger
133
claus
parents: 129
diff changeset
    66
"
claus
parents: 129
diff changeset
    67
!
claus
parents: 129
diff changeset
    68
claus
parents: 129
diff changeset
    69
examples
claus
parents: 129
diff changeset
    70
"
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    71
  basic setup using a selectionInList as model of a selectionInListView:
590
8392a7c03352 examples
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
    72
                                                                        [exBegin]
133
claus
parents: 129
diff changeset
    73
    |m v|
claus
parents: 129
diff changeset
    74
claus
parents: 129
diff changeset
    75
    m := SelectionInList new.
claus
parents: 129
diff changeset
    76
    m list:#('one' 'two' 'three' 'four').
claus
parents: 129
diff changeset
    77
    m selectionIndex:2.
claus
parents: 129
diff changeset
    78
claus
parents: 129
diff changeset
    79
    v := SelectionInListView on:m.
claus
parents: 129
diff changeset
    80
    v open
590
8392a7c03352 examples
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
    81
                                                                        [exEnd]
133
claus
parents: 129
diff changeset
    82
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    83
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    84
  similar, a selectionInList as model of a popUpList:
590
8392a7c03352 examples
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
    85
                                                                        [exBegin]
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    86
    |m v|
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    87
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    88
    m := SelectionInList new.
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    89
    m list:#('one' 'two' 'three' 'four').
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    90
    m selectionIndex:2.
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    91
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    92
    v := PopUpList on:m.
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    93
    v open
590
8392a7c03352 examples
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
    94
                                                                        [exEnd]
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    95
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    96
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    97
  using a combination-instance creation method:
590
8392a7c03352 examples
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
    98
                                                                        [exBegin]
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
    99
    |m v|
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   100
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   101
    m := SelectionInList 
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   102
                with:#('one' 'two' 'three' 'four')
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   103
                initialSelection:2.
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   104
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   105
    v := PopUpList on:m.
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   106
    v open
590
8392a7c03352 examples
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   107
                                                                        [exEnd]
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   108
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   109
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   110
  two different views on the same selectionInList model:
590
8392a7c03352 examples
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   111
                                                                        [exBegin]
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   112
    |m v1 v2|
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   113
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   114
    m := SelectionInList new.
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   115
    m list:#('one' 'two' 'three' 'four').
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   116
    m selectionIndex:2.
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   117
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   118
    v1 := PopUpList on:m.
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   119
    v1 open.
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   120
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   121
    v2 := SelectionInListView on:m.
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   122
    v2 open
590
8392a7c03352 examples
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   123
                                                                        [exEnd]
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   124
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   125
133
claus
parents: 129
diff changeset
   126
  two views on the same selectionInList:
claus
parents: 129
diff changeset
   127
  and a button, which adds an item to the list.
590
8392a7c03352 examples
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   128
                                                                        [exBegin]
133
claus
parents: 129
diff changeset
   129
    |m v1 v2 b numItems|
claus
parents: 129
diff changeset
   130
claus
parents: 129
diff changeset
   131
    numItems := 4.
claus
parents: 129
diff changeset
   132
claus
parents: 129
diff changeset
   133
    m := SelectionInList new.
claus
parents: 129
diff changeset
   134
    m list:((1 to:numItems) collect:[:i | i printString]).
claus
parents: 129
diff changeset
   135
    m selectionIndex:2.
claus
parents: 129
diff changeset
   136
claus
parents: 129
diff changeset
   137
    v1 := ScrollableView forView:(SelectionInListView on:m).
claus
parents: 129
diff changeset
   138
    v1 open.
claus
parents: 129
diff changeset
   139
claus
parents: 129
diff changeset
   140
    v2 := ScrollableView forView:(SelectionInListView on:m).
claus
parents: 129
diff changeset
   141
    v2 open.
claus
parents: 129
diff changeset
   142
claus
parents: 129
diff changeset
   143
    b := Button label:'add item'.
claus
parents: 129
diff changeset
   144
    b action:[numItems := numItems + 1.
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   145
              m list:((1 to:numItems) collect:[:i | i printString]).
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   146
             ].
133
claus
parents: 129
diff changeset
   147
    b open
590
8392a7c03352 examples
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   148
                                                                        [exEnd]
133
claus
parents: 129
diff changeset
   149
"
claus
parents: 129
diff changeset
   150
! !
claus
parents: 129
diff changeset
   151
114
5d736ee65276 Initial revision
claus
parents:
diff changeset
   152
!SelectionInList class methodsFor:'instance creation'!
5d736ee65276 Initial revision
claus
parents:
diff changeset
   153
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   154
with:aList
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   155
    "return a new instance holding aList"
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   156
1541
d90417495d52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
   157
    ^ self new listHolder:(ValueHolder with:aList)
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   158
1541
d90417495d52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
   159
    "Modified: / 21.5.1998 / 03:17:16 / cg"
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   160
!
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   161
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   162
with:aList initialSelection:index
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   163
    "return a new instance holding aList and initially selecting
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   164
     the item at index."
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   165
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   166
    ^ (self with:aList) 
1541
d90417495d52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
   167
        selectionIndexHolder:(ValueHolder with:index)
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   168
1541
d90417495d52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
   169
    "Created: / 24.4.1996 / 08:47:33 / cg"
d90417495d52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
   170
    "Modified: / 21.5.1998 / 03:17:31 / cg"
114
5d736ee65276 Initial revision
claus
parents:
diff changeset
   171
! !
5d736ee65276 Initial revision
claus
parents:
diff changeset
   172
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   173
!SelectionInList methodsFor:'accessing-holders'!
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   174
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   175
listHolder
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   176
    "return the valueHolder which holds the list"
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   177
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   178
    ^ listHolder
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   179
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   180
    "Modified: 24.4.1996 / 08:39:44 / cg"
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   181
!
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   182
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   183
listHolder:aValueHolder
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   184
    "set the valueHolder which holds the list.
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   185
     Q: should we forward a change-notification ?"
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   186
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   187
    listHolder notNil ifTrue:[
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   188
        listHolder removeDependent:self
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   189
    ].
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   190
    listHolder := aValueHolder.
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   191
    listHolder addDependent:self
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   192
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   193
    "Modified: 24.4.1996 / 08:39:59 / cg"
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   194
!
114
5d736ee65276 Initial revision
claus
parents:
diff changeset
   195
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   196
selectionHolder
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   197
    "return someone holding on the selection itself (not the index). 
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   198
     Since we have no one, create an adapter, to get up-to-date values."
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   199
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   200
    ^ AspectAdaptor 
544
c6be88ace7c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 526
diff changeset
   201
        subject:self 
564
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   202
        sendsUpdates:false
544
c6be88ace7c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 526
diff changeset
   203
        accessWith:#selection 
c6be88ace7c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 526
diff changeset
   204
        assignWith:#'selection:' 
c6be88ace7c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 526
diff changeset
   205
        aspect:#selectionIndex
c6be88ace7c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 526
diff changeset
   206
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   207
    "Modified: 24.4.1996 / 08:40:19 / cg"
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   208
!
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   209
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   210
selectionIndexHolder
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   211
    "return the valueHolder which holds the index"
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   212
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   213
    ^ selectionIndexHolder
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   214
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   215
    "Modified: 24.4.1996 / 08:40:31 / cg"
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   216
!
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   217
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   218
selectionIndexHolder:aValueHolder
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   219
    "set the valueHolder which holdes the index.
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   220
     Q: should we forward a change-notification ?"
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   221
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   222
    selectionIndexHolder notNil ifTrue:[
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   223
        selectionIndexHolder removeDependent:self
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   224
    ].
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   225
    selectionIndexHolder := aValueHolder.
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   226
    selectionIndexHolder addDependent:self
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   227
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   228
    "Modified: 24.4.1996 / 08:40:42 / cg"
114
5d736ee65276 Initial revision
claus
parents:
diff changeset
   229
! !
5d736ee65276 Initial revision
claus
parents:
diff changeset
   230
133
claus
parents: 129
diff changeset
   231
!SelectionInList methodsFor:'accessing-values'!
114
5d736ee65276 Initial revision
claus
parents:
diff changeset
   232
129
claus
parents: 114
diff changeset
   233
list
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   234
    "return the list - thats the thingy held by the listHolder"
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   235
129
claus
parents: 114
diff changeset
   236
    ^ listHolder value
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   237
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   238
    "Modified: 24.4.1996 / 08:41:05 / cg"
129
claus
parents: 114
diff changeset
   239
!
claus
parents: 114
diff changeset
   240
133
claus
parents: 129
diff changeset
   241
list:aCollection
577
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
   242
    "set the list - thats the thingy held by the listHolder"
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
   243
1436
72e392844594 send change notification if same list is assigned
Claus Gittinger <cg@exept.de>
parents: 1412
diff changeset
   244
    aCollection == listHolder value ifTrue:[
72e392844594 send change notification if same list is assigned
Claus Gittinger <cg@exept.de>
parents: 1412
diff changeset
   245
        "/ same value set again - send change notification
1440
cc3ac4ec36c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1436
diff changeset
   246
        "/ manually (valueHolder does not ...)
cc3ac4ec36c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1436
diff changeset
   247
        listHolder changed.
2281
40177aeb765c change notifications when changing the listHolder
Claus Gittinger <cg@exept.de>
parents: 2251
diff changeset
   248
    ] ifFalse:[               
2445
311a83c7d4ee update fix for SelectionInList/MultiSelectionInList models
Claus Gittinger <cg@exept.de>
parents: 2368
diff changeset
   249
        aCollection isList ifTrue:[
311a83c7d4ee update fix for SelectionInList/MultiSelectionInList models
Claus Gittinger <cg@exept.de>
parents: 2368
diff changeset
   250
            self listHolder:aCollection.
311a83c7d4ee update fix for SelectionInList/MultiSelectionInList models
Claus Gittinger <cg@exept.de>
parents: 2368
diff changeset
   251
            listHolder changed.
311a83c7d4ee update fix for SelectionInList/MultiSelectionInList models
Claus Gittinger <cg@exept.de>
parents: 2368
diff changeset
   252
        ] ifFalse:[
3541
73dd9da193e7 care for List objects in list:
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   253
            listHolder isList ifTrue:[
73dd9da193e7 care for List objects in list:
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   254
                listHolder contents:aCollection.
73dd9da193e7 care for List objects in list:
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   255
            ] ifFalse:[
73dd9da193e7 care for List objects in list:
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   256
                listHolder value:aCollection.
73dd9da193e7 care for List objects in list:
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   257
            ]
2445
311a83c7d4ee update fix for SelectionInList/MultiSelectionInList models
Claus Gittinger <cg@exept.de>
parents: 2368
diff changeset
   258
        ]
311a83c7d4ee update fix for SelectionInList/MultiSelectionInList models
Claus Gittinger <cg@exept.de>
parents: 2368
diff changeset
   259
"/        listHolder value:aCollection.
1436
72e392844594 send change notification if same list is assigned
Claus Gittinger <cg@exept.de>
parents: 1412
diff changeset
   260
    ].
577
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
   261
1440
cc3ac4ec36c8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1436
diff changeset
   262
    "Modified: / 2.2.1998 / 13:05:56 / cg"
133
claus
parents: 129
diff changeset
   263
!
claus
parents: 129
diff changeset
   264
claus
parents: 129
diff changeset
   265
selection
577
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
   266
    "return the selections value (i.e. the entry in the list - not its index).
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
   267
     If nothing is selected, nil is returned."
129
claus
parents: 114
diff changeset
   268
claus
parents: 114
diff changeset
   269
    |idx|
claus
parents: 114
diff changeset
   270
claus
parents: 114
diff changeset
   271
    idx := self selectionIndex.
claus
parents: 114
diff changeset
   272
    (idx isNil or:[idx == 0]) ifTrue:[^ nil].
claus
parents: 114
diff changeset
   273
    ^ self list at:idx
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   274
577
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
   275
    "Modified: 24.4.1996 / 08:53:23 / cg"
114
5d736ee65276 Initial revision
claus
parents:
diff changeset
   276
!
5d736ee65276 Initial revision
claus
parents:
diff changeset
   277
133
claus
parents: 129
diff changeset
   278
selection:anObject 
claus
parents: 129
diff changeset
   279
    "set the selection to be anObject.
claus
parents: 129
diff changeset
   280
     If anObject is not in the list, the selection is cleared"
claus
parents: 129
diff changeset
   281
claus
parents: 129
diff changeset
   282
    ^ self selectionIndex:(self list indexOf:anObject ifAbsent:0)
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   283
!
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   284
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   285
selectionIndex
577
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
   286
    "return the selections index (1..). Thats the thingy held by the indexHolder.
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
   287
     For ST-80 compatibility, 0 is returned if nothing is selected."
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   288
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   289
    ^ selectionIndexHolder value
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   290
577
163dd2feeece commentary
Claus Gittinger <cg@exept.de>
parents: 576
diff changeset
   291
    "Modified: 24.4.1996 / 08:53:45 / cg"
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   292
!
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   293
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   294
selectionIndex:newIndex
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   295
    "set the selectionIndex"
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   296
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   297
    selectionIndexHolder value ~= newIndex ifTrue:[
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   298
        selectionIndexHolder value:newIndex
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   299
    ]
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   300
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   301
    "Modified: 24.4.1996 / 08:42:04 / cg"
133
claus
parents: 129
diff changeset
   302
! !
claus
parents: 129
diff changeset
   303
claus
parents: 129
diff changeset
   304
!SelectionInList methodsFor:'change & update'!
claus
parents: 129
diff changeset
   305
claus
parents: 129
diff changeset
   306
update:something with:aParameter from:changedObject
claus
parents: 129
diff changeset
   307
    "whenever one of my holders value changes,
claus
parents: 129
diff changeset
   308
     tell my dependents about this"
claus
parents: 129
diff changeset
   309
564
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   310
    |oldSelection|
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   311
133
claus
parents: 129
diff changeset
   312
    changedObject == selectionIndexHolder ifTrue:[
526
8203430fbadd oops - clearing selection was wrong in MultiSelectionInList
ca
parents: 359
diff changeset
   313
        self changed:#selectionIndex
133
claus
parents: 129
diff changeset
   314
    ] ifFalse:[
526
8203430fbadd oops - clearing selection was wrong in MultiSelectionInList
ca
parents: 359
diff changeset
   315
        changedObject == listHolder ifTrue:[
2445
311a83c7d4ee update fix for SelectionInList/MultiSelectionInList models
Claus Gittinger <cg@exept.de>
parents: 2368
diff changeset
   316
            (something == #value 
311a83c7d4ee update fix for SelectionInList/MultiSelectionInList models
Claus Gittinger <cg@exept.de>
parents: 2368
diff changeset
   317
            or:[ listHolder isList ])
311a83c7d4ee update fix for SelectionInList/MultiSelectionInList models
Claus Gittinger <cg@exept.de>
parents: 2368
diff changeset
   318
            ifTrue:[
564
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   319
                oldSelection := selectionIndexHolder value.
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   320
                self clearSelection.  "/ clears without update
526
8203430fbadd oops - clearing selection was wrong in MultiSelectionInList
ca
parents: 359
diff changeset
   321
                self changed:#list.
564
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   322
                oldSelection ~= (selectionIndexHolder value) ifTrue:[
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   323
                    selectionIndexHolder changed:#value
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   324
                ]
526
8203430fbadd oops - clearing selection was wrong in MultiSelectionInList
ca
parents: 359
diff changeset
   325
            ]
8203430fbadd oops - clearing selection was wrong in MultiSelectionInList
ca
parents: 359
diff changeset
   326
        ]
133
claus
parents: 129
diff changeset
   327
    ]
564
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   328
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   329
    "Modified: 20.4.1996 / 13:08:32 / cg"
133
claus
parents: 129
diff changeset
   330
! !
claus
parents: 129
diff changeset
   331
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   332
!SelectionInList methodsFor:'initialization'!
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   333
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   334
initialize
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   335
    "initialize; create the valueHolders for the index and the list"
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   336
1541
d90417495d52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
   337
    self listHolder:(ValueHolder with:List new).
d90417495d52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
   338
    self selectionIndexHolder:(ValueHolder with:self zeroIndex).
564
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   339
1541
d90417495d52 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1440
diff changeset
   340
    "Modified: / 21.5.1998 / 03:17:56 / cg"
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   341
! !
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   342
2748
c1efcd93841b method category rename
Claus Gittinger <cg@exept.de>
parents: 2445
diff changeset
   343
!SelectionInList methodsFor:'obsolete-backward compatibility'!
133
claus
parents: 129
diff changeset
   344
claus
parents: 129
diff changeset
   345
index
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   346
    "return the selections index.
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   347
     This is an OBSOLETE backward compatibility interface"
133
claus
parents: 129
diff changeset
   348
2368
36525e54c1b9 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 2281
diff changeset
   349
    <resource:#obsolete>
36525e54c1b9 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 2281
diff changeset
   350
133
claus
parents: 129
diff changeset
   351
    self obsoleteMethodWarning:'use #selectionIndex'.
claus
parents: 129
diff changeset
   352
    ^ self selectionIndex
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   353
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   354
    "Modified: 24.4.1996 / 08:43:10 / cg"
114
5d736ee65276 Initial revision
claus
parents:
diff changeset
   355
!
5d736ee65276 Initial revision
claus
parents:
diff changeset
   356
129
claus
parents: 114
diff changeset
   357
index:newIndex
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   358
    "set the selections index.
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   359
     This is an OBSOLETE backward compatibility interface"
129
claus
parents: 114
diff changeset
   360
2368
36525e54c1b9 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 2281
diff changeset
   361
    <resource:#obsolete>
36525e54c1b9 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 2281
diff changeset
   362
133
claus
parents: 129
diff changeset
   363
    self obsoleteMethodWarning:'use #selectionIndex:'.
129
claus
parents: 114
diff changeset
   364
    ^ self selectionIndex:newIndex
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   365
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   366
    "Modified: 24.4.1996 / 08:43:06 / cg"
129
claus
parents: 114
diff changeset
   367
!
claus
parents: 114
diff changeset
   368
133
claus
parents: 129
diff changeset
   369
indexHolder
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   370
    "return the valueHolder of the selections index.
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   371
     This is an OBSOLETE backward compatibility interface"
133
claus
parents: 129
diff changeset
   372
2368
36525e54c1b9 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 2281
diff changeset
   373
    <resource:#obsolete>
36525e54c1b9 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 2281
diff changeset
   374
133
claus
parents: 129
diff changeset
   375
    self obsoleteMethodWarning:'use #selectionIndexHolder'.
claus
parents: 129
diff changeset
   376
    ^ self selectionIndexHolder
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   377
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   378
    "Modified: 24.4.1996 / 08:43:35 / cg"
129
claus
parents: 114
diff changeset
   379
!
claus
parents: 114
diff changeset
   380
133
claus
parents: 129
diff changeset
   381
indexHolder:aValueHolder
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   382
    "set the valueHolder of the selections index.
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   383
     This is an OBSOLETE backward compatibility interface"
133
claus
parents: 129
diff changeset
   384
2368
36525e54c1b9 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 2281
diff changeset
   385
    <resource:#obsolete>
36525e54c1b9 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 2281
diff changeset
   386
133
claus
parents: 129
diff changeset
   387
    self obsoleteMethodWarning:'use #selectionIndexHolder:'.
claus
parents: 129
diff changeset
   388
    ^ self selectionIndexHolder:aValueHolder
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   389
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   390
    "Modified: 24.4.1996 / 08:43:43 / cg"
133
claus
parents: 129
diff changeset
   391
! !
claus
parents: 129
diff changeset
   392
1032
e2ff156a2b31 displayString
Claus Gittinger <cg@exept.de>
parents: 975
diff changeset
   393
!SelectionInList methodsFor:'printing & storing'!
e2ff156a2b31 displayString
Claus Gittinger <cg@exept.de>
parents: 975
diff changeset
   394
e2ff156a2b31 displayString
Claus Gittinger <cg@exept.de>
parents: 975
diff changeset
   395
displayString
1332
0794ee877118 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1032
diff changeset
   396
    "return a string for display in inspectors etc."
0794ee877118 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1032
diff changeset
   397
1032
e2ff156a2b31 displayString
Claus Gittinger <cg@exept.de>
parents: 975
diff changeset
   398
    ^ self class name , '(' , self selectionIndex displayString , ')'
e2ff156a2b31 displayString
Claus Gittinger <cg@exept.de>
parents: 975
diff changeset
   399
1332
0794ee877118 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1032
diff changeset
   400
    "Modified: 20.9.1997 / 11:41:31 / cg"
1032
e2ff156a2b31 displayString
Claus Gittinger <cg@exept.de>
parents: 975
diff changeset
   401
! !
e2ff156a2b31 displayString
Claus Gittinger <cg@exept.de>
parents: 975
diff changeset
   402
526
8203430fbadd oops - clearing selection was wrong in MultiSelectionInList
ca
parents: 359
diff changeset
   403
!SelectionInList methodsFor:'private'!
8203430fbadd oops - clearing selection was wrong in MultiSelectionInList
ca
parents: 359
diff changeset
   404
8203430fbadd oops - clearing selection was wrong in MultiSelectionInList
ca
parents: 359
diff changeset
   405
clearSelection
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   406
    "clear the selection.
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   407
     For ST-80 compatibility, a non-selection has an index of 0
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   408
     although, nil sounds more natural to me ... (sigh)"
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   409
564
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   410
    selectionIndexHolder setValue:self zeroIndex.
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   411
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   412
    "Modified: 24.4.1996 / 08:44:37 / cg"
564
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   413
! !
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   414
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   415
!SelectionInList methodsFor:'queries'!
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   416
1412
e2134a704cca add selection queries:
ca
parents: 1340
diff changeset
   417
hasSelection
e2134a704cca add selection queries:
ca
parents: 1340
diff changeset
   418
    "return true, if there is a selection
e2134a704cca add selection queries:
ca
parents: 1340
diff changeset
   419
    "
e2134a704cca add selection queries:
ca
parents: 1340
diff changeset
   420
    ^ self numberOfSelections ~~ 0
e2134a704cca add selection queries:
ca
parents: 1340
diff changeset
   421
!
e2134a704cca add selection queries:
ca
parents: 1340
diff changeset
   422
e2134a704cca add selection queries:
ca
parents: 1340
diff changeset
   423
numberOfSelections
e2134a704cca add selection queries:
ca
parents: 1340
diff changeset
   424
    "return the number of selected entries
e2134a704cca add selection queries:
ca
parents: 1340
diff changeset
   425
    "
e2134a704cca add selection queries:
ca
parents: 1340
diff changeset
   426
    |s|
e2134a704cca add selection queries:
ca
parents: 1340
diff changeset
   427
e2134a704cca add selection queries:
ca
parents: 1340
diff changeset
   428
    s:= selectionIndexHolder value.
e2134a704cca add selection queries:
ca
parents: 1340
diff changeset
   429
    ^ (s ~~ 0 and:[s notNil]) ifTrue:[1] ifFalse:[0]
e2134a704cca add selection queries:
ca
parents: 1340
diff changeset
   430
!
e2134a704cca add selection queries:
ca
parents: 1340
diff changeset
   431
564
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   432
zeroIndex
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   433
    "return the selections index returned when nothing
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   434
     is selected. This method is provided to allow applications
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   435
     to deal transparently with SelectionInList models AND with
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   436
     MultSelectionInList models, which use different no-selection values.
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   437
     Although I would prefer nil, ST-80 uses 0 to represent `no-selection'. (sigh)"
564
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   438
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   439
    ^ 0
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   440
0739243fcc1c zeroIndex stuff / ST-80 compatible 0 for empty selection
Claus Gittinger <cg@exept.de>
parents: 544
diff changeset
   441
    "Created: 20.4.1996 / 13:10:53 / cg"
576
b4b9b6c3a90c commentary & more examples
Claus Gittinger <cg@exept.de>
parents: 564
diff changeset
   442
    "Modified: 24.4.1996 / 08:46:18 / cg"
526
8203430fbadd oops - clearing selection was wrong in MultiSelectionInList
ca
parents: 359
diff changeset
   443
! !
8203430fbadd oops - clearing selection was wrong in MultiSelectionInList
ca
parents: 359
diff changeset
   444
204
2da6481de6d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 200
diff changeset
   445
!SelectionInList class methodsFor:'documentation'!
2da6481de6d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 200
diff changeset
   446
2da6481de6d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 200
diff changeset
   447
version
3541
73dd9da193e7 care for List objects in list:
Claus Gittinger <cg@exept.de>
parents: 2748
diff changeset
   448
    ^ '$Header: /cvs/stx/stx/libwidg/SelectionInList.st,v 1.30 2008-02-04 09:33:20 cg Exp $'
204
2da6481de6d4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 200
diff changeset
   449
! !