From ca47896204482bf4a6979e3838bf7f09f61cebeb Mon Sep 17 00:00:00 2001 From: giy <giy@omp-system.ru> Date: Fri, 02 Sep 2022 14:16:56 +0300 Subject: [PATCH] Обновление до версии 2.9.0 --- QtVsTools.Package/QtVsToolsPackage.cs | 82 ++++++++++++++++++++++++++--------------- 1 files changed, 52 insertions(+), 30 deletions(-) diff --git a/QtVsTools.Package/QtVsToolsPackage.cs b/QtVsTools.Package/QtVsToolsPackage.cs index aad01be..93325f3 100644 --- a/QtVsTools.Package/QtVsToolsPackage.cs +++ b/QtVsTools.Package/QtVsToolsPackage.cs @@ -27,20 +27,14 @@ ****************************************************************************/ using System; -using System.ComponentModel.Design; using System.Diagnostics; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; using System.IO; using System.Linq; using System.Net.Http; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; -using Task = System.Threading.Tasks.Task; -using System.Windows.Forms; using Microsoft.VisualStudio; -using Microsoft.VisualStudio.OLE.Interop; using Microsoft.VisualStudio.Settings; using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Interop; @@ -49,13 +43,15 @@ using Microsoft.Win32; using EnvDTE; +using Task = System.Threading.Tasks.Task; + namespace QtVsTools { using Core; using QtMsBuild; - using SyntaxAnalysis; - using static SyntaxAnalysis.RegExpr; using VisualStudio; + + using static SyntaxAnalysis.RegExpr; [Guid(QtVsToolsPackage.PackageGuidString)] [InstalledProductRegistration("#110", "#112", Version.PRODUCT_VERSION, IconResourceID = 400)] @@ -97,7 +93,7 @@ "Qt", "Versions", 0, 0, true, Sort = 1)] // Legacy options page - [ProvideOptionPage(typeof(Options.QtLegacyOptionsPage), + [ProvideOptionPage(typeof(Legacy.QtOptionsPage), "Qt", "Legacy Project Format", 0, 0, true, Sort = 2)] public sealed class QtVsToolsPackage : AsyncPackage, IVsServiceProvider, IProjectTracker @@ -109,13 +105,13 @@ public string PkgInstallPath { get; private set; } public Options.QtOptionsPage Options => GetDialogPage(typeof(Options.QtOptionsPage)) as Options.QtOptionsPage; - public Options.QtLegacyOptionsPage LegacyOptions - => GetDialogPage(typeof(Options.QtLegacyOptionsPage)) as Options.QtLegacyOptionsPage; + public Legacy.QtOptionsPage LegacyOptions + => GetDialogPage(typeof(Legacy.QtOptionsPage)) as Legacy.QtOptionsPage; public Editors.QtDesigner QtDesigner { get; private set; } public Editors.QtLinguist QtLinguist { get; private set; } - public Editors.QtResourceEditor QtResourceEditor { get; private set; } + private Editors.QtResourceEditor QtResourceEditor { get; set; } - static EventWaitHandle initDone = new EventWaitHandle(false, EventResetMode.ManualReset); + static readonly EventWaitHandle initDone = new EventWaitHandle(false, EventResetMode.ManualReset); static QtVsToolsPackage instance = null; public static QtVsToolsPackage Instance @@ -167,7 +163,6 @@ var timeInitBegin = initTimer.Elapsed; VsServiceProvider.Instance = instance = this; QtProject.ProjectTracker = this; - Messages.JoinableTaskFactory = JoinableTaskFactory; // determine the package installation directory var uri = new Uri(System.Reflection.Assembly @@ -180,7 +175,7 @@ await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var timeUiThreadBegin = initTimer.Elapsed; - if ((Dte = VsServiceProvider.GetService<DTE>()) == null) + if ((Dte = await VsServiceProvider.GetServiceAsync<DTE>()) == null) throw new Exception("Unable to get service: DTE"); QtVSIPSettings.Options = Options; @@ -188,14 +183,14 @@ eventHandler = new DteEventsHandler(Dte); Qml.Debug.Launcher.Initialize(); - QtMainMenu.Initialize(this); - QtSolutionContextMenu.Initialize(this); - QtProjectContextMenu.Initialize(this); - QtItemContextMenu.Initialize(this); + QtMainMenu.Initialize(); + QtSolutionContextMenu.Initialize(); + QtProjectContextMenu.Initialize(); + QtItemContextMenu.Initialize(); RegisterEditorFactory(QtDesigner = new Editors.QtDesigner()); RegisterEditorFactory(QtLinguist = new Editors.QtLinguist()); RegisterEditorFactory(QtResourceEditor = new Editors.QtResourceEditor()); - QtHelp.Initialize(this); + QtHelp.Initialize(); if (!string.IsNullOrEmpty(VsShell.InstallRootDir)) HelperFunctions.VCPath = Path.Combine(VsShell.InstallRootDir, "VC"); @@ -209,9 +204,11 @@ var timeUiThreadEnd = initTimer.Elapsed; var vm = QtVersionManager.The(initDone); - var error = string.Empty; - if (vm.HasInvalidVersions(out error)) + if (vm.HasInvalidVersions(out string error, out bool defaultInvalid)) { + if (defaultInvalid) + vm.SetLatestQtVersionAsDefault(); Messages.Print(error); + } /////////// // Install Qt/MSBuild files from package folder to standard location @@ -306,9 +303,8 @@ ================================================================", urlDownloadQtIo, devRelease)); } - } catch (Exception e) { - Messages.Print( - e.Message + "\r\n\r\nStacktrace:\r\n" + e.StackTrace); + } catch (Exception exception) { + exception.Log(); } finally { initDone.Set(); initTimer.Stop(); @@ -326,11 +322,35 @@ eventHandler.SolutionEvents_Opened(); } + bool TestVersionInstalled() + { + bool newVersion = false; + string versionFile = Path.Combine(PkgInstallPath, "lastversion.txt"); + if (File.Exists(versionFile)) { + string lastVersion = File.ReadAllText(versionFile); + newVersion = (lastVersion!= Version.PRODUCT_VERSION); + } else { + newVersion = true; + } + if (newVersion) + File.WriteAllText(versionFile, Version.PRODUCT_VERSION); + return newVersion; + } + + public void VsMainWindowActivated() + { + if (QtVersionManager.The().GetVersions()?.Length == 0) + Notifications.NoQtVersion.Show(); + if (Options.NotifyInstalled && TestVersionInstalled()) + Notifications.NotifyInstall.Show(); + } + protected override int QueryClose(out bool canClose) { - if (eventHandler != null) { + ThreadHelper.ThrowIfNotOnUIThread(); + + if (eventHandler != null) eventHandler.Disconnect(); - } return base.QueryClose(out canClose); } @@ -381,14 +401,15 @@ File.WriteAllText(Path.Combine(visualizersPath, natvisFile), natvis, System.Text.Encoding.UTF8); - } catch (Exception e) { - Messages.Print( - e.Message + "\r\n\r\nStacktrace:\r\n" + e.StackTrace); + } catch (Exception exception) { + exception.Log(); } } public string GetNatvisPath() { + ThreadHelper.ThrowIfNotOnUIThread(); + try { using (var vsRootKey = Registry.CurrentUser.OpenSubKey(Dte.RegistryRoot)) { if (vsRootKey.GetValue("VisualStudioLocation") is string vsLocation) @@ -433,6 +454,7 @@ void IProjectTracker.AddProject(Project project) { + ThreadHelper.ThrowIfNotOnUIThread(); QtProjectTracker.Add(project); } -- Gitblit v1.9.1