/
FileDirectoryWrapper.class.st
96 lines (76 loc) · 2.2 KB
/
FileDirectoryWrapper.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
Class {
#name : #FileDirectoryWrapper,
#superclass : #ListItemWrapper,
#instVars : [
'itemName',
'balloonText',
'hasContents'
],
#category : #'Tool-FileList'
}
{ #category : #'instance creation' }
FileDirectoryWrapper class >> with: anObject name: aString model: aModel [
^self new
setItem: anObject name: aString model: aModel
]
{ #category : #converting }
FileDirectoryWrapper >> asString [
^itemName
]
{ #category : #accessing }
FileDirectoryWrapper >> balloonText [
^balloonText
]
{ #category : #accessing }
FileDirectoryWrapper >> balloonText: aStringOrNil [
balloonText := aStringOrNil
]
{ #category : #accessing }
FileDirectoryWrapper >> contents [
^((model directoriesFor: item)
sort: [ :a :b | a basename caseInsensitiveLessOrEqual: b basename])
collect: [ :directory|
self class with: directory name: directory basename model: self ]
]
{ #category : #accessing }
FileDirectoryWrapper >> directoriesFor: anItem [
^model directoriesFor: anItem
]
{ #category : #accessing }
FileDirectoryWrapper >> hasContents [
"Return whether this directory has subfolders. The value is cached to
avoid a performance penalty. Also for performance reasons, the code
below will just assume that the directory does indeed have contents in a
few of cases:
1. If the item is not a FileDirectory (thus avoiding the cost
of refreshing directories that are not local)
2. If it's the root directory of a given volume
3. If there is an error computing the FileDirectory's contents
"
hasContents ifNil: [
hasContents := [
item isDirectory
and: [ item isReadable
and: [ item hasDirectories ]]
] on: Error do: [ :error | false ]].
^ hasContents
]
{ #category : #accessing }
FileDirectoryWrapper >> icon [
"Answer a form to be used as icon"
"^ item isRemoteDirectory
ifTrue: [ Smalltalk ui icons smallRemoteOpenIcon]
ifFalse: [Smalltalk ui icons smallOpenIcon]"
^ self iconNamed: #smallOpenIcon
]
{ #category : #accessing }
FileDirectoryWrapper >> setItem: anObject name: aString model: aModel [
item := anObject.
model := aModel.
itemName := aString.
hasContents := nil.
]
{ #category : #accessing }
FileDirectoryWrapper >> settingSelector [
^#setSelectedDirectoryTo:
]