SelectionInTree.st
author Claus Gittinger <cg@exept.de>
Thu, 11 Feb 1999 18:43:51 +0100
changeset 1189 0c2cf8ee62e3
parent 1176 cd9fc4bfb273
child 1204 3940e6cbde19
permissions -rw-r--r--
comment
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
     1
"
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
     2
 COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
     3
              All Rights Reserved
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
     4
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
     5
 This software is furnished under a license and may be used
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    10
 hereby transferred.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    11
"
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    12
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    13
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    14
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    15
Model subclass:#SelectionInTree
762
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    16
	instanceVariableNames:'root list selection showRoot contentsAction labelAction
811
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
    17
		childrenAction iconAction indicatorList indicatorTask accessLock'
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    18
	classVariableNames:''
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    19
	poolDictionaries:''
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    20
	category:'Interface-Support-Models'
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    21
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    22
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    23
!SelectionInTree class methodsFor:'documentation'!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    24
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    25
copyright
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    26
"
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    27
 COPYRIGHT (c) 1997 by eXept Software AG / Claus Gittinger
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    28
              All Rights Reserved
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    29
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    30
 This software is furnished under a license and may be used
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    35
 hereby transferred.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    36
"
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    37
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    38
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    39
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    40
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    41
documentation
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    42
"
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    43
    list and selection holder for hierarchical list structures. Used
1189
0c2cf8ee62e3 comment
Claus Gittinger <cg@exept.de>
parents: 1176
diff changeset
    44
    to buildup file-trees, class trees etc.
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    45
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    46
    Especially suited for use with SelectionInTreeView.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    47
1189
0c2cf8ee62e3 comment
Claus Gittinger <cg@exept.de>
parents: 1176
diff changeset
    48
    Notice: this class replaces SelectionInHierarchy, which provides
0c2cf8ee62e3 comment
Claus Gittinger <cg@exept.de>
parents: 1176
diff changeset
    49
            similar (but less sphisticated) functionality.
0c2cf8ee62e3 comment
Claus Gittinger <cg@exept.de>
parents: 1176
diff changeset
    50
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    51
    [See also:]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    52
        TreeItem
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    53
        SelectionInTreeView
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    54
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    55
    [Author:]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    56
        W. Olberding
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    57
        Claus Atzkern
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    58
"
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    59
! !
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    60
811
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
    61
!SelectionInTree class methodsFor:'instance creation'!
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
    62
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
    63
new
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
    64
    ^ super new initialize
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
    65
! !
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
    66
1174
8d0c73401ea8 ask model for default itemClass
ca
parents: 1166
diff changeset
    67
!SelectionInTree class methodsFor:'defaults'!
8d0c73401ea8 ask model for default itemClass
ca
parents: 1166
diff changeset
    68
8d0c73401ea8 ask model for default itemClass
ca
parents: 1166
diff changeset
    69
defaultItemClass
8d0c73401ea8 ask model for default itemClass
ca
parents: 1166
diff changeset
    70
    "returns the default item class or nil (the default)
8d0c73401ea8 ask model for default itemClass
ca
parents: 1166
diff changeset
    71
    "
8d0c73401ea8 ask model for default itemClass
ca
parents: 1166
diff changeset
    72
    ^ nil
8d0c73401ea8 ask model for default itemClass
ca
parents: 1166
diff changeset
    73
8d0c73401ea8 ask model for default itemClass
ca
parents: 1166
diff changeset
    74
8d0c73401ea8 ask model for default itemClass
ca
parents: 1166
diff changeset
    75
8d0c73401ea8 ask model for default itemClass
ca
parents: 1166
diff changeset
    76
! !
8d0c73401ea8 ask model for default itemClass
ca
parents: 1166
diff changeset
    77
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    78
!SelectionInTree methodsFor:'accessing'!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    79
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    80
list
1189
0c2cf8ee62e3 comment
Claus Gittinger <cg@exept.de>
parents: 1176
diff changeset
    81
    "get the list of currently shown objects
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    82
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    83
    ^ list
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    84
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    85
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    86
root
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    87
    "get the root node
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    88
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    89
    ^ root
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    90
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    91
509
c6c9f5ecb977 add method expand
ca
parents: 496
diff changeset
    92
