Beispiel #1
0
        private static string GetCustomTextForButton(OSMessageBoxButton button, Dictionary <OSMessageBoxButton, string> customButtonLabels, OSMessageBoxButton dialogButtons)
        {
            var buttonText = string.Empty;

            if ((customButtonLabels == null) || !customButtonLabels.TryGetValue(button, out buttonText))
            {
                switch (button)
                {
                case OSMessageBoxButton.OK:
                    if (dialogButtons == OSMessageBoxButton.OK)
                    {
                        buttonText = Resources.Strings.OKButton_Text;
                    }
                    else
                    {
                        buttonText = Resources.Strings.YesButton_Text;
                    }
                    break;

                case OSMessageBoxButton.YesNo:
                    buttonText = Resources.Strings.NoButton_Text;
                    break;

                case OSMessageBoxButton.YesNoCancel:
                    buttonText = Resources.Strings.CancelButtonText;
                    break;
                }
            }
            return(buttonText);
        }
Beispiel #2
0
        private static OSMessageBoxResult PlatformShowCore(string message, string title, System.Exception exception, OSMessageBoxButton buttons, Dictionary <OSMessageBoxButton, string> customButtonLabels, OSMessageBoxIcon icon, OSMessageBoxResult defaultResult, System.Action <OSMessageBoxResult> onComplete)
        {
            var result = OSMessageBoxResult.None;

            if (onComplete == null)
            {
                INTV.Shared.Utility.OSDispatcher.Current.InvokeOnMainDispatcher(() =>
                {
                    using (var messageBox = new NSAlert())
                    {
                        messageBox.MessageText     = title;
                        messageBox.InformativeText = message;
                        messageBox.AlertStyle      = (NSAlertStyle)icon;
                        messageBox.AddButton(GetCustomTextForButton(OSMessageBoxButton.OK, customButtonLabels, buttons));
                        var defaultButton      = messageBox.Buttons[0];
                        var defaultButtonIndex = 0;
                        NSButton buttonTwo     = null;
                        NSButton buttonThree   = null;
                        switch (buttons)
                        {
                        case OSMessageBoxButton.OK:
                            break;

                        case OSMessageBoxButton.YesNo:
                            if (defaultResult == OSMessageBoxResult.No)
                            {
                                defaultButtonIndex = 1;
                            }
                            buttonTwo = messageBox.AddButton(GetCustomTextForButton(OSMessageBoxButton.YesNo, customButtonLabels, buttons));
                            break;

                        case OSMessageBoxButton.YesNoCancel:
                            if (defaultResult == OSMessageBoxResult.Cancel)
                            {
                                defaultButtonIndex = 2;
                            }
                            buttonTwo   = messageBox.AddButton(GetCustomTextForButton(OSMessageBoxButton.YesNo, customButtonLabels, buttons));
                            buttonThree = messageBox.AddButton(GetCustomTextForButton(OSMessageBoxButton.YesNoCancel, customButtonLabels, buttons));
                            break;
                        }
                        if (customButtonLabels != null)
                        {
                            var buttonText = string.Empty;
                            System.Diagnostics.Debug.WriteLineIf((defaultButton != null) && customButtonLabels.TryGetValue(OSMessageBoxButton.OK, out buttonText) && (buttonText != GetCustomTextForButton(OSMessageBoxButton.OK, customButtonLabels, buttons)), "Custom button1 text not used.");
                            System.Diagnostics.Debug.WriteLineIf((buttonTwo != null) && customButtonLabels.TryGetValue(OSMessageBoxButton.YesNo, out buttonText) && (buttonText != GetCustomTextForButton(OSMessageBoxButton.YesNo, customButtonLabels, buttons)), "Custom button2 text not used.");
                            System.Diagnostics.Debug.WriteLineIf((buttonThree != null) && customButtonLabels.TryGetValue(OSMessageBoxButton.YesNoCancel, out buttonText) && (buttonText != GetCustomTextForButton(OSMessageBoxButton.YesNoCancel, customButtonLabels, buttons)), "Custom button3 text not used.");
                        }
                        if (defaultButtonIndex != 0)
                        {
                            defaultButton.KeyEquivalent = string.Empty;
                            messageBox.Buttons[defaultButtonIndex].KeyEquivalent = "\r";
                        }
                        result = (OSMessageBoxResult)(int)messageBox.RunModal();
                    }
                });
            }
            else
            {
                INTV.Shared.Utility.SingleInstanceApplication.MainThreadDispatcher.BeginInvoke(() =>
                {
                    result = ShowCore(message, title, exception, null, buttons, customButtonLabels, icon, defaultResult, null);
                    onComplete(result);
                });
            }
            return(result);
        }
