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