Пример #1
0
        public override IDisposable Login(LoginConfig config) => this.Present(() =>
        {
            var alert = new NSAlert
            {
                AlertStyle      = NSAlertStyle.Informational,
                MessageText     = config.Title ?? string.Empty,
                InformativeText = config.Message ?? string.Empty
            };
            alert.AddButton(config.OkText);
            alert.AddButton(config.CancelText);

            var inputView = new NSStackView(new CGRect(0, 2, 200, 58));
            var txtUser   = new NSTextField(new CGRect(0, 28, 200, 24))
            {
                PlaceholderString = config.LoginPlaceholder,
                StringValue       = config.LoginValue ?? string.Empty
            };
            var txtPassword = new NSSecureTextField(new CGRect(0, 2, 200, 24))
            {
                PlaceholderString = config.PasswordPlaceholder
            };

            inputView.AddSubview(txtUser);
            inputView.AddSubview(txtPassword);

            alert.AccessoryView = inputView;
            alert.Layout();

            alert.BeginSheetForResponse(this.windowFunc(), result => config.OnAction?.Invoke(new LoginResult(result == 1000, txtUser.StringValue, txtPassword.StringValue)));
            return(alert);
        });
Пример #2
0
        public static void CheckPassword(SqliteConnection connection, SqliteConnection _conn, string password, bool isError = false)
        {
            var passwordInput = new NSSecureTextField(new CGRect(0, 0, 300, 20));

            passwordInput.PlaceholderAttributedString = new Foundation.NSAttributedString("Enter password...");

            var passwordAlert = new NSAlert()
            {
                AlertStyle      = isError ? NSAlertStyle.Critical : NSAlertStyle.Informational,
                InformativeText = isError ? "Previous password attempt was incorrect, please retry" : "Enter SittingDucks Password",
                MessageText     = "Authentication Required",
            };

            passwordAlert.AddButton("Enter");
            passwordAlert.AddButton("Change Password");
            passwordAlert.AccessoryView = passwordInput;
            passwordAlert.Layout();
            var result = passwordAlert.RunModal();

            passwordAlert.Dispose();

            if (passwordInput.StringValue != password)
            {
                CheckPassword(connection, _conn, password, true);
            }
            else if (result == 1001)
            {
                NewPassword(connection, _conn);
            }
        }
Пример #3
0
        public override IDisposable Prompt(PromptConfig config) => this.Present(() =>
        {
            var alert = new NSAlert
            {
                AlertStyle      = NSAlertStyle.Informational,
                MessageText     = config.Title ?? string.Empty,
                InformativeText = config.Message ?? string.Empty
            };
            alert.AddButton(config.OkText);
            if (config.IsCancellable)
            {
                alert.AddButton(config.CancelText);
            }

            var txtInput = new NSTextField(new CGRect(0, 0, 300, 24))
            {
                PlaceholderString = config.Placeholder ?? string.Empty,
                StringValue       = config.Text ?? String.Empty
            };

            // TODO: Implement input types validation
            if (config.InputType != InputType.Default || config.MaxLength != null)
            {
                Log.Warn("Acr.UserDialogs", "There is no validation of input types nor MaxLength on this implementation");
            }

            alert.AccessoryView = txtInput;
            alert.Layout();

            alert.BeginSheetForResponse(this.windowFunc(), result => config.OnAction?.Invoke(new PromptResult(result == 1000, txtInput.StringValue)));
            return(alert);
        });
Пример #4
0
        public static async Task <string> RunSearchWindow(NSWindow window)
        {
            var searchQuery = new NSSearchField(new CGRect(0, 0, 300, 20));
            var searchAlert = new NSAlert()
            {
                AlertStyle  = NSAlertStyle.Informational,
                MessageText = "Enter Search Query"
            };

            var subissionButton = searchAlert.AddButton("Enter");

            searchAlert.AddButton("Cancel");
            searchAlert.AccessoryView = searchQuery;
            searchAlert.Layout();

            subissionButton.Enabled = false;

            searchQuery.Changed += (sender, e) =>
            {
                subissionButton.Enabled = searchQuery.StringValue != String.Empty;
            };

            var result = (long)await searchAlert.BeginSheetAsync(window);

            return(result == 1000 ? searchQuery.StringValue : String.Empty);
        }
