/// <summary>
        /// Instructs the progress indicator to hide itself.
        /// </summary>
        /// <remarks>If the indicator is visible and has been showing for at least a minimal amount of time, it will be hidden
        /// immediately. If not, it will hide itself once a the minimum display time has elapsed.</remarks>
        public void Hide()
        {
            if (IsVisible && !_cancelled && (DateTime.Now < _launchTime.AddSeconds(MinDisplayTime)))
            {
                if (_timer != null)
                {
                    _timer.Tick -= ShowProgressIndicator;
                    _timer.Tick -= HideProgressIndicator;
                    _timer.Stop();
                }
                _timer          = new OSDispatcherTimer();
                _timer.Tick    += HideProgressIndicator;
                _timer.Interval = _launchTime.AddSeconds(MinDisplayTime) - DateTime.Now;
                _timer.Start();
            }
            else
            {
                HideProgressIndicator(null, null);
            }
            var application = SingleInstanceApplication.Instance;

            if (application != null)
            {
                application.IsBusy = false;
            }
            CommandManager.InvalidateRequerySuggested();
        }
        /// <summary>
        /// Instructs the progress indicator that it should display itself. It will appear after a brief delay.
        /// </summary>
        /// <param name="task">The task associated with the progress indicator.</param>
        /// <remarks>The progress indicator will display after a brief delay, and will display for a minimum amount of time once shown.
        /// If a task completes quickly, this prevents the progress indicator from appearing only to disappear almost instantaneously.
        /// Similarly, once the indicator becomes visible, it will remain visible for a minimum amount of time so as to be less jarring.</remarks>
        public void Show(AsyncTaskWithProgress task)
        {
            var application = SingleInstanceApplication.Instance;

            if (application != null)
            {
                application.IsBusy = true;
                _task      = task;
                _cancelled = false;
                if (!IsVisible && (_timer == null) && (DisplayDelay > 0))
                {
                    PlatformOnShow(application);
                    _timer          = new OSDispatcherTimer();
                    _timer.Tick    += ShowProgressIndicator;
                    _timer.Interval = TimeSpan.FromSeconds(DisplayDelay);
                    _timer.Start();
                }
                else if (!(DisplayDelay < 0))
                {
                    PlatformOnShow(application);
                    ShowProgressIndicator(this, EventArgs.Empty);
                }
            }
        }
Пример #3
0
        private void HandlePropertyChangedCore(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            var viewModel = (ProgressIndicatorViewModel)DataContext;

            switch (e.PropertyName)
            {
            case ProgressIndicatorViewModel.AllowsCancelPropertyName:
                _cancel.Sensitive = viewModel.AllowsCancel;
                break;

            case ProgressIndicatorViewModel.TitlePropertyName:
                _progressTitle.Text = viewModel.Title;
                break;

            case ProgressIndicatorViewModel.UpdateTextPropertyName:
                _updateText.Text = viewModel.UpdateText;
                break;

            case ProgressIndicatorViewModel.IsIndeterminatePropertyName:
                if (viewModel.IsVisible && viewModel.IsIndeterminate)
                {
                    _pulseTimer.Start();
                }
                else
                {
                    _pulseTimer.Stop();
                }
                break;

            case ProgressIndicatorViewModel.PercentFinishedPropertyName:
                if (!viewModel.IsIndeterminate)
                {
                    _progressBar.Fraction = viewModel.PercentFinished;
                }
                break;

            case ProgressIndicatorViewModel.IsVisiblePropertyName:
                var owner = SingleInstanceApplication.Current.MainWindow;
                if (viewModel.IsVisible)
                {
                    this.Modal = true;
                    int w, h, ownerWidth, ownerHeight;
                    owner.GetSize(out ownerWidth, out ownerHeight);
#if ENABLE_OVERLAY
                    _overlay.Resize(ownerWidth, ownerHeight);
#endif // ENABLE_OVERLAY
                    this.GetSize(out w, out h);
                    this.Resize(System.Math.Max(ownerWidth - WidthPadding, MinimumWindowWidth), System.Math.Min(h, ownerHeight));
                    if (viewModel.IsIndeterminate)
                    {
                        _pulseTimer.Start();
                    }
                }
                else
                {
                    _pulseTimer.Stop();
                    _progressBar.Fraction = 0;
                    INTV.Shared.ComponentModel.CommandManager.InvalidateRequerySuggested();
                }
                this.Visible = viewModel.IsVisible;
#if ENABLE_OVERLAY
                _overlay.Visible  = viewModel.IsVisible;
                this.TransientFor = _overlay;
#else
                this.TransientFor = owner;
#endif // ENABLE_OVERLAY
                this.Modal = viewModel.IsVisible;
                break;
            }
        }