author | Claus Gittinger <cg@exept.de> |
Thu, 12 Sep 2013 15:17:56 +0200 | |
changeset 3246 | d167d433053c |
parent 3159 | 68fc64f31a95 |
child 3325 | 29992c54c3db |
permissions | -rw-r--r-- |
2035 | 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 |
" |
|
1863 | 12 |
"{ Package: 'stx:libview2' }" |
1859 | 13 |
|
1865 | 14 |
Object subclass:#MIMETypeIconLibrary |
1859 | 15 |
instanceVariableNames:'' |
1860 | 16 |
classVariableNames:'Icons MatchedIcons' |
1859 | 17 |
poolDictionaries:'' |
1875 | 18 |
category:'Interface-Smalltalk' |
1859 | 19 |
! |
20 |
||
2035 | 21 |
!MIMETypeIconLibrary class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! ! |
|
1859 | 36 |
|
1865 | 37 |
!MIMETypeIconLibrary class methodsFor:'initialization'! |
1859 | 38 |
|
39 |
initialize |
|
2359 | 40 |
"/ now done lazily, when the first icon is asked for |
1875 | 41 |
"/ self initializeIcons |
1859 | 42 |
! |
43 |
||
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
44 |
initializeIcons |
1876 | 45 |
|icons matchedIcons defaults resources addMapping fileNameToImageMap| |
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
46 |
|
1876 | 47 |
icons := Dictionary new. |
48 |
matchedIcons := OrderedCollection new. |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
49 |
fileNameToImageMap := Dictionary new. |
1859 | 50 |
|
2847 | 51 |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
52 |
defaults := Dictionary new. |
1859 | 53 |
#( |
54 |
"/ internal-type to icon mappings. |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
55 |
#directory 'tiny_yellow_dir.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
56 |
#directoryOpen 'tiny_yellow_dir_open.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
57 |
#directoryLocked 'tiny_yellow_dir_locked.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
58 |
#directoryLink 'tiny_yellow_dir_link.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
59 |
#directoryNetwork 'tiny_yellow_dir_network.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
60 |
#file 'tiny_file_plain.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
61 |
#fileLink 'tiny_file_link.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
62 |
#fileLocked 'tiny_file_lock.xpm' |
1859 | 63 |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
64 |
#executableFile 'tiny_file_exec.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
65 |
#deviceFile 'tiny_file_device.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
66 |
#binaryFile 'tiny_file_binary.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
67 |
#specialFile 'tiny_file_special.xpm' |
1859 | 68 |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
69 |
#addOnLocked 'tiny_addOn_lock.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
70 |
#addOnLinked 'tiny_addOn_link.xpm' |
1859 | 71 |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
72 |
#directoryGray 'tiny_yellow_dir_gray.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
73 |
#directoryOpenGray 'tiny_yellow_dir_open_gray.xpm' |
1859 | 74 |
|
1875 | 75 |
"/ these are soon obsolete |
76 |
#imageFile 'tiny_file_pix.xpm' |
|
77 |
#textFile 'tiny_file_text.xpm' |
|
78 |
||
1859 | 79 |
"/ mime-type to icon mappings. |
80 |
'image/*' 'tiny_file_pix.xpm' |
|
81 |
||
82 |
"/ misc text ... |
|
83 |
||
84 |
'text/html' 'tiny_file_html.xpm' |
|
85 |
"/ 'text/plain' 'tiny_file_text.xpm' |
|
86 |
'text/*' 'tiny_file_text.xpm' |
|
87 |
||
88 |
'application/postscript' 'tiny_file_postscript.xpm' |
|
89 |
'application/pdf' 'tiny_file_pdf.xpm' |
|
90 |
'application/rtf' 'tiny_file_rtf.xpm' |
|
91 |
||
92 |
"/ video formats ... |
|
93 |
||
94 |
"/ 'video/x-sgi-movie' 'tiny_file_movie.xpm' |
|
95 |
"/ 'video/x-msvideo' 'tiny_file_movie.xpm' |
|
96 |
"/ 'video/quicktime' 'tiny_file_movie.xpm' |
|
97 |
"/ 'video/x-mpeg2' 'tiny_file_movie.xpm' |
|
98 |
"/ 'video/mpeg' 'tiny_file_movie.xpm' |
|
99 |
'video/*' 'tiny_file_movie2.xpm' |
|
100 |
'application/vnd.rn-realmedia' 'tiny_file_movie2.xpm' |
|
101 |
||
102 |
"/ audio formats ... |
|
103 |
||
104 |
"/ 'audio/x-pn-realaudio' 'tiny_file_sound.xpm' |
|
105 |
"/ 'audio/x-mpeg' 'tiny_file_sound.xpm' |
|
106 |
"/ 'audio/x-mp3' 'tiny_file_sound.xpm' |
|
107 |
"/ 'audio/x-wav' 'tiny_file_sound.xpm' |
|
108 |
"/ 'audio/x-aiff' 'tiny_file_sound.xpm' |
|
109 |
"/ 'audio/basic' 'tiny_file_sound.xpm' |
|
110 |
"/ 'audio/x-shockwave-flash' 'tiny_file_sound.xpm' |
|
111 |
'audio/*' 'tiny_file_sound.xpm' |
|
112 |
||
113 |
"/ misc stuff |
|
114 |
'application/winword' 'tiny_file_text.xpm' |
|
2359 | 115 |
'application/x-waltop-digital-notepad' 'tiny_file_digital_notepad.xpm' |
1859 | 116 |
|
117 |
"/ binary formats |
|
118 |
'application/binary' 'tiny_file_binary.xpm' |
|
119 |
'application/library' 'tiny_file_binary.xpm' |
|
120 |
'application/shared-library' 'tiny_file_binary.xpm' |
|
121 |
||
122 |
"/ progr. languages |
|
123 |
'application/x-smalltalk-source' 'tiny_file_st.xpm' |
|
124 |
'application/x-smalltalk-source-sif' 'tiny_file_text.xpm' |
|
125 |
'application/x-c-source' 'tiny_file_text.xpm' |
|
126 |
'application/x-c-header' 'tiny_file_text.xpm' |
|
127 |
'application/x-cpp-source' 'tiny_file_text.xpm' |
|
128 |
'application/x-javascript' 'tiny_file_text.xpm' |
|
129 |
'application/x-java-source' 'tiny_file_java.xpm' |
|
130 |
||
131 |
'application/x-sh' 'tiny_file_text.xpm' |
|
132 |
'application/x-csh' 'tiny_file_text.xpm' |
|
133 |
'application/x-tcl' 'tiny_file_text.xpm' |
|
134 |
'application/x-perl' 'tiny_file_text.xpm' |
|
135 |
'application/x-make' 'tiny_file_text.xpm' |
|
136 |
'application/x-batch-script' 'tiny_file_text.xpm' |
|
137 |
'application/x-asn1-source' 'tiny_file_text.xpm' |
|
138 |
||
139 |
"/ compressors / archivers |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
140 |
'application/x-tar' 'tiny_file_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
141 |
'application/x-gtar' 'tiny_file_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
142 |
'application/x-tar-compressed' 'tiny_file_compressed_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
143 |
'application/x-zip-compressed' 'tiny_file_compressed_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
144 |
'application/x-gzip-compressed' 'tiny_file_compressed_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
145 |
'application/x-cpio' 'tiny_file_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
146 |
'application/x-shar' 'tiny_file_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
147 |
'application/java-archive' 'tiny_file_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
148 |
|
2847 | 149 |
'application/x-expecco-testsuite' 'tiny_file_ets.gif' |
150 |
'application/x-expecco-logfile' 'tiny_file_elf.gif' |
|
151 |
||
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
152 |
'*' 'tiny_file_plain.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
153 |
) pairWiseDo:[:fileTypeOrMimeTypePattern :baseName | |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
154 |
defaults at:fileTypeOrMimeTypePattern put:baseName. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
155 |
]. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
156 |
|
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
157 |
addMapping := [:key :baseNameOrName | |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
158 |
|fileName image| |
1859 | 159 |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
160 |
baseNameOrName notNil ifTrue:[ |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
161 |
image := fileNameToImageMap at:baseNameOrName ifAbsent:nil. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
162 |
image isNil ifTrue:[ |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
163 |
image := Smalltalk imageFromFileNamed:baseNameOrName forClass:self. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
164 |
image isNil ifTrue:[ |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
165 |
fileName := 'bitmaps/xpmBitmaps/document_images/' , baseNameOrName. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
166 |
image := Smalltalk imageFromFileNamed:fileName forClass:self. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
167 |
]. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
168 |
]. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
169 |
fileNameToImageMap at:baseNameOrName put:image. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
170 |
key includesMatchCharacters ifTrue:[ |
1877 | 171 |
matchedIcons add:(key -> image). |
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
172 |
] ifFalse:[ |
1877 | 173 |
icons at:key put:image. |
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
174 |
] |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
175 |
] |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
176 |
]. |
1859 | 177 |
|
1956
7bfc5c973c1b
classResources now understood by all classes
Claus Gittinger <cg@exept.de>
parents:
1877
diff
changeset
|
178 |
resources := self classResources. |
7bfc5c973c1b
classResources now understood by all classes
Claus Gittinger <cg@exept.de>
parents:
1877
diff
changeset
|
179 |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
180 |
"all mappings from the resource file" |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
181 |
resources keysAndValuesDo:addMapping. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
182 |
|
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
183 |
"missing mappings from above defaults" |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
184 |
defaults keysAndValuesDo:[:key :baseName | |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
185 |
(resources includesKey:key) ifFalse:[ |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
186 |
addMapping value:key value:baseName |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
187 |
]. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
188 |
]. |
1859 | 189 |
|
1876 | 190 |
Icons := icons. |
191 |
MatchedIcons := matchedIcons. |
|
192 |
||
1859 | 193 |
" |
194 |
self initializeIcons |
|
195 |
" |
|
196 |
! ! |
|
197 |
||
1865 | 198 |
!MIMETypeIconLibrary class methodsFor:'accessing'! |
1859 | 199 |
|
1862 | 200 |
fileTypeIconKeyFor:aFilename |
3159 | 201 |
|info| |
202 |
||
203 |
info := aFilename linkInfo. |
|
204 |
info isNil ifTrue:[ |
|
205 |
^ nil. |
|
206 |
]. |
|
207 |
info isSymbolicLink ifTrue:[ |
|
1862 | 208 |
^ #symbolicLink. |
209 |
]. |
|
3159 | 210 |
info isDirectory ifTrue:[ |
1862 | 211 |
^ #directory. |
212 |
]. |
|
3159 | 213 |
info isSpecialFile ifTrue:[ |
1862 | 214 |
^ #specialFile. |
215 |
]. |
|
216 |
aFilename isExecutableProgram ifTrue:[ |
|
217 |
^ #executableFile |
|
218 |
]. |
|
219 |
^ #file. |
|
3159 | 220 |
|
221 |
" |
|
222 |
self fileTypeIconKeyFor:'/foo/bar' asFilename |
|
223 |
self fileTypeIconKeyFor:'/tmp' asFilename |
|
224 |
self fileTypeIconKeyFor:'/dev/null' asFilename |
|
225 |
self fileTypeIconKeyFor:'Makefile' asFilename |
|
226 |
self fileTypeIconKeyFor:'/usr/bin/make' asFilename |
|
227 |
" |
|
1862 | 228 |
! |
229 |
||
1860 | 230 |
iconForKey:mimeTypeOrKey |
1859 | 231 |
|
1875 | 232 |
^ self icons at:mimeTypeOrKey ifAbsent:nil. |
1860 | 233 |
! |
1859 | 234 |
|
1860 | 235 |
iconForKeyMatching:mimeTypeOrKey |
236 |
||
1861 | 237 |
|icn assoc| |
238 |
||
239 |
icn := self iconForKey:mimeTypeOrKey. |
|
240 |
icn notNil ifTrue:[^icn]. |
|
2065 | 241 |
assoc := self iconForMatchKey:mimeTypeOrKey. |
1861 | 242 |
assoc notNil ifTrue:[^ assoc value]. |
243 |
^ nil. |
|
244 |
! |
|
245 |
||
246 |
iconForMatchKey:matchKey |
|
247 |
||
1875 | 248 |
^ self matchedIcons detect:[:assoc | assoc key match:matchKey] ifNone:nil. |
1862 | 249 |
! |
250 |
||
251 |
iconKeyForFile:aFilenameArg |
|
252 |
"given a fileName, return an appropriate icon" |
|
253 |
||
254 |
|aFilename fileType mimeType suffix| |
|
255 |
||
256 |
aFilename := aFilenameArg. |
|
257 |
||
258 |
aFilenameArg isFilename ifTrue:[ |
|
259 |
fileType := self fileTypeIconKeyFor:aFilename. |
|
260 |
] ifFalse:[ |
|
261 |
fileType := #file |
|
262 |
]. |
|
263 |
||
264 |
(fileType == #directory) ifFalse:[ |
|
265 |
suffix := aFilename suffix. |
|
266 |
(suffix = 'bak' or:[suffix = 'sav']) ifTrue:[ |
|
267 |
aFilename := aFilename withoutSuffix. |
|
268 |
]. |
|
269 |
mimeType := MIMETypes mimeTypeForFilename:aFilename. |
|
270 |
]. |
|
271 |
||
272 |
^ (mimeType ? fileType). |
|
273 |
! |
|
274 |
||
275 |
iconKeyForRemoteDirectory:aFilenameArg |
|
276 |
"given a fileName, return an appropriate icon" |
|
277 |
||
278 |
^ #directoryNetwork |
|
1875 | 279 |
! |
280 |
||
281 |
icons |
|
282 |
Icons isNil ifTrue:[ |
|
283 |
self initializeIcons |
|
284 |
]. |
|
285 |
^ Icons |
|
286 |
! |
|
287 |
||
288 |
matchedIcons |
|
289 |
MatchedIcons isNil ifTrue:[ |
|
290 |
self initializeIcons |
|
291 |
]. |
|
292 |
^ MatchedIcons |
|
1859 | 293 |
! ! |
294 |
||
1865 | 295 |
!MIMETypeIconLibrary class methodsFor:'documentation'! |
1859 | 296 |
|
297 |
version |
|
3159 | 298 |
^ '$Header: /cvs/stx/stx/libview2/MIMETypeIconLibrary.st,v 1.17 2013-05-15 17:29:27 stefan Exp $' |
2847 | 299 |
! |
300 |
||
301 |
version_CVS |
|
3159 | 302 |
^ '$Header: /cvs/stx/stx/libview2/MIMETypeIconLibrary.st,v 1.17 2013-05-15 17:29:27 stefan Exp $' |
1859 | 303 |
! ! |
304 |
||
3159 | 305 |
|
1865 | 306 |
MIMETypeIconLibrary initialize! |