public static DialogResult ShowDialogPath(this CommonDialog dlg, string path)
        {
            DialogResult dlgResult;
            var          fileDialog   = dlg as FileDialog;
            var          folderDialog = dlg as FolderBrowserDialog;

            try
            {
                if (fileDialog != null)
                {
                    fileDialog.FileName         = Path.GetFileName(path);
                    fileDialog.InitialDirectory = Path.GetDirectoryName(path);
                }
                else if (folderDialog != null)
                {
                    folderDialog.SelectedPath = path;
                }
                dlgResult = dlg.ShowDialog();
            }
            catch
            {
                if (fileDialog != null)
                {
                    fileDialog.FileName         = string.Empty;
                    fileDialog.InitialDirectory = string.Empty;
                }
                else if (folderDialog != null)
                {
                    folderDialog.SelectedPath = string.Empty;
                }
                dlgResult = dlg.ShowDialog();
            }

            return(dlgResult);
        }
        public static bool?ShowModal(this CommonDialog dialog)
        {
            var owner = GetDialogOwnerHwnd();

            if (owner != IntPtr.Zero && HwndSource.FromHwnd(owner)?.RootVisual is Window ownerWindow)
            {
                return(dialog.ShowDialog(ownerWindow));
            }

            return(dialog.ShowDialog());
        }
Example #3
0
        /// <summary>
        /// Handles EmuHawk specific issues before showing a modal dialog
        /// </summary>
        public static DialogResult ShowHawkDialog(this CommonDialog form, IWin32Window owner)
        {
            GlobalWin.Sound.StopSound();
            DialogResult result;

            if (owner != null)
            {
                result = form.ShowDialog(owner);
            }
            else
            {
                result = form.ShowDialog();
            }
            GlobalWin.Sound.StartSound();
            return(result);
        }
Example #4
0
 /// <summary>
 /// Shows a dialog with hooked theming disabled, to prevent themed elements being drawn in the unthemed
 /// dialog (half-dark tooltips, dark scrollbars, etc.)
 /// </summary>
 /// <param name="dialog"></param>
 /// <returns></returns>
 internal static DialogResult ShowDialogDark(this CommonDialog dialog)
 {
     using (Config.DarkMode ? new Win32ThemeHooks.DialogScope() : null)
     {
         return(dialog.ShowDialog());
     }
 }
 /// <summary>
 /// Shows a common dialog.
 /// </summary>
 /// <param name="commonDialog">The common dialog to show.</param>
 /// <returns>The common dialog result.</returns>
 public DialogResult ShowDialog(CommonDialog commonDialog)
 {
     if (commonDialog == null)
     {
         throw new ArgumentNullException("commonDialog");
     }
     return(commonDialog.ShowDialog(Owner));
 }
Example #6
0
 public static bool ShowDialog(this CommonDialog dialog)
 {
     using (SpyCenterToActive cta = new SpyCenterToActive())
     {
         bool?result = dialog.ShowDialog(Application.Current.MainWindow);
         return(result.HasValue && result.Value);
     }
 }
Example #7
0
        /// <summary>
        /// Handles EmuHawk specific issues before showing a modal dialog
        /// </summary>
        public static DialogResult ShowHawkDialog(this CommonDialog form)
        {
            GlobalWin.Sound.StopSound();
            var result = form.ShowDialog();

            GlobalWin.Sound.StartSound();
            return(result);
        }
        public void Execute(CoroutineExecutionContext context)
        {
            var result = _commonDialog.ShowDialog().GetValueOrDefault(false);

            Completed(this, new ResultCompletionEventArgs {
                WasCancelled = !result
            });
        }
Example #9
0
 public DialogResult ShowDialog(CommonDialog dialog)
 {
     if (this.uiService is SnapInUIService)
     {
         return(this.snapIn.Console.ShowDialog(dialog));
     }
     return(dialog.ShowDialog(this.uiService.GetDialogOwnerWindow()));
 }