root:aRoot
c6c9f5ecb977 add method expand
ca
parents: 496
diff changeset
    93
    "set a new root
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
    94
    "
1176
cd9fc4bfb273 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1174
diff changeset
    95
    |tree|
cd9fc4bfb273 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1174
diff changeset
    96
762
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
    97
    root notNil ifTrue: [
1176
cd9fc4bfb273 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1174
diff changeset
    98
        tree := root tree.
cd9fc4bfb273 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1174
diff changeset
    99
        root tree:nil.
cd9fc4bfb273 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1174
diff changeset
   100
    ] ifFalse:[
cd9fc4bfb273 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1174
diff changeset
   101
        tree := self
762
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   102
    ].
811
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   103
    self stopRunningTasks.
762
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   104
515
2c09c8688bb8 set parent of root allways to nil
ca
parents: 509
diff changeset
   105
    (root := aRoot) notNil ifTrue:[
1176
cd9fc4bfb273 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1174
diff changeset
   106
        root tree:tree.
762
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   107
        root parent:nil.
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   108
    ].
1189
0c2cf8ee62e3 comment
Claus Gittinger <cg@exept.de>
parents: 1176
diff changeset
   109
    self recomputeList
860
64d52b8e3dbd bug fix in remove:
ca
parents: 857
diff changeset
   110
!
64d52b8e3dbd bug fix in remove:
ca
parents: 857
diff changeset
   111
64d52b8e3dbd bug fix in remove:
ca
parents: 857
diff changeset
   112
value
64d52b8e3dbd bug fix in remove:
ca
parents: 857
diff changeset
   113
    ^ list
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   114
! !
491
c7d57a5e7a21 change root, do not remove children
ca
parents: 482
diff changeset
   115
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   116
!SelectionInTree methodsFor:'accessing behavior'!
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   117
762
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   118
childrenAction
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   119
    "get children action block
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   120
    "
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   121
    ^childrenAction
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   122
!
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   123
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   124
childrenAction:aBlock
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   125
    "set children action block
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   126
    "
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   127
    childrenAction := aBlock.
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   128
!
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   129
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   130
contentsAction
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   131
    "get contents action block
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   132
    "
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   133
    ^contentsAction
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   134
!
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   135
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   136
contentsAction:aBlock
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   137
    "set contents action block
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   138
    "
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   139
    contentsAction := aBlock.
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   140
!
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   141
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   142
iconAction
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   143
    "get icon action block
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   144
    "
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   145
    ^iconAction
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   146
!
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   147
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   148
iconAction:aBlock
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   149
    "set icon action block
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   150
    "
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   151
    iconAction := aBlock.
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   152
!
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   153
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   154
labelAction
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   155
    "get label action block
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   156
    "
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   157
    ^labelAction
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   158
!
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   159
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   160
labelAction:aBlock
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   161
    "set label action block
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   162
    "
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   163
    labelAction := aBlock.
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   164
!
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   165
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   166
showRoot
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   167
    "list with or without root
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   168
    "
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   169
    ^ showRoot
491
c7d57a5e7a21 change root, do not remove children
ca
parents: 482
diff changeset
   170
!
c7d57a5e7a21 change root, do not remove children
ca
parents: 482
diff changeset
   171
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   172
showRoot:aState
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   173
    "list with or without root
491
c7d57a5e7a21 change root, do not remove children
ca
parents: 482
diff changeset
   174
    "
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   175
    aState ~~ showRoot ifTrue:[
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   176
        showRoot := aState.
491
c7d57a5e7a21 change root, do not remove children
ca
parents: 482
diff changeset
   177
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   178
        root notNil ifTrue:[
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   179
            aState ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   180
                list addFirst:root.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   181
                self changed:#insertCollection: with:(Array with:1 with:1 with:nil).
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   182
            ] ifFalse:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   183
                list removeFirst.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   184
                self changed:#removeFrom: with:(Array with:1 with:1 with:nil).
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   185
            ].
