예제 #1
0
        void SolutionEvents_ProjectAdded(Project project)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (HelperFunctions.IsQMakeProject(project))
            {
                InitializeVCProject(project);
                QtProjectTracker.Add(project);
                var      vcpro  = project.Object as VCProject;
                VCFilter filter = null;
                foreach (VCFilter f in vcpro.Filters as IVCCollection)
                {
                    if (f.Name == Filters.HeaderFiles().Name)
                    {
                        filter = f;
                        break;
                    }
                }
                if (filter != null)
                {
                    foreach (VCFile file in filter.Files as IVCCollection)
                    {
                        foreach (VCFileConfiguration config in file.FileConfigurations as IVCCollection)
                        {
                            var tool        = new QtCustomBuildTool(config);
                            var commandLine = tool.CommandLine;
                            if (!string.IsNullOrEmpty(commandLine) && commandLine.Contains("moc.exe"))
                            {
                                var    matches = Regex.Matches(commandLine, "[^ ^\n]+moc\\.(exe\"|exe)");
                                string qtDir;
                                if (matches.Count != 1)
                                {
                                    var vm = QtVersionManager.The();
                                    qtDir = vm.GetInstallPath(vm.GetDefaultVersion());
                                }
                                else
                                {
                                    qtDir = matches[0].ToString().Trim('"');
                                    qtDir = qtDir.Remove(qtDir.LastIndexOf('\\'));
                                    qtDir = qtDir.Remove(qtDir.LastIndexOf('\\'));
                                }
                                qtDir = qtDir.Replace("_(QTDIR)", "$(QTDIR)");
                                HelperFunctions.SetDebuggingEnvironment(project, "PATH="
                                                                        + Path.Combine(qtDir, "bin") + ";$(PATH)", false, config.Name);
                            }
                        }
                    }
                }
                QtProjectIntellisense.Refresh(project);
            }
        }
예제 #2
0
        protected override void OnStart(Process process)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            base.OnStart(process);
            var document = VsShell.GetDocument(Context, ItemId);

            if (document == null)
            {
                return;
            }

            var project = document.ProjectItem?.ContainingProject;

            if (project == null || !QtProjectTracker.IsTracked(project.FullName))
            {
                return;
            }
            string filePath = document.FullName;

            string[] itemId        = new[] { document.ProjectItem?.Name };
            var      lastWriteTime = File.GetLastWriteTime(filePath);

            _ = Task.Run(() =>
            {
                while (!process.WaitForExit(1000))
                {
                    var latestWriteTime = File.GetLastWriteTime(filePath);
                    if (lastWriteTime != latestWriteTime)
                    {
                        lastWriteTime = latestWriteTime;
                        QtProjectIntellisense.Refresh(project, selectedFiles: itemId);
                    }
                }
                if (lastWriteTime != File.GetLastWriteTime(filePath))
                {
                    QtProjectIntellisense.Refresh(project, selectedFiles: itemId);
                }
            });
        }
예제 #3
0
        public void ProjectItemsEvents_ItemAdded(ProjectItem projectItem)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var project = HelperFunctions.GetSelectedQtProject(QtVsToolsPackage.Instance.Dte);
            var qtPro   = QtProject.Create(project);

            if (!HelperFunctions.IsQtProject(project))
            {
                return;
            }

            var vcFile = GetVCFileFromProject(projectItem.Name, qtPro.VCProject);

            if (vcFile == null)
            {
                return;
            }

            try {
                if (HelperFunctions.IsSourceFile(vcFile.Name))
                {
                    if (vcFile.Name.StartsWith("moc_", StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }
                    if (vcFile.Name.StartsWith("qrc_", StringComparison.OrdinalIgnoreCase))
                    {
                        // Do not use precompiled headers with these files
                        QtProject.SetPCHOption(vcFile, pchOption.pchNone);
                        return;
                    }
                    var pcHeaderThrough = qtPro.GetPrecompiledHeaderThrough();
                    if (pcHeaderThrough != null)
                    {
                        var pcHeaderCreator = pcHeaderThrough.Remove(pcHeaderThrough.LastIndexOf('.')) + ".cpp";
                        if (vcFile.Name.EndsWith(pcHeaderCreator, StringComparison.OrdinalIgnoreCase) &&
                            HelperFunctions.CxxFileContainsNotCommented(vcFile, "#include \"" + pcHeaderThrough + "\"", StringComparison.OrdinalIgnoreCase, false))
                        {
                            //File is used to create precompiled headers
                            QtProject.SetPCHOption(vcFile, pchOption.pchCreateUsingSpecific);
                            return;
                        }
                    }
                    if (HelperFunctions.HasQObjectDeclaration(vcFile))
                    {
                        if (!qtPro.IsQtMsBuildEnabled())
                        {
                            HelperFunctions.EnsureCustomBuildToolAvailable(projectItem);
                        }
                        qtPro.AddMocStep(vcFile);
                    }
                }
                else if (HelperFunctions.IsHeaderFile(vcFile.Name))
                {
                    if (vcFile.Name.StartsWith("ui_", StringComparison.OrdinalIgnoreCase))
                    {
                        return;
                    }
                    if (HelperFunctions.HasQObjectDeclaration(vcFile))
                    {
                        if (!qtPro.IsQtMsBuildEnabled())
                        {
                            HelperFunctions.EnsureCustomBuildToolAvailable(projectItem);
                        }
                        qtPro.AddMocStep(vcFile);
                    }
                }
                else if (HelperFunctions.IsUicFile(vcFile.Name))
                {
                    if (!qtPro.IsQtMsBuildEnabled())
                    {
                        HelperFunctions.EnsureCustomBuildToolAvailable(projectItem);
                    }
                    qtPro.AddUic4BuildStep(vcFile);
                    QtProjectIntellisense.Refresh(project);
                }
                else if (HelperFunctions.IsQrcFile(vcFile.Name))
                {
                    if (!qtPro.IsQtMsBuildEnabled())
                    {
                        HelperFunctions.EnsureCustomBuildToolAvailable(projectItem);
                    }
                    qtPro.UpdateRccStep(vcFile, null);
                }
                else if (HelperFunctions.IsTranslationFile(vcFile.Name))
                {
                    Translation.RunlUpdate(vcFile);
                }
            } catch { }
        }
