1:   //  RecentOpen.cs
2:   //  Copyright (C) 2001 Mike Krueger
3:   // 
4:   //  This program is free software; you can redistribute it and/or modify
5:   //  it under the terms of the GNU General Public License as published by
6:   //  the Free Software Foundation; either version 2 of the License, or
7:   //  (at your option) any later version.
8:   //
9:   //  This program is distributed in the hope that it will be useful,
10:   //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11:   //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12:   //  GNU General Public License for more details.
13:   //
14:   //  You should have received a copy of the GNU General Public License
15:   //  along with this program; if not, write to the Free Software
16:   //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17:  
18:   using System;
19:   using System.Xml;
20:   using System.Diagnostics;
21:   using System.Collections;
22:   using System.IO;
23:  
24:   using Core.Properties;
25:  
26:   namespace SharpDevelop.Gui {
27:  
28:       /// <summary>
29:       /// This class handles the recent open files and the recent open project files of SharpDevelop
30:       /// it checks, if the files exists at every creation, and if not it doesn't list them in the 
31:       /// recent files, and they'll not be saved during the next option save.
32:       /// </summary>
33:       public class RecentOpen : IXmlConvertable
34:       {
35:           /// <summary>
36:           /// This variable is the maximal length of lastfile/lastopen entries
37:           /// must be > 0
38:           /// </summary>
39:           int MAX_LENGTH 10;
40:           
41:           ArrayList lastfile    new ArrayList();
42:           ArrayList lastproject new ArrayList();
43:           
44:           public event EventHandler RecentFileChanged;
45:           public event EventHandler RecentProjectChanged;
46:           
47:           public ArrayList RecentFile {
48:               get {
49:                   Debug.Assert(lastfile != null"RecentOpen : set string[] LastFile (value == null)");
50:                   return lastfile;
51:               }
52:           }
53:  
54:           public ArrayList RecentProject {
55:               get {
56:                   Debug.Assert(lastproject != null"RecentOpen : set string[] LastProject (value == null)");
57:                   return lastproject;
58:               }
59:           }
60:           
61:           void OnRecentFileChange()
62:           {
63:               if (RecentFileChanged != null) {
64:                   RecentFileChanged(thisnull);
65:               }
66:           }
67:           
68:           void OnRecentProjectChange()
69:           {
70:               if (RecentProjectChanged != null) {
71:                   RecentProjectChanged(thisnull);
72:               }
73:           }
74:  
75:           public RecentOpen()
76:           {
77:               
78:           }
79:           
80:           public RecentOpen(XmlElement element)
81:           {
82:               XmlNodeList nodes element["FILES"].ChildNodes;
83:               
84:               for (int 0nodes.Count; ++i) {
85:                   if (File.Exists(nodes[i].InnerText)) {
86:                       lastfile.Add(nodes[i].InnerText);
87:                   }
88:               }
89:               
90:               nodes  element["PROJECTS"].ChildNodes;
91:               
92:               for (int 0nodes.Count; ++i) {
93:                   if (File.Exists(nodes[i].InnerText)) {
94:                       lastproject.Add(nodes[i].InnerText);
95:                   }
96:               }
97:           }
98:           
99:           public void AddLastFile(string name// TODO : improve 
100:           {
101:               for (int 0lastfile.Count; ++i)
102:                   if (lastfile[i].ToString() == name)
103:                       lastfile.RemoveAt(i);
104:               
105:               while (lastfile.Count >= MAX_LENGTH
106:                   lastfile.RemoveAt(lastfile.Count 1);
107:               
108:               if (lastfile.Count 0)
109:                   lastfile.Insert(0name);
110:               else
111:                   lastfile.Add(name);
112:               
113:               OnRecentFileChange();
114:           }
115:           
116:           public void AddLastProject(string name// TODO : improve
117:           {
118:               for (int 0lastproject.Count; ++i)
119:                   if (lastproject[i].ToString() == name)
120:                       lastproject.RemoveAt(i);
121:               
122:               while (lastproject.Count >= MAX_LENGTH
123:                   lastproject.RemoveAt(lastproject.Count 1);
124:               
125:               if (lastproject.Count 0)
126:                   lastproject.Insert(0name);
127:               else {
128:                   lastproject.Add(name);            
129:               }
130:               OnRecentProjectChange();
131:           }
132:           
133:           public object     FromXmlElement(XmlElement element)
134:           {
135:               return new RecentOpen(element);
136:           }
137:           
138:           public XmlElement ToXmlElement(XmlDocument doc)
139:           {
140:               XmlElement recent doc.CreateElement("RECENT");
141:               
142:               XmlElement lastfiles doc.CreateElement("FILES");
143:               foreach (string file in lastfile) {
144:                   XmlElement element doc.CreateElement("FILE");
145:                   element.InnerText  file;
146:                   lastfiles.AppendChild(element);
147:               }
148:               
149:               XmlElement lastprojects doc.CreateElement("PROJECTS");
150:               foreach (string project in lastproject) {
151:                   XmlElement element doc.CreateElement("PROJECT");
152:                   element.InnerText project;
153:                   lastprojects.AppendChild(element);
154:               }
155:               
156:               recent.AppendChild(lastfiles);
157:               recent.AppendChild(lastprojects);
158:               
159:               return recent;
160:           }
161:       }
162:   }

This page was automatically generated by SharpDevelop.