Beispiel #1
0
        private void setDirectory(string dir, string value)
        {
            foreach (EnvDTE.Project project in HelperFunctions.ProjectsInSolution(dte))
            {
                VCProject vcProject = project.Object as VCProject;
                if (vcProject == null || vcProject.Files == null)
                {
                    continue;
                }
                QtProject qtProject = QtProject.Create(project);
                if (qtProject == null)
                {
                    continue;
                }

                if (dir == "MocDir")
                {
                    string oldMocDir = QtVSIPSettings.GetMocDirectory(project);
                    QtVSIPSettings.SaveMocDirectory(project, value);
                    qtProject.UpdateMocSteps(oldMocDir);
                }
                else if (dir == "RccDir")
                {
                    string oldRccDir = QtVSIPSettings.GetRccDirectory(project);
                    QtVSIPSettings.SaveRccDirectory(project, value);
                    qtProject.RefreshRccSteps(oldRccDir);
                }
                else if (dir == "UicDir")
                {
                    string oldUicDir = QtVSIPSettings.GetUicDirectory(project);
                    QtVSIPSettings.SaveUicDirectory(project, value);
                    qtProject.UpdateUicSteps(oldUicDir, true);
                }
            }
        }
Beispiel #2
0
        public static void CreateNewTranslationFile(EnvDTE.Project project)
        {
            if (project == null)
            {
                return;
            }

            AddTranslationDialog transDlg = new AddTranslationDialog(project);

            if (transDlg.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    QtProject qtPro = QtProject.Create(project);
                    VCFile    file  = qtPro.AddFileInFilter(Filters.TranslationFiles(), transDlg.TranslationFile, true);
                    Translation.RunlUpdate(file, project);
                }
                catch (QtVSException e)
                {
                    Messages.DisplayErrorMessage(e.Message);
                }
                catch (System.Exception ex)
                {
                    Messages.DisplayErrorMessage(ex.Message);
                }
            }
        }
Beispiel #3
0
        public static void RunlUpdate(EnvDTE.Project project)
        {
            QtProject qtPro = QtProject.Create(project);

            if (qtPro == null)
            {
                return;
            }

            FakeFilter ts       = Filters.TranslationFiles();
            VCFilter   tsFilter = qtPro.FindFilterFromGuid(ts.UniqueIdentifier);

            if (tsFilter == null)
            {
                return;
            }

            IVCCollection files = tsFilter.Files as IVCCollection;

            foreach (VCFile file in files)
            {
                VCFile vcFile = file as VCFile;
                if (HelperFunctions.IsTranslationFile(vcFile))
                {
                    if (!RunlUpdate(vcFile, project))
                    {
                        return;
                    }
                }
            }
        }
Beispiel #4
0
        public static void RunlRelease(EnvDTE.Project project)
        {
            var qtPro = QtProject.Create(project);

            if (qtPro == null)
            {
                return;
            }

            var ts       = Filters.TranslationFiles();
            var tsFilter = qtPro.FindFilterFromGuid(ts.UniqueIdentifier);

            if (tsFilter == null)
            {
                return;
            }

            var files = tsFilter.Files as IVCCollection;

            foreach (VCFile vcFile in files)
            {
                if (HelperFunctions.IsTranslationFile(vcFile.Name))
                {
                    if (!RunlRelease(vcFile))
                    {
                        return;
                    }
                }
            }
        }
Beispiel #5
0
        static void RunTranslationTarget(
            BuildAction buildAction,
            EnvDTE.Project project,
            IEnumerable <string> selectedFiles = null)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            using (WaitDialog.Start(
                       "Qt Visual Studio Tools", "Running translation tool...")) {
                var qtPro = QtProject.Create(project);
                if (project == null || qtPro == null)
                {
                    Messages.Print(
                        "translation: Error accessing project interface");
                    return;
                }

                if (qtPro.FormatVersion < Resources.qtMinFormatVersion_Settings)
                {
                    Messages.Print("translation: Legacy project format");
                    try {
                        Legacy_RunTranslation(buildAction, qtPro, selectedFiles);
                    } catch (Exception e) {
                        Messages.Print(
                            e.Message + "\r\n\r\nStacktrace:\r\n" + e.StackTrace);
                    }
                    return;
                }

                var activeConfig = project.ConfigurationManager?.ActiveConfiguration;
                if (activeConfig == null)
                {
                    Messages.Print(
                        "translation: Error accessing build interface");
                    return;
                }
                var activeConfigId = string.Format("{0}|{1}",
                                                   activeConfig.ConfigurationName, activeConfig.PlatformName);

                var target     = "QtTranslation";
                var properties = new Dictionary <string, string>();
                switch (buildAction)
                {
                case BuildAction.Update:
                    properties["QtTranslationForceUpdate"] = "true";
                    break;

                case BuildAction.Release:
                    properties["QtTranslationForceRelease"] = "true";
                    break;
                }
                if (selectedFiles != null)
                {
                    properties["SelectedFiles"] = string.Join(";", selectedFiles);
                }

                QtProjectBuild.StartBuild(
                    project, project.FullName, activeConfigId, properties, new[] { target });
            }
        }
