Example #1
0
        public bool Run(ExceptionDialogData data)
        {
            using (var alert = new NSAlert()) {
                alert.AlertStyle = NSAlertStyle.Critical;

                var    pix = ImageService.GetPixbuf(Gtk.Stock.DialogError, Gtk.IconSize.Dialog);
                byte[] buf = pix.SaveToBuffer("tiff");
                alert.Icon = new NSImage(NSData.FromArray(buf));

                alert.MessageText     = data.Title ?? "Some Message";
                alert.InformativeText = data.Message ?? "Some Info";

                if (data.Exception != null)
                {
                    var text = new NSTextView(new RectangleF(0, 0, float.MaxValue, float.MaxValue));
                    text.HorizontallyResizable             = true;
                    text.TextContainer.ContainerSize       = new SizeF(float.MaxValue, float.MaxValue);
                    text.TextContainer.WidthTracksTextView = false;
                    text.InsertText(new NSString(data.Exception.ToString()));
                    text.Editable = false;

                    var scrollView = new NSScrollView(new RectangleF(0, 0, 450, 150))
                    {
                        HasHorizontalScroller = true,
                        DocumentView          = text,
                    };
                    ;
                    alert.AccessoryView = scrollView;
                }

                // Hack up a slightly wider than normal alert dialog. I don't know how to do this in a nicer way
                // as the min size constraints are apparently ignored.
                var frame = ((NSPanel)alert.Window).Frame;
                ((NSPanel)alert.Window).SetFrame(new RectangleF(frame.X, frame.Y, Math.Max(frame.Width, 600), frame.Height), true);

                int result = alert.RunModal() - (int)NSAlertButtonReturn.First;

                GtkQuartz.FocusWindow(data.TransientFor ?? MessageService.RootWindow);
            }

            return(true);
        }
		public bool Run (ExceptionDialogData data)
		{
			using (var alert = new NSAlert ()) {
				alert.AlertStyle = NSAlertStyle.Critical;
				
				var pix = ImageService.GetPixbuf (Gtk.Stock.DialogError, Gtk.IconSize.Dialog);
				byte[] buf = pix.SaveToBuffer ("tiff");
				alert.Icon = new NSImage (NSData.FromArray (buf));
				
				alert.MessageText = data.Title ?? "Some Message";
				alert.InformativeText = data.Message ?? "Some Info";

				if (data.Exception != null) {

					var text = new NSTextView (new RectangleF (0, 0, float.MaxValue, float.MaxValue));
					text.HorizontallyResizable = true;
					text.TextContainer.ContainerSize = new SizeF (float.MaxValue, float.MaxValue);
					text.TextContainer.WidthTracksTextView = false;
					text.InsertText (new NSString (data.Exception.ToString ()));
					text.Editable = false;
					
					var scrollView = new NSScrollView (new RectangleF (0, 0, 450, 150)) {
						HasHorizontalScroller = true,
						DocumentView = text,
					};
;
					alert.AccessoryView = scrollView;
				}
				
				// Hack up a slightly wider than normal alert dialog. I don't know how to do this in a nicer way
				// as the min size constraints are apparently ignored.
				var frame = ((NSPanel) alert.Window).Frame;
				((NSPanel) alert.Window).SetFrame (new RectangleF (frame.X, frame.Y, Math.Max (frame.Width, 600), frame.Height), true);
				
				int result = alert.RunModal () - (int)NSAlertButtonReturn.First;
				
				GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
			}
			
			return true;
		}