예제 #4
0
        private void execHandler(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var command = sender as OleMenuCommand;

            if (command == null)
            {
                return;
            }

            switch ((CommandId)command.CommandID.ID)
            {
            case CommandId.ImportPriFileProjectId:
                ExtLoader.ImportPriFile(HelperFunctions.GetSelectedQtProject(QtVsToolsPackage.Instance.Dte));
                break;

            case CommandId.ExportPriFileProjectId:
                ExtLoader.ExportPriFile();
                break;

            case CommandId.ExportProFileProjectId:
                ExtLoader.ExportProFile();
                break;

            case CommandId.lUpdateOnProjectId:
                Translation.RunlUpdate(HelperFunctions.GetSelectedQtProject(QtVsToolsPackage.Instance.Dte));
                break;

            case CommandId.lReleaseOnProjectId:
                Translation.RunlRelease(HelperFunctions.GetSelectedQtProject(QtVsToolsPackage.Instance.Dte));
                break;

            case CommandId.ConvertToQtProjectId:
            case CommandId.ConvertToQmakeProjectId: {
                var caption = SR.GetString("ConvertTitle");
                var text    = SR.GetString("ConvertConfirmation");
                if (MessageBox.Show(text, caption, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    HelperFunctions.ToggleProjectKind(HelperFunctions.GetSelectedProject(QtVsToolsPackage
                                                                                         .Instance.Dte));
                }
            }
            break;

            case CommandId.QtProjectSettingsProjectId: {
                var pro            = HelperFunctions.GetSelectedQtProject(QtVsToolsPackage.Instance.Dte);
                int projectVersion = QtProject.GetFormatVersion(pro);
                if (projectVersion >= Resources.qtMinFormatVersion_Settings)
                {
                    QtVsToolsPackage.Instance.Dte.ExecuteCommand("Project.Properties");
                }
                else if (pro != null)
                {
                    using (var formProjectQtSettings = new FormProjectQtSettings()) {
                        formProjectQtSettings.SetProject(pro);
                        formProjectQtSettings.StartPosition = FormStartPosition.CenterParent;
                        var ww = new MainWinWrapper(QtVsToolsPackage.Instance.Dte);
                        formProjectQtSettings.ShowDialog(ww);
                    }
                }
                else
                {
                    MessageBox.Show(SR.GetString("NoProjectOpened"));
                }
            }
            break;

            case CommandId.ChangeProjectQtVersionProjectId: {
                var pro = HelperFunctions.GetSelectedQtProject(QtVsToolsPackage.Instance.Dte);
                if (HelperFunctions.IsQMakeProject(pro))
                {
                    using (var formChangeQtVersion = new FormChangeQtVersion()) {
                        formChangeQtVersion.UpdateContent(ChangeFor.Project);
                        var ww = new MainWinWrapper(QtVsToolsPackage.Instance.Dte);
                        if (formChangeQtVersion.ShowDialog(ww) == DialogResult.OK)
                        {
                            var qtVersion = formChangeQtVersion.GetSelectedQtVersion();
                            HelperFunctions.SetDebuggingEnvironment(pro, "PATH=" + QtVersionManager
                                                                    .The().GetInstallPath(qtVersion) + @"\bin;$(PATH)", true);
                        }
                    }
                }
            }
            break;

            case CommandId.ProjectConvertToQtMsBuild: {
                QtMsBuildConverter.ProjectToQtMsBuild(
                    HelperFunctions.GetSelectedProject(QtVsToolsPackage.Instance.Dte));
            }
            break;

            case CommandId.ProjectRefreshIntelliSense: {
                var selectedProject = HelperFunctions.GetSelectedProject(QtVsToolsPackage.Instance.Dte);
                var tracker         = QtProjectTracker.Get(selectedProject, selectedProject.FullName);
                QtProjectIntellisense.Refresh(tracker.Project);
            }
            break;
            }
        }