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