491
c7d57a5e7a21 change root, do not remove children
ca
parents: 482
diff changeset
   186
        ].
c7d57a5e7a21 change root, do not remove children
ca
parents: 482
diff changeset
   187
    ].
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   188
! !
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   189
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   190
!SelectionInTree methodsFor:'accessing hierarchy'!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   191
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   192
collapse:something 
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   193
    "collapse a node or collection of nodes
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   194
    "
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   195
    |listChanged|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   196
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   197
    listChanged := false.
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   198
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   199
    self each:something do:[:aNode|
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   200
        aNode isCollapsable ifTrue:[
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   201
            aNode collapse.
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   202
            listChanged := true
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   203
        ]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   204
    ].
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   205
    listChanged ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   206
        self listFromRoot.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   207
        self changed:#list.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   208
    ]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   209
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   210
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   211
509
c6c9f5ecb977 add method expand
ca
parents: 496
diff changeset
   212
expand
c6c9f5ecb977 add method expand
ca
parents: 496
diff changeset
   213
    "expand the root
c6c9f5ecb977 add method expand
ca
parents: 496
diff changeset
   214
    "
c6c9f5ecb977 add method expand
ca
parents: 496
diff changeset
   215
    self expand:root
c6c9f5ecb977 add method expand
ca
parents: 496
diff changeset
   216
!
c6c9f5ecb977 add method expand
ca
parents: 496
diff changeset
   217
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   218
expand:something 
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   219
    "expand a node or collection of nodes
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   220
    "
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   221
    |listChanged|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   222
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   223
    listChanged := false.
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   224
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   225
    self each:something do:[:aNode|
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   226
        aNode isExpandable ifTrue:[
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   227
            aNode expand.
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   228
            listChanged := true
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   229
        ]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   230
    ].
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   231
    listChanged ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   232
        self listFromRoot.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   233
        self changed:#list.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   234
    ]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   235
! !
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   236
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   237
!SelectionInTree methodsFor:'accessing hierarchy new'!
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   238
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   239
doCollapse:something
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   240
    "collapse all children under an item or a sequence of items;
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   241
     if the list changed, notifications are raised
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   242
    "
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   243
    self each:something do:[:anItem|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   244
        self collapseItem:anItem do:[ anItem collapse ]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   245
    ]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   246
!
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   247
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   248
doCollapseAll:something
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   249
    "collapse all children and subChildren under an item or sequence of items;
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   250
     if the list changed, notifications are raised
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   251
    "
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   252
    self each:something do:[:anItem|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   253
        self collapseItem:anItem do:[ anItem collapseAll ]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   254
    ]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   255
!
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   256
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   257
doExpand:something
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   258
    "expand all children under an item or collection of items;
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   259
     if the list changed, notifications are raised
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   260
    "
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   261
    self each:something do:[:anItem|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   262
        self expandItem:anItem do:[anItem expand]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   263
    ]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   264
!
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   265
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   266
doExpandAll:something
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   267
    "expand all children and subChildren under an item or sequence of items;
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   268
     if the list changed, notifications are raised
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   269
    "
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   270
    self each:something do:[:anItem|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   271
        self expandItem:anItem do:[anItem expandAll]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   272
    ]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   273