Пример #5
0
        //Update initial
        partial void UpdateInitAmt(NSButton updateInitBtn)
        {
            ////Push data
            var conn           = new SQLite.SQLiteConnection(DbPath);
            var initial        = conn.Table <InitialValue>().OrderByDescending(x => x.id).First();
            var initialValue   = initial.Value;
            var initialValueId = initial.id;

            // Wireup events
            updateInitBtn.Activated += (sender, e) => {
                // Get button and product
                var btn = sender as NSButton;

                // Configure alert
                var alert = new NSAlert()
                {
                    AlertStyle      = NSAlertStyle.Informational,
                    InformativeText = $"可以修改你的初始Money",
                    MessageText     = $"修改初始",
                };
                alert.AddButton("取消");
                alert.AddButton("确定");

                // initial value override
                var input = new NSTextField(new CGRect(0, 0, 300, 20));
                input.StringValue   = String.Format("{0}", initialValue);
                alert.AccessoryView = input;
                alert.Layout();

                alert.BeginSheetForResponse(View.Window, (result) =>
                {
                    Console.WriteLine(result);
                    // Should we delete the requested row?
                    if (result == 1001)
                    {
                        // update init value

                        conn.Update(new InitialValue(float.Parse(input.StringValue)));
                        Console.WriteLine(conn.Update(new InitialValue(float.Parse(input.StringValue), initialValueId)));
                        Console.WriteLine(conn.Table <InitialValue>().OrderByDescending(x => x.id).First().Value);
                        ReloadTable();
                    }
                });
            };
        }
Пример #6
0
        void ShowAlert(NSObject sender)
        {
            if (ShowAlertAsSheet)
            {
                var input = new NSTextField(new CGRect(0, 0, 300, 20));

                var alert = new NSAlert()
                {
                    AlertStyle      = NSAlertStyle.Informational,
                    InformativeText = "This is the body of the alert where you describe the situation and any actions to correct it.",
                    MessageText     = "Alert Title",
                };
                alert.AddButton("Ok");
                alert.AddButton("Cancel");
                alert.AddButton("Maybe");
                alert.ShowsSuppressionButton = true;
                alert.AccessoryView          = input;
                alert.Layout();
                alert.BeginSheetForResponse(this, (result) => {
                    Console.WriteLine("Alert Result: {0}, Suppress: {1}", result, alert.SuppressionButton.State == NSCellStateValue.On);
                });
            }
            else
            {
                var input = new NSTextField(new CGRect(0, 0, 300, 20));

                var alert = new NSAlert()
                {
                    AlertStyle      = NSAlertStyle.Informational,
                    InformativeText = "This is the body of the alert where you describe the situation and any actions to correct it.",
                    MessageText     = "Alert Title",
                };
                alert.AddButton("Ok");
                alert.AddButton("Cancel");
                alert.AddButton("Maybe");
                alert.ShowsSuppressionButton = true;
                alert.AccessoryView          = input;
                alert.Layout();
                var result = alert.RunModal();
                Console.WriteLine("Alert Result: {0}, Suppress: {1}", result, alert.SuppressionButton.State == NSCellStateValue.On);
            }
        }
Пример #7
0
        partial void CustomSubViewClicked(NSObject sender)
        {
            var input = new NSTextField(new CGRect(0, 0, 300, 20));

            var alert = new NSAlert()
            {
                AlertStyle      = NSAlertStyle.Informational,
                InformativeText = "This is the body of the alert where you describe the situation and any actions to correct it.",
                MessageText     = "Alert Title"
            };

            alert.AddButton("OK");
            alert.AddButton("Cancel");
            alert.AddButton("Maybe");
            alert.ShowsSuppressionButton = true;
            alert.AccessoryView          = input;
            alert.Layout();
            var result = alert.RunModal();

            Console.WriteLine("Alert Result: {0}, Suppress: {1}", result, alert.SuppressionButton.State == NSCellStateValue.On);
        }
Пример #8
0
        public ImportOptions AskImportOptions()
        {
            var import = new ImportViewController();
            var alert  = new NSAlert()
            {
                AlertStyle      = NSAlertStyle.Informational,
                InformativeText = "This will scan the auto-saved data files in your Synthesia data directory and import the selected data for any song entries matching those in the current metadata file.\n\nCAUTION: Matching song data will always overwrite the selected fields in this metadata file!  This cannot be reversed.  Save a backup copy first if you are unsure.",
                MessageText     = "Import from Synthesia",
                AccessoryView   = import.View
            };

            alert.AddButton("Import");
            alert.AddButton("Cancel");
            alert.Layout();

            if (alert.RunSheetModal(Window) == (int)NSAlertButtonReturn.Second)
            {
                return(ImportOptions.Cancel);
            }

            ImportOptions result = 0;

            if (import.StandardSource)
            {
                result |= ImportOptions.StandardPath;
            }
            if (import.FingerHints)
            {
                result |= ImportOptions.FingerHints;
            }
            if (import.HandParts)
            {
                result |= ImportOptions.HandParts;
            }
            if (import.Parts)
            {
                result |= ImportOptions.Parts;
            }
            return(result);
        }
