コード例 #1
0
ファイル: Vsix.cs プロジェクト: wencan002/vstools
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited,
        /// so this is the place where you can put all the initialization code that rely on services
        /// provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            Instance = this;
            base.Initialize();

            Dte = (this as IServiceProvider).GetService(typeof(DTE)) as DTE;

            // determine the package installation directory
            var uri = new Uri(System.Reflection.Assembly.GetExecutingAssembly().EscapedCodeBase);

            PkgInstallPath = Path.GetDirectoryName(Uri.UnescapeDataString(uri.AbsolutePath)) + @"\";

            var vm    = QtVersionManager.The();
            var error = string.Empty;

            if (vm.HasInvalidVersions(out error))
            {
                Messages.DisplayErrorMessage(error);
            }
            eventHandler = new DteEventsHandler(Dte);

            QtMainMenu.Initialize(this);
            QtSolutionContextMenu.Initialize(this);
            QtProjectContextMenu.Initialize(this);
            QtItemContextMenu.Initialize(this);
            DefaultEditorsHandler.Initialize(Dte);
            QtHelpMenu.Initialize(this);

            try {
                CopyTextMateLanguageFiles();
                UpdateDefaultEditors(Mode.Startup);
            } catch (Exception e) {
                MessageBox.Show(e.Message + "\r\n\r\nStacktrace:\r\n" + e.StackTrace);
            }
        }
コード例 #2
0
 /// <summary>
 /// Initializes the singleton instance of the command.
 /// </summary>
 /// <param name="package">Owner package, not null.</param>
 public static void Initialize(Package package)
 {
     Instance = new QtProjectContextMenu(package);
 }
コード例 #3
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited,
        /// so this is the place where you can put all the initialization code that rely on services
        /// provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            Instance = this;
            base.Initialize();

            Dte = (this as IServiceProvider).GetService(typeof(DTE)) as DTE;

            // determine the package installation directory
            var uri = new Uri(System.Reflection.Assembly.GetExecutingAssembly().EscapedCodeBase);

            PkgInstallPath = Path.GetDirectoryName(Uri.UnescapeDataString(uri.AbsolutePath)) + @"\";

            var QtMsBuildPath = Path.Combine(
                Environment.GetEnvironmentVariable("LocalAppData"), "QtMsBuild");

            try {
                if (!Directory.Exists(QtMsBuildPath))
                {
                    Directory.CreateDirectory(QtMsBuildPath);
                }
                var qtMsBuildFiles = Directory.GetFiles(
                    Path.Combine(PkgInstallPath, "QtMsBuild"));
                foreach (var qtMsBuildFile in qtMsBuildFiles)
                {
                    File.Copy(qtMsBuildFile,
                              Path.Combine(QtMsBuildPath, Path.GetFileName(qtMsBuildFile)), true);
                }
            } catch {
                QtMsBuildPath = Path.Combine(PkgInstallPath, "QtMsBuild");
            }

            Environment.SetEnvironmentVariable(
                "QtMsBuild", QtMsBuildPath,
                EnvironmentVariableTarget.User);

            Environment.SetEnvironmentVariable(
                "QtMsBuild", QtMsBuildPath,
                EnvironmentVariableTarget.Process);

            var vm    = QtVersionManager.The();
            var error = string.Empty;

            if (vm.HasInvalidVersions(out error))
            {
                Messages.PaneMessageSafe(Dte, error, 5000);
            }
            eventHandler = new DteEventsHandler(Dte);

            QtMainMenu.Initialize(this);
            QtSolutionContextMenu.Initialize(this);
            QtProjectContextMenu.Initialize(this);
            QtItemContextMenu.Initialize(this);
            DefaultEditorsHandler.Initialize(Dte);
            QtHelpMenu.Initialize(this);

            try {
                CopyTextMateLanguageFiles();
                UpdateDefaultEditors(Mode.Startup);
            } catch (Exception e) {
                Messages.PaneMessageSafe(Dte,
                                         e.Message + "\r\n\r\nStacktrace:\r\n" + e.StackTrace, 5000);
            }

            var modules = QtModules.Instance.GetAvailableModuleInformation();

            foreach (var module in modules)
            {
                if (!string.IsNullOrEmpty(module.ResourceName))
                {
                    var translatedName = SR.GetString(module.ResourceName);
                    if (!string.IsNullOrEmpty(translatedName))
                    {
                        module.Name = translatedName;
                    }
                }
            }
        }
