1
// FileItem.cs created with MonoDevelop
2
// User: dave at 2:25 PM 9/13/2007
4
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
9
using System.Collections;
13
namespace Do.PluginLib.Builtin
16
public class FileItem : IFileItem
19
static Hashtable extensionTypes;
25
extensionTypes = new Hashtable ();
27
// Register extensions for specialized subclasses.
28
// See note in ImageFileItem.cs
29
extentions = new string[] { "jpg", "jpeg", "png", "gif" };
30
foreach (string ext in extentions) {
31
FileItem.RegisterExtensionForFileItemType (ext, typeof (ImageFileItem));
35
public static bool RegisterExtensionForFileItemType (string ext, Type fi_type)
37
if (extensionTypes.ContainsKey (ext)) {
40
extensionTypes[ext] = fi_type;
44
public static FileItem Create (string uri)
50
ext = System.IO.Path.GetExtension (uri).ToLower ();
51
if (ext.StartsWith (".")) {
52
ext = ext.Substring (1);
54
if (extensionTypes.ContainsKey (ext)) {
55
fi_type = extensionTypes[ext] as Type;
57
fi_type = typeof (FileItem);
60
result = (FileItem) System.Activator.CreateInstance (fi_type, new string[] {uri});
62
result = new FileItem (uri);
67
public static string ShortUri (string uri) {
70
uri = (uri == null ? "" : uri);
71
home = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);
72
uri = uri.Replace (home, "~");
76
string uri, name, icon, mime_type;
78
public FileItem (string uri)
81
this.name = Path.GetFileName (uri);
82
this.mime_type = Gnome.Vfs.Global.GetMimeType (uri);
84
if (System.IO.Directory.Exists (uri)) {
88
icon = mime_type.Replace ('/', '-');
89
icon = string.Format ("gnome-mime-{0}", icon);
90
} catch (NullReferenceException) {
96
public virtual string Name {
100
public virtual string Description {
101
get { return ShortUri (uri); }
104
public virtual string Icon {
112
public string MimeType {
113
get { return mime_type; }