[Monodevelop-patches-list] r2016 - in trunk/MonoDevelop/Core/src/Main/Base: . Commands Services/File
commit-watcher at mono-cvs.ximian.com
commit-watcher at mono-cvs.ximian.com
Tue Nov 2 15:06:23 EST 2004
Author: jluke
Date: 2004-11-02 15:06:23 -0500 (Tue, 02 Nov 2004)
New Revision: 2016
Modified:
trunk/MonoDevelop/Core/src/Main/Base/ChangeLog
trunk/MonoDevelop/Core/src/Main/Base/Commands/AutostartCommands.cs
trunk/MonoDevelop/Core/src/Main/Base/Services/File/RecentFiles.cs
trunk/MonoDevelop/Core/src/Main/Base/Services/File/RecentOpen.cs
Log:
2004-11-02 John Luke <john.luke at gmail.com>
* Services/File/RecentOpen.cs: use simpler RecentFiles AddWithLimit
* Services/File/RecentFiles.cs: sort and return items in the right order
among some other incremental improvements, should also fix bug #68999
* Commands/AutoStartCommands.cs: revert Todds workaround from yesterday
Modified: trunk/MonoDevelop/Core/src/Main/Base/ChangeLog
===================================================================
--- trunk/MonoDevelop/Core/src/Main/Base/ChangeLog 2004-11-02 03:02:12 UTC (rev 2015)
+++ trunk/MonoDevelop/Core/src/Main/Base/ChangeLog 2004-11-02 20:06:23 UTC (rev 2016)
@@ -1,3 +1,10 @@
+2004-11-02 John Luke <john.luke at gmail.com>
+
+ * Services/File/RecentOpen.cs: use simpler RecentFiles AddWithLimit
+ * Services/File/RecentFiles.cs: sort and return items in the right order
+ among some other incremental improvements, should also fix bug #68999
+ * Commands/AutoStartCommands.cs: revert Todds workaround from yesterday
+
2004-11-01 Fawad Halim <fawad at fawad.net>
* Internal/Parser/SharpAssemblyLayer/SharpAssemblyParameter.cs
Modified: trunk/MonoDevelop/Core/src/Main/Base/Commands/AutostartCommands.cs
===================================================================
--- trunk/MonoDevelop/Core/src/Main/Base/Commands/AutostartCommands.cs 2004-11-02 03:02:12 UTC (rev 2015)
+++ trunk/MonoDevelop/Core/src/Main/Base/Commands/AutostartCommands.cs 2004-11-02 20:06:23 UTC (rev 2016)
@@ -62,7 +62,7 @@
RecentOpen recentOpen = ((IFileService)MonoDevelop.Core.Services.ServiceManager.GetService (typeof (IFileService))).RecentOpen;
if (recentOpen.RecentProject != null && recentOpen.RecentProject.Length > 0) {
- projectService.OpenCombine(recentOpen.RecentProject[recentOpen.RecentProject.Length - 1].ToString());
+ projectService.OpenCombine(recentOpen.RecentProject[0].ToString());
}
}
Modified: trunk/MonoDevelop/Core/src/Main/Base/Services/File/RecentFiles.cs
===================================================================
--- trunk/MonoDevelop/Core/src/Main/Base/Services/File/RecentFiles.cs 2004-11-02 03:02:12 UTC (rev 2015)
+++ trunk/MonoDevelop/Core/src/Main/Base/Services/File/RecentFiles.cs 2004-11-02 20:06:23 UTC (rev 2016)
@@ -30,6 +30,10 @@
// implementation of the freedesktop.org Recent Files spec
// http://freedesktop.org/Standards/recent-file-spec/recent-file-spec-0.2.html
+// Note: the file may not exist, apps should account for that themselves
+
+// Lets keep things sorted as we go, and reverse before saving it.
+
namespace Freedesktop.RecentFiles
{
// Currently using XmlSerializer to read/write the recent files list
@@ -59,7 +63,6 @@
[XmlElement ("RecentItem")]
public RecentItem[] RecentItems;
- // FIXME: maybe not write until Save () is called manually
public void AddItem (RecentItem item)
{
if (RecentItems == null)
@@ -96,6 +99,26 @@
Save ();
}
+ // ensure that that only max items are kept in group
+ public void AddWithLimit (RecentItem item, string group, int max)
+ {
+ if (max < 1)
+ throw new ArgumentException ("max must be > 0");
+
+ // we add it first in case the Uri is already there
+ AddItem (item);
+
+ // then we adjust for the limit
+ RecentItem[] inGroup = GetItemsInGroup (group);
+ if (inGroup.Length > max)
+ {
+ while (inGroup.Length > max) {
+ RemoveItem (GetOldestItem (inGroup));
+ inGroup = GetItemsInGroup (group);
+ }
+ }
+ }
+
public void Clear ()
{
RecentItems = null;
@@ -130,26 +153,6 @@
Save ();
}
-/*
- private void ClearMissing ()
- {
- ArrayList list = new ArrayList ();
- foreach (RecentItem ri in RecentItems)
- {
- // we cant test !file:// Uris can we?
- if (!ri.Uri.StartsWith ("file://"))
- list.Add (ri);
- else if (File.Exists (ri.Uri.Substring (7)))
- list.Add (ri);
- }
-
- RecentItem[] items = new RecentItem [list.Count];
- list.CopyTo (items);
- RecentItems = items;
- Save ();
- }
-*/
-
private void EmitChangedEvent ()
{
if (Changed != null)
@@ -163,6 +166,7 @@
XmlTextReader reader = new XmlTextReader (RecentFileStore);
RecentFiles rf = (RecentFiles) serializer.Deserialize (reader);
reader.Close ();
+ rf.Sort ();
return rf;
}
catch (IOException e)
@@ -183,9 +187,6 @@
if (RecentItems == null)
return null;
- // disable for now
- // ClearMissing ();
-
ArrayList list = new ArrayList ();
foreach (RecentItem ri in RecentItems)
{
@@ -201,17 +202,49 @@
return items;
}
+ public RecentItem[] GetMostRecentInGroup (int count, string group)
+ {
+ if (count < 1)
+ throw new ArgumentException ("count must be > 0");
+
+ RecentItem[] inGroup = GetItemsInGroup (group);
+ return GetMostRecent (count, inGroup);
+ }
+
+ public RecentItem[] GetMostRecent (int count)
+ {
+ if (count < 1)
+ throw new ArgumentException ("count must be > 0");
+
+ return GetMostRecent (count, RecentItems);
+ }
+
+ // return the last X items in newest to oldest order
+ private RecentItem[] GetMostRecent (int count, RecentItem[] items)
+ {
+ if (count >= items.Length)
+ {
+ return items;
+ }
+ else
+ {
+ RecentItem[] countedItems = new RecentItem[count];
+ // get the last count items
+ Array.Copy (items, items.Length - count - 1, countedItems, 0, count);
+
+ return countedItems;
+ }
+ }
+
+ public static RecentItem GetOldestItem (RecentItem[] items)
+ {
+ return items[items.Length - 1];
+ }
+
public RecentItem OldestItem
{
get {
- RecentItem item = RecentItems[0];
- for (int i = 1; i < RecentItems.Length; i ++)
- {
- // the lowest number is the oldest
- if (RecentItems[i].Timestamp < item.Timestamp)
- item = RecentItems[i];
- }
- return item;
+ return RecentItems[0];
}
}
@@ -229,10 +262,16 @@
}
else if (ri.Uri == item.Uri)
{
- // remove the groups
- foreach (string g in item.Groups)
- ri.RemoveGroup (g);
- l.Add (ri);
+ if (ri.Groups != null)
+ {
+ // remove the groups
+ if (item.Groups != null)
+ {
+ foreach (string g in item.Groups)
+ ri.RemoveGroup (g);
+ }
+ l.Add (ri);
+ }
}
else
{
@@ -277,9 +316,15 @@
}
}
+ // FIXME: only append new items, instead of re-writing
// Save implies EmitChangedEvent (otherwise why would we save?)
private void Save ()
{
+ // make sure we are in order
+ this.Sort ();
+ // but we need to write in oldest-to-newest order
+ Array.Reverse (RecentItems);
+
// if we specifically set Encoding UTF 8 here it writes the BOM
// which confuses others (egg-recent-files) I guess
XmlTextWriter writer = new XmlTextWriter (new StreamWriter (RecentFileStore));
@@ -287,8 +332,18 @@
serializer.Serialize (writer, this);
writer.Close ();
EmitChangedEvent ();
+
+ // back to normal
+ this.Sort ();
}
+ // this gives us the items in newest-to-oldest order
+ public void Sort ()
+ {
+ if (RecentItems != null)
+ Array.Sort (RecentItems);
+ }
+
public override string ToString ()
{
if (RecentItems == null)
@@ -310,7 +365,7 @@
}
}
- public class RecentItem
+ public class RecentItem : IComparable
{
[XmlElement ("URI")]
public string Uri;
@@ -380,6 +435,21 @@
AddGroup (s);
}
+ // we want newer items first
+ public int CompareTo (object item)
+ {
+ RecentItem other = item as RecentItem;
+ if (other == null)
+ throw new ArgumentException ("item is not of type " + typeof (RecentItem));
+
+ if (this.Timestamp == other.Timestamp)
+ return 0;
+ else if (this.Timestamp < other.Timestamp)
+ return 1; // older
+ else
+ return -1; // newer
+ }
+
public static int NewTimestamp
{
get {
Modified: trunk/MonoDevelop/Core/src/Main/Base/Services/File/RecentOpen.cs
===================================================================
--- trunk/MonoDevelop/Core/src/Main/Base/Services/File/RecentOpen.cs 2004-11-02 03:02:12 UTC (rev 2015)
+++ trunk/MonoDevelop/Core/src/Main/Base/Services/File/RecentOpen.cs 2004-11-02 20:06:23 UTC (rev 2016)
@@ -73,19 +73,7 @@
public void AddLastFile (string name)
{
- if (lastfile != null && lastfile.Length >= MAX_LENGTH)
- {
- RecentItem oldestItem = lastfile[0];
- for (int i = 1; i < lastfile.Length - 1; i ++)
- {
- // the lowest number is the oldest
- if (lastfile[i].Timestamp < oldestItem.Timestamp)
- oldestItem = lastfile[i];
- }
- recentFiles.RemoveItem (oldestItem);
- }
-
- recentFiles.AddItem (new RecentItem (new Uri (name), Vfs.GetMimeType (name), "MonoDevelop Files"));
+ recentFiles.AddWithLimit (new RecentItem (new Uri (name), Vfs.GetMimeType (name), "MonoDevelop Files"), "MonoDevelop Files", MAX_LENGTH);
UpdateLastFile ();
}
@@ -105,19 +93,7 @@
public void AddLastProject (string name)
{
- if (lastproject != null && lastproject.Length >= MAX_LENGTH)
- {
- RecentItem oldestItem = lastproject[0];
- for (int i = 1; i < lastproject.Length; i ++)
- {
- // the lowest number is the oldest
- if (lastproject[i].Timestamp < oldestItem.Timestamp)
- oldestItem = lastproject[i];
- }
- recentFiles.RemoveItem (oldestItem);
- }
-
- recentFiles.AddItem (new RecentItem (new Uri (name), Vfs.GetMimeType (name), "MonoDevelop Projects"));
+ recentFiles.AddWithLimit (new RecentItem (new Uri (name), Vfs.GetMimeType (name), "MonoDevelop Projects"), "MonoDevelop Projects", MAX_LENGTH);
UpdateLastProject ();
}
More information about the Monodevelop-patches-list
mailing list