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