Example #3
0
        public bool Run(ExceptionDialogData data)
        {
            using (var alert = new NSAlert {
                AlertStyle = NSAlertStyle.Critical
            }) {
                IdeTheme.ApplyTheme(alert.Window);
                alert.Icon = NSApplication.SharedApplication.ApplicationIconImage;

                alert.MessageText = data.Title ?? GettextCatalog.GetString("Error");

                if (!string.IsNullOrEmpty(data.Message))
                {
                    alert.InformativeText = data.Message;
                }

                List <AlertButton> buttons = null;
                if (data.Buttons != null && data.Buttons.Length > 0)
                {
                    buttons = data.Buttons.Reverse().ToList();
                }

                if (buttons != null)
                {
                    foreach (var button in buttons)
                    {
                        var label = button.Label;
                        if (button.IsStockButton)
                        {
                            label = Gtk.Stock.Lookup(label).Label;
                        }
                        label = label.Replace("_", "");

                        //this message seems to be a standard Mac message since alert handles it specially
                        if (button == AlertButton.CloseWithoutSave)
                        {
                            label = GettextCatalog.GetString("Don't Save");
                        }

                        alert.AddButton(label);
                    }
                }

                if (data.Exception != null)
                {
                    var         scrollSize = new CGSize(400, 130);
                    const float spacing    = 4;

                    string title    = GettextCatalog.GetString("View details");
                    string altTitle = GettextCatalog.GetString("Hide details");

                    var buttonFrame = new CGRect(0, 0, 0, 0);
                    var button      = new NSButton(buttonFrame)
                    {
                        BezelStyle     = NSBezelStyle.Disclosure,
                        Title          = "",
                        AlternateTitle = "",
                    };
                    button.SetButtonType(NSButtonType.OnOff);
                    button.SizeToFit();

                    var label = new MDClickableLabel(title)
                    {
                        Alignment = NSTextAlignment.Left,
                    };
                    label.SizeToFit();

                    button.SetFrameSize(new CGSize(button.Frame.Width, NMath.Max(button.Frame.Height, label.Frame.Height)));
                    label.SetFrameOrigin(new CGPoint(button.Frame.Width + 5, button.Frame.Y));

                    var text = new MyTextView(new CGRect(0, 0, float.MaxValue, float.MaxValue))
                    {
                        HorizontallyResizable = true,
                    };
                    text.TextContainer.ContainerSize       = new CGSize(float.MaxValue, float.MaxValue);
                    text.TextContainer.WidthTracksTextView = true;
                    text.InsertText(new NSString(data.Exception.ToString()));
                    text.Editable = false;

                    var scrollView = new NSScrollView(new CGRect(CGPoint.Empty, CGSize.Empty))
                    {
                        HasHorizontalScroller = true,
                        HasVerticalScroller   = true,
                    };

                    var accessory = new NSView(new CGRect(0, 0, scrollSize.Width, button.Frame.Height));
                    accessory.AddSubview(scrollView);
                    accessory.AddSubview(button);
                    accessory.AddSubview(label);

                    alert.AccessoryView = accessory;

                    button.Activated += delegate {
                        nfloat change;
                        if (button.State == NSCellStateValue.On)
                        {
                            change                  = scrollSize.Height + spacing;
                            label.StringValue       = altTitle;
                            scrollView.Hidden       = false;
                            scrollView.Frame        = new CGRect(CGPoint.Empty, scrollSize);
                            scrollView.DocumentView = text;
                        }
                        else
                        {
                            change            = -(scrollSize.Height + spacing);
                            label.StringValue = title;
                            scrollView.Hidden = true;
                            scrollView.Frame  = new CGRect(CGPoint.Empty, CGSize.Empty);
                        }
                        var f = accessory.Frame;
                        f.Height       += change;
                        accessory.Frame = f;
                        var lf = label.Frame;
                        lf.Y       += change;
                        label.Frame = lf;
                        var bf = button.Frame;
                        bf.Y        += change;
                        button.Frame = bf;
                        label.SizeToFit();
                        var panel = alert.Window;
                        var pf    = panel.Frame;
                        pf.Height += change;
                        pf.Y      -= change;
                        panel.SetFrame(pf, true, true);
                        //unless we assign the icon again, it starts nesting old icon into the warning icon
                        alert.Icon = NSApplication.SharedApplication.ApplicationIconImage;
                        alert.Layout();
                    };
                    label.OnMouseUp += (sender, e) => button.PerformClick(e.Event);
                }

                var result = (int)(nint)alert.RunModal() - (int)(long)NSAlertButtonReturn.First;
                data.ResultButton = buttons != null ? buttons [result] : null;
                GtkQuartz.FocusWindow(data.TransientFor ?? MessageService.RootWindow);
            }

            return(true);
        }
		public bool Run (ExceptionDialogData data)
		{
			using (var alert = new NSAlert { AlertStyle = NSAlertStyle.Critical }) {
				alert.Icon = NSApplication.SharedApplication.ApplicationIconImage;
				
				alert.MessageText = data.Title ?? GettextCatalog.GetString ("Error");
				
				if (!string.IsNullOrEmpty (data.Message)) {
					alert.InformativeText = data.Message;
				}

				List<AlertButton> buttons = null;
				if (data.Buttons != null && data.Buttons.Length > 0)
					buttons = data.Buttons.Reverse ().ToList ();

				if (buttons != null) {
					foreach (var button in buttons) {
						var label = button.Label;
						if (button.IsStockButton)
							label = Gtk.Stock.Lookup (label).Label;
						label = label.Replace ("_", "");

						//this message seems to be a standard Mac message since alert handles it specially
						if (button == AlertButton.CloseWithoutSave)
							label = GettextCatalog.GetString ("Don't Save");

						alert.AddButton (label);
					}
				}

				if (data.Exception != null) {
					var scrollSize = new CGSize (400, 130);
					const float spacing = 4;
					
					string title = GettextCatalog.GetString ("View details");
					string altTitle = GettextCatalog.GetString ("Hide details");
					
					var buttonFrame = new CGRect (0, 0, 0, 0);
					var button = new NSButton (buttonFrame) {
						BezelStyle = NSBezelStyle.Disclosure,
						Title = "",
						AlternateTitle = "",
					};
					button.SetButtonType (NSButtonType.OnOff);
					button.SizeToFit ();
					
					var label = new MDClickableLabel (title) {
						Alignment = NSTextAlignment.Left,
					};
					label.SizeToFit ();
					
					button.SetFrameSize (new CGSize (button.Frame.Width, NMath.Max (button.Frame.Height, label.Frame.Height)));
					label.SetFrameOrigin (new CGPoint (button.Frame.Width + 5, button.Frame.Y));
					
					var text = new MyTextView (new CGRect (0, 0, float.MaxValue, float.MaxValue)) {
						HorizontallyResizable = true,
					};
					text.TextContainer.ContainerSize = new CGSize (float.MaxValue, float.MaxValue);
					text.TextContainer.WidthTracksTextView = true;
					text.InsertText (new NSString (data.Exception.ToString ()));
					text.Editable = false;

					var scrollView = new NSScrollView (new CGRect (CGPoint.Empty, CGSize.Empty)) {
						HasHorizontalScroller = true,
						HasVerticalScroller = true,
					};
					
					var accessory = new NSView (new CGRect (0, 0, scrollSize.Width, button.Frame.Height));
					accessory.AddSubview (scrollView);
					accessory.AddSubview (button);
					accessory.AddSubview (label);
					
					alert.AccessoryView = accessory;
					
					button.Activated += delegate {
						nfloat change;
						if (button.State == NSCellStateValue.On) {
							change = scrollSize.Height + spacing;
							label.StringValue = altTitle;
							scrollView.Hidden = false;
							scrollView.Frame = new CGRect (CGPoint.Empty, scrollSize);
							scrollView.DocumentView = text;
						} else {
							change = -(scrollSize.Height + spacing);
							label.StringValue = title;
							scrollView.Hidden = true;
							scrollView.Frame = new CGRect (CGPoint.Empty, CGSize.Empty);
						}
						var f = accessory.Frame;
						f.Height += change;
						accessory.Frame = f;
						var lf = label.Frame;
						lf.Y += change;
						label.Frame = lf;
						var bf = button.Frame;
						bf.Y += change;
						button.Frame = bf;
						label.SizeToFit ();
						var panel = alert.Window;
						var pf = panel.Frame;
						pf.Height += change;
						pf.Y -= change;
						panel.SetFrame (pf, true, true);
						//unless we assign the icon again, it starts nesting old icon into the warning icon
						alert.Icon = NSApplication.SharedApplication.ApplicationIconImage;
						alert.Layout ();
					};
					label.OnMouseUp += (sender, e) => button.PerformClick (e.Event);
				}

				var result = (int)(nint)alert.RunModal () - (int)(long)NSAlertButtonReturn.First;
				data.ResultButton = buttons != null ? buttons [result] : null;
				GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
			}
			
			return true;
		}