Example #1
0
        internal MessageDialog(TMPWindow parentWindow, TMPDialogSettings settings)
            : base(parentWindow, settings)
        {
            InitializeComponent();

            PART_MessageScrollViewer.Height = DialogSettings.MaximumBodyHeight;
        }
Example #2
0
        private async void TMPWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = !MainViewModel.Instance.IsShutdown && MainViewModel.Instance.QuitConfirmationEnabled;
            if (MainViewModel.Instance.IsShutdown)
            {
                return;
            }

            var mySettings = new TMPDialogSettings()
            {
                AffirmativeButtonText = "Завершение работы с программой",
                NegativeButtonText    = "Отменить",
                AnimateShow           = true,
                AnimateHide           = false
            };
            var result = await this.ShowMessageAsync("Выход из программы?",
                                                     "Вы действительно хотите закрыть программу?",
                                                     MessageDialogStyle.AffirmativeAndNegative, mySettings);

            MainViewModel.Instance.IsShutdown = result == MessageDialogResult.Affirmative;

            if (MainViewModel.Instance.IsShutdown)
            {
                App.Current.Shutdown(0);
            }
        }
Example #3
0
        private async Task <bool> ShowProgress(string title, string message, bool isCancelable = false, TMPDialogSettings settings = null)
        {
            statusBarAppStatus.Content = message;

            await CloseProgress();

            if (settings == null)
            {
                settings = new TMPDialogSettings()
                {
                    AnimateHide = false, AnimateShow = false
                }
            }
            ;

            if (progressController != null)
            {
                if (progressController.IsOpen == true)
                {
                    progressController.SetMessage(message);
                }
                else
                {
                    progressController = await this.ShowProgressAsync(MainViewModel.Instance.Title, message, isCancelable, settings);
                }
            }
            else
            {
                progressController = await this.ShowProgressAsync(title, message, isCancelable, settings);

                progressController.SetIndeterminate();
            }
            return(true);
        }
Example #4
0
        internal ProgressDialog(TMPWindow parentWindow, TMPDialogSettings settings)
            : base(parentWindow, settings)
        {
            InitializeComponent();

            if (parentWindow.TMPDialogOptions.ColorScheme == TMPDialogColorScheme.Theme)
            {
                try
                {
                    ProgressBarForeground = ThemeManager.GetResourceFromAppStyle(parentWindow, "AccentColorBrush") as Brush;
                }
                catch (Exception) { }
            }
            else
            {
                ProgressBarForeground = Brushes.White;
            }
        }
Example #5
0
        /// <summary>
        /// Creates a InputDialog inside of the current window.
        /// </summary>
        /// <param name="window">The TMPWindow</param>
        /// <param name="title">The title of the MessageDialog.</param>
        /// <param name="message">The message contained within the MessageDialog.</param>
        /// <param name="settings">Optional settings that override the global tmp dialog settings.</param>
        /// <returns>The text that was entered or null (Nothing in Visual Basic) if the user cancelled the operation.</returns>
        public static Task <string> ShowInputAsync(this TMPWindow window, string title, string message, TMPDialogSettings settings = null)
        {
            window.Dispatcher.VerifyAccess();
            return(HandleOverlayOnShow(settings, window).ContinueWith(z =>
            {
                return (Task <string>)window.Dispatcher.Invoke(new Func <Task <string> >(() =>
                {
                    if (settings == null)
                    {
                        settings = window.TMPDialogOptions;
                    }

                    //create the dialog control
                    var dialog = new InputDialog(window, settings)
                    {
                        Title = title,
                        Message = message,
                        Input = settings.DefaultText
                    };

                    SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, dialog);
                    dialog.SizeChangedHandler = sizeHandler;

                    return dialog.WaitForLoadAsync().ContinueWith(x =>
                    {
                        if (DialogOpened != null)
                        {
                            window.Dispatcher.BeginInvoke(new Action(() => DialogOpened(window, new DialogStateChangedEventArgs())));
                        }

                        return dialog.WaitForButtonPressAsync().ContinueWith(y =>
                        {
                            //once a button as been clicked, begin removing the dialog.

                            dialog.OnClose();

                            if (DialogClosed != null)
                            {
                                window.Dispatcher.BeginInvoke(new Action(() => DialogClosed(window, new DialogStateChangedEventArgs())));
                            }

                            Task closingTask = (Task)window.Dispatcher.Invoke(new Func <Task>(() => dialog._WaitForCloseAsync()));
                            return closingTask.ContinueWith(a =>
                            {
                                return ((Task)window.Dispatcher.Invoke(new Func <Task>(() =>
                                {
                                    window.SizeChanged -= sizeHandler;

                                    window.tmpDialogContainer.Children.Remove(dialog); //remove the dialog from the container

                                    return HandleOverlayOnHide(settings, window);
                                }))).ContinueWith(y3 => y).Unwrap();
                            });
                        }).Unwrap();
                    }).Unwrap().Unwrap();
                }));
            }).Unwrap());
        }