!
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   274
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   275
doMakeVisible:something
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   276
    "make an item or list of items to become visible
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   277
    "
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   278
    |anchor parent|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   279
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   280
    self each:something do:[:anItem|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   281
        parent := anItem.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   282
        anchor := nil.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   283
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   284
        [(parent := parent parent) notNil] whileTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   285
            parent hidden ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   286
                anchor notNil ifTrue:[ anchor expand ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   287
                anchor := parent.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   288
            ]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   289
        ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   290
        anchor notNil ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   291
            self expandItem:anchor do:[anchor expand]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   292
        ]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   293
    ]
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   294
! !
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   295
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   296
!SelectionInTree methodsFor:'adding & removing'!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   297
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   298
add:something after:aChild
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   299
    "add a node or collection of nodes to parent after a child
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   300
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   301
    "add a node or collection of nodes to after a child
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   302
    "
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   303
    |p|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   304
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   305
    (aChild notNil and:[(p := aChild parent) notNil]) ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   306
        self add:something afterIndex:(p indexOfChild:aChild) below:p
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   307
    ]
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   308
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   309
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   310
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   311
add:something afterIndex:anIndex below:aParent
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   312
    "add a node or collection of nodes to parent after an index
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   313
    "
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   314
    self add:something beforeIndex:(anIndex + 1) below:aParent
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   315
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   316
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   317
add:something before:aChild
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   318
    "add a node or collection of nodes to before a child
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   319
    "
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   320
    |p|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   321
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   322
    (aChild notNil and:[(p := aChild parent) notNil]) ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   323
        self add:something beforeIndex:(p indexOfChild:aChild) below:p
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   324
    ]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   325
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   326
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   327
add:something beforeIndex:anIndex below:aParent
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   328
    "add a node or collection of nodes to parent before an index
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   329
    "
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   330
    |children start index size pList|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   331
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   332
    (    aParent isNil
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   333
     or:[something isNil
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   334
     or:[(something isCollection and:[something isEmpty])]]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   335
    ) ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   336
        ^ self
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   337
    ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   338
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   339
    (start := self indexOf:aParent) == 0 ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   340
        "/
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   341
        "/ parent not visible; list not changed
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   342
        "/
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   343
        aParent add:something beforeIndex:anIndex.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   344
        ^ self
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   345
    ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   346
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   347
    aParent shown ifFalse:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   348
        aParent add:something beforeIndex:anIndex.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   349
        self changed:#at: with:start.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   350
        ^ self
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   351
    ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   352
    children := aParent children.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   353
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   354
    (children isEmpty or:[anIndex <= 1]) ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   355
        index := 1.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   356
    ] ifFalse:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   357
        size  := children size.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   358
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   359
        anIndex > size ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   360
            index := size + 1.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   361
            start := aParent numberOfAllVisibleChildren + start.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   362
        ] ifFalse:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   363
            index := anIndex.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   364
            start := (self indexOf:(children at:index)) - 1.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   365
        ]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   366
    ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   367
    aParent add:something beforeIndex:index.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   368
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   369
    (start := start + 1) == 0 ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   370
        "/
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   371
        "/ not visible
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   372
        "/
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   373
        ^ self
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   374
    ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   375
    pList := OrderedCollection new:2048.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   376
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   377
    self each:something do:[:aNode|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   378
        pList add:aNode.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   379
        aNode addVisibleChildrenTo:pList
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   380
    ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   381
    pList isEmpty ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   382
        ^ self
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   383
    ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   384
    list addAll:pList beforeIndex:start.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   385
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   386
    self changed:#insertCollection:
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   387
            with:(Array with:start with:pList size with:aParent).
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   388
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   389
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   390
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   391
add:something below:aParent
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   392
    "add a node or collection of nodes to parent
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   393
    "
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   394
    aParent notNil ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   395
        self add:something beforeIndex:(aParent numberOfChildren + 1) below:aParent
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   396
    ]
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   397
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   398
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   399
remove:something
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   400
    "remove a node or collection of nodes
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   401
    "
