Наша сборка Qt VS Tools
giy
2022-09-02 ca47896204482bf4a6979e3838bf7f09f61cebeb
QtVsTools.Core/WaitDialog.cs
@@ -27,25 +27,21 @@
****************************************************************************/
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;
@@ -53,14 +49,15 @@
        {
            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;
@@ -76,6 +73,8 @@
        static WaitDialog Create(IVsThreadedWaitDialogFactory dialogFactory)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (factory == null) {
                factory = dialogFactory ?? VsServiceProvider
                    .GetService<SVsThreadedWaitDialogFactory, IVsThreadedWaitDialogFactory>();
@@ -83,8 +82,7 @@
                    return null;
            }
            IVsThreadedWaitDialog2 vsWaitDialog = null;
            factory.CreateInstance(out vsWaitDialog);
            factory.CreateInstance(out IVsThreadedWaitDialog2 vsWaitDialog);
            if (vsWaitDialog == null)
                return null;
@@ -105,6 +103,8 @@
            bool showMarqueeProgress = true,
            IVsThreadedWaitDialogFactory dialogFactory = null)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var dialog = Create(dialogFactory);
            if (dialog == null)
                return null;
@@ -129,6 +129,8 @@
            bool isCancelable = false,
            IVsThreadedWaitDialogFactory dialogFactory = null)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var dialog = Create(dialogFactory);
            if (dialog == null)
                return null;
@@ -151,12 +153,13 @@
            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;
@@ -167,18 +170,22 @@
        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();
            });
        }
    }
}