Example #10
0
        }                               // To remove the constructor from the documentation!

        ///////////////////////////////////////////////////////////////////////
        // CommonDialog

        /// <summary>
        /// Show a command dialog box at the center of the active window.
        /// </summary>
        public static DialogResult ShowDialog(CommonDialog dlg)
        {
            CenterWindow centerWindow = new CenterWindow(IntPtr.Zero);
            DialogResult dlgResult    = dlg.ShowDialog();

            centerWindow.Dispose();
            return(dlgResult);
        }
 /// <summary>
 /// Shows the form as a modal dialog box with the application main window as the owner.
 /// </summary>
 public static DialogResult ShowDialog(this SolidEdgeFramework.Application application, CommonDialog dialog)
 {
     if (dialog == null)
     {
         throw new ArgumentNullException("dialog");
     }
     return(dialog.ShowDialog(application.GetNativeWindow()));
 }
 /// <summary>
 ///  Runs a common dialog box with the owner defined in this class.
 /// </summary>
 /// <param name="dlg">Dialog to show.</param>
 /// <returns>One of the <see cref="T:System.Windows.Forms.DialogResult"/> values.</returns>
 /// <exception cref="ArgumentNullException">dlg is null.</exception>
 protected DialogResult ShowDialog(CommonDialog dlg)
 {
     if (dlg == null)
     {
         throw new ArgumentNullException("dlg");
     }
     return(dlg.ShowDialog(Owner));
 }
        private void OpenDialog(CommonDialog dialog, TextBox text)
        {
            DialogResult result = dialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                text.Text = (dialog as FileDialog)?.FileName ?? (dialog as FolderBrowserDialog).SelectedPath;
            }
        }
Example #14
0
        public static DialogResult ShowModalDialog(Form parent, CommonDialog dialog)
        {
            parent.Enabled = false;
            DialogResult r = dialog.ShowDialog();

            parent.Enabled = true;
            dialog.Dispose();
            return(r);
        }
Example #15
0
        /// <summary>
        /// Show a command dialog box at the center of the owner window.
        /// </summary>
        public static DialogResult ShowDialog(CommonDialog dlg, IWin32Window owner)
        {
            IntPtr       handle       = (owner == null) ? IntPtr.Zero: owner.Handle;
            CenterWindow centerWindow = new CenterWindow(handle);
            DialogResult dlgResult    = dlg.ShowDialog();

            centerWindow.Dispose();
            return(dlgResult);
        }
Example #16
0
        /// <summary>
        /// Handles EmuHawk specific issues before showing a modal dialog
        /// </summary>
        public static DialogResult ShowHawkDialog(this CommonDialog form)
        {
            GlobalWin.Sound.StopSound();
            using var tempForm = new Form { TopMost = true };
            var result = form.ShowDialog(tempForm);

            GlobalWin.Sound.StartSound();
            return(result);
        }
        public static bool?ShowDialog(CommonDialog window)
        {
            ShowingDialogCount++;
            var result = window.ShowDialog();

            ShowingDialogCount--;

            return(result);
        }
Example #18
0
        public static CommonDialog DialogResultIsOK(this CommonDialog dialog, Action callback)
        {
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                callback();
            }

            return(dialog);
        }
Example #19
0
        protected DialogResult ShowDialog(CommonDialog dialog)
        {
            if (InvokeRequired)
            {
                ShowDialogCallback d = ShowDialog;
                return((DialogResult)Invoke(d, new Object[] { dialog }));
            }

            return(dialog.ShowDialog(this));
        }
Example #20
0
        public static bool ShowDialog(this CommonDialog dialog, DependencyObject owner)
        {
            using (SpyCenterToActive cta = new SpyCenterToActive())
            {
                Window win = WindowExtension.GetOwner(owner);

                bool?result = dialog.ShowDialog(win);
                return(result.HasValue && result.Value);
            }
        }
Example #21
0
        private void OnSearchAlbumEvent(object parameter)
        {
            var viewModel = container.Resolve <IAlbumSearchViewModel>();
            var dialog    = new CommonDialog()
            {
                DialogContent = new AlbumSearchView(viewModel)
            };

            dialog.ShowDialog();
        }
        /// <summary>
        ///     Shows a <see cref="CommonDialog"/> asynchronously.
        /// </summary>
        /// <param name="dialog">The dialog to show.</param>
        /// <returns>The result of <code>dialog.ShowDialog()</code>.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="dialog"/> is null.</exception>
        /// <remarks>
        ///     Essentially performs a <code>Task.Yield()</code> before a <code>ShowDialog()</code> call to allow other more important tasks to run,
        ///     but the main operation remains synchronous and will block the UI thread.
        ///     No marshalling takes place, this method should be called from the UI thread.
        /// </remarks>
        public static async Task <bool?> ShowDialogAsync(this CommonDialog dialog)
        {
            if (dialog == null)
            {
                throw new ArgumentNullException(nameof(dialog));
            }

            await Task.Yield();

            return(dialog.ShowDialog());
        }
        public static DialogResult ShowDialog(this CommonDialog dialog, IWin32Window owner, FormStartPosition position)
        {
            if (owner == null)
            {
                return(dialog.ShowDialog());
            }
            if (position != FormStartPosition.CenterParent && position != FormStartPosition.CenterScreen)
            {
                return(dialog.ShowDialog(owner));
            }

            // TODO: implement
            //using (Form form = new Form())
            //{
            //    form.Owner = owner as Form;
            //    form.StartPosition = position;
            //    return dialog.ShowDialog(form);
            //}
            return(dialog.ShowDialog(owner));
        }