コード例 #4
0
 /// <summary>
 /// Initializes the singleton instance of the command.
 /// </summary>
 public static void Initialize()
 {
     Instance = new QtProjectContextMenu();
 }
コード例 #5
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();
            }
        }
コード例 #6
0
ファイル: Vsix.cs プロジェクト: freall/vstools
        protected override async Task InitializeAsync(
            CancellationToken cancellationToken,
            IProgress <ServiceProgressData> progress)
#endif
        {
            try
            {
                var timeInitBegin = initTimer.Elapsed;
                VsServiceProvider.Instance = instance = this;
                QtProject.ProjectTracker   = this;

#if !VS2013
                ///////////////////////////////////////////////////////////////////////////////////
                // Switch to main (UI) thread
                await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

                var timeUiThreadBegin = initTimer.Elapsed;
#endif

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

                VsShellSettings.Manager = new ShellSettingsManager(this as IServiceProvider);

                eventHandler = new DteEventsHandler(Dte);
                DefaultEditorsClient.Initialize(eventHandler);
                DefaultEditorsClient.Instance.Listen();

                Qml.Debug.Launcher.Initialize();
                QtMainMenu.Initialize(this);
                QtSolutionContextMenu.Initialize(this);
                QtProjectContextMenu.Initialize(this);
                QtItemContextMenu.Initialize(this);
                DefaultEditorsHandler.Initialize(Dte);
                QtHelpMenu.Initialize(this);

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

#if !VS2013
                ///////////////////////////////////////////////////////////////////////////////////
                // Switch to background thread
                await TaskScheduler.Default;
                var timeUiThreadEnd = initTimer.Elapsed;
#endif

                var vm    = QtVersionManager.The(initDone);
                var error = string.Empty;
                if (vm.HasInvalidVersions(out error))
                {
                    Messages.PaneMessageSafe(Dte, error, 5000);
                }

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

                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);
                            if (File.Exists(targetPath))
                            {
                                File.Replace(targetPathTemp, targetPath, null);
                            }
                            else
                            {
                                File.Move(targetPathTemp, targetPath);
                            }
                        }
                    }
                } catch {
                    QtMsBuildDefault = Path.Combine(PkgInstallPath, "QtMsBuild");
                }

                var QtMsBuildPath = Environment.GetEnvironmentVariable("QtMsBuild");
                if (string.IsNullOrEmpty(QtMsBuildPath))
                {
                    Environment.SetEnvironmentVariable(
                        "QtMsBuild", QtMsBuildDefault,
                        EnvironmentVariableTarget.User);

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

                CopyTextMateLanguageFiles();
                UpdateDefaultEditors(Mode.Startup);
                CopyNatvisFile();

                var modules = QtModules.Instance.GetAvailableModuleInformation();
                foreach (var module in modules)
                {
                    if (!string.IsNullOrEmpty(module.ResourceName))
                    {
                        var translatedName = SR.GetString(module.ResourceName, this);
                        if (!string.IsNullOrEmpty(translatedName))
                        {
                            module.Name = translatedName;
                        }
                    }
                }

                Messages.PaneMessageSafe(Dte, string.Format("\r\n"
                                                            + "== Qt Visual Studio Tools version {0}\r\n"
                                                            + "\r\n"
                                                            + "   Initialized in: {1:0.##} msecs\r\n"
#if !VS2013
                                                            + "   Main (UI) thread: {2:0.##} msecs\r\n"
#endif
                                                            , Version.USER_VERSION
                                                            , (initTimer.Elapsed - timeInitBegin).TotalMilliseconds
#if !VS2013
                                                            , (timeUiThreadEnd - timeUiThreadBegin).TotalMilliseconds
#endif
                                                            ), 5000);
            }
            catch (Exception e)
            {
                Messages.PaneMessageSafe(Dte,
                                         e.Message + "\r\n\r\nStacktrace:\r\n" + e.StackTrace, 5000);
            }
            finally
            {
                initDone.Set();
                initTimer.Stop();
            }
        }