~bas-dotbas/do/win32-next

« back to all changes in this revision

Viewing changes to Do/src/Do.Core/ItemSource.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
// ItemSource.cs created with MonoDevelop
 
2
// User: dave at 1:08 AM 8/17/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
 
 
10
using Do.Universe;
 
11
 
 
12
namespace Do.Core
 
13
{
 
14
        
 
15
        public class ItemSource : GCObject 
 
16
        {
 
17
        
 
18
                public static readonly string DefaultItemSourceName = "";
 
19
                public static readonly string DefaultItemSourceDescription = "";
 
20
                public static readonly string DefaultItemSourceIcon = "";
 
21
                
 
22
                private bool enabled;
 
23
                protected IItemSource source;
 
24
                protected List<Item> items;
 
25
                
 
26
                public ItemSource (IItemSource source)
 
27
                {
 
28
                        if (source == null) {
 
29
                                throw new ArgumentNullException ();
 
30
                        }
 
31
                        this.source = source;
 
32
                        items = new List<Item> ();
 
33
                        foreach (IItem item in source.Items) {
 
34
                                items.Add (new Item (item));
 
35
                        }
 
36
                        enabled = true;
 
37
                }
 
38
                
 
39
                public override string Name {
 
40
                        get { return (source.Name == null ? DefaultItemSourceName : source.Name); }
 
41
                }
 
42
                
 
43
                public override string Description {
 
44
                        get { return (source.Description == null ? DefaultItemSourceDescription : source.Description); }
 
45
                }
 
46
                
 
47
                public override string Icon {
 
48
                        get { return (source.Icon == null ? DefaultItemSourceIcon : source.Icon); }
 
49
                }
 
50
                
 
51
                public bool UpdateItems () {
 
52
                        if (source.UpdateItems ()) {
 
53
                                items.Clear ();
 
54
                                items = new List<Item> ();
 
55
                                foreach (IItem item in source.Items) {
 
56
                                        items.Add (new Item (item));
 
57
                                }
 
58
                                return true;
 
59
                        } else {
 
60
                                return false;
 
61
                        }
 
62
                }
 
63
                
 
64
                public ICollection<Item> Items {
 
65
                        get { return items; }
 
66
                }
 
67
                
 
68
                public bool Enabled {
 
69
                        get { return enabled; }
 
70
                        set { enabled = value; }
 
71
                }
 
72
                
 
73
                public override string ToString ()
 
74
                {
 
75
                        string items_str = GetType().ToString() + " {";
 
76
                        foreach (Item item in items) {
 
77
                                items_str = String.Format ("{0}\t{1}\n", items_str, item);
 
78
                        }
 
79
                        items_str += "}";
 
80
                        return items_str;
 
81
                }
 
82
                
 
83
        }
 
84
}