~cszikszoy/do-plugins/fix-confluence

« back to all changes in this revision

Viewing changes to Shelf/src/ShelfItemSource.cs

Add shelf plugin.  Initial import.  May still have bugs from transition out of core.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ShelfItemSource.cs
 
2
//
 
3
//GNOME Do is the legal property of its developers. Please refer to the
 
4
//COPYRIGHT file distributed with this
 
5
//source distribution.
 
6
//
 
7
// This program is free software; you can redistribute it and/or modify
 
8
// it under the terms of the GNU General Public License as published by
 
9
// the Free Software Foundation; either version 2 of the License, or
 
10
// (at your option) any later version.
 
11
//
 
12
// This program is distributed in the hope that it will be useful,
 
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
15
// GNU General Public License for more details.
 
16
// 
 
17
// You should have received a copy of the GNU General Public License
 
18
// along with this program; if not, write to the Free Software
 
19
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
20
//
 
21
//
 
22
 
 
23
using System;
 
24
using System.IO;
 
25
using System.Collections.Generic;
 
26
using System.Runtime.Serialization;
 
27
using System.Runtime.Serialization.Formatters.Binary;
 
28
 
 
29
using Do.Universe;
 
30
 
 
31
namespace Do.Universe
 
32
{       
 
33
        public class ShelfItem : IItem
 
34
        {
 
35
                private string name;
 
36
                
 
37
                private List<IItem> items = new List<IItem> ();
 
38
                
 
39
                public List<IItem> Items {
 
40
                        get {
 
41
                                return items ?? items = new List<IItem> ();
 
42
                        }
 
43
                }
 
44
                
 
45
                public ShelfItem (string name)
 
46
                {
 
47
                        this.name = name;
 
48
                }
 
49
                
 
50
                public string ShelfName {
 
51
                        get {
 
52
                                return name;
 
53
                        }
 
54
                }
 
55
                
 
56
                public string Name {
 
57
                        get {
 
58
                                return name + " Shelf";
 
59
                        }
 
60
                }
 
61
                
 
62
                public string Description {
 
63
                        get {
 
64
                                return "Your " + name + " Shelf Items";
 
65
                        }
 
66
                }
 
67
 
 
68
                public string Icon {
 
69
                        get {
 
70
                                return "folder-saved-search";
 
71
                        }
 
72
                }
 
73
                
 
74
                public void AddItem (IItem item)
 
75
                {
 
76
                        if (Items.Contains (item)) return;
 
77
                
 
78
                        Items.Add (item); //temp items
 
79
                }
 
80
                
 
81
                public void RemoveItem (IItem item)
 
82
                {
 
83
                        Items.Remove (item);
 
84
                }
 
85
        }
 
86
        
 
87
        public class ShelfItemSource : IItemSource
 
88
        {       
 
89
                
 
90
                static Dictionary<string,ShelfItem> shelf;
 
91
                static string defaultName;
 
92
                
 
93
                public string Name {
 
94
                        get {
 
95
                                return "Shelf Item Source";
 
96
                        }
 
97
                }
 
98
 
 
99
                public string Description {
 
100
                        get {
 
101
                                return "Your Shelf Items";
 
102
                        }
 
103
                }
 
104
 
 
105
                public string Icon {
 
106
                        get {
 
107
                                return "folder-saved-search";
 
108
                        }
 
109
                }
 
110
 
 
111
                public Type[] SupportedItemTypes {
 
112
                        get {
 
113
                                return new Type [] {
 
114
                                        typeof (ShelfItem),
 
115
                                };
 
116
                        }
 
117
                }
 
118
 
 
119
                public ICollection<IItem> Items {
 
120
                        get {
 
121
                                List<IItem> items = new List<IItem> ();
 
122
                                if (shelf != null) {
 
123
                                        foreach (IItem item in shelf.Values)
 
124
                                                items.Add (item);
 
125
                                }
 
126
                                
 
127
                                return items;
 
128
                        }
 
129
                }
 
130
                
 
131
                public ICollection<IItem> ChildrenOfItem (IItem item)
 
132
                {
 
133
                        return (item as ShelfItem).Items;
 
134
                }
 
135
 
 
136
                static ShelfItemSource ()
 
137
                {
 
138
                        shelf = new Dictionary<string,ShelfItem> ();
 
139
                }
 
140
                
 
141
                public ShelfItemSource ()
 
142
                {
 
143
                        defaultName = "Default";
 
144
                        
 
145
                        if (shelf.Count == 0) {
 
146
                                shelf.Add (defaultName, new ShelfItem (defaultName));
 
147
                        }
 
148
                }
 
149
 
 
150
                public void UpdateItems ()
 
151
                {
 
152
                }
 
153
                
 
154
                static public void AddToDefault (IItem item)
 
155
                {
 
156
                        shelf[defaultName].AddItem (item);
 
157
                }
 
158
                
 
159
                static public void RemoveFromDefault (IItem item)
 
160
                {
 
161
                        shelf[defaultName].RemoveItem (item);
 
162
                }
 
163
        }
 
164
}