Example #24
0
        private void OnRegisterNewUserCommand(MouseDownArgs parameter)
        {
            var viewModel = container.Resolve <IUserRegistrationViewModel>();

            var dialog = new CommonDialog()
            {
                DialogContent = new UserRegistrationView(viewModel),
                HeaderText    = HeaderTextHelper.CreateHeaderText(typeof(User), false)
            };

            dialog.ShowDialog();
        }
Example #25
0
 public override void ExecuteTarget(Component target)
 {
     OnBeforeExecute(EventArgs.Empty);
     executeResult = dialog.ShowDialog() == DialogResult.OK;
     if (executeResult)
     {
         OnAccept(EventArgs.Empty);
     }
     else
     {
         OnCancel(EventArgs.Empty);
     }
 }
Example #26
0
        /// <summary>
        /// Browse and set a path based on the invoking button
        /// </summary>
        private void BrowseForPath(Button button)
        {
            // If the button is null, we can't do anything
            if (button == null)
            {
                return;
            }

            // Strips button prefix to obtain the setting name
            string pathSettingName = button.Name.Substring(0, button.Name.IndexOf("Button"));

            // TODO: hack for now, then we'll see
            bool shouldBrowseForPath = pathSettingName == "DefaultOutputPath";

            CommonDialog dialog = shouldBrowseForPath ? (CommonDialog)CreateFolderBrowserDialog() : CreateOpenFileDialog();

            using (dialog)
            {
                DialogResult result = dialog.ShowDialog();
                if (result == DialogResult.OK)
                {
                    string path;
                    bool   exists;

                    if (shouldBrowseForPath)
                    {
                        path   = (dialog as FolderBrowserDialog).SelectedPath;
                        exists = Directory.Exists(path);
                    }
                    else
                    {
                        path   = (dialog as OpenFileDialog).FileName;
                        exists = File.Exists(path);
                    }

                    if (exists)
                    {
                        TextBoxForPathSetting(pathSettingName).Text = path;
                    }
                    else
                    {
                        CustomMessageBox.Show(
                            "Specified path doesn't exists!",
                            "Error",
                            MessageBoxButton.OK,
                            MessageBoxImage.Error
                            );
                    }
                }
            }
        }
Example #27
0
            private void HiddenForm_Shown(object?sender, EventArgs _)
            {
                Hide();
                try
                {
                    var result = _form.ShowDialog(_owner);
                    _taskSource.SetResult(result);
                }
                catch (Exception e)
                {
                    _taskSource.SetException(e);
                }

                Close();
            }
Example #28
0
        private string _ShowFolderDialogOrFileDialogAndGetPath(CommonDialog dialog)
        {
            switch (dialog.ShowDialog())
            {
            case DialogResult.OK:
                return(dialog is FolderBrowserDialog
                        ? ((FolderBrowserDialog)dialog).SelectedPath
                        : ((FileDialog)dialog).FileName);

            case DialogResult.Cancel:
                return(null);
            }

            return(null);
        }
Example #29
0
        private void CreateOrEditAlbum(Album album, bool isEditMode)
        {
            IAlbumEditViewModel viewModel = container.Resolve <IAlbumEditViewModel>();

            viewModel.IsEditMode = isEditMode;
            viewModel.Album      = album;

            var dialog = new CommonDialog()
            {
                DialogContent = new AlbumEditView(viewModel),
                HeaderText    = HeaderTextHelper.CreateHeaderText(typeof(Album), isEditMode)
            };

            dialog.ShowDialog();
        }
Example #30
0
        public void CredentialRequiered(object sender, EventArgs <CredentialRequieredArgs> args)
        {
            CredentialInputViewModel vm = new CredentialInputViewModel();
            CommonDialog             f  = new CommonDialog(vm)
            {
                Owner = this, WindowStyle = WindowStyle.ToolWindow
            };

            f.ShowDialog();
            if (vm.Result == true)
            {
                args.Data.Login    = vm.Login;
                args.Data.Password = vm.Password;
            }
        }