author | Claus Gittinger <cg@exept.de> |
Wed, 23 Aug 2006 01:58:25 +0200 | |
changeset 2165 | 308101564aa0 |
parent 2065 | 0b1f3120a544 |
child 2359 | 283d81512850 |
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 |
" |
|
12 |
||
1863 | 13 |
"{ Package: 'stx:libview2' }" |
1859 | 14 |
|
1865 | 15 |
Object subclass:#MIMETypeIconLibrary |
1859 | 16 |
instanceVariableNames:'' |
1860 | 17 |
classVariableNames:'Icons MatchedIcons' |
1859 | 18 |
poolDictionaries:'' |
1875 | 19 |
category:'Interface-Smalltalk' |
1859 | 20 |
! |
21 |
||
2035 | 22 |
!MIMETypeIconLibrary class methodsFor:'documentation'! |
23 |
||
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 |
! ! |
|
1859 | 37 |
|
1865 | 38 |
!MIMETypeIconLibrary class methodsFor:'initialization'! |
1859 | 39 |
|
40 |
initialize |
|
1875 | 41 |
"/ now done lazily, when trhe first icon is asked for |
42 |
"/ self initializeIcons |
|
1859 | 43 |
! |
44 |
||
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
45 |
initializeIcons |
1876 | 46 |
|icons matchedIcons defaults resources addMapping fileNameToImageMap| |
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
47 |
|
1876 | 48 |
icons := Dictionary new. |
49 |
matchedIcons := OrderedCollection new. |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
50 |
fileNameToImageMap := Dictionary new. |
1859 | 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' |
|
115 |
||
116 |
"/ binary formats |
|
117 |
'application/binary' 'tiny_file_binary.xpm' |
|
118 |
'application/library' 'tiny_file_binary.xpm' |
|
119 |
'application/shared-library' 'tiny_file_binary.xpm' |
|
120 |
||
121 |
"/ progr. languages |
|
122 |
'application/x-smalltalk-source' 'tiny_file_st.xpm' |
|
123 |
'application/x-smalltalk-source-sif' 'tiny_file_text.xpm' |
|
124 |
'application/x-c-source' 'tiny_file_text.xpm' |
|
125 |
'application/x-c-header' 'tiny_file_text.xpm' |
|
126 |
'application/x-cpp-source' 'tiny_file_text.xpm' |
|
127 |
'application/x-javascript' 'tiny_file_text.xpm' |
|
128 |
'application/x-java-source' 'tiny_file_java.xpm' |
|
129 |
||
130 |
'application/x-sh' 'tiny_file_text.xpm' |
|
131 |
'application/x-csh' 'tiny_file_text.xpm' |
|
132 |
'application/x-tcl' 'tiny_file_text.xpm' |
|
133 |
'application/x-perl' 'tiny_file_text.xpm' |
|
134 |
'application/x-make' 'tiny_file_text.xpm' |
|
135 |
'application/x-batch-script' 'tiny_file_text.xpm' |
|
136 |
'application/x-asn1-source' 'tiny_file_text.xpm' |
|
137 |
||
138 |
"/ compressors / archivers |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
139 |
'application/x-tar' 'tiny_file_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
140 |
'application/x-gtar' 'tiny_file_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
141 |
'application/x-tar-compressed' 'tiny_file_compressed_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
142 |
'application/x-zip-compressed' 'tiny_file_compressed_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
143 |
'application/x-gzip-compressed' 'tiny_file_compressed_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
144 |
'application/x-cpio' 'tiny_file_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
145 |
'application/x-shar' 'tiny_file_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
146 |
'application/java-archive' 'tiny_file_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
147 |
|
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
148 |
'*' 'tiny_file_plain.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
149 |
) pairWiseDo:[:fileTypeOrMimeTypePattern :baseName | |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
150 |
defaults at:fileTypeOrMimeTypePattern put:baseName. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
151 |
]. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
152 |
|
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
153 |
addMapping := [:key :baseNameOrName | |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
154 |
|fileName image| |
1859 | 155 |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
156 |
baseNameOrName notNil ifTrue:[ |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
157 |
image := fileNameToImageMap at:baseNameOrName ifAbsent:nil. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
158 |
image isNil ifTrue:[ |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
159 |
image := Smalltalk imageFromFileNamed:baseNameOrName forClass:self. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
160 |
image isNil ifTrue:[ |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
161 |
fileName := 'bitmaps/xpmBitmaps/document_images/' , baseNameOrName. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
162 |
image := Smalltalk imageFromFileNamed:fileName forClass:self. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
163 |
]. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
164 |
]. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
165 |
fileNameToImageMap at:baseNameOrName put:image. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
166 |
key includesMatchCharacters ifTrue:[ |
1877 | 167 |
matchedIcons add:(key -> image). |
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
168 |
] ifFalse:[ |
1877 | 169 |
icons at:key put:image. |
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
170 |
] |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
171 |
] |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
172 |
]. |
1859 | 173 |
|
1956
7bfc5c973c1b
classResources now understood by all classes
Claus Gittinger <cg@exept.de>
parents:
1877
diff
changeset
|
174 |
resources := self classResources. |
7bfc5c973c1b
classResources now understood by all classes
Claus Gittinger <cg@exept.de>
parents:
1877
diff
changeset
|
175 |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
176 |
"all mappings from the resource file" |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
177 |
resources keysAndValuesDo:addMapping. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
178 |
|
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
179 |
"missing mappings from above defaults" |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
180 |
defaults keysAndValuesDo:[:key :baseName | |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
181 |
(resources includesKey:key) ifFalse:[ |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
182 |
addMapping value:key value:baseName |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
183 |
]. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
184 |
]. |
1859 | 185 |
|
1876 | 186 |
Icons := icons. |
187 |
MatchedIcons := matchedIcons. |
|
188 |
||
1859 | 189 |
" |
190 |
self initializeIcons |
|
191 |
" |
|
192 |
! ! |
|
193 |
||
1865 | 194 |
!MIMETypeIconLibrary class methodsFor:'accessing'! |
1859 | 195 |
|
1862 | 196 |
fileTypeIconKeyFor:aFilename |
197 |
aFilename isSymbolicLink ifTrue:[ |
|
198 |
^ #symbolicLink. |
|
199 |
]. |
|
200 |
aFilename isDirectory ifTrue:[ |
|
201 |
^ #directory. |
|
202 |
]. |
|
203 |
aFilename isSpecialFile ifTrue:[ |
|
204 |
^ #specialFile. |
|
205 |
]. |
|
206 |
aFilename isExecutableProgram ifTrue:[ |
|
207 |
^ #executableFile |
|
208 |
]. |
|
209 |
^ #file. |
|
210 |
! |
|
211 |
||
1860 | 212 |
iconForKey:mimeTypeOrKey |
1859 | 213 |
|
1875 | 214 |
^ self icons at:mimeTypeOrKey ifAbsent:nil. |
1860 | 215 |
! |
1859 | 216 |
|
1860 | 217 |
iconForKeyMatching:mimeTypeOrKey |
218 |
||
1861 | 219 |
|icn assoc| |
220 |
||
221 |
icn := self iconForKey:mimeTypeOrKey. |
|
222 |
icn notNil ifTrue:[^icn]. |
|
2065 | 223 |
assoc := self iconForMatchKey:mimeTypeOrKey. |
1861 | 224 |
assoc notNil ifTrue:[^ assoc value]. |
225 |
^ nil. |
|
226 |
! |
|
227 |
||
228 |
iconForMatchKey:matchKey |
|
229 |
||
1875 | 230 |
^ self matchedIcons detect:[:assoc | assoc key match:matchKey] ifNone:nil. |
1862 | 231 |
! |
232 |
||
233 |
iconKeyForFile:aFilenameArg |
|
234 |
"given a fileName, return an appropriate icon" |
|
235 |
||
236 |
|aFilename fileType mimeType suffix| |
|
237 |
||
238 |
aFilename := aFilenameArg. |
|
239 |
||
240 |
aFilenameArg isFilename ifTrue:[ |
|
241 |
fileType := self fileTypeIconKeyFor:aFilename. |
|
242 |
] ifFalse:[ |
|
243 |
fileType := #file |
|
244 |
]. |
|
245 |
||
246 |
(fileType == #directory) ifFalse:[ |
|
247 |
suffix := aFilename suffix. |
|
248 |
(suffix = 'bak' or:[suffix = 'sav']) ifTrue:[ |
|
249 |
aFilename := aFilename withoutSuffix. |
|
250 |
]. |
|
251 |
mimeType := MIMETypes mimeTypeForFilename:aFilename. |
|
252 |
]. |
|
253 |
||
254 |
^ (mimeType ? fileType). |
|
255 |
! |
|
256 |
||
257 |
iconKeyForRemoteDirectory:aFilenameArg |
|
258 |
"given a fileName, return an appropriate icon" |
|
259 |
||
260 |
^ #directoryNetwork |
|
1875 | 261 |
! |
262 |
||
263 |
icons |
|
264 |
Icons isNil ifTrue:[ |
|
265 |
self initializeIcons |
|
266 |
]. |
|
267 |
^ Icons |
|
268 |
! |
|
269 |
||
270 |
matchedIcons |
|
271 |
MatchedIcons isNil ifTrue:[ |
|
272 |
self initializeIcons |
|
273 |
]. |
|
274 |
^ MatchedIcons |
|
1859 | 275 |
! ! |
276 |
||
1865 | 277 |
!MIMETypeIconLibrary class methodsFor:'documentation'! |
1859 | 278 |
|
279 |
version |
|
2065 | 280 |
^ '$Header: /cvs/stx/stx/libview2/MIMETypeIconLibrary.st,v 1.14 2005-10-05 15:45:46 cg Exp $' |
1859 | 281 |
! ! |
282 |
||
1865 | 283 |
MIMETypeIconLibrary initialize! |