Beispiel #6
0
        void debugStartEvents_BeforeExecute(string Guid, int ID, object CustomIn, object CustomOut, ref bool CancelDefault)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var debugger = dte.Debugger;

            if (debugger != null && debugger.CurrentMode != dbgDebugMode.dbgDesignMode)
            {
                return;
            }
            var selectedProject = HelperFunctions.GetSelectedQtProject(dte);

            if (selectedProject != null)
            {
                if (QtProject.GetFormatVersion(selectedProject) >= Resources.qtMinFormatVersion_Settings)
                {
                    return;
                }
                var qtProject = QtProject.Create(selectedProject);
                if (qtProject != null)
                {
                    qtProject.SetQtEnvironment();

                    var qtVersion   = qtProject.GetQtVersion();
                    var versionInfo = QtVersionManager.The().GetVersionInfo(qtVersion);
                    if (!string.IsNullOrEmpty(versionInfo.Namespace()))
                    {
                        QtVsToolsPackage.Instance.CopyNatvisFiles(versionInfo.Namespace());
                    }
                }
            }
        }
Beispiel #7
0
 public void SetProject(Project pro)
 {
     project   = pro;
     qtProject = QtProject.Create(project);
     InitModules();
     qtSettings = new ProjectQtSettings(project);
     OptionsPropertyGrid.SelectedObject = qtSettings;
 }
Beispiel #8
0
        public void SaveSettings()
        {
            var updateMoc = false;
            var qtPro     = QtProject.Create(project);

            if (oldMocDir != newMocDir)
            {
                QtVSIPSettings.SaveMocDirectory(project, newMocDir);
                updateMoc = true;
            }
            if (oldMocOptions != newMocOptions)
            {
                QtVSIPSettings.SaveMocOptions(project, newMocOptions);
                updateMoc = true;
            }
            if (updateMoc)
            {
                qtPro.UpdateMocSteps(oldMocDir);
            }

            if (oldUicDir != newUicDir)
            {
                QtVSIPSettings.SaveUicDirectory(project, newUicDir);
                qtPro.UpdateUicSteps(oldUicDir, true);
            }

            if (oldRccDir != newRccDir)
            {
                QtVSIPSettings.SaveRccDirectory(project, newRccDir);
                qtPro.RefreshRccSteps(oldRccDir);
            }

            if (oldLUpdateOnBuild != newLUpdateOnBuild)
            {
                QtVSIPSettings.SaveLUpdateOnBuild(project, newLUpdateOnBuild);
            }

            if (oldLUpdateOptions != newLUpdateOptions)
            {
                QtVSIPSettings.SaveLUpdateOptions(project, newLUpdateOptions);
            }

            if (oldLReleaseOptions != newLReleaseOptions)
            {
                QtVSIPSettings.SaveLReleaseOptions(project, newLReleaseOptions);
            }

            if (oldQtVersion != newQtVersion)
            {
                var newProjectCreated = false;
                var versionChanged    = qtPro.ChangeQtVersion(oldQtVersion, newQtVersion, ref newProjectCreated);
                if (versionChanged && newProjectCreated)
                {
                    project = qtPro.Project;
                }
            }
        }
Beispiel #9
0
        public void UseSelectedProject(EnvDTE.DTE app)
        {
            pro = HelperFunctions.GetSelectedQtProject(app);
            if (pro == null)
            {
                throw new QtVSException("Can't find a selected project");
            }

            qtPro = QtProject.Create(pro);
        }
Beispiel #10
0
        public void OnBuildProjConfigBegin(string projectName, string projectConfig, string platform, string solutionConfig)
        {
            if (currentBuildAction != vsBuildAction.vsBuildActionBuild &&
                currentBuildAction != vsBuildAction.vsBuildActionRebuildAll)
            {
                return;     // Don't do anything, if we're not building.
            }

            Project project = null;

            foreach (var p in HelperFunctions.ProjectsInSolution(dte))
            {
                if (p.UniqueName == projectName)
                {
                    project = p;
                    break;
                }
            }
            if (project == null || !HelperFunctions.IsQtProject(project))
            {
                return;
            }

            if (QtProject.GetFormatVersion(project) >= Resources.qtMinFormatVersion_Settings)
            {
                return;
            }

            var qtpro          = QtProject.Create(project);
            var versionManager = QtVersionManager.The();
            var qtVersion      = versionManager.GetProjectQtVersion(project, platform);

            if (qtVersion == null)
            {
                Messages.DisplayCriticalErrorMessage(SR.GetString("ProjectQtVersionNotFoundError", projectName, projectConfig, platform));
                dte.ExecuteCommand("Build.Cancel", "");
                return;
            }

            if (!QtVSIPSettings.GetDisableAutoMocStepsUpdate())
            {
                if (qtpro.ConfigurationRowNamesChanged)
                {
                    qtpro.UpdateMocSteps(QtVSIPSettings.GetMocDirectory(project));
                }
            }

            // Solution config is given to function to get QTDIR property
            // set correctly also during batch build
            qtpro.SetQtEnvironment(qtVersion, solutionConfig, true);
            if (QtVSIPSettings.GetLUpdateOnBuild(project))
            {
                Translation.RunlUpdate(project);
            }
        }
