Exemplo n.º 1
0
        /// <summary>
        /// Shows a modal dialog.
        /// </summary>
        /// <param name="dialog">The dialog to show.</param>
        /// <param name="alwaysClose">If set to <c>true</c> always close the dialog as soon as a response is known.</param>
        /// <param name="closeForResponses">If <paramref name="alwaysClose"/> is <c>false</c>, only the provided values will exit the dialog run loop.</param>
        /// <returns>A value indicating whether the dialog was cancelled (<c>false</c>), aborted (<c>null</c>) or approved (<c>true</c>).</returns>
        /// <remarks>Dialogs with 'sub-functions' should always use a response value of Gtk.ResponseType.None. Other explicit values
        /// may be ignored -- that is, only specific values will exit the dialog if the <paramref name="closeForResponses"/> argument
        /// is non-empty and <paramref name="alwaysClose"/> is <c>false</c>. If alwaysClose is false and no response values for close are
        /// provided, it is a Bad Thing and you shouldn't do that.</remarks>
        public static bool?ShowDialog(this Gtk.Dialog dialog, bool alwaysClose, params Gtk.ResponseType[] closeForResponses)
        {
            bool?accepted = null;
            var  result   = Gtk.ResponseType.None;

            do
            {
                result = (Gtk.ResponseType)dialog.Run();
                if (result != Gtk.ResponseType.None)
                {
                    switch (result)
                    {
                    case Gtk.ResponseType.Reject:
                    case Gtk.ResponseType.Cancel:
                    case Gtk.ResponseType.Close:
                    case Gtk.ResponseType.No:
                        accepted = false;
                        break;

                    case Gtk.ResponseType.Accept:
                    case Gtk.ResponseType.Apply:
                    case Gtk.ResponseType.Help:
                    case Gtk.ResponseType.Yes:
                    case Gtk.ResponseType.Ok:
                        accepted = true;
                        break;

                    default:
                        break;
                    }
                }
            }while (!alwaysClose && ((closeForResponses == null) || !closeForResponses.Contains(result)));
            VisualHelpers.Close(dialog);
            return(accepted);
        }
Exemplo n.º 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(() =>
                {
                    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);
        }
Exemplo n.º 3
0
        /// <inheritdoc/>
        public override FileBrowserDialogResult ShowDialog()
        {
            var fileChooserAction = IsFolderBrowser ? Gtk.FileChooserAction.SelectFolder : Gtk.FileChooserAction.Open;
            var buttons           = new object[] { Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, Gtk.Stock.Open, Gtk.ResponseType.Accept };

            using (var dialog = new Gtk.FileChooserDialog(Title, SingleInstanceApplication.Instance.MainWindow, fileChooserAction, buttons))
            {
                dialog.SelectMultiple = Multiselect;
                foreach (var filter in _filters)
                {
                    var fileFilter = new Gtk.FileFilter()
                    {
                        Name = filter.Key
                    };
                    fileFilter.AddCustom(Gtk.FileFilterFlags.Filename, info => FileFilter(dialog, info));
                    dialog.AddFilter(fileFilter);
                }

                var response = (Gtk.ResponseType)dialog.Run();
                _files = dialog.Filenames;
                VisualHelpers.Close(dialog);
                var dialogResult = FileBrowserDialogResult.None;
                switch (response)
                {
                case Gtk.ResponseType.Accept:
                    dialogResult = FileBrowserDialogResult.Ok;
                    break;

                case Gtk.ResponseType.Cancel:
                    dialogResult = FileBrowserDialogResult.Cancel;
                    break;

                default:
                    break;
                }
                return(dialogResult);
            }
        }
Exemplo n.º 4
0
 /// <inheritdoc/>
 protected override void OnResponse(Gtk.ResponseType response_id)
 {
     base.OnResponse(response_id);
     VisualHelpers.Close(this);
 }