1522
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2004 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
1367
|
13 |
"{ Package: 'stx:libbasic2' }"
|
|
14 |
|
|
15 |
Object subclass:#FileSorter
|
|
16 |
instanceVariableNames:'directoriesBeforeFiles selector sortCaseless sortReverse'
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Interface-Tools-File'
|
|
20 |
!
|
|
21 |
|
1368
|
22 |
!FileSorter class methodsFor:'documentation'!
|
|
23 |
|
1522
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 2004 by eXept Software AG
|
|
27 |
All Rights Reserved
|
|
28 |
|
|
29 |
This software is furnished under a license and may be used
|
|
30 |
only in accordance with the terms of that license and with the
|
|
31 |
inclusion of the above copyright notice. This software may not
|
|
32 |
be provided or otherwise made available to, or used by, any
|
|
33 |
other person. No title to or ownership of the software is
|
|
34 |
hereby transferred.
|
|
35 |
"
|
|
36 |
!
|
|
37 |
|
1368
|
38 |
documentation
|
|
39 |
"
|
|
40 |
sort files by selector
|
|
41 |
care for directoriesBeforeFiles sortCaseless sortReverse
|
|
42 |
|
|
43 |
[author:]
|
|
44 |
Christian Penk
|
|
45 |
|
|
46 |
[instance variables:]
|
|
47 |
directoriesBeforeFiles: if true all directories and files will be sorted
|
|
48 |
independently by the selector and the directories
|
|
49 |
are before files
|
|
50 |
sortCaseless: if true and the selector is #baseName ignore upper
|
|
51 |
and lowercase in sort
|
|
52 |
sortReverse: if true starts with highest value of the sort
|
|
53 |
|
|
54 |
[class variables:]
|
|
55 |
|
|
56 |
[see also:]
|
|
57 |
|
|
58 |
"
|
|
59 |
! !
|
1367
|
60 |
|
|
61 |
!FileSorter class methodsFor:'instance creation'!
|
|
62 |
|
|
63 |
directoriesBeforeFiles:arg1 selector:arg2 sortCaseless:arg3 sortReverse:arg4
|
|
64 |
^ self new directoriesBeforeFiles:arg1 selector:arg2 sortCaseless:arg3 sortReverse:arg4
|
|
65 |
! !
|
|
66 |
|
|
67 |
!FileSorter methodsFor:'accessing'!
|
|
68 |
|
|
69 |
directoriesBeforeFiles
|
1368
|
70 |
^ directoriesBeforeFiles ? false
|
1367
|
71 |
!
|
|
72 |
|
|
73 |
directoriesBeforeFiles:something
|
|
74 |
directoriesBeforeFiles := something.
|
|
75 |
!
|
|
76 |
|
|
77 |
directoriesBeforeFiles:directoriesBeforeFilesArg selector:selectorArg sortCaseless:sortCaselessArg sortReverse:sortReverseArg
|
|
78 |
"set instance variables (automatically generated)"
|
|
79 |
|
|
80 |
directoriesBeforeFiles := directoriesBeforeFilesArg.
|
|
81 |
selector := selectorArg.
|
|
82 |
sortCaseless := sortCaselessArg.
|
|
83 |
sortReverse := sortReverseArg.
|
|
84 |
!
|
|
85 |
|
|
86 |
selector
|
|
87 |
^ selector
|
|
88 |
!
|
|
89 |
|
|
90 |
selector:something
|
|
91 |
selector := something.
|
|
92 |
!
|
|
93 |
|
|
94 |
sortCaseless
|
1368
|
95 |
^ sortCaseless ? false
|
1367
|
96 |
!
|
|
97 |
|
|
98 |
sortCaseless:something
|
|
99 |
sortCaseless := something.
|
|
100 |
!
|
|
101 |
|
|
102 |
sortReverse
|
|
103 |
^ sortReverse ? false
|
|
104 |
!
|
|
105 |
|
|
106 |
sortReverse:something
|
|
107 |
sortReverse := something.
|
|
108 |
! !
|
|
109 |
|
|
110 |
!FileSorter methodsFor:'action'!
|
|
111 |
|
|
112 |
sortItemList:aList
|
|
113 |
|
1369
|
114 |
|selectorSymbol instanceSortBlock cmpOp sortBlock locSortReverse|
|
1367
|
115 |
|
|
116 |
selectorSymbol := selector asSymbol.
|
|
117 |
sortReverse ifTrue:[
|
|
118 |
cmpOp := #'>'
|
|
119 |
] ifFalse:[
|
|
120 |
cmpOp := #'<'
|
|
121 |
].
|
1369
|
122 |
locSortReverse := self sortReverse.
|
1367
|
123 |
instanceSortBlock := [:a :b |
|
|
124 |
|entry1 entry2|
|
|
125 |
|
|
126 |
entry1 := (a perform:selectorSymbol).
|
|
127 |
entry2 := (b perform:selectorSymbol).
|
|
128 |
((entry1 isNil) or:[entry2 isNil]) ifTrue:[
|
|
129 |
((entry1 isNil) and:[entry2 isNil]) ifTrue:[
|
|
130 |
true
|
|
131 |
] ifFalse:[
|
|
132 |
((entry1 notNil) and:[entry2 isNil]) ifTrue:[
|
1369
|
133 |
locSortReverse
|
1367
|
134 |
] ifFalse:[
|
1369
|
135 |
locSortReverse not
|
1367
|
136 |
]
|
|
137 |
]
|
|
138 |
] ifFalse:[
|
|
139 |
((selector = #baseName) and:[sortCaseless]) ifTrue:[
|
|
140 |
entry1 := entry1 asLowercase.
|
|
141 |
entry2 := entry2 asLowercase.
|
|
142 |
].
|
|
143 |
entry1 perform:cmpOp with:entry2
|
|
144 |
]
|
|
145 |
].
|
|
146 |
directoriesBeforeFiles ifTrue:[
|
|
147 |
sortBlock := [:a :b|
|
|
148 |
|aIsDir bIsDir res|
|
|
149 |
|
|
150 |
aIsDir := a isDirectory.
|
|
151 |
bIsDir := b isDirectory.
|
|
152 |
(aIsDir ~~ bIsDir) ifTrue:[
|
|
153 |
res := aIsDir
|
|
154 |
] ifFalse:[
|
|
155 |
res := instanceSortBlock value:a value:b.
|
|
156 |
].
|
|
157 |
res
|
|
158 |
].
|
|
159 |
] ifFalse:[
|
|
160 |
sortBlock := instanceSortBlock.
|
|
161 |
].
|
|
162 |
|
|
163 |
aList sort:sortBlock.
|
|
164 |
^ aList
|
|
165 |
! !
|
|
166 |
|
|
167 |
!FileSorter class methodsFor:'documentation'!
|
|
168 |
|
|
169 |
version
|
1522
|
170 |
^ '$Header: /cvs/stx/stx/libbasic2/FileSorter.st,v 1.4 2005-02-02 11:03:47 cg Exp $'
|
1367
|
171 |
! !
|