Beispiel #3
0
 /// <summary>
 /// Show a message box and wait for a result.
 /// </summary>
 /// <param name="message">The detailed message to display.</param>
 /// <param name="title">Title for the message box.</param>
 /// <param name="exception">Exception information to report, if applicable.</param>
 /// <param name="buttons">The buttons to show in the dialog box.</param>
 /// <param name="onComplete">Upon completion of the dialog, this delegate will be called, if not <c>null</c>,</param>
 public static void Show(string message, string title, Exception exception, OSMessageBoxButton buttons, Action <OSMessageBoxResult> onComplete)
 {
     Show(message, title, exception, null, buttons, OSMessageBoxIcon.None, OSMessageBoxResult.OK, onComplete);
 }
Beispiel #4
0
        private static OSMessageBoxResult ShowCore(string message, string title, Exception exception, string reportText, OSMessageBoxButton buttons, Dictionary <OSMessageBoxButton, string> customButtonLabels, OSMessageBoxIcon icon, OSMessageBoxResult defaultResult, Action <OSMessageBoxResult> onComplete)
        {
            var result          = OSMessageBoxResult.None;
            var useErrorReport  = exception != null;
            var reportException = useErrorReport;

            if (useErrorReport)
            {
                foreach (Predicate <Exception> predicate in _exceptionFilters.GetInvocationList())
                {
                    reportException = predicate(exception);
                    if (!reportException)
                    {
                        break;
                    }
                }
            }
            var hideExtraButtons = false;

#if USE_BETA_ERROR_REPORT
            useErrorReport   = true;
            hideExtraButtons = exception == null;
#endif // USE_BETA_ERROR_REPORT
            if (useErrorReport)
            {
                var messageLine = message;
                var dialog      = ReportDialog.Create(title, messageLine);
                dialog.Exception  = reportException ? exception : null;
                dialog.ReportText = reportText;
                dialog.ShowCopyToClipboardButton = !hideExtraButtons;
                dialog.ShowSendEmailButton       = !hideExtraButtons;
                var buttonText = GetCustomTextForButton(OSMessageBoxButton.OK, null, buttons);
                var showResult = dialog.ShowDialog(buttonText);
                if (showResult.HasValue)
                {
                    result = showResult.Value ? OSMessageBoxResult.OK : OSMessageBoxResult.Cancel;
                    if (buttons != OSMessageBoxButton.OK)
                    {
                        result = showResult.Value ? OSMessageBoxResult.Yes : OSMessageBoxResult.No;
                    }
                }
            }
            else
            {
                var dialogMessage = new System.Text.StringBuilder(message);
                if (!string.IsNullOrWhiteSpace(reportText))
                {
                    dialogMessage.AppendLine().AppendLine().Append(reportText);
                }
                result = PlatformShowCore(dialogMessage.ToString(), title, exception, buttons, customButtonLabels, icon, defaultResult, onComplete);
            }
            return(result);
        }
