HierarchicalFileList.st
author Claus Gittinger <cg@exept.de>
Mon, 19 Aug 2002 18:08:03 +0200
changeset 2138 4175c127f9b8
parent 2130 8b64928cd378
child 2140 7dfe3b338437
permissions -rw-r--r--
removed baseName
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1431
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
     1
"
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
     2
 COPYRIGHT (c) 1999 by eXept Software AG
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
     3
              All Rights Reserved
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
     4
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
     5
 This software is furnished under a license and may be used
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
     6
 only in accordance with the terms of that license and with the
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
     8
 be provided or otherwise made available to, or used by, any
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
     9
 other person.  No title to or ownership of the software is
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    10
 hereby transferred.
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    11
"
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    12
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    13
1780
867e59c91ff7 use icons derived from FileBrowser
ca
parents: 1582
diff changeset
    14
"{ Package: 'stx:libwidg2' }"
867e59c91ff7 use icons derived from FileBrowser
ca
parents: 1582
diff changeset
    15
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
HierarchicalList subclass:#HierarchicalFileList
2138
4175c127f9b8 removed baseName
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
    17
	instanceVariableNames:'icons matchBlock showCursor'
4175c127f9b8 removed baseName
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
    18
	classVariableNames:''
4175c127f9b8 removed baseName
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
    19
	poolDictionaries:''
4175c127f9b8 removed baseName
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
    20
	category:'Views-Support'
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
HierarchicalItem subclass:#File
2138
4175c127f9b8 removed baseName
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
    24
	instanceVariableNames:'fileName icon'
4175c127f9b8 removed baseName
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
    25
	classVariableNames:''
4175c127f9b8 removed baseName
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
    26
	poolDictionaries:''
4175c127f9b8 removed baseName
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
    27
	privateIn:HierarchicalFileList
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
HierarchicalFileList::File subclass:#Directory
2138
4175c127f9b8 removed baseName
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
    31
	instanceVariableNames:'modificationTime'
4175c127f9b8 removed baseName
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
    32
	classVariableNames:''
4175c127f9b8 removed baseName
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
    33
	poolDictionaries:''
4175c127f9b8 removed baseName
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
    34
	privateIn:HierarchicalFileList::File
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
1431
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    37
!HierarchicalFileList class methodsFor:'documentation'!
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    38
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    39
copyright
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    40
"
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    41
 COPYRIGHT (c) 1999 by eXept Software AG
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    42
              All Rights Reserved
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    43
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    44
 This software is furnished under a license and may be used
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    45
 only in accordance with the terms of that license and with the
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    46
 inclusion of the above copyright notice.   This software may not
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    47
 be provided or otherwise made available to, or used by, any
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    48
 other person.  No title to or ownership of the software is
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    49
 hereby transferred.
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    50
"
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    51
0cc20a8f2f7c docu & copyright
Claus Gittinger <cg@exept.de>
parents: 1430
diff changeset
    52
! !
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
!HierarchicalFileList class methodsFor:'examples'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
test
2130
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
    57
"
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
    58
self test
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
    59
"
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
    60
    |top sel list|
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
    list := HierarchicalFileList new.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
    list directory:(Filename homeDirectory).
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
    list showRoot:false.
2130
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
    65
    list matchBlock:[:fn :isDir| true ].
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
    top := StandardSystemView new; extent:300@300.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
    sel := ScrollableView for:HierarchicalListView miniScroller:true
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
                       origin:0.0@0.0 corner:1.0@1.0 in:top.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
    sel list:list.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    list root expand.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
    sel doubleClickAction:[:i| (list at:i) toggleExpand ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
    sel   indicatorAction:[:i| (list at:i) toggleExpand ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
    top open.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
! !
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
!HierarchicalFileList class methodsFor:'resources'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
icons
1780
867e59c91ff7 use icons derived from FileBrowser
ca
parents: 1582
diff changeset
    83
    ^ FileBrowser icons.
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
! !
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
!HierarchicalFileList methodsFor:'accessing'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
directory
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
    "returns the root directory or nil
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
    ^ root notNil ifTrue:[root fileName] ifFalse:[nil]
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
directory:aDirectory
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
    "set the root directory or nil
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
    |directory|
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
1960
2363303c1c8c monitoring must be enebled by user (no longer automatically)
ca
parents: 1867
diff changeset
   104
"/    must explicitly enabled by user: ca
2363303c1c8c monitoring must be enebled by user (no longer automatically)
ca
parents: 1867
diff changeset
   105
"/    monitoringTaskDelay := 1.
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
    (aDirectory notNil and:[(directory := aDirectory asFilename) exists]) ifTrue:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
        directory isDirectory ifFalse:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
            directory := directory directory
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
        ]
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
    ] ifFalse:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
        directory := nil
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
    directory = self directory ifFalse:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
        directory notNil ifTrue:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
            directory := File fileName:directory isDirectory:true
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
        ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
        self root:directory
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
    ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