860
64d52b8e3dbd bug fix in remove:
ca
parents: 857
diff changeset
   402
    |node coll index loNums loItem start size parent stop|
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   403
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   404
    something isNil ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   405
        ^ something
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   406
    ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   407
    loNums := SortedCollection new.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   408
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   409
    self each:something do:[:el|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   410
        node := el isNumber ifTrue:[list at:el ifAbsent:nil]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   411
                           ifFalse:[el].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   412
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   413
        node notNil ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   414
            self stopIndicatorValidationFor:node.
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   415
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   416
            node parent isNil ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   417
                "/ remove all including root
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   418
                node == root ifTrue:[ self root:nil ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   419
              ^ something
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   420
            ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   421
            index := self indexOf:node.
811
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   422
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   423
            index == 0 ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   424
                "/ not visible
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   425
                node parent removeChild:node
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   426
            ] ifFalse:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   427
                loNums add:index
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   428
            ].
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   429
        ]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   430
    ].
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   431
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   432
    loNums isEmpty ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   433
        "/ nothing visible changed
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   434
        ^ something
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   435
    ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   436
    loItem := OrderedCollection new.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   437
    loNums do:[:i| loItem add:(list at:i)].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   438
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   439
    loItem do:[:aNode|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   440
        start := self indexOf:aNode.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   441
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   442
        start ~~ 0 ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   443
            parent := aNode parent.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   444
            size   := 1 + aNode numberOfAllVisibleChildren.
860
64d52b8e3dbd bug fix in remove:
ca
parents: 857
diff changeset
   445
            stop   := start + size - 1.
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   446
            parent remove:aNode.
860
64d52b8e3dbd bug fix in remove:
ca
parents: 857
diff changeset
   447
            list removeFromIndex:start toIndex:stop.
811
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   448
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   449
            self changed:#removeFrom:
860
64d52b8e3dbd bug fix in remove:
ca
parents: 857
diff changeset
   450
                    with:(Array with:start with:stop with:parent).
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   451
        ]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   452
    ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   453
    ^ something
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   454
!
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   455
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   456
removeAllOtherThanRoot
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   457
    "remove all other than the root
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   458
    "
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   459
    |listChanged|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   460
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   461
    root notNil ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   462
        listChanged := root isCollapsable.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   463
        root children:(OrderedCollection new).
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   464
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   465
        listChanged ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   466
            self listFromRoot.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   467
            self changed:#list
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   468
        ]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   469
    ]
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   470
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   471
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   472
removeIndex:something
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   473
    "remove a node at index or collection of indexed nodes
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   474
    "
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   475
    self remove:something
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   476
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   477
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   478
removeSelection
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   479
    "remove selected nodes
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   480
    "
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   481
    |sel|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   482
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   483
    sel := self selectionIndex.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   484
    self selectionIndex:nil.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   485
    self remove:sel.
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   486
! !
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   487
758
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   488
!SelectionInTree methodsFor:'change & update'!
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   489
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   490
invalidate
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   491
    "called; something changed what requires a redraw but no recomputation.
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   492
     for example a name
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   493
    "
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   494
    self dependents do:[:aDependent|
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   495
        aDependent isView ifTrue:[ aDependent invalidate ]
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   496
    ].
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   497
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   498
762
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   499
!
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   500
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   501
update:something with:aParameter from:aModel
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   502
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   503
    self dependents do:[:aDependent|
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   504
        aDependent update:something with:aParameter from:aModel
df337e82f064 supports dynamic read behavior for contents, label, children, and icon of tree items
tz
parents: 758
diff changeset
   505
    ]
758
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   506
! !
0f0b16a16fa7 add method: #invalidate
ca
parents: 585
diff changeset
   507
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   508
!SelectionInTree methodsFor:'enumerating'!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   509
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   510
each:something do:aBlock
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   511
    "evaluate a block for something or in case of a collection for each
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   512
     element in the collection
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   513
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   514
    something notNil ifTrue:[
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   515
        something isCollection ifTrue:[something do:[:el|aBlock value:el]]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   516
                              ifFalse:[aBlock value:something]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   517
    ]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   518
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   519
! !
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   520
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   521
!SelectionInTree methodsFor:'initialization'!
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   522
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   523
initialize
811
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   524
1166
d062a52bc7cc list attribute changed from OrderedCollection to List
Claus Gittinger <cg@exept.de>
parents: 1155
diff changeset
   525
    showRoot      := true.
811
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   526
    indicatorList := OrderedCollection new.
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   527
    accessLock    := Semaphore forMutualExclusion.
1166
d062a52bc7cc list attribute changed from OrderedCollection to List
Claus Gittinger <cg@exept.de>
parents: 1155
diff changeset
   528
    list          := List new.
d062a52bc7cc list attribute changed from OrderedCollection to List
Claus Gittinger <cg@exept.de>
parents: 1155
diff changeset
   529
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   530
    super initialize.
811
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   531
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   532
! !
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   533
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   534
!SelectionInTree methodsFor:'private'!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   535
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   536
recomputeList
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   537
    "Travers the tree and build a new list."
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   538
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   539
    self listFromRoot.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   540
    self changed:#list.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   541