Beispiel #11
0
 void debugStartWithoutDebuggingEvents_BeforeExecute(string Guid, int ID, object CustomIn, object CustomOut, ref bool CancelDefault)
 {
     EnvDTE.Project selectedProject = HelperFunctions.GetSelectedQtProject(dte);
     if (selectedProject != null)
     {
         QtProject qtProject = QtProject.Create(selectedProject);
         if (qtProject != null)
         {
             qtProject.SetQtEnvironment();
         }
     }
 }
Beispiel #12
0
        void ProjectItemsEvents_ItemRemoved(ProjectItem ProjectItem)
        {
            Project pro = HelperFunctions.GetSelectedQtProject(VSPackage.dte);

            if (pro == null)
            {
                return;
            }

            QtProject qtPro = QtProject.Create(pro);

            qtPro.RemoveGeneratedFiles(ProjectItem.Name);
        }
Beispiel #13
0
        void ProjectItemsEvents_ItemRemoved(ProjectItem ProjectItem)
        {
            var pro = HelperFunctions.GetSelectedQtProject(Vsix.Instance.Dte);

            if (pro == null)
            {
                return;
            }

            var qtPro = QtProject.Create(pro);

            qtPro.RemoveGeneratedFiles(ProjectItem.Name);
        }
Beispiel #14
0
        private void changeSolutionQtVersion(object sender, EventArgs e)
        {
            var manager = QtVersionManager.The();

            if (formChangeQtVersion == null)
            {
                formChangeQtVersion = new FormChangeQtVersion();
            }
            formChangeQtVersion.UpdateContent(ChangeFor.Solution);
            if (formChangeQtVersion.ShowDialog() == DialogResult.OK)
            {
                var newQtVersion = formChangeQtVersion.GetSelectedQtVersion();
                if (newQtVersion != null)
                {
                    string currentPlatform = null;
                    try {
                        //SolutionConfiguration config = VSPackage.dte.Solution.SolutionBuild.ActiveConfiguration;
                        //SolutionConfiguration2 config2 = config as SolutionConfiguration2;
                        //currentPlatform = config2.PlatformName;
                        Project       prj    = VSPackage.dte.Solution.Projects.Item(1);
                        Configuration config = prj.ConfigurationManager.ActiveConfiguration;
                        currentPlatform = config.PlatformName;
                    }
                    catch {
                    }
                    if (string.IsNullOrEmpty(currentPlatform))
                    {
                        return;
                    }


                    foreach (var project in HelperFunctions.ProjectsInSolution(VSPackage.dte))
                    {
                        if (HelperFunctions.IsQtProject(project))
                        {
                            string OldQtVersion = manager.GetProjectQtVersion(project, currentPlatform);
                            if (OldQtVersion == null)
                            {
                                OldQtVersion = manager.GetDefaultVersion();
                            }

                            var qtProject         = QtProject.Create(project);
                            var newProjectCreated = false;
                            qtProject.ChangeQtVersion(OldQtVersion, newQtVersion, ref newProjectCreated);
                        }
                    }
                    manager.SaveSolutionQtVersion(VSPackage.dte.Solution, newQtVersion);
                }
            }
        }