Example #6
0
        /// <summary>
        /// Hides a visible TMP Dialog instance.
        /// </summary>
        /// <param name="window">The window with the dialog that is visible.</param>
        /// <param name="dialog">The dialog instance to hide.</param>
        /// <returns>A task representing the operation.</returns>
        /// <exception cref="InvalidOperationException">
        /// The <paramref name="dialog"/> is not visible in the window.
        /// This happens if <see cref="ShowTMPDialogAsync"/> hasn't been called before.
        /// </exception>
        public static Task HideTMPDialogAsync(this TMPWindow window, BaseTMPDialog dialog, TMPDialogSettings settings = null)
        {
            window.Dispatcher.VerifyAccess();
            if (!window.tmpDialogContainer.Children.Contains(dialog))
            {
                throw new InvalidOperationException("The provided dialog is not visible in the specified window.");
            }

            window.SizeChanged -= dialog.SizeChangedHandler;

            dialog.OnClose();

            Task closingTask = (Task)window.Dispatcher.Invoke(new Func <Task>(dialog._WaitForCloseAsync));

            return(closingTask.ContinueWith(a =>
            {
                if (DialogClosed != null)
                {
                    window.Dispatcher.BeginInvoke(new Action(() => DialogClosed(window, new DialogStateChangedEventArgs())));
                }

                return (Task)window.Dispatcher.Invoke(new Func <Task>(() =>
                {
                    window.tmpDialogContainer.Children.Remove(dialog); //remove the dialog from the container

                    return HandleOverlayOnHide(settings, window);
                }));
            }).Unwrap());
        }
Example #7
0
        /// <summary>
        /// Adds a TMP Dialog instance to the specified window and makes it visible.
        /// <para>Note that this method returns as soon as the dialog is loaded and won't wait on a call of <see cref="HideTMPDialogAsync"/>.</para>
        /// <para>You can still close the resulting dialog with <see cref="HideTMPDialogAsync"/>.</para>
        /// </summary>
        /// <param name="window">The owning window of the dialog.</param>
        /// <param name="dialog">The dialog instance itself.</param>
        /// <returns>A task representing the operation.</returns>
        /// <exception cref="InvalidOperationException">The <paramref name="dialog"/> is already visible in the window.</exception>
        public static Task ShowTMPDialogAsync(this TMPWindow window, BaseTMPDialog dialog, TMPDialogSettings settings = null)
        {
            window.Dispatcher.VerifyAccess();
            if (window.tmpDialogContainer.Children.Contains(dialog))
            {
                throw new InvalidOperationException("The provided dialog is already visible in the specified window.");
            }

            return(HandleOverlayOnShow(settings, window).ContinueWith(z =>
            {
                dialog.Dispatcher.Invoke(new Action(() =>
                {
                    SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, dialog);
                    dialog.SizeChangedHandler = sizeHandler;
                }));
            }).ContinueWith(y =>
                            ((Task)dialog.Dispatcher.Invoke(new Func <Task>(() => dialog.WaitForLoadAsync().ContinueWith(x =>
            {
                dialog.OnShown();

                if (DialogOpened != null)
                {
                    DialogOpened(window, new DialogStateChangedEventArgs());
                }
            }))))));
        }
Example #8
0
 private static Task HandleOverlayOnShow(TMPDialogSettings settings, TMPWindow window)
 {
     return(settings == null ? window.ShowOverlayAsync() : Task.Factory.StartNew(() => window.Dispatcher.Invoke(new Action(window.ShowOverlay))));
 }
Example #9
0
        /// <summary>
        /// Creates a ProgressDialog inside of the current window.
        /// </summary>
        /// <param name="window">The TMPWindow</param>
        /// <param name="title">The title of the ProgressDialog.</param>
        /// <param name="message">The message within the ProgressDialog.</param>
        /// <param name="isCancelable">Determines if the cancel button is visible.</param>
        /// <param name="settings">Optional Settings that override the global tmp dialog settings.</param>
        /// <returns>A task promising the instance of ProgressDialogController for this operation.</returns>
        public static Task <ProgressDialogController> ShowProgressAsync(this TMPWindow window, string title, string message, bool isCancelable = false, TMPDialogSettings settings = null)
        {
            window.Dispatcher.VerifyAccess();

            return(HandleOverlayOnShow(settings, window).ContinueWith(z =>
            {
                return ((Task <ProgressDialogController>)window.Dispatcher.Invoke(new Func <Task <ProgressDialogController> >(() =>
                {
                    var dialog = new ProgressDialog(window)
                    {
                        Message = message,
                        Title = title,
                        IsCancelable = isCancelable
                    };

                    if (settings == null)
                    {
                        settings = window.TMPDialogOptions;
                    }

                    dialog.NegativeButtonText = settings.NegativeButtonText;

                    SizeChangedEventHandler sizeHandler = SetupAndOpenDialog(window, dialog);
                    dialog.SizeChangedHandler = sizeHandler;

                    return dialog.WaitForLoadAsync().ContinueWith(x =>
                    {
                        if (DialogOpened != null)
                        {
                            window.Dispatcher.BeginInvoke(new Action(() => DialogOpened(window, new DialogStateChangedEventArgs())));
                        }

                        return new ProgressDialogController(dialog, () =>
                        {
                            dialog.OnClose();

                            if (DialogClosed != null)
                            {
                                window.Dispatcher.BeginInvoke(new Action(() => DialogClosed(window, new DialogStateChangedEventArgs())));
                            }

                            Task closingTask = (Task)window.Dispatcher.Invoke(new Func <Task>(() => dialog._WaitForCloseAsync()));
                            return closingTask.ContinueWith(a =>
                            {
                                return (Task)window.Dispatcher.Invoke(new Func <Task>(() =>
                                {
                                    window.SizeChanged -= sizeHandler;

                                    window.tmpDialogContainer.Children.Remove(dialog); //remove the dialog from the container

                                    return HandleOverlayOnHide(settings, window);
                                }));
                            }).Unwrap();
                        });
                    });
                })));
            }).Unwrap());
        }
Example #10
0
 internal InputDialog(TMPWindow parentWindow, TMPDialogSettings settings)
     : base(parentWindow, settings)
 {
     InitializeComponent();
 }