~bas-dotbas/do/win32-next

« back to all changes in this revision

Viewing changes to PluginLib/src/Builtin/DirectoryFileItemSource.cs

  • Committer: djsiegel at gmail
  • Date: 2007-10-13 21:55:22 UTC
  • Revision ID: djsiegel@gmail.com-20071013215522-n0vjgog0tyjfnpno
Restructured plugins library.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// RecentFileItemSource.cs created with MonoDevelop
2
 
// User: dave at 2:18 PM 9/13/2007
3
 
//
4
 
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
5
 
//
6
 
 
7
 
using System;
8
 
using System.Collections.Generic;
9
 
using System.IO;
10
 
 
11
 
using Do.PluginLib;
12
 
 
13
 
namespace Do.PluginLib.Builtin
14
 
{
15
 
        
16
 
        public class DirectoryFileItemSource : IItemSource
17
 
        {
18
 
                
19
 
                List<IItem> items;
20
 
                int levels;
21
 
                string path;
22
 
                bool include_hidden;
23
 
 
24
 
                static DirectoryFileItemSource ()
25
 
                {
26
 
                        Gnome.Vfs.Vfs.Initialize ();
27
 
                }
28
 
 
29
 
                public DirectoryFileItemSource (string path, int levels)
30
 
                {
31
 
                        string home;
32
 
                        
33
 
                        home = System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal);
34
 
                        path = path.Replace ("~", home);
35
 
                        
36
 
                        this.path = path;
37
 
                        this.levels = levels;
38
 
                        this.items = new List<IItem> ();
39
 
                        this.include_hidden = false;
40
 
                        UpdateItems ();
41
 
                }
42
 
                
43
 
                public string Name {
44
 
                        get { return path; }
45
 
                }
46
 
                
47
 
                public string Description {
48
 
                        get { return string.Format("Finds items in directory '{0}'", path); }
49
 
                }
50
 
                
51
 
                public string Icon {
52
 
                        get { return "folder"; }
53
 
                }
54
 
                
55
 
                public ICollection<IItem> Items {
56
 
                        get { return items; }
57
 
                }
58
 
                
59
 
                public bool UpdateItems ()
60
 
                {
61
 
                        ReadItems (path, levels);
62
 
                        return true;
63
 
                }
64
 
                
65
 
                protected virtual void ReadItems (string dir, int levels)
66
 
                {
67
 
                        string[] files;
68
 
                        string[] directories;
69
 
                        FileItem item;
70
 
                        
71
 
                        if (levels == 0) return;
72
 
                        try {
73
 
                                files = Directory.GetFiles (dir);
74
 
                                directories = Directory.GetDirectories (dir);
75
 
                        } catch (DirectoryNotFoundException) {
76
 
                                return;
77
 
                        }
78
 
                        foreach (string file in files) {
79
 
                                if (!include_hidden && Path.GetFileName (file).StartsWith (".")) {
80
 
                                        continue;
81
 
                                }
82
 
                                item = FileItem.Create (file);
83
 
                                items.Add (item);
84
 
                        }
85
 
                        foreach (string directory in directories) {
86
 
                                if (!include_hidden && Path.GetFileName (directory).StartsWith (".")) {
87
 
                                        continue;
88
 
                                }
89
 
                                item = FileItem.Create (directory);
90
 
                                items.Add (item);
91
 
                                ReadItems (directory, levels - 1);
92
 
                        }
93
 
                }
94
 
        }
95
 
}