2
// MacAlertFileDialogHandler.cs
5
// Michael Hutchinson <mhutchinson@novell.com>
7
// Copyright (c) 2010 Novell, 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.Platform.Mac
42
class MacAlertDialogHandler : IAlertDialogHandler
44
public bool Run (AlertDialogData data)
46
using (var alert = new NSAlert ()) {
48
if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Information) {
49
alert.AlertStyle = NSAlertStyle.Critical;
50
} else if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Warning) {
51
alert.AlertStyle = NSAlertStyle.Warning;
52
} else if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Information) {
53
alert.AlertStyle = NSAlertStyle.Informational;
56
//FIXME: use correct size so we don't get horrible scaling?
57
if (!string.IsNullOrEmpty (data.Message.Icon)) {
58
var pix = ImageService.GetPixbuf (data.Message.Icon, Gtk.IconSize.Dialog);
59
byte[] buf = pix.SaveToBuffer ("tiff");
61
fixed (byte* b = buf) {
62
alert.Icon = new NSImage (NSData.FromBytes ((IntPtr)b, (uint)buf.Length));
67
alert.MessageText = data.Message.Text;
68
alert.InformativeText = data.Message.SecondaryText ?? "";
70
var buttons = data.Buttons.Reverse ().ToList ();
72
for (int i = 0; i < buttons.Count - 1; i++) {
73
if (i == data.Message.DefaultButton) {
74
var next = buttons[i];
75
for (int j = buttons.Count - 1; j >= i; j--) {
84
foreach (var button in buttons) {
85
var label = button.Label;
86
if (button.IsStockButton)
87
label = Gtk.Stock.Lookup (label).Label;
88
label = label.Replace ("_", "");
90
//this message seems to be a standard Mac message since alert handles it specially
91
if (button == AlertButton.CloseWithoutSave)
92
label = GettextCatalog.GetString ("Don't Save");
94
alert.AddButton (label);
98
NSButton[] optionButtons = null;
99
if (data.Options.Count > 0) {
100
var box = new MDBox (LayoutDirection.Vertical, 2, 2);
101
optionButtons = new NSButton[data.Options.Count];
103
for (int i = data.Options.Count - 1; i >= 0; i--) {
104
var option = data.Options[i];
105
var button = new NSButton () {
108
State = option.Value? NSCellStateValue.On : NSCellStateValue.Off,
110
button.SetButtonType (NSButtonType.Switch);
111
optionButtons[i] = button;
112
box.Add (new MDAlignment (button, true) { XAlign = LayoutAlign.Begin });
116
alert.AccessoryView = box.View;
119
NSButton applyToAllCheck = null;
120
if (data.Message.AllowApplyToAll) {
121
alert.ShowsSuppressionButton = true;
122
applyToAllCheck = alert.SuppressionButton;
123
applyToAllCheck.Title = GettextCatalog.GetString ("Apply to all");
128
int result = alert.RunModal () - (int)NSAlertButtonReturn.First;
130
data.ResultButton = buttons [result];
132
if (optionButtons != null) {
133
foreach (var button in optionButtons) {
134
var option = data.Options[button.Tag];
135
data.Message.SetOptionValue (option.Id, button.State != 0);
139
if (applyToAllCheck != null && applyToAllCheck.State != 0)
140
data.ApplyToAll = true;
142
GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);