Пример #1
0
 private void F1HelpEvents_BeforeExecute(
     string Guid, int ID, object CustomIn, object CustomOut, ref bool CancelDefault)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     if (QtVsToolsPackage.Instance.Options.TryQtHelpOnF1Pressed && QtHelp.QueryEditorContextHelp())
     {
         CancelDefault = true;
     }
 }
Пример #2
0
 public static void Initialize()
 {
     Instance = new QtHelp();
 }
Пример #3
0
        protected override async Task InitializeAsync(
            CancellationToken cancellationToken,
            IProgress <ServiceProgressData> progress)
        {
            try {
                var timeInitBegin = initTimer.Elapsed;
                VsServiceProvider.Instance = instance = this;
                QtProject.ProjectTracker   = this;

                // determine the package installation directory
                var uri = new Uri(System.Reflection.Assembly
                                  .GetExecutingAssembly().EscapedCodeBase);
                PkgInstallPath = Path.GetDirectoryName(
                    Uri.UnescapeDataString(uri.AbsolutePath)) + @"\";

                ///////////////////////////////////////////////////////////////////////////////////
                // Switch to main (UI) thread
                await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

                var timeUiThreadBegin = initTimer.Elapsed;

                if ((Dte = await VsServiceProvider.GetServiceAsync <DTE>()) == null)
                {
                    throw new Exception("Unable to get service: DTE");
                }

                QtVSIPSettings.Options = Options;

                eventHandler = new DteEventsHandler(Dte);

                Qml.Debug.Launcher.Initialize();
                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();

                if (!string.IsNullOrEmpty(VsShell.InstallRootDir))
                {
                    HelperFunctions.VCPath = Path.Combine(VsShell.InstallRootDir, "VC");
                }

                GetTextMateLanguagePath();
                GetNatvisPath();

                ///////////////////////////////////////////////////////////////////////////////////
                // Switch to background thread
                await TaskScheduler.Default;
                var timeUiThreadEnd = initTimer.Elapsed;

                var vm = QtVersionManager.The(initDone);
                if (vm.HasInvalidVersions(out string error))
                {
                    Messages.Print(error);
                }

                ///////////
                // Install Qt/MSBuild files from package folder to standard location
                //  -> %LOCALAPPDATA%\QtMsBuild
                //
                var QtMsBuildDefault = Path.Combine(
                    Environment.GetEnvironmentVariable("LocalAppData"), "QtMsBuild");
                try {
                    var qtMsBuildDefaultUri = new Uri(QtMsBuildDefault + "\\");
                    var qtMsBuildVsixPath   = Path.Combine(PkgInstallPath, "QtMsBuild");
                    var qtMsBuildVsixUri    = new Uri(qtMsBuildVsixPath + "\\");
                    if (qtMsBuildVsixUri != qtMsBuildDefaultUri)
                    {
                        var qtMsBuildVsixFiles = Directory
                                                 .GetFiles(qtMsBuildVsixPath, "*", SearchOption.AllDirectories)
                                                 .Select(x => qtMsBuildVsixUri.MakeRelativeUri(new Uri(x)));
                        foreach (var qtMsBuildFile in qtMsBuildVsixFiles)
                        {
                            var sourcePath     = new Uri(qtMsBuildVsixUri, qtMsBuildFile).LocalPath;
                            var targetPath     = new Uri(qtMsBuildDefaultUri, qtMsBuildFile).LocalPath;
                            var targetPathTemp = targetPath + ".tmp";
                            Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
                            File.Copy(sourcePath, targetPathTemp, overwrite: true);
                            ////////
                            // Copy Qt/MSBuild files to standard location, taking care not to
                            // overwrite the updated Qt props file, possibly containing user-defined
                            // build settings (written by the VS Property Manager). This file is
                            // recognized as being named "Qt.props" and containing the import
                            // statement for qt_private.props.
                            //
                            string qtPrivateImport =
                                @"<Import Project=""$(MSBuildThisFileDirectory)\qt_private.props""";
                            Func <string, bool> isUpdateQtProps = (string filePath) =>
                            {
                                return(Path.GetFileName(targetPath).Equals("Qt.props", IGNORE_CASE) &&
                                       File.ReadAllText(targetPath).Contains(qtPrivateImport));
                            };
                            if (!File.Exists(targetPath))
                            {
                                // Target file does not exist
                                //  -> Create new
                                File.Move(targetPathTemp, targetPath);
                            }
                            else if (!isUpdateQtProps(targetPath))
                            {
                                // Target file is not the updated Qt.props
                                //  -> Overwrite
                                File.Replace(targetPathTemp, targetPath, null);
                            }
                            else
                            {
                                // Target file *is* the updated Qt.props; skip!
                                //  -> Remove temp file
                                File.Delete(targetPathTemp);
                            }
                        }
                    }
                } catch {
                    /////////
                    // Error copying files to standard location.
                    //  -> FAIL-SAFE: use source folder (within package) as the standard location
                    QtMsBuildDefault = Path.Combine(PkgInstallPath, "QtMsBuild");
                }

                ///////
                // Set %QTMSBUILD% by default to point to standard location of Qt/MSBuild
                //
                var QtMsBuildPath = Environment.GetEnvironmentVariable("QtMsBuild");
                if (string.IsNullOrEmpty(QtMsBuildPath))
                {
                    Environment.SetEnvironmentVariable(
                        "QtMsBuild", QtMsBuildDefault,
                        EnvironmentVariableTarget.User);

                    Environment.SetEnvironmentVariable(
                        "QtMsBuild", QtMsBuildDefault,
                        EnvironmentVariableTarget.Process);
                }

                CopyTextMateLanguageFiles();
                CopyNatvisFiles();

                Messages.Print(string.Format("\r\n"
                                             + "== Qt Visual Studio Tools version {0}\r\n"
                                             + "\r\n"
                                             + "   Initialized in: {1:0.##} msecs\r\n"
                                             + "   Main (UI) thread: {2:0.##} msecs\r\n"
                                             , Version.USER_VERSION
                                             , (initTimer.Elapsed - timeInitBegin).TotalMilliseconds
                                             , (timeUiThreadEnd - timeUiThreadBegin).TotalMilliseconds
                                             ));

                var devRelease = await GetLatestDevelopmentReleaseAsync();

                if (devRelease != null)
                {
                    Messages.Print(string.Format(@"
    ================================================================
      Qt Visual Studio Tools version {1} PREVIEW available at:
      {0}{1}/
    ================================================================",
                                                 urlDownloadQtIo, devRelease));
                }
            } catch (Exception e) {
                Messages.Print(
                    e.Message + "\r\n\r\nStacktrace:\r\n" + e.StackTrace);
            } finally {
                initDone.Set();
                initTimer.Stop();
            }

            ///////////////////////////////////////////////////////////////////////////////////
            // Switch to main (UI) thread
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            /////////
            // Check if a solution was opened during initialization.
            // If so, fire solution open event.
            //
            if (Dte?.Solution?.IsOpen == true)
            {
                eventHandler.SolutionEvents_Opened();
            }
        }