Beispiel #15
0
        protected override void BeforeTemplateExpansion()
        {
            Parameter[NewClass.SourceFileName] = WizardData.ClassSourceFile;
            Parameter[NewClass.HeaderFileName] = WizardData.ClassHeaderFile;

            var array = WizardData.ClassName.Split(new[] { "::" },
                                                   StringSplitOptions.RemoveEmptyEntries);
            var className = array.LastOrDefault();
            var baseClass = WizardData.BaseClass;

            Parameter[NewQtItem.ClassName] = className;
            Parameter[NewQtItem.BaseClass] = baseClass;

            var include = new StringBuilder();
            var pro     = HelperFunctions.GetSelectedQtProject(Dte);

            if (pro != null)
            {
                var qtProject = QtProject.Create(pro);
                if (qtProject != null && qtProject.UsesPrecompiledHeaders())
                {
                    include.AppendLine(string.Format("#include \"{0}\"", qtProject
                                                     .GetPrecompiledHeaderThrough()));
                }
            }
            include.AppendLine(string.Format("#include \"{0}\"", WizardData.ClassHeaderFile));
            Parameter[NewQtItem.Include] = FormatParam(include);

            if (!string.IsNullOrEmpty(baseClass))
            {
                Parameter[NewQtItem.QObject] = WizardData.InsertQObjectMacro
                                                    ? "\r\n    Q_OBJECT\r\n" : "";
                Parameter[NewQtItem.BaseClassDecl]       = " : public " + baseClass;
                Parameter[NewQtItem.Signature]           = WizardData.ConstructorSignature;
                Parameter[NewQtItem.BaseClassInclude]    = "#include <" + baseClass + ">\r\n\r\n";
                Parameter[NewQtItem.BaseClassWithParent] = string.IsNullOrEmpty(WizardData
                                                                                .ConstructorSignature) ? "" : "\r\n    : " + baseClass + "(parent)";
            }

            string nsBegin = string.Empty, nsEnd = string.Empty;

            for (var i = 0; i < array.Length - 1; ++i)
            {
                nsBegin += "namespace " + array[i] + " {\r\n";
                nsEnd    = "} // namespace " + array[i] + "\r\n" + nsEnd;
            }
            Parameter[Meta.NamespaceBegin] = nsBegin;
            Parameter[Meta.NamespaceEnd]   = nsEnd;
        }
Beispiel #16
0
        void ProjectItemsEvents_ItemRemoved(ProjectItem ProjectItem)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var pro = HelperFunctions.GetSelectedQtProject(QtVsToolsPackage.Instance.Dte);

            if (pro == null)
            {
                return;
            }

            var qtPro = QtProject.Create(pro);

            qtPro.RemoveGeneratedFiles(ProjectItem.Name);
        }
Beispiel #17
0
        void debugStartWithoutDebuggingEvents_BeforeExecute(string Guid, int ID, object CustomIn, object CustomOut, ref bool CancelDefault)
        {
            var selectedProject = HelperFunctions.GetSelectedQtProject(dte);

            if (selectedProject != null)
            {
                if (QtProject.GetFormatVersion(selectedProject) >= Resources.qtMinFormatVersion_Settings)
                {
                    return;
                }
                var qtProject = QtProject.Create(selectedProject);
                if (qtProject != null)
                {
                    qtProject.SetQtEnvironment();
                }
            }
        }
Beispiel #18
0
        void ProjectItemsEvents_ItemRenamed(ProjectItem ProjectItem, string OldName)
        {
            if (OldName == null)
            {
                return;
            }
            Project pro = HelperFunctions.GetSelectedQtProject(VSPackage.dte);

            if (pro == null)
            {
                return;
            }

            QtProject qtPro = QtProject.Create(pro);

            qtPro.RemoveGeneratedFiles(OldName);
            ProjectItemsEvents_ItemAdded(ProjectItem);
        }
Beispiel #19
0
        void ProjectItemsEvents_ItemRenamed(ProjectItem ProjectItem, string OldName)
        {
            if (OldName == null)
            {
                return;
            }
            var pro = HelperFunctions.GetSelectedQtProject(Vsix.Instance.Dte);

            if (pro == null)
            {
                return;
            }

            var qtPro = QtProject.Create(pro);

            qtPro.RemoveGeneratedFiles(OldName);
            ProjectItemsEvents_ItemAdded(ProjectItem);
        }
Beispiel #20
0
        protected override void OnProjectGenerated(Project project)
        {
            var qtProject = QtProject.Create(project);

            qtProject.CreateQrcFile(WizardData.ClassName, WizardData.QrcFile);

            IWizardConfiguration configWinRT = Configurations
                                               .Where(whereConfigTargetIsWindowsStore)
                                               .FirstOrDefault();

            if (configWinRT != null)
            {
                var projDir     = Parameter[NewProject.DestinationDirectory];
                var qmakeTmpDir = Path.Combine(projDir, "qmake_tmp");
                Directory.CreateDirectory(qmakeTmpDir);

                var dummyPro = Path.Combine(qmakeTmpDir,
                                            string.Format("{0}.pro", Parameter[NewProject.SafeName]));
                File.WriteAllText(dummyPro, "SOURCES = main.cpp\r\n");

                var qmake = new QMakeImport(configWinRT.QtVersion, dummyPro);
                qmake.Run(setVCVars: true);

                var qmakeAssetsDir = Path.Combine(qmakeTmpDir, "assets");
                var projAssetsDir  = Path.Combine(projDir, "assets");
                if (Directory.Exists(qmakeAssetsDir))
                {
                    if (Directory.Exists(projAssetsDir))
                    {
                        Directory.Delete(projAssetsDir, recursive: true);
                    }
                    Directory.Move(qmakeAssetsDir, projAssetsDir);
                }

                var manifestFile = Path.Combine(qmakeTmpDir, "Package.appxmanifest");
                if (File.Exists(manifestFile))
                {
                    File.Move(manifestFile, Path.Combine(projDir, "Package.appxmanifest"));
                }

                Directory.Delete(qmakeTmpDir, recursive: true);
            }
        }
