예제 #1
0
        public bool AskYesNo(string Question, string Caption = null)
        {
            if (MainForm.IsUiThread)
            {
                Caption = Caption ?? ProductInfo.ProductName;

                bool res;
                try
                {
                    BeforeShowDialog?.Invoke();
                    switch (MessageBox.Show(Parent, Question, Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1))
                    {
                    case DialogResult.Yes:
                        res = true;
                        break;

                    default:
                        res = false;
                        break;
                    }
                }
                finally
                {
                    AfterShowDialog?.Invoke();
                }
                return(res);
            }
            else
            {
                return((bool)MainForm.Instance.Invoke(new Func <bool>(
                                                          () => { return AskYesNo(Question, Caption); })));
            }
        }
예제 #2
0
        // MESSAGE BOXES

        public void ExceptionAlert(Exception Ex, string Message = "", string Caption = null)
        {
            if (MainForm.IsUiThread)
            {
                Caption = Caption ?? ProductInfo.ProductName;
                try
                {
                    BeforeShowDialog?.Invoke();
                    switch (MessageBox.Show(Parent,
                                            "An exception has occurred. Copy details to clipboard?",
                                            Caption,
                                            MessageBoxButtons.YesNo,
                                            MessageBoxIcon.Question,
                                            MessageBoxDefaultButton.Button1))
                    {
                    case DialogResult.Yes:
                        ClipboardText = Ex.ToReport();
                        break;

                    default:
                        break;
                    }
                }
                finally
                {
                    AfterShowDialog?.Invoke();
                }
            }
            else
            {
                MainForm.Instance.Invoke(new Action(() => { ExceptionAlert(Ex, Message, Caption); }));
            }
        }
예제 #3
0
 public void InformUser(string Information, string Caption = null)
 {
     if (MainForm.IsUiThread)
     {
         Caption = Caption ?? ProductInfo.ProductName;
         try
         {
             BeforeShowDialog?.Invoke();
             MessageBox.Show(Parent, Information, Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         finally
         {
             AfterShowDialog?.Invoke();
         }
     }
     else
     {
         MainForm.Instance.Invoke(new Action(() => { InformUser(Information, Caption); }));
     }
 }
예제 #4
0
        // PATHS AND FILE DIALOGS

        public string UserSelectFile(bool Save, string DefaultPath, string Title, string Filter, string DefaultExtension, bool SelectFileInDialog)
        {
            System.Diagnostics.Debug.Assert(MainForm.IsUiThread);

            string dir = DefaultPath.Length > 0 ? Path.GetDirectoryName(DefaultPath) :
                         Storage.DocsPath;

            if (!Directory.Exists(dir))
            {
                dir = Storage.DocsPath;
            }

            if (!Save && !File.Exists(DefaultPath))
            {
                DefaultPath = String.Empty;
            }

            FileDialog dialog;

            if (Save)
            {
                dialog = new SaveFileDialog()
                {
                    OverwritePrompt = true
                };
            }
            else
            {
                dialog = new OpenFileDialog()
                {
                    Multiselect = false,
                };
            }
            dialog.Title            = Title;
            dialog.FileName         = (SelectFileInDialog && DefaultPath.Length > 0) ? Path.GetFileName(DefaultPath) : null;
            dialog.InitialDirectory = dir;
            dialog.ValidateNames    = true;
            dialog.Filter           = Filter;
            dialog.AddExtension     = true;
            dialog.DefaultExt       = DefaultExtension;
            dialog.CheckFileExists  = !Save;
            dialog.CheckPathExists  = true;

            DialogResult dr;

            try
            {
                BeforeShowDialog?.Invoke();
                dr = dialog.ShowDialog(Parent);
            }
            finally
            {
                AfterShowDialog?.Invoke();
            }

            string path = dialog.FileName;

            if (dr == DialogResult.OK && path.Length > 0)
            {
                if (Save || File.Exists(path))
                {
                    return(path);
                }
            }

            return(string.Empty);
        }