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