Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortherzok <marius.ungureanu@xamarin.com>2016-06-29 17:32:31 +0300
committertherzok <marius.ungureanu@xamarin.com>2016-07-01 16:17:08 +0300
commit4153a8ee6492bc8957efc151f0f2e22e175df75b (patch)
treed1658076cc967c1a7760de834758bde2908fc087 /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop
parent88d89b3280222ca2c9f60e6db87153c0ad298645 (diff)
[Ide] Optimize RecentFiles updates.
This modifies RecentFiles updates so that we do the following: * Split Projects/Files into different events. This way we can guarantee that for the WelcomePage, for example, we can subscribe only to project changes that will cause a refresh of the items in the list. * Don't trigger updates of recent items if nothing has changed between the old and the new version. These updates can happen because we send an IDE update event and also have the filesystemwatcher events triggering updates for us.
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/RecentFileStorage.cs41
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/RecentItemsChangedEventArgs.cs40
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/RecentOpen.cs52
3 files changed, 120 insertions, 13 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/RecentFileStorage.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/RecentFileStorage.cs
index b31007c063..906a1a1b08 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/RecentFileStorage.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/RecentFileStorage.cs
@@ -347,21 +347,46 @@ namespace MonoDevelop.Ide.Desktop
{
return fileName.StartsWith ("file://") ? fileName : "file://" + fileName;
}
-
+
+ RecentItemUnionComparer comparer = new RecentItemUnionComparer ();
void OnRecentFilesChanged (List<RecentItem> list)
{
+ string[] union;
lock (cacheLock) {
+ union = cachedItemList
+ // Filter what changed only.
+ .Except (list, comparer)
+ .Concat (list.Except (cachedItemList, comparer))
+ // Get the distinct groups
+ .SelectMany (it => it.Groups)
+ .Distinct ()
+ .ToArray ();
cachedItemList = list;
}
- Runtime.RunInMainThread (() => {
- if (changed != null)
- changed (this, EventArgs.Empty);
- });
+ if (union.Length > 0) {
+ Runtime.RunInMainThread (() => {
+ if (changed != null)
+ changed (this, new RecentItemsChangedEventArgs (union));
+ });
+ }
}
-
- EventHandler changed;
- public event EventHandler RecentFilesChanged {
+
+ class RecentItemUnionComparer : IEqualityComparer<RecentItem>
+ {
+ public bool Equals (RecentItem x, RecentItem y)
+ {
+ return x.Uri.Equals (y.Uri) && x.Timestamp.Equals (y.Timestamp);
+ }
+
+ public int GetHashCode (RecentItem obj)
+ {
+ return obj.Uri.GetHashCode () ^ obj.Timestamp.GetHashCode ();
+ }
+ }
+
+ EventHandler<RecentItemsChangedEventArgs> changed;
+ public event EventHandler<RecentItemsChangedEventArgs> RecentFilesChanged {
add {
lock (this) {
if (changed == null)
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/RecentItemsChangedEventArgs.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/RecentItemsChangedEventArgs.cs
new file mode 100644
index 0000000000..754176154f
--- /dev/null
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/RecentItemsChangedEventArgs.cs
@@ -0,0 +1,40 @@
+//
+// RecentItemsChangedEventArgs.cs
+//
+// Author:
+// therzok <marius.ungureanu@xamarin.com>
+//
+// Copyright (c) 2016 (c) Marius Ungureanu
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+using System.Collections.Generic;
+
+namespace MonoDevelop.Ide.Desktop
+{
+ class RecentItemsChangedEventArgs : EventArgs
+ {
+ public IEnumerable<string> Groups { get; }
+
+ public RecentItemsChangedEventArgs (IEnumerable<string> groups)
+ {
+ Groups = groups;
+ }
+ }
+}
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/RecentOpen.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/RecentOpen.cs
index 939b9dcd10..db49ba0f04 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/RecentOpen.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Desktop/RecentOpen.cs
@@ -54,11 +54,47 @@ namespace MonoDevelop.Ide.Desktop
{
recentFiles = new RecentFileStorage (storageFile);
recentFiles.RemoveMissingFiles (fileGroup);
+
+ recentFiles.RecentFilesChanged += OnRecentFilesChanged;
}
-
+
+ void OnRecentFilesChanged (object sender, RecentItemsChangedEventArgs args)
+ {
+ changed?.Invoke (sender, args);
+ if (args.Groups.Any (i => i.Contains (projGroup)))
+ projectsChanged?.Invoke (sender, args);
+ if (args.Groups.Any (i => i.Contains (fileGroup)))
+ filesChanged?.Invoke (sender, args);
+ }
+
+ event EventHandler changed;
public override event EventHandler Changed {
- add { recentFiles.RecentFilesChanged += value; }
- remove { recentFiles.RecentFilesChanged -= value; }
+ add {
+ changed += value;
+ }
+ remove {
+ changed -= value;
+ }
+ }
+
+ event EventHandler projectsChanged;
+ public override event EventHandler ProjectsChanged {
+ add {
+ projectsChanged += value;
+ }
+ remove {
+ projectsChanged -= value;
+ }
+ }
+
+ event EventHandler filesChanged;
+ public override event EventHandler FilesChanged {
+ add {
+ filesChanged += value;
+ }
+ remove {
+ filesChanged -= value;
+ }
}
protected override IList<RecentFile> OnGetProjects ()
@@ -147,8 +183,11 @@ namespace MonoDevelop.Ide.Desktop
public void Dispose ()
{
- recentFiles.Dispose ();
- recentFiles = null;
+ if (recentFiles != null) {
+ recentFiles.RecentFilesChanged -= OnRecentFilesChanged;
+ recentFiles.Dispose ();
+ recentFiles = null;
+ }
}
}
@@ -196,6 +235,9 @@ namespace MonoDevelop.Ide.Desktop
}
public abstract event EventHandler Changed;
+ // TODO: Make these abstract for 7.0.
+ public virtual event EventHandler ProjectsChanged;
+ public virtual event EventHandler FilesChanged;
public abstract void ClearProjects ();
public abstract void ClearFiles ();
public abstract void AddFile (string fileName, string displayName);