diff options
author | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2012-01-26 06:11:08 +0400 |
---|---|---|
committer | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2012-01-26 06:24:44 +0400 |
commit | 0833faf7e5795a2a75f54ecd97a85910c96c2e6c (patch) | |
tree | c3a726752a98ba1474e322f5f091000bca5eb649 /main/src/addins/MacPlatform/Dialogs/MacAlertDialogHandler.cs | |
parent | 9adf4a3812372d6fda776e71c479eb90c6d152ac (diff) |
[Ide] Make alert dialogs cancelable
Diffstat (limited to 'main/src/addins/MacPlatform/Dialogs/MacAlertDialogHandler.cs')
-rw-r--r-- | main/src/addins/MacPlatform/Dialogs/MacAlertDialogHandler.cs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/main/src/addins/MacPlatform/Dialogs/MacAlertDialogHandler.cs b/main/src/addins/MacPlatform/Dialogs/MacAlertDialogHandler.cs index 2e8357dc33..cbb125a7a7 100644 --- a/main/src/addins/MacPlatform/Dialogs/MacAlertDialogHandler.cs +++ b/main/src/addins/MacPlatform/Dialogs/MacAlertDialogHandler.cs @@ -49,7 +49,7 @@ namespace MonoDevelop.MacIntegration alert.AlertStyle = NSAlertStyle.Critical; } else if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Warning) { alert.AlertStyle = NSAlertStyle.Warning; - } else if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Information) { + } else { //if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Information) { alert.AlertStyle = NSAlertStyle.Informational; } @@ -62,6 +62,9 @@ namespace MonoDevelop.MacIntegration alert.Icon = new NSImage (NSData.FromBytes ((IntPtr)b, (uint)buf.Length)); } } + } else { + //for some reason the NSAlert doesn't pick up the app icon by default + alert.Icon = NSApplication.SharedApplication.ApplicationIconImage; } alert.MessageText = data.Message.Text; @@ -129,9 +132,30 @@ namespace MonoDevelop.MacIntegration ((NSPanel) alert.Window).SetFrame (new RectangleF (frame.X, frame.Y, Math.Max (frame.Width, 600), frame.Height), true); alert.Layout (); + bool cancelled = false, completed = false; + if (data.Message.CancellationToken.CanBeCanceled) { + data.Message.CancellationToken.Register (delegate { + alert.InvokeOnMainThread (() => { + if (!completed) { + cancelled = true; + NSApplication.SharedApplication.AbortModal (); + } + }); + }); + } + int result = alert.RunModal () - (int)NSAlertButtonReturn.First; + completed = true; - data.ResultButton = buttons [result]; + if (result < 0 || result > buttons.Count) { + cancelled = true; + } else { + data.ResultButton = buttons [result]; + } + + if (cancelled || data.Message.CancellationToken.IsCancellationRequested) { + data.SetResultToCancelled (); + } if (optionButtons != null) { foreach (var button in optionButtons) { |