/// <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();
        }
 private void ShowProgressIndicator(object sender, EventArgs e)
 {
     _launchTime = DateTime.Now;
     IsVisible   = true;
     if (_timer != null)
     {
         _timer.Tick -= ShowProgressIndicator;
         _timer.Tick -= HideProgressIndicator;
         _timer.Stop();
     }
     _timer = null;
 }
Ejemplo n.º 3
0
        private ProgressIndicator(ProgressIndicatorViewModel viewModel, Gtk.Window owner)
            : base(Gtk.WindowType.Toplevel)
        {
#if ENABLE_OVERLAY
            _overlay = new ProgressIndicatorOverlay(owner);
#endif // ENABLE_OVERLAY
            _pulseTimer                = new OSDispatcherTimer();
            _pulseTimer.Interval       = System.TimeSpan.FromMilliseconds(TimerTickMilliseconds);
            _pulseTimer.Tick          += Pulse;
            DataContext                = viewModel;
            viewModel.PropertyChanged += HandlePropertyChanged;
            this.Build();
            this.DefaultHeight = -1;
            _cancel.Label      = ProgressIndicatorViewModel.Cancel;
        }
        private void HideProgressIndicator(object sender, EventArgs e)
        {
            _cancelled  = false;
            _launchTime = DateTime.MinValue;
            IsVisible   = false;
            if (_timer != null)
            {
                _timer.Stop();
            }
            _timer = null;
            _task  = null;
            var application = SingleInstanceApplication.Instance;

            if ((application != null) && (application.MainWindow != null))
            {
                PlatformOnHide(application);
            }
            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);
                }
            }
        }