! !
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   542
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   543
!SelectionInTree methodsFor:'private hierarchy'!
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   544
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   545
collapseItem:anItem do:collapseBlock
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   546
    "collapse all children under an item; raise a notification if
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   547
     the list changed
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   548
    "
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   549
    |start stop size|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   550
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   551
    anItem isCollapsable ifFalse:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   552
        ^ self
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   553
    ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   554
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   555
    (start := self indexOf:anItem) == 0 ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   556
        "/
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   557
        "/ item not visible
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   558
        "/
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   559
        collapseBlock value.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   560
    ] ifFalse:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   561
        size := anItem numberOfAllVisibleChildren.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   562
        collapseBlock value.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   563
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   564
        size == 0 ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   565
            "/
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   566
            "/ no children before; list not changed 
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   567
            "/
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   568
            self changed:#at: with:start
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   569
        ] ifFalse:[        
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   570
            stop  := start + size.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   571
            start := start + 1.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   572
            list removeFromIndex:start toIndex:stop.
860
64d52b8e3dbd bug fix in remove:
ca
parents: 857
diff changeset
   573
            self changed:#removeFrom: with:(Array with:start with:stop with:anItem).
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   574
        ]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   575
    ]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   576
!
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   577
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   578
expandItem:anItem do:expandBlock
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   579
    "expand all children under an item; raise a notification if
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   580
     the list changed
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   581
    "
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   582
    |start size pList|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   583
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   584
    anItem isExpandable ifFalse:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   585
        ^ self
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   586
    ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   587
    expandBlock value.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   588
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   589
    (start := self indexOf:anItem) ~~ 0 ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   590
        anItem addVisibleChildrenTo:(pList := OrderedCollection new:2048).
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   591
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   592
        (size := pList size) ~~ 0 ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   593
            start := 1 + start.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   594
            list addAll:pList beforeIndex:start.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   595
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   596
            self changed:#insertCollection:
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   597
                    with:(Array with:start with:size with:anItem).
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   598
        ] ifFalse:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   599
            self changed:#at: with:start
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   600
        ]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   601
    ]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   602
!
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   603
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   604
listFromRoot
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   605
    "Travers the tree and build a new list;
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   606
     no change notification is raised
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   607
    "
