| | |
| | | ****************************************************************************/
|
| | |
|
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.IO;
|
| | | using System.Linq;
|
| | | using System.Windows.Forms;
|
| | | using Microsoft.VisualStudio;
|
| | | using Microsoft.VisualStudio.Shell;
|
| | | using Microsoft.VisualStudio.Shell.Interop;
|
| | | using Microsoft.VisualStudio.VCProjectEngine;
|
| | | using QtVsTools.VisualStudio;
|
| | |
|
| | | namespace QtVsTools.Core
|
| | | {
|
| | | using VisualStudio;
|
| | |
|
| | | public class WaitDialog : IDisposable
|
| | | {
|
| | | static IVsThreadedWaitDialogFactory factory = null;
|
| | |
|
| | | public IVsThreadedWaitDialog2 VsWaitDialog { get; private set; }
|
| | | private IVsThreadedWaitDialog2 VsWaitDialog { get; set; }
|
| | |
|
| | | public bool Running { get; private set; }
|
| | | private bool Running { get; set; }
|
| | |
|
| | | bool? vsDialogCanceled = null;
|
| | |
|
| | |
| | | {
|
| | | get
|
| | | {
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | if (vsDialogCanceled.HasValue)
|
| | | return vsDialogCanceled.Value;
|
| | |
|
| | | if (VsWaitDialog == null)
|
| | | return false;
|
| | |
|
| | | bool canceled = false;
|
| | | int res = VsWaitDialog.HasCanceled(out canceled);
|
| | | int res = VsWaitDialog.HasCanceled(out bool canceled);
|
| | | if (res != VSConstants.S_OK)
|
| | | return false;
|
| | |
|
| | |
| | |
|
| | | static WaitDialog Create(IVsThreadedWaitDialogFactory dialogFactory)
|
| | | {
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | if (factory == null) {
|
| | | factory = dialogFactory ?? VsServiceProvider
|
| | | .GetService<SVsThreadedWaitDialogFactory, IVsThreadedWaitDialogFactory>();
|
| | |
| | | return null;
|
| | | }
|
| | |
|
| | | IVsThreadedWaitDialog2 vsWaitDialog = null;
|
| | | factory.CreateInstance(out vsWaitDialog);
|
| | | factory.CreateInstance(out IVsThreadedWaitDialog2 vsWaitDialog);
|
| | | if (vsWaitDialog == null)
|
| | | return null;
|
| | |
|
| | |
| | | bool showMarqueeProgress = true,
|
| | | IVsThreadedWaitDialogFactory dialogFactory = null)
|
| | | {
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | var dialog = Create(dialogFactory);
|
| | | if (dialog == null)
|
| | | return null;
|
| | |
| | | bool isCancelable = false,
|
| | | IVsThreadedWaitDialogFactory dialogFactory = null)
|
| | | {
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | var dialog = Create(dialogFactory);
|
| | | if (dialog == null)
|
| | | return null;
|
| | |
| | | string statusBarText = null,
|
| | | bool disableCancel = false)
|
| | | {
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | if (!Running)
|
| | | return;
|
| | |
|
| | | bool canceled = false;
|
| | | int res = VsWaitDialog.UpdateProgress(message, progressText,
|
| | | statusBarText, currentStep, totalSteps, disableCancel, out canceled);
|
| | | statusBarText, currentStep, totalSteps, disableCancel, out bool canceled);
|
| | |
|
| | | if (res != VSConstants.S_OK)
|
| | | return;
|
| | |
| | |
|
| | | public void Stop()
|
| | | {
|
| | | ThreadHelper.ThrowIfNotOnUIThread();
|
| | |
|
| | | if (!Running)
|
| | | return;
|
| | |
|
| | | Running = false;
|
| | | int canceled = 0;
|
| | | VsWaitDialog.EndWaitDialog(out canceled);
|
| | | VsWaitDialog.EndWaitDialog(out int canceled);
|
| | | Canceled = (canceled != 0);
|
| | | }
|
| | |
|
| | | void IDisposable.Dispose()
|
| | | {
|
| | | Stop();
|
| | | ThreadHelper.JoinableTaskFactory.Run(async () => {
|
| | | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
|
| | | Stop();
|
| | | });
|
| | | }
|
| | | }
|
| | | }
|