[Monodevelop-patches-list] r1075 - trunk/MonoDevelop/src/Main/Base/Services/File

commit-watcher at mono-cvs.ximian.com commit-watcher at mono-cvs.ximian.com
Mon Mar 1 19:20:02 EST 2004


Author: jluke
Date: 2004-03-01 19:20:02 -0500 (Mon, 01 Mar 2004)
New Revision: 1075

Added:
   trunk/MonoDevelop/src/Main/Base/Services/File/FdoRecentFiles.cs
   trunk/MonoDevelop/src/Main/Base/Services/File/RecentItem.cs
Log:
beginning of Freedesktop.org recent files implementation
untested and not in the build


Added: trunk/MonoDevelop/src/Main/Base/Services/File/FdoRecentFiles.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Services/File/FdoRecentFiles.cs	2004-03-01 21:42:30 UTC (rev 1074)
+++ trunk/MonoDevelop/src/Main/Base/Services/File/FdoRecentFiles.cs	2004-03-02 00:20:02 UTC (rev 1075)
@@ -0,0 +1,125 @@
+//
+// Author: John Luke  <jluke at cfl.rr.com>
+//
+// Copyright 2004 John Luke
+//
+
+using System;
+using System.Collections;
+using System.IO;
+using System.Xml;
+using System.Xml.XPath;
+
+// implementation of the freedesktop.org Recent Files spec
+// http://freedesktop.org/Standards/recent-file-spec/recent-file-spec-0.2.html
+
+namespace ICSharpCode.SharpDevelop.Services
+{
+	public class FdoRecentFiles
+	{
+		// The document should be stored in "~/.recently-used",
+
+		// and it should contain no more than 500 items.
+		int totalMaxLength = 500;
+
+		// MD only wants to save last 10 in its group
+		int maxLength = 10;                                            
+        ArrayList lastfile = new ArrayList();
+        ArrayList lastproject = new ArrayList();
+
+		XmlDocument doc;
+
+		public event EventHandler RecentFileChanged;
+        public event EventHandler RecentProjectChanged;
+
+		public FdoRecentFiles ()
+		{
+			string recentFile = Environment.GetEnvironmentVariable ("HOME");
+			recentFile = Path.Combine (recentFile, ".recently_used");
+			Console.WriteLine (recentFile);
+
+			if (File.Exists (recentFile))
+			{
+				// use POSIX lockf ()
+				doc = new XmlDocument ();
+				doc.Load (recentFile);
+
+				XPathNavigator nav = doc.CreateNavigator ();
+				XPathNodeIterator xni = nav.Select ("/RecentFiles/RecentItem");
+				Console.WriteLine ("Total Items {0}", xni.Count);
+			}
+			else
+			{
+				// use POSIX lockf ()
+				Console.WriteLine ("{0} does not exist.", recentFile);
+				// create it
+			}
+
+			FileSystemWatcher watcher = new FileSystemWatcher (recentFile);
+			watcher.Changed += new FileSystemEventHandler (OnWatcherChanged);
+		}
+
+		void OnWatcherChanged (object o, FileSystemEventArgs args)
+		{
+			// TODO
+			// decide if projects or files changed or both
+			Console.WriteLine ("on watcher changed");
+		}
+
+		void OnRecentFileChange ()
+        {
+            if (RecentFileChanged != null)
+			{
+                RecentFileChanged (this, null);
+            }
+        }
+                                                                       
+        void OnRecentProjectChange ()
+        {
+            if (RecentProjectChanged != null)
+			{
+                RecentProjectChanged (this, null);
+            }
+        }
+
+		public ArrayList RecentFiles
+		{
+            get
+			{
+				return lastfile;
+            }
+        }
+                                                                       
+        public ArrayList RecentProjects
+		{
+            get
+			{
+                return lastproject;
+            }
+        }
+
+		public void AddFile (string file_uri)
+		{
+			// uri must be unique
+			// or just update timestamp and group
+		}
+
+		public void AddProject (string file_uri)
+		{
+			// uri must be unique
+			// or just update timestamp and group
+		}
+
+		// spec doesn't mention removal
+		public void ClearFiles ()
+		{
+
+		}
+
+		// spec doesn't mention removal
+		public void ClearProjects ()
+		{
+
+		}
+	}
+}

Added: trunk/MonoDevelop/src/Main/Base/Services/File/RecentItem.cs
===================================================================
--- trunk/MonoDevelop/src/Main/Base/Services/File/RecentItem.cs	2004-03-01 21:42:30 UTC (rev 1074)
+++ trunk/MonoDevelop/src/Main/Base/Services/File/RecentItem.cs	2004-03-02 00:20:02 UTC (rev 1075)
@@ -0,0 +1,55 @@
+//
+// Author: John Luke  <jluke at cfl.rr.com>
+//
+// Copyright 2004 John Luke
+//
+
+// support class for FdoRecentFiles.cs
+
+using System;
+using MonoDevelop.Gui.Utils;
+
+namespace ICSharpCode.SharpDevelop.Services
+{
+	public class RecentItem
+	{
+		// must be a valid uri ex. file://
+		private string uri;
+		private string mime;
+		// the number of seconds sinced the Epoch when the item was added to the list.
+		private string timestamp;
+		// may need to change to allow for > 1
+		// lets wait til it's needed though
+		private string group;
+		
+		// these 3 are required
+		public RecentItem (string uri)
+		{
+			this.uri = uri;
+			this.mime = Vfs.GetMimeType (uri);
+			// FIXME 00:00:00 UTC on January 1, 1970 (Unix Epoch)
+			// Now - Epoch in seconds
+			this.timestamp = DateTime.Now.ToString ();
+		}
+
+		public string Mime
+		{
+			get { return mime; }
+		}
+
+		public string Uri
+		{
+			get { return uri; }
+		}
+
+		public string Timestamp
+		{
+			get { return timestamp; }
+		}
+
+		public string Group
+		{
+			get { return group; }
+		}
+	}
+}




More information about the Monodevelop-patches-list mailing list