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:
authorMarius Ungureanu <marius.ungureanu@xamarin.com>2015-09-18 11:30:36 +0300
committerMarius Ungureanu <marius.ungureanu@xamarin.com>2015-09-18 11:41:39 +0300
commit90afd0c3393cb57340174e1cda444b9566ef7d1e (patch)
tree533372bf68ce7c9dbceaf0ed6aa124b3416e8b3f
parent2363a900f2c76a64b63ef2752aa1e54f58aefff8 (diff)
[Mac] Use a smarter timer system.
-rw-r--r--main/src/addins/MacPlatform/MainToolbar/MainToolbar.cs55
-rw-r--r--main/src/addins/MacPlatform/MainToolbar/SelectorView.cs7
2 files changed, 42 insertions, 20 deletions
diff --git a/main/src/addins/MacPlatform/MainToolbar/MainToolbar.cs b/main/src/addins/MacPlatform/MainToolbar/MainToolbar.cs
index 7484a54f2a..0f736344e7 100644
--- a/main/src/addins/MacPlatform/MainToolbar/MainToolbar.cs
+++ b/main/src/addins/MacPlatform/MainToolbar/MainToolbar.cs
@@ -119,6 +119,17 @@ namespace MonoDevelop.MacIntegration.MainToolbar
return e;
}
+ bool IsCorrectNotification (NSView view, NSObject notifObject)
+ {
+ var window = selector.Window;
+
+ // Skip updates with a null Window. Only crashes on Mavericks.
+ // The View gets updated once again when the window resize finishes.
+ // We're getting notified about all windows in the application (for example, NSPopovers) that change size when really we only care about
+ // the window the bar is in.
+ return window != null && notifObject == window;
+ }
+
NSToolbarItem CreateSelectorToolbarItem ()
{
var selector = new SelectorView ();
@@ -135,24 +146,40 @@ namespace MonoDevelop.MacIntegration.MainToolbar
selector.OverflowInfoRequested += (o, e) => {
FillOverflowInfo (e);
};
- Action<NSNotification> resizeAction = notif => DispatchService.GuiDispatch (() => {
- // Skip updates with a null Window. Only crashes on Mavericks.
- // The View gets updated once again when the window resize finishes.
- var window = selector.Window;
- if (window == null)
+
+ IDisposable resizeTimer = null;
+ NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.WillStartLiveResizeNotification, notif => DispatchService.GuiDispatch (() => {
+ if (!IsCorrectNotification (selector, notif.Object))
return;
- // We're getting notified about all windows in the application (for example, NSPopovers) that change size when really we only care about
- // the window the bar is in.
- if (notif.Object != window)
+ if (resizeTimer != null)
+ resizeTimer.Dispose ();
+
+ resizeTimer = Application.TimeoutInvoke (100, () => {
+ if (widget.Items.Length != widget.VisibleItems.Length)
+ selector.RequestResize ();
+ return true;
+ });
+ }));
+
+ NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidResizeNotification, notif => DispatchService.GuiDispatch (() => {
+ if (!IsCorrectNotification (selector, notif.Object))
return;
// Don't check difference in overflow menus. This could cause issues since we're doing resizing of widgets and the views might go in front
// or behind while we're doing the resize request.
selector.RequestResize ();
- });
- NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidResizeNotification, resizeAction);
- NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidEndLiveResizeNotification, resizeAction);
+ }));
+
+ NSNotificationCenter.DefaultCenter.AddObserver (NSWindow.DidEndLiveResizeNotification, notif => DispatchService.GuiDispatch (() => {
+ if (!IsCorrectNotification (selector, notif.Object))
+ return;
+
+ if (resizeTimer != null)
+ resizeTimer.Dispose ();
+
+ resizeTimer = Application.TimeoutInvoke (300, selector.RequestResize);
+ }));
var pathSelector = (SelectorView.PathSelectorView)selector.Subviews [0];
pathSelector.ConfigurationChanged += (sender, e) => {
@@ -299,12 +326,6 @@ namespace MonoDevelop.MacIntegration.MainToolbar
}
throw new NotImplementedException ();
};
-
- Application.TimeoutInvoke (1000, () => {
- if (widget.Items.Length != widget.VisibleItems.Length)
- selector.RequestResize ();
- return true;
- });
}
internal void Initialize ()
diff --git a/main/src/addins/MacPlatform/MainToolbar/SelectorView.cs b/main/src/addins/MacPlatform/MainToolbar/SelectorView.cs
index 8fc69e6dea..3c4c4fbfc4 100644
--- a/main/src/addins/MacPlatform/MainToolbar/SelectorView.cs
+++ b/main/src/addins/MacPlatform/MainToolbar/SelectorView.cs
@@ -69,7 +69,7 @@ namespace MonoDevelop.MacIntegration.MainToolbar
AddSubview (pathSelectorView);
}
- public CGSize RequestResize ()
+ public bool RequestResize ()
{
var p = (PathSelectorView)Subviews [0];
var overflowInfo = new OverflowInfoEventArgs ();
@@ -87,13 +87,14 @@ namespace MonoDevelop.MacIntegration.MainToolbar
SetNeedsDisplay ();
p.SetNeedsDisplay ();
+ return true;
}
- return size;
+ return false;
}
public override void ViewWillDraw ()
{
- var size = RequestResize ();
+ RequestResize ();
base.ViewWillDraw ();
}