Beispiel #5
0
 /// <summary>
 /// Show a message box and wait for a result.
 /// </summary>
 /// <param name="message">The detailed message to display.</param>
 /// <param name="title">Title for the message box.</param>
 /// <param name="exception">Exception information to report, if applicable.</param>
 /// <param name="buttons">The buttons to show in the dialog box.</param>
 /// <param name="icon">The icon to show in the dialog box.</param>
 /// <returns>The result of the dialog.</returns>
 public static OSMessageBoxResult Show(string message, string title, Exception exception, OSMessageBoxButton buttons, OSMessageBoxIcon icon)
 {
     return(Show(message, title, exception, buttons, icon, OSMessageBoxResult.OK));
 }
Beispiel #6
0
 /// <summary>
 /// Show a message box and wait for a result.
 /// </summary>
 /// <param name="message">The detailed message to display.</param>
 /// <param name="title">Title for the message box.</param>
 /// <param name="exception">Exception information to report, if applicable.</param>
 /// <param name="buttons">The buttons to show in the dialog box.</param>
 /// <param name="icon">The icon to show in the dialog box.</param>
 /// <param name="defaultResult">The default result.</param>
 /// <returns>The result of the dialog.</returns>
 public static OSMessageBoxResult Show(string message, string title, Exception exception, OSMessageBoxButton buttons, OSMessageBoxIcon icon, OSMessageBoxResult defaultResult)
 {
     return(ShowCore(message, title, exception, null, buttons, null, icon, defaultResult, null));
 }
Beispiel #7
0
 /// <summary>
 /// Show a message box and wait for a result.
 /// </summary>
 /// <param name="message">The detailed message to display.</param>
 /// <param name="title">Title for the message box.</param>
 /// <param name="buttons">The buttons to show in the dialog box.</param>
 /// <param name="customButtonLabels">Custom button names.</param>
 /// <param name="icon">The icon to show in the dialog box.</param>
 /// <returns>The result of the dialog.</returns>
 /// <remarks>Custom button names are not supported in Windows.</remarks>
 public static OSMessageBoxResult Show(string message, string title, OSMessageBoxButton buttons, Dictionary <OSMessageBoxButton, string> customButtonLabels, OSMessageBoxIcon icon)
 {
     return(ShowCore(message, title, null, null, buttons, customButtonLabels, icon, OSMessageBoxResult.OK, null));
 }
Beispiel #8
0
 /// <summary>
 /// Show a message box and wait for a result.
 /// </summary>
 /// <param name="message">The detailed message to display.</param>
 /// <param name="title">Title for the message box.</param>
 /// <param name="buttons">The buttons to show in the dialog box.</param>
 /// <returns>The result of the dialog.</returns>
 public static OSMessageBoxResult Show(string message, string title, OSMessageBoxButton buttons)
 {
     return(Show(message, title, null, buttons, OSMessageBoxIcon.None, OSMessageBoxResult.OK));
 }
Beispiel #9
0
 /// <summary>
 /// Show a message box and wait for a result.
 /// </summary>
 /// <param name="message">The detailed message to display.</param>
 /// <param name="title">Title for the message box.</param>
 /// <param name="exception">Exception information to report, if applicable.</param>
 /// <param name="reportText">Additional report text. If <paramref name="exception"/> is non-<c>null</c>, will be included in the error details, otherwise it will be part of the general message.</param>
 /// <param name="buttons">The buttons to show in the dialog box.</param>
 /// <param name="icon">The icon to show in the dialog box.</param>
 /// <param name="defaultResult">The default result.</param>
 /// <param name="onComplete">Upon completion of the dialog, this delegate will be called, if not <c>null</c>,</param>
 public static void Show(string message, string title, Exception exception, string reportText, OSMessageBoxButton buttons, OSMessageBoxIcon icon, OSMessageBoxResult defaultResult, Action <OSMessageBoxResult> onComplete)
 {
     ShowCore(message, title, exception, reportText, buttons, null, icon, defaultResult, onComplete);
 }