Пример #9
0
        protected virtual NSAlert CreateNativeActionSheet(ActionSheetConfig config)
        {
            var alert = new NSAlert
            {
                AlertStyle      = NSAlertStyle.Informational,
                MessageText     = config.Title ?? string.Empty,
                InformativeText = config.Message ?? string.Empty
            };

            if (config.Cancel != null)
            {
                alert.AddButton(config.Cancel.Text);
            }

            var extraSpace = config.Destructive == null ? 30 : 60;
            var inputView  = new NSStackView(new CGRect(0, 0, 200, (config.Options.Count * 30) + extraSpace));

            var yPos = config.Options.Count * 30 + (config.Destructive == null ? 0 : 1) * 30;

            foreach (var item in config.Options)
            {
                this.AddActionSheetOption(item, alert.Window, inputView, yPos);
                yPos -= 30;
            }

            if (config.Destructive != null)
            {
                this.AddActionSheetOption(config.Destructive, alert.Window, inputView, yPos, true);
            }

            alert.AccessoryView = inputView;
            alert.Layout();

            alert.BeginSheetForResponse(this.windowFunc(), _ => { });
            return(alert);
        }
Пример #10
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);
        }
Пример #11
0
        public bool Run(AlertDialogData data)
        {
            using (var alert = new NSAlert()) {
                alert.Window.Title = data.Title ?? BrandingService.ApplicationName;
                IdeTheme.ApplyTheme(alert.Window);

                bool stockIcon;
                if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Error || data.Message.Icon == Gtk.Stock.DialogError)
                {
                    alert.AlertStyle = NSAlertStyle.Critical;
                    stockIcon        = true;
                }
                else if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Warning || data.Message.Icon == Gtk.Stock.DialogWarning)
                {
                    alert.AlertStyle = NSAlertStyle.Critical;
                    stockIcon        = true;
                }
                else
                {
                    alert.AlertStyle = NSAlertStyle.Informational;
                    stockIcon        = data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Information;
                }

                if (!stockIcon && !string.IsNullOrEmpty(data.Message.Icon))
                {
                    var img = ImageService.GetIcon(data.Message.Icon, Gtk.IconSize.Dialog);
                    // HACK: VK The icon is not rendered in dark style correctly
                    //       Use light variant and reder it here
                    //       as long as NSAppearance.NameVibrantDark is broken
                    if (IdeTheme.UserInterfaceSkin == Skin.Dark)
                    {
                        alert.Icon = img.WithStyles("-dark").ToBitmap(GtkWorkarounds.GetScaleFactor()).ToNSImage();
                    }
                    else
                    {
                        alert.Icon = img.ToNSImage();
                    }
                }
                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;
                alert.InformativeText = data.Message.SecondaryText ?? "";

                var buttons = data.Buttons.Reverse().ToList();

                for (int i = 0; i < buttons.Count - 1; i++)
                {
                    if (i == data.Message.DefaultButton)
                    {
                        var next = buttons[i];
                        for (int j = buttons.Count - 1; j >= i; j--)
                        {
                            var tmp = buttons[j];
                            buttons[j] = next;
                            next       = tmp;
                        }
                        break;
                    }
                }

                var wrappers = new List <AlertButtonWrapper> (buttons.Count);
                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");
                    }

                    var nsbutton      = alert.AddButton(label);
                    var wrapperButton = new AlertButtonWrapper(nsbutton, data.Message, button, alert);
                    wrappers.Add(wrapperButton);
                    nsbutton.Target = wrapperButton;
                    nsbutton.Action = new ObjCRuntime.Selector("buttonActivatedAction");
                }


                NSButton[] optionButtons = null;
                if (data.Options.Count > 0)
                {
                    var box = new MDBox(LayoutDirection.Vertical, 2, 2);
                    optionButtons = new NSButton[data.Options.Count];

                    for (int i = data.Options.Count - 1; i >= 0; i--)
                    {
                        var option = data.Options[i];
                        var button = new NSButton {
                            Title = option.Text,
                            Tag   = i,
                            State = option.Value? NSCellStateValue.On : NSCellStateValue.Off,
                        };
                        button.SetButtonType(NSButtonType.Switch);
                        optionButtons[i] = button;
                        box.Add(new MDAlignment(button, true)
                        {
                            XAlign = LayoutAlign.Begin
                        });
                    }

                    box.Layout();
                    alert.AccessoryView = box.View;
                }

                NSButton applyToAllCheck = null;
                if (data.Message.AllowApplyToAll)
                {
                    alert.ShowsSuppressionButton = true;
                    applyToAllCheck       = alert.SuppressionButton;
                    applyToAllCheck.Title = GettextCatalog.GetString("Apply to all");
                }

                // 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 = alert.Window.Frame;
                alert.Window.SetFrame(new CGRect(frame.X, frame.Y, NMath.Max(frame.Width, 600), frame.Height), true);
                alert.Layout();

                bool completed = false;
                if (data.Message.CancellationToken.CanBeCanceled)
                {
                    data.Message.CancellationToken.Register(delegate {
                        alert.InvokeOnMainThread(() => {
                            if (!completed)
                            {
                                NSApplication.SharedApplication.AbortModal();
                            }
                        });
                    });
                }

                if (!data.Message.CancellationToken.IsCancellationRequested)
                {
                    var result = (int)alert.RunModal() - (long)(int)NSAlertButtonReturn.First;

                    completed = true;
                    if (result >= 0 && result < buttons.Count)
                    {
                        data.ResultButton = buttons [(int)result];
                    }
                    else
                    {
                        data.ResultButton = null;
                    }
                }

                if (data.ResultButton == null || data.Message.CancellationToken.IsCancellationRequested)
                {
                    data.SetResultToCancelled();
                }

                if (optionButtons != null)
                {
                    foreach (var button in optionButtons)
                    {
                        var option = data.Options[(int)button.Tag];
                        data.Message.SetOptionValue(option.Id, button.State != 0);
                    }
                }

                if (applyToAllCheck != null && applyToAllCheck.State != 0)
                {
                    data.ApplyToAll = true;
                }



                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;
		}