842
636d8a543c35 call clearContents to reinitialize the list
ca
parents: 811
diff changeset
   608
    list clearContents.
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   609
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   610
    root notNil ifTrue:[
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   611
        showRoot ifTrue:[ list add:root ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   612
        root addVisibleChildrenTo:list
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   613
    ]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   614
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   615
! !
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   616
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   617
!SelectionInTree methodsFor:'queries'!
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   618
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   619
indexOf:anItem
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   620
    "returns the index of an item or 0
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   621
    "
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   622
    ^ anItem notNil ifTrue:[list identityIndexOf:anItem]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   623
                   ifFalse:[0]
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   624
! !
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   625
849
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   626
!SelectionInTree methodsFor:'searching'!
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   627
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   628
detectItem:aOneArgBlock
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   629
    "detect an item the evaluation of the block returns true. The
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   630
     argument to the block is the item.
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   631
    "
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   632
    root notNil ifTrue:[
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   633
        ^ root detectChild:aOneArgBlock
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   634
    ].
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   635
    ^ nil
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   636
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   637
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   638
!
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   639
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   640
detectItem:aTwoArgBlock arguments:aListOfArgs
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   641
    "detect an item the evaluation of the block returns true. The
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   642
     first argument to the block is the item, the second argument
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   643
     the value derived from the argument list at an index
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   644
    "
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   645
    root notNil ifTrue:[
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   646
        ^ root detectChild:aTwoArgBlock arguments:aListOfArgs index:1
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   647
    ].
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   648
    ^ nil
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   649
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   650
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   651
! !
f7d8363fc24f support more detectItem mechanisms
ca
parents: 842
diff changeset
   652
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   653
!SelectionInTree methodsFor:'selection'!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   654
906
6173137343de need method #selectedNode
tz
parents: 860
diff changeset
   655
selectedNode
6173137343de need method #selectedNode
tz
parents: 860
diff changeset
   656
    "returns selected node or nil
6173137343de need method #selectedNode
tz
parents: 860
diff changeset
   657
    "
6173137343de need method #selectedNode
tz
parents: 860
diff changeset
   658
    |nodes|
6173137343de need method #selectedNode
tz
parents: 860
diff changeset
   659
    (nodes := self selectedNodes) notNil ifTrue: [
6173137343de need method #selectedNode
tz
parents: 860
diff changeset
   660
        ^nodes first
6173137343de need method #selectedNode
tz
parents: 860
diff changeset
   661
    ].
6173137343de need method #selectedNode
tz
parents: 860
diff changeset
   662
    ^nil
6173137343de need method #selectedNode
tz
parents: 860
diff changeset
   663
6173137343de need method #selectedNode
tz
parents: 860
diff changeset
   664
6173137343de need method #selectedNode
tz
parents: 860
diff changeset
   665
!
6173137343de need method #selectedNode
tz
parents: 860
diff changeset
   666
857
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   667
selectedNodes
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   668
    "returns list of selected nodes or nil
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   669
    "
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   670
    |node coll|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   671
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   672
    selection isNil ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   673
        ^ nil
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   674
    ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   675
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   676
    selection isCollection ifFalse:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   677
        node := list at:selection ifAbsent:nil.
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   678
      ^ node notNil ifTrue:[Array with:node] ifFalse:[nil]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   679
    ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   680
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   681
    selection isEmpty ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   682
        ^ nil
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   683
    ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   684
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   685
    coll := OrderedCollection new:(selection size).
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   686
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   687
    selection do:[:idx|
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   688
        (node := list at:idx ifAbsent:nil) notNil ifTrue:[
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   689
            coll add:node
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   690
        ]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   691
    ].
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   692
    ^ coll notEmpty ifTrue:[coll] ifFalse:[nil]
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   693
        
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   694
!
d8e14b853cb7 methods for adding & removing items are
ca
parents: 849
diff changeset
   695
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   696
selection
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   697
    "get the selection or nil
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   698
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   699
    ^ self selectionIndex
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   700
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   701
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   702
selection:indexesOrNil
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   703
    "set the selection
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   704
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   705
    self selectionIndex:indexesOrNil
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   706
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   707
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   708
selectionIndex
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   709
    "get the selection or nil
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   710
    "
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   711
    ^ selection
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   712
!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   713
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   714
selectionIndex:indexesOrNil
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   715
    "set the selection
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   716
    "
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   717
    |oldSel|
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   718
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   719
    oldSel := selection.
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   720
    self setSelectionIndex:indexesOrNil.
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   721
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   722
    oldSel = selection ifFalse:[
585
5a0ed2305998 bug fixes:
ca
parents: 515
diff changeset
   723
        self changed:#selectionIndex
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   724
    ]
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   725
!
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   726
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   727
setSelection:indexesOrNil
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   728
    "set the selection without raising a notification
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   729
    "
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   730
    self setSelectionIndex:indexesOrNil
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   731
!
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   732
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   733
setSelectionIndex:indexesOrNil
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   734
    "set the selection without raising a notification
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   735
    "
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   736
    |indexes|
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   737
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   738
    indexes := indexesOrNil.
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   739
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   740
    indexes size == 0 ifTrue:[
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   741
        (indexes isCollection or:[indexes == 0]) ifTrue:[
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   742
            indexes := nil
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   743
        ]
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   744
    ].
496
d511fde77222 show or hide root directory
ca
parents: 491
diff changeset
   745
    selection := indexes
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   746
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   747
! !
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   748
811
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   749
!SelectionInTree methodsFor:'update indication task'!
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   750
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   751
startIndicatorValidationFor:aNode
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   752
    "add a node to list of updating indications
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   753
    "
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   754
    |index|
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   755
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   756
    accessLock critical:[
1155
ff5b146ca277 run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   757
        |prio|
ff5b146ca277 run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   758
811
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   759
        index := indicatorList identityIndexOf:aNode.
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   760
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   761
        index ~~ 0 ifTrue:[
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   762
            indicatorList removeIndex:index.    "/ reorganize list to be faster
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   763
        ].
1155
ff5b146ca277 run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   764
        indicatorList addLast: "addFirst:" aNode.
811
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   765
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   766
        indicatorTask isNil ifTrue:[
1155
ff5b146ca277 run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   767
            prio := Processor activePriority.
811
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   768
            indicatorTask := [
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   769
                [ self taskCycle ] whileTrue:[ Processor yield ]
1155
ff5b146ca277 run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   770
            ] forkAt:(prio - 1).
ff5b146ca277 run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   771
            indicatorTask priorityRange:(prio-1 to:prio).
811
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   772
        ]
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   773
    ].
1155
ff5b146ca277 run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   774
ff5b146ca277 run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   775
    "Modified: / 26.9.1998 / 15:20:44 / cg"
811
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   776
!
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   777
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   778
stopIndicatorValidationFor:aNodeOrList
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   779
    "remove a node or list of nodes from list of updating indications
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   780
    "
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   781
    accessLock critical:[
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   782
        aNodeOrList isCollection ifTrue:[
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   783
            aNodeOrList do:[:aNode|
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   784
                indicatorList removeIdentical:aNode ifAbsent:nil
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   785
            ]
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   786
        ] ifFalse:[
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   787
            indicatorList removeIdentical:aNodeOrList ifAbsent:nil
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   788
        ]
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   789
    ]
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   790
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   791
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   792
!
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   793
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   794
stopRunningTasks
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   795
    "stop task
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   796
    "
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   797
    accessLock critical:[ indicatorList removeAll ]
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   798
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   799
!
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   800
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   801
taskCycle
1155
ff5b146ca277 run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   802
    "run one cycle fetching indicator state.
ff5b146ca277 run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   803
     This is done in the background to avoid long startup
ff5b146ca277 run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   804
     delays, in case the indicator information takes long to
ff5b146ca277 run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   805
     gather (i.e. when reading directories)"
ff5b146ca277 run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   806
811
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   807
    |node|
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   808
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   809
    accessLock critical:[
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   810
        indicatorList isEmpty ifTrue:[          "/ queue is empty; terminate task
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   811
            indicatorTask := nil.
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   812
            ^ false
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   813
        ].
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   814
        node := indicatorList removeFirst.      "/ run task on first node
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   815
        node hasValidIndicator ifTrue:[         "/ up to date
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   816
            ^ true
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   817
        ].
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   818
        node setShowIndicator:false             "/ disable registry
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   819
    ].
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   820
1145
3ee5513dff2a no change
Claus Gittinger <cg@exept.de>
parents: 906
diff changeset
   821
    (DirectoryContents 
3ee5513dff2a no change
Claus Gittinger <cg@exept.de>
parents: 906
diff changeset
   822
        directoryNamed:(node fileName) 
3ee5513dff2a no change
Claus Gittinger <cg@exept.de>
parents: 906
diff changeset
   823
        detect:(node matchAction)) 
3ee5513dff2a no change
Claus Gittinger <cg@exept.de>
parents: 906
diff changeset
   824
    ifTrue:[
811
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   825
        node showIndicator:true
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   826
    ].
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   827
    ^ true
1145
3ee5513dff2a no change
Claus Gittinger <cg@exept.de>
parents: 906
diff changeset
   828
1155
ff5b146ca277 run the indicator update process with a prio-range,
Claus Gittinger <cg@exept.de>
parents: 1145
diff changeset
   829
    "Modified: / 26.9.1998 / 15:11:16 / cg"
811
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   830
! !
a688e8f11bc6 async. reading of directory indicators
ca
parents: 762
diff changeset
   831
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   832
!SelectionInTree class methodsFor:'documentation'!
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   833
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   834
version
1189
0c2cf8ee62e3 comment
Claus Gittinger <cg@exept.de>
parents: 1176
diff changeset
   835
    ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTree.st,v 1.21 1999-02-11 17:43:51 cg Exp $'
458
e4b907c8f0ce intitial checkin
ca
parents:
diff changeset
   836
! !