1863
|
1 |
"{ Package: 'stx:libview2' }"
|
1859
|
2 |
|
|
3 |
Object subclass:#MimeTypeIconLibrary
|
|
4 |
instanceVariableNames:''
|
1860
|
5 |
classVariableNames:'Icons MatchedIcons'
|
1859
|
6 |
poolDictionaries:''
|
|
7 |
category:'Interface-Smalltalk'
|
|
8 |
!
|
|
9 |
|
|
10 |
|
|
11 |
!MimeTypeIconLibrary class methodsFor:'initialization'!
|
|
12 |
|
|
13 |
initialize
|
1860
|
14 |
self initializeIcons
|
1859
|
15 |
!
|
|
16 |
|
|
17 |
initializeFileTypeIcons
|
|
18 |
|resources|
|
|
19 |
|
|
20 |
resources := ResourcePack for:self.
|
|
21 |
|
|
22 |
#(
|
|
23 |
"/ internal-type to icon mappings.
|
|
24 |
(#directory 'ICON_DIRECTORY' 'tiny_yellow_dir.xpm' )
|
|
25 |
(#directoryOpen 'ICON_DIRECTORY_OPEN' 'tiny_yellow_dir_open.xpm' )
|
|
26 |
(#directoryLocked 'ICON_DIRECTORY_LOCKED' 'tiny_yellow_dir_locked.xpm' )
|
|
27 |
(#directoryLink 'ICON_DIRECTORY_LINK' 'tiny_yellow_dir_link.xpm' )
|
|
28 |
(#directoryNetwork 'ICON_DIRECTORY_NETWORK' 'tiny_yellow_dir_network.xpm' )
|
|
29 |
(#file 'ICON_FILE' 'tiny_file_plain.xpm' )
|
|
30 |
(#fileLink 'ICON_FILE_LINK' 'tiny_file_link.xpm' )
|
|
31 |
(#fileLocked 'ICON_FILE_LOCKED' 'tiny_file_lock.xpm' )
|
|
32 |
(#imageFile 'ICON_IMAGE_FILE' 'tiny_file_pix.xpm' )
|
|
33 |
(#textFile 'ICON_TEXT_FILE' 'tiny_file_text.xpm' )
|
|
34 |
(#executableFile 'ICON_EXECUTABLEFILE' 'tiny_file_exec.xpm' )
|
|
35 |
(#deviceFile 'ICON_DEVICE_FILE' 'tiny_file_device.xpm' )
|
|
36 |
(#binaryFile 'ICON_BINARY_FILE' 'tiny_file_binary.xpm' )
|
|
37 |
(#specialFile 'ICON_SPECIALFILE' 'tiny_file_special.xpm' )
|
|
38 |
|
|
39 |
(#addOnLocked 'ICON_ADDON_LOCKED' 'tiny_addOn_lock.xpm' )
|
|
40 |
(#addOnLinked 'ICON_ADDON_LINKED' 'tiny_addOn_link.xpm' )
|
|
41 |
|
|
42 |
(#directoryGray 'ICON_DIRECTORY_GRAY' 'tiny_yellow_dir_gray.xpm' )
|
|
43 |
(#directoryOpenGray 'ICON_DIRECTORY_OPEN_GRAY' 'tiny_yellow_dir_open_gray.xpm' )
|
|
44 |
) do:[:entry |
|
|
45 |
|key resource defaultName nm img|
|
|
46 |
|
|
47 |
key := entry at:1.
|
|
48 |
resource := entry at:2.
|
|
49 |
defaultName := entry at:3.
|
|
50 |
|
|
51 |
resource notNil ifTrue:[
|
|
52 |
nm := resources at:resource default:nil.
|
|
53 |
].
|
|
54 |
nm isNil ifTrue:[
|
|
55 |
nm := 'xpmBitmaps/document_images/' , defaultName
|
|
56 |
].
|
|
57 |
Icons at:key put:(Smalltalk imageFromFileNamed:nm forClass:self).
|
|
58 |
]
|
|
59 |
|
|
60 |
"
|
|
61 |
self initializeFileTypeIcons
|
|
62 |
"
|
|
63 |
!
|
|
64 |
|
|
65 |
initializeIcons
|
|
66 |
Icons := Dictionary new.
|
|
67 |
MatchedIcons := OrderedCollection new.
|
|
68 |
self initializeFileTypeIcons.
|
|
69 |
self initializeMimeTypeIcons.
|
|
70 |
|
|
71 |
"
|
|
72 |
self initializeIcons
|
|
73 |
"
|
|
74 |
|
|
75 |
"Modified: / 1.8.1998 / 17:39:27 / cg"
|
|
76 |
!
|
|
77 |
|
|
78 |
initializeMimeTypeIcons
|
|
79 |
#(
|
|
80 |
"/ mime-type to icon mappings.
|
|
81 |
"/ 'image/jpeg' 'tiny_file_pix.xpm'
|
|
82 |
"/ 'image/gif' 'tiny_file_pix.xpm'
|
|
83 |
"/ 'image/tiff' 'tiny_file_pix.xpm'
|
|
84 |
"/ 'image/x-xbitmap' 'tiny_file_pix.xpm'
|
|
85 |
"/ 'image/x-xpixmap' 'tiny_file_pix.xpm'
|
|
86 |
"/ 'image/x-png' 'tiny_file_pix.xpm'
|
|
87 |
"/ 'image/x-photo-cd' 'tiny_file_pix.xpm'
|
|
88 |
"/ 'image/x-MS-bmp' 'tiny_file_pix.xpm'
|
|
89 |
"/ 'image/x-rgb' 'tiny_file_pix.xpm'
|
|
90 |
"/ 'image/x-portable-pixmap' 'tiny_file_pix.xpm'
|
|
91 |
"/ 'image/x-portable-graymap' 'tiny_file_pix.xpm'
|
|
92 |
"/ 'image/x-portable-bitmap' 'tiny_file_pix.xpm'
|
|
93 |
"/ 'image/x-portable-anymap' 'tiny_file_pix.xpm'
|
|
94 |
"/ 'image/x-xwindowdump' 'tiny_file_pix.xpm'
|
|
95 |
"/ 'image/x-cmu-raster' 'tiny_file_pix.xpm'
|
|
96 |
"/ 'image/x-targa' 'tiny_file_pix.xpm'
|
|
97 |
'image/*' 'tiny_file_pix.xpm'
|
|
98 |
|
|
99 |
"/ misc text ...
|
|
100 |
|
|
101 |
'text/html' 'tiny_file_html.xpm'
|
|
102 |
"/ 'text/plain' 'tiny_file_text.xpm'
|
|
103 |
'text/*' 'tiny_file_text.xpm'
|
|
104 |
|
|
105 |
'application/postscript' 'tiny_file_postscript.xpm'
|
|
106 |
'application/pdf' 'tiny_file_pdf.xpm'
|
|
107 |
'application/rtf' 'tiny_file_rtf.xpm'
|
|
108 |
|
|
109 |
"/ video formats ...
|
|
110 |
|
|
111 |
"/ 'video/x-sgi-movie' 'tiny_file_movie.xpm'
|
|
112 |
"/ 'video/x-msvideo' 'tiny_file_movie.xpm'
|
|
113 |
"/ 'video/quicktime' 'tiny_file_movie.xpm'
|
|
114 |
"/ 'video/x-mpeg2' 'tiny_file_movie.xpm'
|
|
115 |
"/ 'video/mpeg' 'tiny_file_movie.xpm'
|
|
116 |
'video/*' 'tiny_file_movie2.xpm'
|
|
117 |
'application/vnd.rn-realmedia' 'tiny_file_movie2.xpm'
|
|
118 |
|
|
119 |
"/ audio formats ...
|
|
120 |
|
|
121 |
"/ 'audio/x-pn-realaudio' 'tiny_file_sound.xpm'
|
|
122 |
"/ 'audio/x-mpeg' 'tiny_file_sound.xpm'
|
|
123 |
"/ 'audio/x-mp3' 'tiny_file_sound.xpm'
|
|
124 |
"/ 'audio/x-wav' 'tiny_file_sound.xpm'
|
|
125 |
"/ 'audio/x-aiff' 'tiny_file_sound.xpm'
|
|
126 |
"/ 'audio/basic' 'tiny_file_sound.xpm'
|
|
127 |
"/ 'audio/x-shockwave-flash' 'tiny_file_sound.xpm'
|
|
128 |
'audio/*' 'tiny_file_sound.xpm'
|
|
129 |
|
|
130 |
"/ misc stuff
|
|
131 |
'application/winword' 'tiny_file_text.xpm'
|
|
132 |
|
|
133 |
"/ binary formats
|
|
134 |
'application/binary' 'tiny_file_binary.xpm'
|
|
135 |
'application/library' 'tiny_file_binary.xpm'
|
|
136 |
'application/shared-library' 'tiny_file_binary.xpm'
|
|
137 |
|
|
138 |
"/ progr. languages
|
|
139 |
'application/x-smalltalk-source' 'tiny_file_st.xpm'
|
|
140 |
'application/x-smalltalk-source-sif' 'tiny_file_text.xpm'
|
|
141 |
'application/x-c-source' 'tiny_file_text.xpm'
|
|
142 |
'application/x-c-header' 'tiny_file_text.xpm'
|
|
143 |
'application/x-cpp-source' 'tiny_file_text.xpm'
|
|
144 |
'application/x-javascript' 'tiny_file_text.xpm'
|
|
145 |
'application/x-java-source' 'tiny_file_java.xpm'
|
|
146 |
|
|
147 |
'application/x-sh' 'tiny_file_text.xpm'
|
|
148 |
'application/x-csh' 'tiny_file_text.xpm'
|
|
149 |
'application/x-tcl' 'tiny_file_text.xpm'
|
|
150 |
'application/x-perl' 'tiny_file_text.xpm'
|
|
151 |
'application/x-make' 'tiny_file_text.xpm'
|
|
152 |
'application/x-batch-script' 'tiny_file_text.xpm'
|
|
153 |
'application/x-asn1-source' 'tiny_file_text.xpm'
|
|
154 |
|
|
155 |
"/ compressors / archivers
|
|
156 |
'application/x-tar' 'tiny_file_archive.xpm'
|
|
157 |
'application/x-gtar' 'tiny_file_archive.xpm'
|
|
158 |
'application/x-tar-compressed' 'tiny_file_compressed_archive.xpm'
|
|
159 |
'application/x-zip-compressed' 'tiny_file_compressed_archive.xpm'
|
|
160 |
'application/x-gzip-compressed' 'tiny_file_compressed_archive.xpm'
|
|
161 |
'application/x-cpio' 'tiny_file_archive.xpm'
|
|
162 |
'application/x-shar' 'tiny_file_archive.xpm'
|
|
163 |
'application/java-archive' 'tiny_file_archive.xpm'
|
|
164 |
|
|
165 |
'*' 'tiny_file_plain.xpm'
|
|
166 |
) pairWiseDo:[:mimeTypePattern :fileName |
|
|
167 |
| nm |
|
|
168 |
|
|
169 |
nm := 'xpmBitmaps/document_images/' , fileName.
|
|
170 |
mimeTypePattern includesMatchCharacters ifTrue:[
|
|
171 |
MatchedIcons add:(mimeTypePattern-> (Smalltalk imageFromFileNamed:nm forClass:self)).
|
|
172 |
] ifFalse:[
|
|
173 |
Icons at:mimeTypePattern put:(Smalltalk imageFromFileNamed:nm forClass:self).
|
|
174 |
]
|
|
175 |
]
|
|
176 |
|
|
177 |
"
|
|
178 |
self initializeIcons
|
|
179 |
"
|
|
180 |
! !
|
|
181 |
|
|
182 |
!MimeTypeIconLibrary class methodsFor:'accessing'!
|
|
183 |
|
1862
|
184 |
fileTypeIconKeyFor:aFilename
|
|
185 |
aFilename isSymbolicLink ifTrue:[
|
|
186 |
^ #symbolicLink.
|
|
187 |
].
|
|
188 |
aFilename isDirectory ifTrue:[
|
|
189 |
^ #directory.
|
|
190 |
].
|
|
191 |
aFilename isSpecialFile ifTrue:[
|
|
192 |
^ #specialFile.
|
|
193 |
].
|
|
194 |
aFilename isExecutableProgram ifTrue:[
|
|
195 |
^ #executableFile
|
|
196 |
].
|
|
197 |
^ #file.
|
|
198 |
!
|
|
199 |
|
1860
|
200 |
iconForKey:mimeTypeOrKey
|
1859
|
201 |
|
1860
|
202 |
^ Icons at:mimeTypeOrKey ifAbsent:nil.
|
|
203 |
!
|
1859
|
204 |
|
1860
|
205 |
iconForKeyMatching:mimeTypeOrKey
|
|
206 |
|
1861
|
207 |
|icn assoc|
|
|
208 |
|
|
209 |
icn := self iconForKey:mimeTypeOrKey.
|
|
210 |
icn notNil ifTrue:[^icn].
|
|
211 |
assoc := self iconForMatchKey:mimeTypeOrKey.
|
|
212 |
assoc notNil ifTrue:[^ assoc value].
|
|
213 |
^ nil.
|
|
214 |
!
|
|
215 |
|
|
216 |
iconForMatchKey:matchKey
|
|
217 |
|
|
218 |
^ MatchedIcons detect:[:assoc | assoc key match:matchKey] ifNone:nil.
|
1862
|
219 |
!
|
|
220 |
|
|
221 |
iconKeyForFile:aFilenameArg
|
|
222 |
"given a fileName, return an appropriate icon"
|
|
223 |
|
|
224 |
|aFilename fileType mimeType suffix|
|
|
225 |
|
|
226 |
aFilename := aFilenameArg.
|
|
227 |
|
|
228 |
aFilenameArg isFilename ifTrue:[
|
|
229 |
fileType := self fileTypeIconKeyFor:aFilename.
|
|
230 |
] ifFalse:[
|
|
231 |
fileType := #file
|
|
232 |
].
|
|
233 |
|
|
234 |
(fileType == #directory) ifFalse:[
|
|
235 |
suffix := aFilename suffix.
|
|
236 |
(suffix = 'bak' or:[suffix = 'sav']) ifTrue:[
|
|
237 |
aFilename := aFilename withoutSuffix.
|
|
238 |
].
|
|
239 |
mimeType := MIMETypes mimeTypeForFilename:aFilename.
|
|
240 |
].
|
|
241 |
|
|
242 |
^ (mimeType ? fileType).
|
|
243 |
!
|
|
244 |
|
|
245 |
iconKeyForRemoteDirectory:aFilenameArg
|
|
246 |
"given a fileName, return an appropriate icon"
|
|
247 |
|
|
248 |
^ #directoryNetwork
|
1859
|
249 |
! !
|
|
250 |
|
|
251 |
!MimeTypeIconLibrary class methodsFor:'documentation'!
|
|
252 |
|
|
253 |
version
|
1863
|
254 |
^ '$Header: /cvs/stx/stx/libview2/MIMETypeIconLibrary.st,v 1.5 2003-12-01 17:22:55 cg Exp $'
|
1859
|
255 |
! !
|
|
256 |
|
|
257 |
MimeTypeIconLibrary initialize!
|