Beispiel #21
0
        void debugStartEvents_BeforeExecute(string Guid, int ID, object CustomIn, object CustomOut, ref bool CancelDefault)
        {
            var debugger = dte.Debugger;

            if (debugger != null && debugger.CurrentMode != dbgDebugMode.dbgDesignMode)
            {
                return;
            }
            var selectedProject = HelperFunctions.GetSelectedQtProject(dte);

            if (selectedProject != null)
            {
                var qtProject = QtProject.Create(selectedProject);
                if (qtProject != null)
                {
                    qtProject.SetQtEnvironment();
                }
            }
        }
Beispiel #22
0
        public void ProjectFinishedGenerating(Project project)
        {
            var qtProject = QtProject.Create(project);

            QtVSIPSettings.SaveUicDirectory(project, null);
            QtVSIPSettings.SaveMocDirectory(project, null);
            QtVSIPSettings.SaveMocOptions(project, null);
            QtVSIPSettings.SaveRccDirectory(project, null);
            QtVSIPSettings.SaveLUpdateOnBuild(project);
            QtVSIPSettings.SaveLUpdateOptions(project, null);
            QtVSIPSettings.SaveLReleaseOptions(project, null);

            var vm        = QtVersionManager.The();
            var qtVersion = vm.GetDefaultVersion();
            var vi        = VersionInformation.Get(vm.GetInstallPath(qtVersion));

            if (vi.GetVSPlatformName() != "Win32")
            {
                qtProject.SelectSolutionPlatform(vi.GetVSPlatformName());
            }
            vm.SaveProjectQtVersion(project, qtVersion);

            qtProject.MarkAsQtProject("v1.0");
            qtProject.AddDirectories();

            var type = TemplateType.Application | TemplateType.ConsoleSystem;

            qtProject.WriteProjectBasicConfigurations(type, false);

            foreach (VCFile file in (IVCCollection)qtProject.VCProject.Files)
            {
                qtProject.AdjustWhitespace(file.FullPath);
            }

            qtProject.AddModule(QtModule.Main);
            foreach (var module in data.Modules)
            {
                qtProject.AddModule(QtModules.Instance.ModuleIdByName(module));
            }
            qtProject.SetQtEnvironment(qtVersion);
            qtProject.Finish(); // Collapses all project nodes.
        }
Beispiel #23
0
 private void SaveModules()
 {
     qtProject = QtProject.Create(project);
     for (int i = 0; i < moduleMap.Count; ++i)
     {
         ModuleMapItem item            = moduleMap[i];
         bool          isModuleChecked = item.checkbox.Checked;
         if (isModuleChecked != item.initialValue)
         {
             if (isModuleChecked)
             {
                 qtProject.AddModule(item.moduleId);
             }
             else
             {
                 qtProject.RemoveModule(item.moduleId);
             }
         }
     }
 }
Beispiel #24
0
        private void OnQRCFileSaved(string fileName)
        {
            foreach (EnvDTE.Project project in HelperFunctions.ProjectsInSolution(dte))
            {
                VCProject vcProject = project.Object as VCProject;
                if (vcProject == null || vcProject.Files == null)
                {
                    continue;
                }

                VCFile vcFile = (VCFile)((IVCCollection)vcProject.Files).Item(fileName);
                if (vcFile == null)
                {
                    continue;
                }

                QtProject qtProject = QtProject.Create(project);
                qtProject.UpdateRccStep(vcFile, null);
            }
        }
Beispiel #25
0
        private void ImportSolution(FileInfo mainInfo, string qtVersion)
        {
            VersionInformation versionInfo = QtVersionManager.The().GetVersionInfo(qtVersion);
            FileInfo           VCInfo      = RunQmake(mainInfo, ".sln", true, versionInfo);

            if (null == VCInfo)
            {
                return;
            }
            ReplaceAbsoluteQtDirInSolution(VCInfo);

            try
            {
                if (CheckQtVersion(versionInfo))
                {
                    dteObject.Solution.Open(VCInfo.FullName);
                    if (qtVersion != null)
                    {
                        QtVersionManager.The().SaveSolutionQtVersion(dteObject.Solution, qtVersion);
                        foreach (Project prj in HelperFunctions.ProjectsInSolution(dteObject))
                        {
                            QtVersionManager.The().SaveProjectQtVersion(prj, qtVersion);
                            QtProject qtPro = QtProject.Create(prj);
                            qtPro.SetQtEnvironment();
                            ApplyPostImportSteps(qtPro);
                        }
                    }
                }

                Messages.PaneMessage(dteObject, "--- (Import): Finished opening " + VCInfo.Name);
            }
            catch (Exception e)
            {
                Messages.DisplayCriticalErrorMessage(e);
            }
        }
