Beispiel #1
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 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);
            }
        }
Beispiel #2
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;
                    }
                }
            }
        }
 public static void Initialize(EnvDTE.DTE dte)
 {
     Instance = new DefaultEditorsHandler(dte);
 }
Beispiel #4
0
        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();
            }
        }