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