author | Claus Gittinger <cg@exept.de> |
Tue, 18 May 2004 13:47:52 +0200 | |
changeset 1984 | 43a42772be56 |
parent 1956 | 7bfc5c973c1b |
child 2035 | 8678c3d21507 |
permissions | -rw-r--r-- |
1863 | 1 |
"{ Package: 'stx:libview2' }" |
1859 | 2 |
|
1865 | 3 |
Object subclass:#MIMETypeIconLibrary |
1859 | 4 |
instanceVariableNames:'' |
1860 | 5 |
classVariableNames:'Icons MatchedIcons' |
1859 | 6 |
poolDictionaries:'' |
1875 | 7 |
category:'Interface-Smalltalk' |
1859 | 8 |
! |
9 |
||
10 |
||
1865 | 11 |
!MIMETypeIconLibrary class methodsFor:'initialization'! |
1859 | 12 |
|
13 |
initialize |
|
1875 | 14 |
"/ now done lazily, when trhe first icon is asked for |
15 |
"/ self initializeIcons |
|
1859 | 16 |
! |
17 |
||
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
18 |
initializeIcons |
1876 | 19 |
|icons matchedIcons defaults resources addMapping fileNameToImageMap| |
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
20 |
|
1876 | 21 |
icons := Dictionary new. |
22 |
matchedIcons := OrderedCollection new. |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
23 |
fileNameToImageMap := Dictionary new. |
1859 | 24 |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
25 |
defaults := Dictionary new. |
1859 | 26 |
#( |
27 |
"/ internal-type to icon mappings. |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
28 |
#directory 'tiny_yellow_dir.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
29 |
#directoryOpen 'tiny_yellow_dir_open.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
30 |
#directoryLocked 'tiny_yellow_dir_locked.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
31 |
#directoryLink 'tiny_yellow_dir_link.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
32 |
#directoryNetwork 'tiny_yellow_dir_network.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
33 |
#file 'tiny_file_plain.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
34 |
#fileLink 'tiny_file_link.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
35 |
#fileLocked 'tiny_file_lock.xpm' |
1859 | 36 |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
37 |
#executableFile 'tiny_file_exec.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
38 |
#deviceFile 'tiny_file_device.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
39 |
#binaryFile 'tiny_file_binary.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
40 |
#specialFile 'tiny_file_special.xpm' |
1859 | 41 |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
42 |
#addOnLocked 'tiny_addOn_lock.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
43 |
#addOnLinked 'tiny_addOn_link.xpm' |
1859 | 44 |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
45 |
#directoryGray 'tiny_yellow_dir_gray.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
46 |
#directoryOpenGray 'tiny_yellow_dir_open_gray.xpm' |
1859 | 47 |
|
1875 | 48 |
"/ these are soon obsolete |
49 |
#imageFile 'tiny_file_pix.xpm' |
|
50 |
#textFile 'tiny_file_text.xpm' |
|
51 |
||
1859 | 52 |
"/ mime-type to icon mappings. |
53 |
'image/*' 'tiny_file_pix.xpm' |
|
54 |
||
55 |
"/ misc text ... |
|
56 |
||
57 |
'text/html' 'tiny_file_html.xpm' |
|
58 |
"/ 'text/plain' 'tiny_file_text.xpm' |
|
59 |
'text/*' 'tiny_file_text.xpm' |
|
60 |
||
61 |
'application/postscript' 'tiny_file_postscript.xpm' |
|
62 |
'application/pdf' 'tiny_file_pdf.xpm' |
|
63 |
'application/rtf' 'tiny_file_rtf.xpm' |
|
64 |
||
65 |
"/ video formats ... |
|
66 |
||
67 |
"/ 'video/x-sgi-movie' 'tiny_file_movie.xpm' |
|
68 |
"/ 'video/x-msvideo' 'tiny_file_movie.xpm' |
|
69 |
"/ 'video/quicktime' 'tiny_file_movie.xpm' |
|
70 |
"/ 'video/x-mpeg2' 'tiny_file_movie.xpm' |
|
71 |
"/ 'video/mpeg' 'tiny_file_movie.xpm' |
|
72 |
'video/*' 'tiny_file_movie2.xpm' |
|
73 |
'application/vnd.rn-realmedia' 'tiny_file_movie2.xpm' |
|
74 |
||
75 |
"/ audio formats ... |
|
76 |
||
77 |
"/ 'audio/x-pn-realaudio' 'tiny_file_sound.xpm' |
|
78 |
"/ 'audio/x-mpeg' 'tiny_file_sound.xpm' |
|
79 |
"/ 'audio/x-mp3' 'tiny_file_sound.xpm' |
|
80 |
"/ 'audio/x-wav' 'tiny_file_sound.xpm' |
|
81 |
"/ 'audio/x-aiff' 'tiny_file_sound.xpm' |
|
82 |
"/ 'audio/basic' 'tiny_file_sound.xpm' |
|
83 |
"/ 'audio/x-shockwave-flash' 'tiny_file_sound.xpm' |
|
84 |
'audio/*' 'tiny_file_sound.xpm' |
|
85 |
||
86 |
"/ misc stuff |
|
87 |
'application/winword' 'tiny_file_text.xpm' |
|
88 |
||
89 |
"/ binary formats |
|
90 |
'application/binary' 'tiny_file_binary.xpm' |
|
91 |
'application/library' 'tiny_file_binary.xpm' |
|
92 |
'application/shared-library' 'tiny_file_binary.xpm' |
|
93 |
||
94 |
"/ progr. languages |
|
95 |
'application/x-smalltalk-source' 'tiny_file_st.xpm' |
|
96 |
'application/x-smalltalk-source-sif' 'tiny_file_text.xpm' |
|
97 |
'application/x-c-source' 'tiny_file_text.xpm' |
|
98 |
'application/x-c-header' 'tiny_file_text.xpm' |
|
99 |
'application/x-cpp-source' 'tiny_file_text.xpm' |
|
100 |
'application/x-javascript' 'tiny_file_text.xpm' |
|
101 |
'application/x-java-source' 'tiny_file_java.xpm' |
|
102 |
||
103 |
'application/x-sh' 'tiny_file_text.xpm' |
|
104 |
'application/x-csh' 'tiny_file_text.xpm' |
|
105 |
'application/x-tcl' 'tiny_file_text.xpm' |
|
106 |
'application/x-perl' 'tiny_file_text.xpm' |
|
107 |
'application/x-make' 'tiny_file_text.xpm' |
|
108 |
'application/x-batch-script' 'tiny_file_text.xpm' |
|
109 |
'application/x-asn1-source' 'tiny_file_text.xpm' |
|
110 |
||
111 |
"/ compressors / archivers |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
112 |
'application/x-tar' 'tiny_file_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
113 |
'application/x-gtar' 'tiny_file_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
114 |
'application/x-tar-compressed' 'tiny_file_compressed_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
115 |
'application/x-zip-compressed' 'tiny_file_compressed_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
116 |
'application/x-gzip-compressed' 'tiny_file_compressed_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
117 |
'application/x-cpio' 'tiny_file_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
118 |
'application/x-shar' 'tiny_file_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
119 |
'application/java-archive' 'tiny_file_archive.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
120 |
|
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
121 |
'*' 'tiny_file_plain.xpm' |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
122 |
) pairWiseDo:[:fileTypeOrMimeTypePattern :baseName | |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
123 |
defaults at:fileTypeOrMimeTypePattern put:baseName. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
124 |
]. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
125 |
|
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
126 |
addMapping := [:key :baseNameOrName | |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
127 |
|fileName image| |
1859 | 128 |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
129 |
baseNameOrName notNil ifTrue:[ |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
130 |
image := fileNameToImageMap at:baseNameOrName ifAbsent:nil. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
131 |
image isNil ifTrue:[ |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
132 |
image := Smalltalk imageFromFileNamed:baseNameOrName forClass:self. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
133 |
image isNil ifTrue:[ |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
134 |
fileName := 'bitmaps/xpmBitmaps/document_images/' , baseNameOrName. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
135 |
image := Smalltalk imageFromFileNamed:fileName forClass:self. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
136 |
]. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
137 |
]. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
138 |
fileNameToImageMap at:baseNameOrName put:image. |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
139 |
key includesMatchCharacters ifTrue:[ |
1877 | 140 |
matchedIcons add:(key -> image). |
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
141 |
] ifFalse:[ |
1877 | 142 |
icons at:key put:image. |
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
143 |
] |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
144 |
] |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
145 |
]. |
1859 | 146 |
|
1956
7bfc5c973c1b
classResources now understood by all classes
Claus Gittinger <cg@exept.de>
parents:
1877
diff
changeset
|
147 |
resources := self classResources. |
7bfc5c973c1b
classResources now understood by all classes
Claus Gittinger <cg@exept.de>
parents:
1877
diff
changeset
|
148 |
|
1869
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
149 |
"all mappings from the resource file" |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
150 |
resources keysAndValuesDo:addMapping. |
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 |
"missing mappings from above defaults" |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
153 |
defaults keysAndValuesDo:[:key :baseName | |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
154 |
(resources includesKey:key) ifFalse:[ |
c6800c75b7d0
resource file handling cleaned up
Claus Gittinger <cg@exept.de>
parents:
1865
diff
changeset
|
155 |
addMapping value:key value:baseName |
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 |
]. |
1859 | 158 |
|
1876 | 159 |
Icons := icons. |
160 |
MatchedIcons := matchedIcons. |
|
161 |
||
1859 | 162 |
" |
163 |
self initializeIcons |
|
164 |
" |
|
165 |
! ! |
|
166 |
||
1865 | 167 |
!MIMETypeIconLibrary class methodsFor:'accessing'! |
1859 | 168 |
|
1862 | 169 |
fileTypeIconKeyFor:aFilename |
170 |
aFilename isSymbolicLink ifTrue:[ |
|
171 |
^ #symbolicLink. |
|
172 |
]. |
|
173 |
aFilename isDirectory ifTrue:[ |
|
174 |
^ #directory. |
|
175 |
]. |
|
176 |
aFilename isSpecialFile ifTrue:[ |
|
177 |
^ #specialFile. |
|
178 |
]. |
|
179 |
aFilename isExecutableProgram ifTrue:[ |
|
180 |
^ #executableFile |
|
181 |
]. |
|
182 |
^ #file. |
|
183 |
! |
|
184 |
||
1860 | 185 |
iconForKey:mimeTypeOrKey |
1859 | 186 |
|
1875 | 187 |
^ self icons at:mimeTypeOrKey ifAbsent:nil. |
1860 | 188 |
! |
1859 | 189 |
|
1860 | 190 |
iconForKeyMatching:mimeTypeOrKey |
191 |
||
1861 | 192 |
|icn assoc| |
193 |
||
194 |
icn := self iconForKey:mimeTypeOrKey. |
|
195 |
icn notNil ifTrue:[^icn]. |
|
196 |
assoc := self iconForMatchKey:mimeTypeOrKey. |
|
197 |
assoc notNil ifTrue:[^ assoc value]. |
|
198 |
^ nil. |
|
199 |
! |
|
200 |
||
201 |
iconForMatchKey:matchKey |
|
202 |
||
1875 | 203 |
^ self matchedIcons detect:[:assoc | assoc key match:matchKey] ifNone:nil. |
1862 | 204 |
! |
205 |
||
206 |
iconKeyForFile:aFilenameArg |
|
207 |
"given a fileName, return an appropriate icon" |
|
208 |
||
209 |
|aFilename fileType mimeType suffix| |
|
210 |
||
211 |
aFilename := aFilenameArg. |
|
212 |
||
213 |
aFilenameArg isFilename ifTrue:[ |
|
214 |
fileType := self fileTypeIconKeyFor:aFilename. |
|
215 |
] ifFalse:[ |
|
216 |
fileType := #file |
|
217 |
]. |
|
218 |
||
219 |
(fileType == #directory) ifFalse:[ |
|
220 |
suffix := aFilename suffix. |
|
221 |
(suffix = 'bak' or:[suffix = 'sav']) ifTrue:[ |
|
222 |
aFilename := aFilename withoutSuffix. |
|
223 |
]. |
|
224 |
mimeType := MIMETypes mimeTypeForFilename:aFilename. |
|
225 |
]. |
|
226 |
||
227 |
^ (mimeType ? fileType). |
|
228 |
! |
|
229 |
||
230 |
iconKeyForRemoteDirectory:aFilenameArg |
|
231 |
"given a fileName, return an appropriate icon" |
|
232 |
||
233 |
^ #directoryNetwork |
|
1875 | 234 |
! |
235 |
||
236 |
icons |
|
237 |
Icons isNil ifTrue:[ |
|
238 |
self initializeIcons |
|
239 |
]. |
|
240 |
^ Icons |
|
241 |
! |
|
242 |
||
243 |
matchedIcons |
|
244 |
MatchedIcons isNil ifTrue:[ |
|
245 |
self initializeIcons |
|
246 |
]. |
|
247 |
^ MatchedIcons |
|
1859 | 248 |
! ! |
249 |
||
1865 | 250 |
!MIMETypeIconLibrary class methodsFor:'documentation'! |
1859 | 251 |
|
252 |
version |
|
1956
7bfc5c973c1b
classResources now understood by all classes
Claus Gittinger <cg@exept.de>
parents:
1877
diff
changeset
|
253 |
^ '$Header: /cvs/stx/stx/libview2/MIMETypeIconLibrary.st,v 1.12 2004-03-12 12:43:46 cg Exp $' |
1859 | 254 |
! ! |
255 |
||
1865 | 256 |
MIMETypeIconLibrary initialize! |