Пример #13
0
        public bool Run(AlertDialogData data)
        {
            using (var alert = new NSAlert()) {
                alert.Window.Title = data.Title ?? BrandingService.ApplicationName;
                IdeTheme.ApplyTheme(alert.Window);

                bool stockIcon;
                if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Error || data.Message.Icon == Gtk.Stock.DialogError)
                {
                    alert.AlertStyle = NSAlertStyle.Critical;
                    stockIcon        = true;
                }
                else if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Warning || data.Message.Icon == Gtk.Stock.DialogWarning)
                {
                    alert.AlertStyle = NSAlertStyle.Critical;
                    stockIcon        = true;
                }
                else
                {
                    alert.AlertStyle = NSAlertStyle.Informational;
                    stockIcon        = data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Information;
                }

                if (!stockIcon && !string.IsNullOrEmpty(data.Message.Icon))
                {
                    var img = ImageService.GetIcon(data.Message.Icon, Gtk.IconSize.Dialog);
                    // HACK: The icon is not rendered in dark mode (VibrantDark or DarkAqua) correctly.
                    //       Use light variant and reder it here.
                    // TODO: Recheck rendering issues with DarkAqua on final Mojave
                    if (IdeTheme.UserInterfaceTheme == Theme.Dark)
                    {
                        alert.Icon = img.WithStyles("-dark").ToBitmap(GtkWorkarounds.GetScaleFactor()).ToNSImage();
                    }
                    else
                    {
                        alert.Icon = img.ToNSImage();
                    }
                }
                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;

                int accessoryViewItemsCount = data.Options.Count;

                string secondaryText = data.Message.SecondaryText ?? string.Empty;
                if (TryGetMessageView(secondaryText, out NSView messageView))
                {
                    accessoryViewItemsCount++;
                }
                else
                {
                    alert.InformativeText = secondaryText;
                }

                var accessoryViews      = accessoryViewItemsCount > 0 ? new NSView [accessoryViewItemsCount] : null;
                int accessoryViewsIndex = 0;

                if (messageView != null)
                {
                    accessoryViews [accessoryViewsIndex++] = messageView;
                }

                var buttons = data.Buttons.Reverse().ToList();

                for (int i = 0; i < buttons.Count - 1; i++)
                {
                    if (i == data.Message.DefaultButton)
                    {
                        var next = buttons[i];
                        for (int j = buttons.Count - 1; j >= i; j--)
                        {
                            var tmp = buttons[j];
                            buttons[j] = next;
                            next       = tmp;
                        }
                        break;
                    }
                }

                var wrappers = new List <AlertButtonWrapper> (buttons.Count);
                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");
                    }

                    var nsbutton      = alert.AddButton(label);
                    var wrapperButton = new AlertButtonWrapper(nsbutton, data.Message, button, alert);
                    wrappers.Add(wrapperButton);
                    nsbutton.Target = wrapperButton;
                    nsbutton.Action = new ObjCRuntime.Selector("buttonActivatedAction");
                }

                NSButton [] optionButtons = null;
                if (data.Options.Count > 0)
                {
                    optionButtons = new NSButton [data.Options.Count];

                    for (int i = data.Options.Count - 1; i >= 0; i--)
                    {
                        var option = data.Options[i];
                        var button = new NSButton {
                            Title = option.Text,
                            Tag   = i,
                            State = option.Value? NSCellStateValue.On : NSCellStateValue.Off,
                        };
                        button.SetButtonType(NSButtonType.Switch);
                        button.SizeToFit();
                        optionButtons [i] = button;
                        accessoryViews [accessoryViewsIndex++] = button;
                    }
                }

                var accessoryView = ArrangeAccessoryViews(accessoryViews);
                if (accessoryView != null)
                {
                    if (accessoryViews?[0] == messageView)
                    {
                        accessoryView.SetCustomSpacing(accessoryView.Spacing * 2, messageView);
                        var size = accessoryView.Frame.Size;
                        size.Height += accessoryView.Spacing;
                        accessoryView.SetFrameSize(size);
                    }
                    alert.AccessoryView = accessoryView;
                }

                NSButton applyToAllCheck = null;
                if (data.Message.AllowApplyToAll)
                {
                    alert.ShowsSuppressionButton = true;
                    applyToAllCheck       = alert.SuppressionButton;
                    applyToAllCheck.Title = GettextCatalog.GetString("Apply to all");
                }

                // 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 = alert.Window.Frame;
                alert.Window.SetFrame(new CGRect(frame.X, frame.Y, NMath.Max(frame.Width, 600), frame.Height), true);
                alert.Layout();

                bool completed = false;
                if (data.Message.CancellationToken.CanBeCanceled)
                {
                    data.Message.CancellationToken.Register(delegate {
                        alert.InvokeOnMainThread(() => {
                            if (!completed)
                            {
                                if (alert.Window.IsSheet && alert.Window.SheetParent != null)
                                {
                                    alert.Window.SheetParent.EndSheet(alert.Window);
                                }
                                else
                                {
                                    NSApplication.SharedApplication.AbortModal();
                                }
                            }
                        });
                    });
                }

                int response = -1000;

                var parent = data.TransientFor;
                if (parent == null && IdeApp.Workbench?.RootWindow?.Visible == true)
                {
                    parent = IdeApp.Workbench?.RootWindow;
                }
                NSWindow nativeParent;
                try {
                    nativeParent = parent;
                } catch (NotSupportedException) {
                    nativeParent = null;
                }
                if (!data.Message.CancellationToken.IsCancellationRequested)
                {
                    // sheeting is broken on High Sierra with dark NSAppearance
                    var sheet = IdeTheme.UserInterfaceTheme != Theme.Dark || MacSystemInformation.OsVersion != MacSystemInformation.HighSierra;

                    // We have an issue with accessibility when using sheets, so disable it here
                    sheet &= !IdeServices.DesktopService.AccessibilityInUse;

                    if (!sheet || nativeParent == null)
                    {
                        // Force the alert window to be focused for accessibility
                        NSApplication.SharedApplication.AccessibilityFocusedWindow = alert.Window;
                        alert.Window.AccessibilityFocused = true;

                        if (nativeParent != null)
                        {
                            nativeParent.AccessibilityFocused = false;
                        }

                        alert.Window.ReleasedWhenClosed = true;
                        response = (int)alert.RunModal();

                        // Focus the old window
                        NSApplication.SharedApplication.AccessibilityFocusedWindow = nativeParent;
                    }
                    else
                    {
                        alert.BeginSheet(nativeParent, (modalResponse) => {
                            response = (int)modalResponse;
                            NSApplication.SharedApplication.StopModal();
                        });

                        NSApplication.SharedApplication.RunModalForWindow(alert.Window);
                    }
                }

                var result = response - (long)(int)NSAlertButtonReturn.First;

                completed = true;

                if (result >= 0 && result < buttons.Count)
                {
                    data.ResultButton = buttons [(int)result];
                }
                else
                {
                    data.ResultButton = null;
                }

                if (data.ResultButton == null || data.Message.CancellationToken.IsCancellationRequested)
                {
                    data.SetResultToCancelled();
                }

                if (optionButtons != null)
                {
                    foreach (var button in optionButtons)
                    {
                        var option = data.Options[(int)button.Tag];
                        data.Message.SetOptionValue(option.Id, button.State != 0);
                    }
                }

                if (applyToAllCheck != null && applyToAllCheck.State != 0)
                {
                    data.ApplyToAll = true;
                }

                if (nativeParent != null)
                {
                    nativeParent.MakeKeyAndOrderFront(nativeParent);
                }
                else
                {
                    IdeServices.DesktopService.FocusWindow(parent);
                }
            }

            return(true);
        }