Beispiel #10
0
        private static OSMessageBoxResult PlatformShowCore(string message, string title, Exception exception, OSMessageBoxButton buttons, Dictionary <OSMessageBoxButton, string> customButtonLabels, OSMessageBoxIcon icon, OSMessageBoxResult defaultResult, Action <OSMessageBoxResult> onComplete)
        {
            var result      = OSMessageBoxResult.None;
            var appInstance = INTV.Shared.Utility.SingleInstanceApplication.Instance;

            INTV.Shared.Utility.OSDispatcher.Current.InvokeOnMainDispatcher(() =>
            {
                var owner = (appInstance == null) ? null : appInstance.MainWindow;
                result    = OSMessageBoxResult.None;
                if (onComplete == null)
                {
                    result = (OSMessageBoxResult)System.Windows.MessageBox.Show(owner, message, title, (System.Windows.MessageBoxButton)buttons, (System.Windows.MessageBoxImage)icon, (System.Windows.MessageBoxResult)defaultResult);
                }
                else
                {
                    INTV.Shared.Utility.SingleInstanceApplication.MainThreadDispatcher.BeginInvoke(() =>
                    {
                        result = ShowCore(message, title, exception, null, buttons, customButtonLabels, icon, defaultResult, null);
                        onComplete(result);
                    });
                }
            });
            return(result);
        }
Beispiel #11
0
        private static OSMessageBoxResult PlatformShowCore(string message, string title, System.Exception exception, OSMessageBoxButton buttons, Dictionary <OSMessageBoxButton, string> customButtonLabels, OSMessageBoxIcon icon, OSMessageBoxResult defaultResult, System.Action <OSMessageBoxResult> onComplete)
        {
            var result = OSMessageBoxResult.None;

            if (onComplete == null)
            {
                INTV.Shared.Utility.OSDispatcher.Current.InvokeOnMainDispatcher(() =>
                {
                    var nativeButtons = Gtk.ButtonsType.Ok;
                    switch (buttons)
                    {
                    case OSMessageBoxButton.OK:
                    case OSMessageBoxButton.YesNo:
                        nativeButtons = (Gtk.ButtonsType)buttons;
                        break;

                    case OSMessageBoxButton.YesNoCancel:
                        nativeButtons = Gtk.ButtonsType.None;         // we'll add buttons below
                        break;
                    }

                    var parent = Gtk.Window.ListToplevels().FirstOrDefault(w => w.IsActive || w.IsFocus);
                    if (parent == null)
                    {
                        parent = INTV.Shared.Utility.SingleInstanceApplication.Instance.MainWindow;
                    }

                    using (var messageBox = new Gtk.MessageDialog(parent, Gtk.DialogFlags.Modal, (Gtk.MessageType)icon, nativeButtons, "{0}", message))
                    {
                        messageBox.Title           = title;
                        messageBox.MessageType     = (Gtk.MessageType)icon;
                        messageBox.DefaultResponse = (Gtk.ResponseType)defaultResult;
                        switch (buttons)
                        {
                        case OSMessageBoxButton.OK:
                        case OSMessageBoxButton.YesNo:
                            break;

                        case OSMessageBoxButton.YesNoCancel:
                            messageBox.AddButton(Resources.Strings.YesButton_Text, Gtk.ResponseType.Yes);
                            messageBox.AddButton(Resources.Strings.NoButton_Text, Gtk.ResponseType.No);
                            messageBox.AddButton(Resources.Strings.CancelButtonText, Gtk.ResponseType.Cancel);
                            break;
                        }
                        result = (OSMessageBoxResult)messageBox.Run();
                        VisualHelpers.Close(messageBox);
                    }
                });
            }
            else
            {
                INTV.Shared.Utility.SingleInstanceApplication.MainThreadDispatcher.BeginInvoke(() =>
                {
                    result = ShowCore(message, title, exception, null, buttons, customButtonLabels, icon, defaultResult, null);
                    onComplete(result);
                });
            }

            return(result);
        }