! !
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
!HierarchicalFileList methodsFor:'actions'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
matchBlock
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
    "set the matchBlock - if non-nil, it controls which files are visible.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
    ^ matchBlock
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
        
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
matchBlock:aBlock
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
    "set the matchBlock - if non-nil, it controls which files are visible.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
    matchBlock := aBlock.
1866
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   136
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   137
    root notNil ifTrue:[
1867
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   138
        self recursionLock critical:[
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   139
            self stopMonitoringTask.
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   140
            root matchBlockChanged.
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   141
        ].
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   142
        self startMonitoringTask.
1866
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   143
    ].
1867
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   144
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
! !
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
2104
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   147
!HierarchicalFileList methodsFor:'private monitoring task'!
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   148
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   149
monitoringCycle
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   150
    "the block evaluated by the monitoring task; test whether directory is expanded
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   151
     otherwise we have not to evaluate the directory contents.
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   152
     think about remote file-systems
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   153
    "
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   154
    |index item|
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   155
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   156
    item  := root.
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   157
    index := showRoot ifTrue:[1] ifFalse:[0].
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   158
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   159
    [item notNil] whileTrue:[
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   160
        (item isDirectory and:[item getChildren notNil]) ifTrue:[
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   161
            "/ children already initialized; thus we can update the contents
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   162
            item monitoringCycle
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   163
        ].
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   164
        Processor yield.
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   165
        index := index + 1.
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   166
        item  := self at:index ifAbsent:nil.
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   167
    ].
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   168
! !
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   169
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
!HierarchicalFileList methodsFor:'protocol'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
childrenFor:anItem
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
    "returns all visible children derived from the physical
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
     directory contents.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
    |contents list block|
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
2130
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
   178
    anItem isDirectory ifFalse:[^ #()].
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
1581
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   180
    contents := DirectoryContents directoryNamed:(anItem fileName).
2130
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
   181
    contents ifNil:[ ^ #() ].
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
2130
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
   184
    list  := SortedCollection sortBlock:[:a :b| |res|
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
   185
        a isDirectory == b isDirectory ifTrue:[ res := a baseName <= b baseName ]
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
   186
                                      ifFalse:[ res := a isDirectory ].
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
   187
        res
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
   188
    ].
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
   189
    block := self matchBlockFor:anItem.
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
   190
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
   191
    block isNil ifTrue:[
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
   192
        contents contentsDo:[:fn :isDir|
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
   193
            list add:(File fileName:fn isDirectory:isDir)
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
   194
        ]
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
   195
    ] ifFalse:[
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
   196
        contents contentsDo:[:fn :isDir|
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
   197
            (block value:fn value:isDir) ifTrue:[
1581
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   198
                list add:(File fileName:fn isDirectory:isDir)
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   199
            ]
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
        ]
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
    ].
2130
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
   202
    list isEmpty ifTrue:[^ #()].
8b64928cd378 sort children: directories first
ca
parents: 2128
diff changeset
   203
  ^ list asOrderedCollection
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
hasChildrenFor:anItem
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
    "returns true if the physical directory contains at least
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
     one visible item otherwise false.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
    |block|
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
    anItem isDirectory ifFalse:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
        ^ false
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
    ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
    (block := self matchBlockFor:anItem) isNil ifTrue:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
        block := [:aFilename :isDirectory| true ]
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
    ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
    ^ DirectoryContents directoryNamed:(anItem fileName) detect:block
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
iconFor:anItem
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
    "returns the icon for an item
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
    "
1867
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   225
    |fn key suff mimeType icn|
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
    fn := anItem fileName.
1867
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   228
    icons isNil ifTrue:[ icons := self class icons ].
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
    fn isDirectory ifTrue:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
        (fn isReadable and:[fn isExecutable]) ifTrue:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
            key := fn isSymbolicLink ifTrue:[#directoryLink]
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
                                    ifFalse:[#directory]
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
        ] ifFalse:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
            key := #directoryLocked
1867
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   236
        ].
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   237
        ^ icons at:key ifAbsent:nil
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
    ].
1867
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   239
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   240
    fn isReadable     ifFalse:[ ^ icons at:#fileLocked ifAbsent:nil ].
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   241
    fn isSymbolicLink  ifTrue:[ ^ icons at:#fileLink   ifAbsent:nil ].
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   242
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   243
    suff := fn suffix.
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   244
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   245
    (suff = 'bak' or:[suff = 'sav']) ifTrue:[
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   246
        suff := fn withoutSuffix suffix.
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
    ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
1867
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   249
    suff size > 0 ifTrue:[
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   250
        ( #( 'o' 'so' 'a' ) includes:suff) ifTrue:[
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   251
             ^ icons at:#executableFile ifAbsent:nil
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   252
        ].        
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   253
        mimeType := MIMETypes mimeTypeForSuffix:suff.
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   254
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   255
        mimeType notNil ifTrue:[
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   256
            (icn := icons at:mimeType ifAbsent:nil) notNil ifTrue:[^ icn].
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   257
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   258
            (mimeType startsWith:'image/') ifTrue:[
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   259
                ^ icons at:#imageFile ifAbsent:nil
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   260
            ].
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   261
        ].
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   262
    ].
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   263
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   264
    fn isExecutableProgram ifTrue:[
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   265
        ^ icons at:#executableFile ifAbsent:nil
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   266
    ].
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   267
    ^ icons at:#file ifAbsent:nil
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
matchBlockFor:anItem
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
    "get the matchBlock - if non-nil, it controls which files are
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
     visible within the physical directory
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
    ^ matchBlock        
2095
46120b1fd644 can change icon
penk
parents: 1960
diff changeset
   275
!
46120b1fd644 can change icon
penk
parents: 1960
diff changeset
   276
46120b1fd644 can change icon
penk
parents: 1960
diff changeset
   277
validateIcon:anIcon for:anItem
46120b1fd644 can change icon
penk
parents: 1960
diff changeset
   278
    ^ anIcon
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
! !
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
1581
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   281
!HierarchicalFileList methodsFor:'searching'!
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   282
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   283
detectItemFor:aPathOrFilename
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   284
    "make a filename visible
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   285
    "
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   286
    |file node p1 p2 sz|
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   287
1582
bed19387e545 bug fix
ca
parents: 1581
diff changeset
   288
    aPathOrFilename isNil ifTrue:[^ nil].
1581
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   289
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   290
    file := aPathOrFilename asFilename.
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   291
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   292
    file exists ifFalse:[
1582
bed19387e545 bug fix
ca
parents: 1581
diff changeset
   293
        ^ nil
1581
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   294
    ].
1582
bed19387e545 bug fix
ca
parents: 1581
diff changeset
   295
    (node := root) isNil ifTrue:[^ nil].
1581
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   296
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   297
    p1 := node pathName.
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   298
    p2 := file pathName.
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   299
1582
bed19387e545 bug fix
ca
parents: 1581
diff changeset
   300
    (p2 startsWith:p1) ifFalse:[^ nil].
1581
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   301
    sz := 1 + p1 size.
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   302
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   303
    (p1 last == Filename separator) ifFalse:[
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   304
        sz := sz + 1.
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   305
    ].
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   306
1582
bed19387e545 bug fix
ca
parents: 1581
diff changeset
   307
    p2 size > sz ifFalse:[^ nil].
1581
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   308
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   309
    p2 :=  Filename components:(p2 copyFrom:sz).
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   310
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   311
    p2 do:[:bn|
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   312
        node := node detect:[:el| el baseName = bn] ifNone:nil.
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   313
        node isNil ifTrue:[^ nil ].
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   314
    ].
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   315
    ^ node
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   316
! !
5a8b7ce35090 detct item for a specific fileName
ca
parents: 1431
diff changeset
   317
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   318
!HierarchicalFileList::File class methodsFor:'instance creation'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   319
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
fileName:aFileName isDirectory:isDirectory
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
    "instance creation
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
    |item|
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   324
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
    item := isDirectory ifTrue:[Directory new] ifFalse:[HierarchicalFileList::File new].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
    item fileName:aFileName.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
  ^ item
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
! !
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
!HierarchicalFileList::File methodsFor:'accessing'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
baseName
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
    "returns the baseName
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
    "
2138
4175c127f9b8 removed baseName
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   336
    ^ fileName baseName.
4175c127f9b8 removed baseName
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   337
"/    ^ baseName
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
children
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
    "always returns an empty list
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
    ^ #()
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
fileName
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
    "returns the fileName
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   348
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
    ^ fileName
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   350
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   351
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   352
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   353
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
fileName:fname
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
    "instance creation
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   356
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   357
    fileName := fname.
2138
4175c127f9b8 removed baseName
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   358
"/    baseName := fname baseName.
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   359
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   360
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   361
icon
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   362
    "returns the icon key
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   363
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
    |model|
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
2095
46120b1fd644 can change icon
penk
parents: 1960
diff changeset
   366
    model := self model.
46120b1fd644 can change icon
penk
parents: 1960
diff changeset
   367
    model ifNil:[^ nil].
46120b1fd644 can change icon
penk
parents: 1960
diff changeset
   368
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   369
    icon isNil ifTrue:[
2095
46120b1fd644 can change icon
penk
parents: 1960
diff changeset
   370
        icon := model iconFor:self
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
    ].
2095
46120b1fd644 can change icon
penk
parents: 1960
diff changeset
   372
    ^ model validateIcon:icon for:self
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   373
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   374
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   375
label
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   376
    "returns the printable name, the baseName
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   377
    "
2138
4175c127f9b8 removed baseName
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   378
    ^ self baseName
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   379
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   380
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
pathName
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
    "returns the pathName
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   384
    ^ fileName pathName
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   385
! !
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   387
!HierarchicalFileList::File methodsFor:'accessing hierarchy'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   389
recursiveExpand
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
    "redefined to expand
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   391
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   392
    self expand
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   393
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   394
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
! !
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   396
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
!HierarchicalFileList::File methodsFor:'invalidate'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   398
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   399
invalidate
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   400
    "invalidate the contents
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   401
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
    self invalidateRepairNow:false
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   403
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   404
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   405
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   406
invalidateRepairNow
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   407
    "invalidate the contents; repair now
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   408
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   409
    self invalidateRepairNow:true
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   410
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   411
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   412
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   413
invalidateRepairNow:doRepair
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   414
    "invalidate the contents; dependent on the boolean
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   415
     do repair immediately
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   416
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   417
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   418
1866
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   419
!
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   420
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   421
matchBlockChanged
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   422
    "called if the matchBlock changed
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   423
    "
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   424
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   425
! !
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   426
2127
effea319e46b add printString method to see file for Item
penk
parents: 2104
diff changeset
   427
!HierarchicalFileList::File methodsFor:'printing'!
effea319e46b add printString method to see file for Item
penk
parents: 2104
diff changeset
   428
effea319e46b add printString method to see file for Item
penk
parents: 2104
diff changeset
   429
printString
effea319e46b add printString method to see file for Item
penk
parents: 2104
diff changeset
   430
effea319e46b add printString method to see file for Item
penk
parents: 2104
diff changeset
   431
    ^ super printString, ' for: ', self fileName asString
effea319e46b add printString method to see file for Item
penk
parents: 2104
diff changeset
   432
! !
effea319e46b add printString method to see file for Item
penk
parents: 2104
diff changeset
   433
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   434
!HierarchicalFileList::File methodsFor:'queries'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   435
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   436
hasChildren
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   437
    "always returns false
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   438
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   439
    ^ false
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   440
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   441
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   442
isDirectory
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   443
    "always returns false
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   445
    ^ false
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   446
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   447
! !
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   448
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   449
!HierarchicalFileList::File::Directory methodsFor:'accessing'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
children
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
    "returns the list of children
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   454
    |model list|
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   455
1867
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   456
    children notNil ifTrue:[
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   457
        ^ children
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   458
    ].
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   459
1867
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   460
    (model := self model) isNil ifTrue:[
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   461
        "/ must reread later
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   462
        modificationTime := children := nil.
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   463
        ^ nil
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   464
    ].
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   465
1867
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   466
    children := #().
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   467
    modificationTime := fileName modificationTime.
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   468
    list := model childrenFor:self.
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   469
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   470
    list size ~~ 0 ifTrue:[
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   471
        list do:[:aChild| aChild parent:self].
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   472
        children := list.
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   473
    ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   474
    ^ children
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   475
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   476
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   477
icon
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   478
    "returns the icon
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   479
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   480
    (isExpanded and:[children size ~~ 0]) ifTrue:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   481
        ^ nil
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   482
    ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   483
    ^ super icon
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   484
! !
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   485
2104
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   486
!HierarchicalFileList::File::Directory methodsFor:'accessing-hierarchy'!
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   487
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   488
expand
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   489
    "expand children; must redefine to raise a notification
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   490
     if children are not yet initialized and after initialization empty.
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   491
    "
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   492
    |notInit|
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   493
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   494
    notInit := children isNil.
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   495
    super expand.
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   496
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   497
    notInit ifTrue:[
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   498
        (children notNil and:[children isEmpty]) ifTrue:[
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   499
            "/ no children exists
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   500
            "/ indicator +/- has changed to unexistant
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   501
            self changed:#redraw
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   502
        ]
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   503
    ].
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   504
! !
327f2f77ec12 support remote file-systems (not reading contents of directory if not yet initialized)
ca
parents: 2095
diff changeset
   505
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   506
!HierarchicalFileList::File::Directory methodsFor:'queries'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   507
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   508
hasChildren
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   509
    "returns true if children exists
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   510
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
    ^ children isNil or:[children notEmpty]
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   512
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   513
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   514
isDirectory
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   515
    "always returns true
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   516
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   517
    ^ true
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   518
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   519
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   520
! !
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   521
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   522
!HierarchicalFileList::File::Directory methodsFor:'validation'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   523
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   524
invalidateRepairNow:doRepair
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   525
    "invalidate contents
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   526
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   527
    modificationTime := nil.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   528
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   529
    doRepair ifTrue:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   530
        self monitoringCycle
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   531
    ] ifFalse:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   532
        (isExpanded or:[children size == 0]) ifFalse:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   533
            children := nil
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   534
        ]
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   535
    ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   536
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   537
!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   538
1866
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   539
matchBlockChanged
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   540
    "called if the matchBlock changed
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   541
    "
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   542
    modificationTime := nil.
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   543
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   544
    isExpanded ifFalse:[
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   545
        children := nil.
1867
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   546
    ] ifTrue:[
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   547
        self monitoringCycle.
1866
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   548
1867
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   549
        children size ~~ 0 ifTrue:[
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   550
            children do:[:aChild| aChild matchBlockChanged ]
a50479cd3653 recompute list if matchBlock changed
ca
parents: 1866
diff changeset
   551
        ]
1866
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   552
    ].
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   553
!
2993c95f7f69 recompute list if matchBlock changed
ca
parents: 1780
diff changeset
   554
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   555
monitoringCycle
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   556
    "run monitoring cycle
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   557
    "
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   558
    |list size name modifyTime isNotEmpty wasNotEmpty model|
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   559
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   560
    modifyTime := fileName modificationTime.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   561
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   562
    (modificationTime notNil and:[modifyTime <= modificationTime]) ifTrue:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   563
        ^ self
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   564
    ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   565
    model := self model.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   566
    modificationTime := modifyTime.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   567
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   568
    isExpanded ifFalse:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   569
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   570
     "/ CHECK WHETHER CHILDREN EXIST( INDICATOR )
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   571
     "/ =========================================
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   572
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   573
        isNotEmpty := model hasChildrenFor:self.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   574
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   575
     "/ check whether has changed durring evaluation
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   576
        (isExpanded or:[modificationTime ~= modifyTime]) ifFalse:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   577
            wasNotEmpty := children isNil.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   578
            children    := isNotEmpty ifTrue:[nil] ifFalse:[#()].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   579
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   580
            wasNotEmpty ~~ isNotEmpty ifTrue:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   581
                self changed
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   582
            ]
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   583
        ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   584
        ^ self
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   585
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   586
    ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   587
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   588
 "/ START MERGING( CONTENTS IS VISIBLE )
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   589
 "/ ====================================
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   590
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   591
    list := model childrenFor:self.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   592
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   593
    list size == 0 ifTrue:[                         "/ contents becomes empty
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   594
        ^ self removeAll                            "/ clear contents
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   595
    ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   596
    (size := children size) == 0 ifTrue:[           "/ old contents was empty 
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   597
        ^ self addAll:list.                         "/ take over new contents
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   598
    ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   599
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   600
    size to:1 by:-1 do:[:anIndex|                   "/ remove invisible items
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   601
        name := (children at:anIndex) baseName.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   602
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   603
        (list findFirst:[:i|i baseName = name]) == 0 ifTrue:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   604
            self removeIndex:anIndex
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   605
        ]
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   606
    ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   607
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   608
    list keysAndValuesDo:[:anIndex :anItem|         "/ add new visible items
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   609
        name := anItem baseName.
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   610
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   611
        (children findFirst:[:i|i baseName = name]) == 0 ifTrue:[
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   612
            self add:anItem beforeIndex:anIndex
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   613
        ]
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   614
    ].
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   615
! !
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   616
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   617
!HierarchicalFileList class methodsFor:'documentation'!
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   618
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   619
version
2138
4175c127f9b8 removed baseName
Claus Gittinger <cg@exept.de>
parents: 2130
diff changeset
   620
    ^ '$Header: /cvs/stx/stx/libwidg2/HierarchicalFileList.st,v 1.16 2002-08-19 16:08:03 cg Exp $'
1390
62dc950b9140 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   621
! !