Beispiel #26
0
        public void ProjectFinishedGenerating(Project project)
        {
            var qtProject = QtProject.Create(project);

            QtVSIPSettings.SaveUicDirectory(project, null);
            QtVSIPSettings.SaveMocDirectory(project, null);
            QtVSIPSettings.SaveMocOptions(project, null);
            QtVSIPSettings.SaveRccDirectory(project, null);
            QtVSIPSettings.SaveLUpdateOnBuild(project);
            QtVSIPSettings.SaveLUpdateOptions(project, null);
            QtVSIPSettings.SaveLReleaseOptions(project, null);

            var vm        = QtVersionManager.The();
            var qtVersion = vm.GetDefaultVersion();
            var vi        = VersionInformation.Get(vm.GetInstallPath(qtVersion));

            if (vi.GetVSPlatformName() != "Win32")
            {
                qtProject.SelectSolutionPlatform(vi.GetVSPlatformName());
            }
            vm.SaveProjectQtVersion(project, qtVersion);

            qtProject.MarkAsQtProject("v1.0");
            qtProject.AddDirectories();

            var type = TemplateType.Application | TemplateType.GUISystem;

            qtProject.WriteProjectBasicConfigurations(type, data.UsePrecompiledHeader);

            qtProject.AddModule(QtModule.Main);
            foreach (var module in data.Modules)
            {
                qtProject.AddModule(QtModules.Instance.ModuleIdByName(module));
            }

            var vcProject = qtProject.VCProject;
            var files     = vcProject.GetFilesWithItemType(@"None") as IVCCollection;

            foreach (var vcFile in files)
            {
                vcProject.RemoveFile(vcFile);
            }

            if (data.UsePrecompiledHeader)
            {
                qtProject.AddFileToProject(@"stdafx.cpp", Filters.SourceFiles());
                qtProject.AddFileToProject(@"stdafx.h", Filters.HeaderFiles());
            }

            qtProject.AddFileToProject(data.ClassSourceFile, Filters.SourceFiles());
            qtProject.AddFileToProject(data.ClassHeaderFile, Filters.HeaderFiles());
            qtProject.AddFileToProject(data.UiFile, Filters.FormFiles());
            var qrc = qtProject.CreateQrcFile(data.ClassName, data.QrcFile);

            qtProject.AddFileToProject(qrc, Filters.ResourceFiles());

            if (data.AddDefaultAppIcon)
            {
                try {
                    var icon = vcProject.ProjectDirectory + "\\" + vcProject.ItemName + ".ico";
                    if (!File.Exists(icon))
                    {
                        File.Move(vcProject.ProjectDirectory + "\\gui.ico", icon);
                        var attribs = File.GetAttributes(icon);
                        File.SetAttributes(icon, attribs & (~FileAttributes.ReadOnly));
                    }

                    var rcFile = vcProject.ProjectDirectory + "\\" + vcProject.ItemName + ".rc";
                    if (!File.Exists(rcFile))
                    {
                        FileStream fs = null;
                        try {
                            fs = File.Create(rcFile);
                            using (var sw = new StreamWriter(fs)) {
                                fs = null;
                                sw.WriteLine("IDI_ICON1\t\tICON\t\tDISCARDABLE\t\""
                                             + vcProject.ItemName + ".ico\"" + sw.NewLine);
                            }
                        } finally {
                            if (fs != null)
                            {
                                fs.Dispose();
                            }
                        }
                        vcProject.AddFile(rcFile);
                    }
                } catch { }
            }

            foreach (VCFile file in (IVCCollection)qtProject.VCProject.Files)
            {
                qtProject.AdjustWhitespace(file.FullPath);
            }

            qtProject.SetQtEnvironment(qtVersion);
            qtProject.Finish(); // Collapses all project nodes.
        }