Пример #14
0
        public bool Run(AlertDialogData data)
        {
            using (var alert = new NSAlert()) {
                if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Information)
                {
                    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)
                {
                    alert.AlertStyle = NSAlertStyle.Informational;
                }

                //FIXME: use correct size so we don't get horrible scaling?
                if (!string.IsNullOrEmpty(data.Message.Icon))
                {
                    var    pix = ImageService.GetPixbuf(data.Message.Icon, Gtk.IconSize.Dialog);
                    byte[] buf = pix.SaveToBuffer("tiff");
                    unsafe
                    {
                        fixed(byte *b = buf)
                        {
                            alert.Icon = new NSImage(NSData.FromBytes((IntPtr)b, (uint)buf.Length));
                        }
                    }
                }

                alert.MessageText     = data.Message.Text;
                alert.InformativeText = data.Message.SecondaryText ?? "";

                var buttons = data.Buttons.Reverse().ToList();

                for (int i = 0; i < buttons.Count - 1; i++)
                {
                    if (i == data.Message.DefaultButton)
                    {
                        var next = buttons[i];
                        for (int j = buttons.Count - 1; j >= i; j--)
                        {
                            var tmp = buttons[j];
                            buttons[j] = next;
                            next       = tmp;
                        }
                        break;
                    }
                }

                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);
                }


                NSButton[] optionButtons = null;
                if (data.Options.Count > 0)
                {
                    var box = new MDBox(LayoutDirection.Vertical, 2, 2);
                    optionButtons = new NSButton[data.Options.Count];

                    for (int i = data.Options.Count - 1; i >= 0; i--)
                    {
                        var option = data.Options[i];
                        var button = new NSButton()
                        {
                            Title = option.Text,
                            Tag   = i,
                            State = option.Value? NSCellStateValue.On : NSCellStateValue.Off,
                        };
                        button.SetButtonType(NSButtonType.Switch);
                        optionButtons[i] = button;
                        box.Add(new MDAlignment(button, true)
                        {
                            XAlign = LayoutAlign.Begin
                        });
                    }

                    box.Layout();
                    alert.AccessoryView = box.View;
                }

                NSButton applyToAllCheck = null;
                if (data.Message.AllowApplyToAll)
                {
                    alert.ShowsSuppressionButton = true;
                    applyToAllCheck       = alert.SuppressionButton;
                    applyToAllCheck.Title = GettextCatalog.GetString("Apply to all");
                }

                alert.Layout();

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

                data.ResultButton = buttons [result];

                if (optionButtons != null)
                {
                    foreach (var button in optionButtons)
                    {
                        var option = data.Options[button.Tag];
                        data.Message.SetOptionValue(option.Id, button.State != 0);
                    }
                }

                if (applyToAllCheck != null && applyToAllCheck.State != 0)
                {
                    data.ApplyToAll = true;
                }

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

            return(true);
        }
