2
// MacErrorDialogHandler.cs
5
// Alan McGovern <alan@xamarin.com>
7
// Copyright 2011 Xamarin, Inc.
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30
using System.Collections.Generic;
31
using MonoMac.Foundation;
34
using MonoDevelop.Core;
35
using MonoDevelop.Ide;
36
using MonoDevelop.Ide.Extensions;
37
using MonoDevelop.Components.Extensions;
38
using MonoDevelop.MacInterop;
40
namespace MonoDevelop.MacIntegration
42
class MacExceptionDialogHandler : IExceptionDialogHandler
44
class MyTextView : NSTextView
46
public MyTextView (RectangleF frame)
52
public override void KeyDown (NSEvent theEvent)
54
if (theEvent.ModifierFlags.HasFlag (NSEventModifierMask.CommandKeyMask)) {
55
switch (theEvent.Characters) {
68
base.KeyDown (theEvent);
72
public bool Run (ExceptionDialogData data)
74
using (var alert = new NSAlert { AlertStyle = NSAlertStyle.Critical }) {
75
alert.Icon = NSApplication.SharedApplication.ApplicationIconImage;
77
alert.MessageText = data.Title ?? GettextCatalog.GetString ("Error");
79
if (!string.IsNullOrEmpty (data.Message)) {
80
alert.InformativeText = data.Message;
83
List<AlertButton> buttons = null;
84
if (data.Buttons != null && data.Buttons.Length > 0)
85
buttons = data.Buttons.Reverse ().ToList ();
87
if (buttons != null) {
88
foreach (var button in buttons) {
89
var label = button.Label;
90
if (button.IsStockButton)
91
label = Gtk.Stock.Lookup (label).Label;
92
label = label.Replace ("_", "");
94
//this message seems to be a standard Mac message since alert handles it specially
95
if (button == AlertButton.CloseWithoutSave)
96
label = GettextCatalog.GetString ("Don't Save");
98
alert.AddButton (label);
102
if (data.Exception != null) {
103
var scrollSize = new SizeF (400, 130);
106
string title = GettextCatalog.GetString ("View details");
107
string altTitle = GettextCatalog.GetString ("Hide details");
109
var buttonFrame = new RectangleF (0, 0, 0, 0);
110
var button = new NSButton (buttonFrame) {
111
BezelStyle = NSBezelStyle.Disclosure,
115
button.SetButtonType (NSButtonType.OnOff);
118
var label = new MDClickableLabel (title) {
119
Alignment = NSTextAlignment.Left,
123
button.SetFrameSize (new SizeF (button.Frame.Width, Math.Max (button.Frame.Height, label.Frame.Height)));
124
label.SetFrameOrigin (new PointF (button.Frame.Width + 5, button.Frame.Y));
126
var text = new MyTextView (new RectangleF (0, 0, float.MaxValue, float.MaxValue)) {
127
HorizontallyResizable = true,
129
text.TextContainer.ContainerSize = new SizeF (float.MaxValue, float.MaxValue);
130
text.TextContainer.WidthTracksTextView = true;
131
text.InsertText (new NSString (data.Exception.ToString ()));
132
text.Editable = false;
134
var scrollView = new NSScrollView (new RectangleF (PointF.Empty, SizeF.Empty)) {
135
HasHorizontalScroller = true,
136
HasVerticalScroller = true,
139
var accessory = new NSView (new RectangleF (0, 0, scrollSize.Width, button.Frame.Height));
140
accessory.AddSubview (scrollView);
141
accessory.AddSubview (button);
142
accessory.AddSubview (label);
144
alert.AccessoryView = accessory;
146
button.Activated += delegate {
148
if (button.State == NSCellStateValue.On) {
149
change = scrollSize.Height + spacing;
150
label.StringValue = altTitle;
151
scrollView.Hidden = false;
152
scrollView.Frame = new RectangleF (PointF.Empty, scrollSize);
153
scrollView.DocumentView = text;
155
change = -(scrollSize.Height + spacing);
156
label.StringValue = title;
157
scrollView.Hidden = true;
158
scrollView.Frame = new RectangleF (PointF.Empty, SizeF.Empty);
160
var f = accessory.Frame;
163
var lf = label.Frame;
166
var bf = button.Frame;
170
var panel = (NSPanel) alert.Window;
171
var pf = panel.Frame;
174
panel.SetFrame (pf, true, true);
175
//unless we assign the icon again, it starts nesting old icon into the warning icon
176
alert.Icon = NSApplication.SharedApplication.ApplicationIconImage;
179
label.OnMouseUp += (sender, e) => button.PerformClick (e.Event);
182
int result = alert.RunModal () - (int)NSAlertButtonReturn.First;
183
data.ResultButton = buttons != null ? buttons [result] : null;
184
GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
190
class MDClickableLabel: MDLabel
192
public MDClickableLabel (string text) : base (text)
196
public override void MouseDown (NSEvent theEvent)
198
if (OnMouseDown != null)
199
OnMouseDown (this, new NSEventArgs (theEvent));
201
base.MouseDown (theEvent);
204
public event EventHandler<NSEventArgs> OnMouseDown;
206
public override void MouseUp (NSEvent theEvent)
208
if (OnMouseUp != null)
209
OnMouseUp (this, new NSEventArgs (theEvent));
211
base.MouseUp (theEvent);
214
public event EventHandler<NSEventArgs> OnMouseUp;
216
public override void MouseEntered (NSEvent theEvent)
218
if (OnMouseEntered != null)
219
OnMouseEntered (this, new NSEventArgs (theEvent));
221
base.MouseEntered (theEvent);
224
public event EventHandler<NSEventArgs> OnMouseEntered;
226
public override void MouseExited (NSEvent theEvent)
228
if (OnMouseExited != null)
229
OnMouseExited (this, new NSEventArgs (theEvent));
231
base.MouseExited (theEvent);
234
public event EventHandler<NSEventArgs> OnMouseExited;
236
public override void MouseMoved (NSEvent theEvent)
238
if (OnMouseMoved != null)
239
OnMouseMoved (this, new NSEventArgs (theEvent));
241
base.MouseMoved (theEvent);
244
public event EventHandler<NSEventArgs> OnMouseMoved;
247
class NSEventArgs : EventArgs
249
public NSEventArgs (NSEvent evt)
254
public NSEvent Event { get; private set; }
b'\\ No newline at end of file'