Beispiel #27
0
        private void execHandler(object sender, EventArgs e)
        {
            var command = sender as OleMenuCommand;

            if (command == null)
            {
                return;
            }

            switch (command.CommandID.ID)
            {
            case lUpdateOnSolutionId:
                Translation.RunlUpdate(Vsix.Instance.Dte.Solution);
                break;

            case lReleaseOnSolutionId:
                Translation.RunlRelease(Vsix.Instance.Dte.Solution);
                break;

            case ChangeSolutionQtVersionId:
                var newQtVersion = string.Empty;
                using (var formChangeQtVersion = new FormChangeQtVersion()) {
                    formChangeQtVersion.UpdateContent(ChangeFor.Solution);
                    if (formChangeQtVersion.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    newQtVersion = formChangeQtVersion.GetSelectedQtVersion();
                    if (newQtVersion == null)
                    {
                        return;
                    }
                }

                string currentPlatform = null;
                try {
                    var config2 = Vsix.Instance.Dte.Solution.SolutionBuild
                                  .ActiveConfiguration as SolutionConfiguration2;
                    currentPlatform = config2.PlatformName;
                } catch { }
                if (string.IsNullOrEmpty(currentPlatform))
                {
                    return;
                }

                var dte = Vsix.Instance.Dte;
                foreach (var project in HelperFunctions.ProjectsInSolution(dte))
                {
                    if (HelperFunctions.IsQtProject(project))
                    {
                        var OldQtVersion = QtVersionManager.The().GetProjectQtVersion(project,
                                                                                      currentPlatform);
                        if (OldQtVersion == null)
                        {
                            OldQtVersion = QtVersionManager.The().GetDefaultVersion();
                        }

                        var created   = false;
                        var qtProject = QtProject.Create(project);
                        qtProject.ChangeQtVersion(OldQtVersion, newQtVersion, ref created);
                    }
                }
                QtVersionManager.The().SaveSolutionQtVersion(dte.Solution, newQtVersion);
                break;
            }
        }
Beispiel #28
0
 protected override void OnProjectGenerated(Project project)
 {
     var qtProject = QtProject.Create(project);
     qtProject.AddActiveQtBuildStep("1.0", Parameter[NewProject.SafeName] + ".def");
 }
Beispiel #29
0
        public void ProjectItemsEvents_ItemAdded(ProjectItem projectItem)
        {
            Project   project = HelperFunctions.GetSelectedQtProject(VSPackage.dte);
            QtProject qtPro   = QtProject.Create(project);

            if (!HelperFunctions.IsQtProject(project))
            {
                return;
            }
            VCFilter filter = null;
            VCFile   vcFile = GetVCFileFromProject(projectItem.Name, qtPro.VCProject);

            if (vcFile == null)
            {
                return;
            }

            try
            {
                // Try to find the filter, the file is located in
                // If the file is not inside any filter, move it to
                // the according one, used by the Add-in
                filter = (VCFilter)vcFile.Parent;
            }
            catch { }

            try
            {
                FakeFilter ui  = Filters.FormFiles();
                FakeFilter qrc = Filters.ResourceFiles();
                FakeFilter ts  = Filters.TranslationFiles();
                FakeFilter h   = Filters.HeaderFiles();
                FakeFilter src = Filters.SourceFiles();

                VCFilter uiFilter  = qtPro.FindFilterFromGuid(ui.UniqueIdentifier);
                VCFilter tsFilter  = qtPro.FindFilterFromGuid(ts.UniqueIdentifier);
                VCFilter qrcFilter = qtPro.FindFilterFromGuid(qrc.UniqueIdentifier);
                VCFilter hFilter   = qtPro.FindFilterFromGuid(h.UniqueIdentifier);
                VCFilter srcFilter = qtPro.FindFilterFromGuid(src.UniqueIdentifier);

                if (HelperFunctions.HasSourceFileExtension(vcFile.Name))
                {
                    if (vcFile.Name.ToLower().StartsWith("moc_"))
                    {
                        return;
                    }
                    else if (vcFile.Name.ToLower().StartsWith("qrc_"))
                    {
                        // Do not use precompiled headers with these files
                        QtProject.SetPCHOption(vcFile, pchOption.pchNone);
                        return;
                    }
                    string pcHeaderThrough = qtPro.GetPrecompiledHeaderThrough();
                    if (pcHeaderThrough != null)
                    {
                        string pcHeaderCreator = pcHeaderThrough.Remove(pcHeaderThrough.LastIndexOf('.')) + ".cpp";
                        if (vcFile.Name.ToLower().EndsWith(pcHeaderCreator.ToLower()) &&
                            HelperFunctions.CxxFileContainsNotCommented(vcFile, "#include \"" + pcHeaderThrough + "\"", false, false))
                        {
                            //File is used to create precompiled headers
                            QtProject.SetPCHOption(vcFile, pchOption.pchCreateUsingSpecific);
                            return;
                        }
                    }
                    if (filter == null && !HelperFunctions.IsInFilter(vcFile, src))
                    {
                        if (null == srcFilter && qtPro.VCProject.CanAddFilter(src.Name))
                        {
                            srcFilter                  = (VCFilter)qtPro.VCProject.AddFilter(src.Name);
                            srcFilter.Filter           = src.Filter;
                            srcFilter.ParseFiles       = src.ParseFiles;
                            srcFilter.UniqueIdentifier = src.UniqueIdentifier;
                        }
                        qtPro.RemoveItem(projectItem);
                        qtPro.AddFileToProject(vcFile.FullPath, src);
                    }
                    if (HelperFunctions.HasQObjectDeclaration(vcFile))
                    {
//#if (VS2010 || VS2012 || VS2013 || VS2015)
                        HelperFunctions.EnsureCustomBuildToolAvailable(projectItem);
//#endif
                        qtPro.AddMocStep(vcFile);
                    }
                }
                else if (HelperFunctions.HasHeaderFileExtension(vcFile.Name))
                {
                    if (vcFile.Name.ToLower().StartsWith("ui_"))
                    {
                        return;
                    }
                    if (filter == null && !HelperFunctions.IsInFilter(vcFile, h))
                    {
                        if (null == hFilter && qtPro.VCProject.CanAddFilter(h.Name))
                        {
                            hFilter                  = (VCFilter)qtPro.VCProject.AddFilter(h.Name);
                            hFilter.Filter           = h.Filter;
                            hFilter.ParseFiles       = h.ParseFiles;
                            hFilter.UniqueIdentifier = h.UniqueIdentifier;
                        }
                        qtPro.RemoveItem(projectItem);
                        qtPro.AddFileToProject(vcFile.FullPath, h);
                    }
                    if (HelperFunctions.HasQObjectDeclaration(vcFile))
                    {
//#if (VS2010 || VS2012 || VS2013 || VS2015)
                        HelperFunctions.EnsureCustomBuildToolAvailable(projectItem);
//#endif
                        qtPro.AddMocStep(vcFile);
                    }
                }
                else if (vcFile.Name.EndsWith(".ui"))
                {
                    if (filter == null && !HelperFunctions.IsInFilter(vcFile, ui))
                    {
                        if (null == uiFilter && qtPro.VCProject.CanAddFilter(ui.Name))
                        {
                            uiFilter                  = (VCFilter)qtPro.VCProject.AddFilter(ui.Name);
                            uiFilter.Filter           = ui.Filter;
                            uiFilter.ParseFiles       = ui.ParseFiles;
                            uiFilter.UniqueIdentifier = ui.UniqueIdentifier;
                        }
                        qtPro.RemoveItem(projectItem);
                        qtPro.AddFileToProject(vcFile.FullPath, ui);
                    }
//#if (VS2010 || VS2012 || VS2013 || VS2015)
                    HelperFunctions.EnsureCustomBuildToolAvailable(projectItem);
//#endif
                    qtPro.AddUic4BuildStep(vcFile);
                }
                else if (vcFile.Name.EndsWith(".qrc"))
                {
                    if (filter == null && !HelperFunctions.IsInFilter(vcFile, qrc))
                    {
                        if (null == qrcFilter && qtPro.VCProject.CanAddFilter(qrc.Name))
                        {
                            qrcFilter                  = (VCFilter)qtPro.VCProject.AddFilter(qrc.Name);
                            qrcFilter.Filter           = qrc.Filter;
                            qrcFilter.ParseFiles       = qrc.ParseFiles;
                            qrcFilter.UniqueIdentifier = qrc.UniqueIdentifier;
                        }
                        qtPro.RemoveItem(projectItem);
                        qtPro.AddFileToProject(vcFile.FullPath, qrc);
                    }
//#if (VS2010 || VS2012 || VS2013 || VS2015)
                    HelperFunctions.EnsureCustomBuildToolAvailable(projectItem);
//#endif
                    qtPro.UpdateRccStep(vcFile, null);
                }
                else if (HelperFunctions.IsTranslationFile(vcFile))
                {
                    if (filter == null && !HelperFunctions.IsInFilter(vcFile, ts))
                    {
                        if (null == tsFilter && qtPro.VCProject.CanAddFilter(ts.Name))
                        {
                            tsFilter                  = (VCFilter)qtPro.VCProject.AddFilter(ts.Name);
                            tsFilter.Filter           = ts.Filter;
                            tsFilter.ParseFiles       = ts.ParseFiles;
                            tsFilter.UniqueIdentifier = ts.UniqueIdentifier;
                        }
                        qtPro.RemoveItem(projectItem);
                        qtPro.AddFileToProject(vcFile.FullPath, ts);
                    }
                }
            }
            catch { }

            return;
        }
Beispiel #30
-2
        private void ImportSolution(FileInfo mainInfo, string qtVersion)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var versionInfo = QtVersionManager.The().GetVersionInfo(qtVersion);
            var VCInfo      = RunQmake(mainInfo, ".sln", true, versionInfo);

            if (null == VCInfo)
            {
                return;
            }
            ImportQMakeSolution(VCInfo, versionInfo);

            try {
                if (CheckQtVersion(versionInfo))
                {
                    dteObject.Solution.Open(VCInfo.FullName);
                    if (qtVersion != null)
                    {
                        QtVersionManager.The().SaveSolutionQtVersion(dteObject.Solution, qtVersion);
                        foreach (var prj in HelperFunctions.ProjectsInSolution(dteObject))
                        {
                            QtVersionManager.The().SaveProjectQtVersion(prj, qtVersion);
                            var qtPro = QtProject.Create(prj);
                            qtPro.SetQtEnvironment();
                            ApplyPostImportSteps(qtPro);
                        }
                    }
                }

                Messages.Print("--- (Import): Finished opening " + VCInfo.Name);
            } catch (Exception e) {
                Messages.DisplayCriticalErrorMessage(e);
            }
        }