Пример #15
0
        public bool Run(AlertDialogData data)
        {
            using (var alert = new NSAlert()) {
                alert.Window.Title = data.Title ?? BrandingService.ApplicationName;

                if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Information)
                {
                    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) {
                {
                    alert.AlertStyle = NSAlertStyle.Informational;
                }

                //FIXME: use correct size so we don't get horrible scaling?
                if (!string.IsNullOrEmpty(data.Message.Icon))
                {
                    var    pix = ImageService.GetPixbuf(data.Message.Icon, Gtk.IconSize.Dialog);
                    byte[] buf = pix.SaveToBuffer("tiff");
                    unsafe
                    {
                        fixed(byte *b = buf)
                        {
                            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;
                alert.InformativeText = data.Message.SecondaryText ?? "";

                var buttons = data.Buttons.Reverse().ToList();

                for (int i = 0; i < buttons.Count - 1; i++)
                {
                    if (i == data.Message.DefaultButton)
                    {
                        var next = buttons[i];
                        for (int j = buttons.Count - 1; j >= i; j--)
                        {
                            var tmp = buttons[j];
                            buttons[j] = next;
                            next       = tmp;
                        }
                        break;
                    }
                }

                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);
                }


                NSButton[] optionButtons = null;
                if (data.Options.Count > 0)
                {
                    var box = new MDBox(LayoutDirection.Vertical, 2, 2);
                    optionButtons = new NSButton[data.Options.Count];

                    for (int i = data.Options.Count - 1; i >= 0; i--)
                    {
                        var option = data.Options[i];
                        var button = new NSButton()
                        {
                            Title = option.Text,
                            Tag   = i,
                            State = option.Value? NSCellStateValue.On : NSCellStateValue.Off,
                        };
                        button.SetButtonType(NSButtonType.Switch);
                        optionButtons[i] = button;
                        box.Add(new MDAlignment(button, true)
                        {
                            XAlign = LayoutAlign.Begin
                        });
                    }

                    box.Layout();
                    alert.AccessoryView = box.View;
                }

                NSButton applyToAllCheck = null;
                if (data.Message.AllowApplyToAll)
                {
                    alert.ShowsSuppressionButton = true;
                    applyToAllCheck       = alert.SuppressionButton;
                    applyToAllCheck.Title = GettextCatalog.GetString("Apply to all");
                }

                // 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);
                alert.Layout();

                bool completed = false;
                if (data.Message.CancellationToken.CanBeCanceled)
                {
                    data.Message.CancellationToken.Register(delegate {
                        alert.InvokeOnMainThread(() => {
                            if (!completed)
                            {
                                NSApplication.SharedApplication.AbortModal();
                            }
                        });
                    });
                }

                if (!data.Message.CancellationToken.IsCancellationRequested)
                {
                    int result = alert.RunModal() - (int)NSAlertButtonReturn.First;
                    completed = true;
                    if (result >= 0 && result < buttons.Count)
                    {
                        data.ResultButton = buttons [result];
                    }
                    else
                    {
                        data.ResultButton = null;
                    }
                }

                if (data.ResultButton == null || data.Message.CancellationToken.IsCancellationRequested)
                {
                    data.SetResultToCancelled();
                }

                if (optionButtons != null)
                {
                    foreach (var button in optionButtons)
                    {
                        var option = data.Options[button.Tag];
                        data.Message.SetOptionValue(option.Id, button.State != 0);
                    }
                }

                if (applyToAllCheck != null && applyToAllCheck.State != 0)
                {
                    data.ApplyToAll = true;
                }

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

            return(true);
        }
Пример #16
0
		void ShowAlert (NSObject sender) {
			if (ShowAlertAsSheet) {
				var input = new NSTextField (new CGRect (0, 0, 300, 20));

				var alert = new NSAlert () {
					AlertStyle = NSAlertStyle.Informational,
					InformativeText = "This is the body of the alert where you describe the situation and any actions to correct it.",
					MessageText = "Alert Title",
				};
				alert.AddButton ("Ok");
				alert.AddButton ("Cancel");
				alert.AddButton ("Maybe");
				alert.ShowsSuppressionButton = true;
				alert.AccessoryView = input;
				alert.Layout ();
				alert.BeginSheetForResponse (this, (result) => {
					Console.WriteLine ("Alert Result: {0}, Suppress: {1}", result, alert.SuppressionButton.State == NSCellStateValue.On);
				});
			} else {
				var input = new NSTextField (new CGRect (0, 0, 300, 20));

				var alert = new NSAlert () {
					AlertStyle = NSAlertStyle.Informational,
					InformativeText = "This is the body of the alert where you describe the situation and any actions to correct it.",
					MessageText = "Alert Title",
				};
				alert.AddButton ("Ok");
				alert.AddButton ("Cancel");
				alert.AddButton ("Maybe");
				alert.ShowsSuppressionButton = true;
				alert.AccessoryView = input;
				alert.Layout ();
				var result = alert.RunModal ();
				Console.WriteLine ("Alert Result: {0}, Suppress: {1}", result, alert.SuppressionButton.State == NSCellStateValue.On);
			}
		}
		public bool Run (AlertDialogData data)
		{
			using (var alert = new NSAlert ()) {
				alert.Window.Title = data.Title ?? BrandingService.ApplicationName;
				IdeTheme.ApplyTheme (alert.Window);

				bool stockIcon;
				if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Error || data.Message.Icon == Gtk.Stock.DialogError) {
					alert.AlertStyle = NSAlertStyle.Critical;
					stockIcon = true;
				} else if (data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Warning || data.Message.Icon == Gtk.Stock.DialogWarning) {
					alert.AlertStyle = NSAlertStyle.Critical;
					stockIcon = true;
				} else {
					alert.AlertStyle = NSAlertStyle.Informational;
					stockIcon = data.Message.Icon == MonoDevelop.Ide.Gui.Stock.Information;
				}

				if (!stockIcon && !string.IsNullOrEmpty (data.Message.Icon)) {
					var img = ImageService.GetIcon (data.Message.Icon, Gtk.IconSize.Dialog);
					// HACK: VK The icon is not rendered in dark style correctly
					//       Use light variant and reder it here
					//       as long as NSAppearance.NameVibrantDark is broken
					if (IdeTheme.UserInterfaceTheme == Theme.Dark)
						alert.Icon = img.WithStyles ("-dark").ToBitmap (GtkWorkarounds.GetScaleFactor ()).ToNSImage ();
					else
						alert.Icon = img.ToNSImage ();
				} 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;
				alert.InformativeText = data.Message.SecondaryText ?? "";
				
				var buttons = data.Buttons.Reverse ().ToList ();
				
				for (int i = 0; i < buttons.Count - 1; i++) {
					if (i == data.Message.DefaultButton) {
						var next = buttons[i];
						for (int j = buttons.Count - 1; j >= i; j--) {
							var tmp = buttons[j];
							buttons[j] = next;
							next = tmp;
						}
						break;
					}
				}
				
				var wrappers = new List<AlertButtonWrapper> (buttons.Count);
				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");

					var nsbutton = alert.AddButton (label);
					var wrapperButton = new AlertButtonWrapper (nsbutton, data.Message, button, alert);
					wrappers.Add (wrapperButton);
					nsbutton.Target = wrapperButton;
					nsbutton.Action = new ObjCRuntime.Selector ("buttonActivatedAction");
				}
				
				
				NSButton[] optionButtons = null;
				if (data.Options.Count > 0) {
					var box = new MDBox (LayoutDirection.Vertical, 2, 2);
					optionButtons = new NSButton[data.Options.Count];
					
					for (int i = data.Options.Count - 1; i >= 0; i--) {
						var option = data.Options[i];
						var button = new NSButton {
							Title = option.Text,
							Tag = i,
							State = option.Value? NSCellStateValue.On : NSCellStateValue.Off,
						};
						button.SetButtonType (NSButtonType.Switch);
						optionButtons[i] = button;
						box.Add (new MDAlignment (button, true) { XAlign = LayoutAlign.Begin });
					}
					
					box.Layout ();
					alert.AccessoryView = box.View;
				}
				
				NSButton applyToAllCheck = null;
				if (data.Message.AllowApplyToAll) {
					alert.ShowsSuppressionButton = true;
					applyToAllCheck = alert.SuppressionButton;
					applyToAllCheck.Title = GettextCatalog.GetString ("Apply to all");
				}
				
				// 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 = alert.Window.Frame;
				alert.Window.SetFrame (new CGRect (frame.X, frame.Y, NMath.Max (frame.Width, 600), frame.Height), true);
				alert.Layout ();
				
				bool completed = false;
				if (data.Message.CancellationToken.CanBeCanceled) {
					data.Message.CancellationToken.Register (delegate {
						alert.InvokeOnMainThread (() => {
							if (!completed) {
								NSApplication.SharedApplication.AbortModal ();
							}
						});
					});
				}
				
				if (!data.Message.CancellationToken.IsCancellationRequested) {

					var result = (int)alert.RunModal () - (long)(int)NSAlertButtonReturn.First;
					
					completed = true;
					if (result >= 0 && result < buttons.Count) {
						data.ResultButton = buttons [(int)result];
					} else {
						data.ResultButton = null;
					}
				}
				
				if (data.ResultButton == null || data.Message.CancellationToken.IsCancellationRequested) {
					data.SetResultToCancelled ();
				}
				
				if (optionButtons != null) {
					foreach (var button in optionButtons) {
						var option = data.Options[(int)button.Tag];
						data.Message.SetOptionValue (option.Id, button.State != 0);
					}
				}
				
				if (applyToAllCheck != null && applyToAllCheck.State != 0)
					data.ApplyToAll = true;



				GtkQuartz.FocusWindow (data.TransientFor ?? MessageService.RootWindow);
			}
			
			return true;
		}
Пример #18
0
        public static void NewPassword(SqliteConnection connection, SqliteConnection _conn)
        {
            var newPasswordInput = new NSStackView(new CGRect(0, 0, 300, 50));

            var originalPassword = new NSSecureTextField(new CGRect(0, 25, 300, 20));

            originalPassword.PlaceholderAttributedString = new Foundation.NSAttributedString("Type new password...");
            var confirmedPassword = new NSSecureTextField(new CGRect(0, 0, 300, 20));

            confirmedPassword.PlaceholderAttributedString = new Foundation.NSAttributedString("Confirm password...");

            newPasswordInput.AddSubview(originalPassword);
            newPasswordInput.AddSubview(confirmedPassword);

            var newPasswordAlert = new NSAlert()
            {
                AlertStyle      = NSAlertStyle.Informational,
                InformativeText = "Enter new password to secure SittingDucks",
                MessageText     = "Adding New Password",
            };
            var enterButton = newPasswordAlert.AddButton("Enter");

            originalPassword.NextKeyView  = confirmedPassword;
            confirmedPassword.NextKeyView = enterButton;

            newPasswordAlert.AccessoryView = newPasswordInput;
            newPasswordAlert.Layout();
            var result = newPasswordAlert.RunModal();

            if (result == 1000 && originalPassword.StringValue == confirmedPassword.StringValue)
            {
                bool shouldClose;
                var  encryptedPassword = EncryptionTool.Encrypt(originalPassword.StringValue);

                (_conn, shouldClose) = SqliteManager.OpenConnection(connection);

                // Execute query
                using (var command = connection.CreateCommand())
                {
                    // Create new command
                    command.CommandText = "UPDATE [System] SET ID = @COL1, Password = @COL2, INIT = @COL3";

                    // Populate with data from the record
                    command.Parameters.AddWithValue("@COL1", new Guid());
                    command.Parameters.AddWithValue("@COL2", encryptedPassword);
                    command.Parameters.AddWithValue("@COL3", true);

                    // Write to database
                    command.ExecuteNonQuery();
                }

                _conn = SqliteManager.CloseConnection(shouldClose, connection);

                newPasswordAlert.Dispose();

                var confirmPasswordAlert = new NSAlert()
                {
                    AlertStyle      = NSAlertStyle.Informational,
                    InformativeText = "Remember this password, store it somewhere safe! You will not be able to recover it if lost.",
                    MessageText     = "Password sucessfully saved",
                };
                confirmPasswordAlert.AddButton("OK");
                var confirmResult = confirmPasswordAlert.RunModal();

                if (confirmResult == 1000)
                {
                    confirmPasswordAlert.Dispose();
                }
            }
            else if (result == 1000 && originalPassword.StringValue != confirmedPassword.StringValue)
            {
                newPasswordAlert.AlertStyle      = NSAlertStyle.Warning;
                newPasswordAlert.InformativeText = "Passwords do not match";
            }
        }