Ejemplo n.º 1
0
        public static bool RunlRelease(VCFile vcFile)
        {
            if (vcFile == null)
            {
                return(false);
            }

            var success = true;

            try {
                var vcProject = vcFile.project as VCProject;
                var cmdLine   = string.Empty;
                if (HelperFunctions.IsQtProject(vcProject))
                {
                    var options = QtVSIPSettings.GetLReleaseOptions();
                    if (!string.IsNullOrEmpty(options))
                    {
                        cmdLine += options + " ";
                    }
                }
                var project = vcProject.Object as EnvDTE.Project;
                Messages.PaneMessage(project.DTE,
                                     "--- (lrelease) file: " + vcFile.FullPath);

                cmdLine += vcFile.RelativePath.Quoute();
                StartProcess(Resources.lreleaseCommand, cmdLine, vcProject.ProjectDirectory,
                             HelperFunctions.GetSelectedQtProject(project.DTE));
            } catch (QtVSException e) {
                success = false;
                Messages.DisplayErrorMessage(e.Message);
            }

            return(success);
        }
Ejemplo n.º 2
0
        public static bool RunlRelease(VCFile vcFile)
        {
            bool success = true;

            try
            {
                VCProject vcProject = vcFile.project as VCProject;
                string    cmdLine   = "";
                if (HelperFunctions.IsQtProject(vcProject))
                {
                    string options = QtVSIPSettings.GetLReleaseOptions();
                    if (!string.IsNullOrEmpty(options))
                    {
                        cmdLine += options + " ";
                    }
                }
                EnvDTE.Project project = vcProject.Object as EnvDTE.Project;
                Messages.PaneMessage(project.DTE,
                                     "--- (lrelease) file: " + vcFile.FullPath);

                cmdLine += vcFile.RelativePath;
                HelperFunctions.StartExternalQtApplication(Resources.lreleaseCommand, cmdLine,
                                                           vcProject.ProjectDirectory, HelperFunctions.GetSelectedQtProject(project.DTE), true,
                                                           null);
            }
            catch (QtVSException e)
            {
                success = false;
                Messages.DisplayErrorMessage(e.Message);
            }

            return(success);
        }
Ejemplo n.º 3
0
        public void SaveSettings()
        {
            QtVSIPSettings.SaveMocDirectory(newMocDir);
            QtVSIPSettings.SaveMocOptions(newMocOptions);
            QtVSIPSettings.SaveUicDirectory(newUicDir);
            QtVSIPSettings.SaveRccDirectory(newRccDir);
            QtVSIPSettings.SaveLUpdateOnBuild(newLUpdateOnBuild);
            QtVSIPSettings.SaveLUpdateOptions(newLUpdateOptions);
            QtVSIPSettings.SaveLReleaseOptions(newLReleaseOptions);
            QtVSIPSettings.SaveAskBeforeCheckoutFile(newAskBeforeCheckoutFile);
            QtVSIPSettings.SaveDisableCheckoutFiles(newDisableCheckoutFiles);
            QtVSIPSettings.SaveDisableAutoMocStepsUpdate(newDisableAutoMOCStepsUpdate);

            var settingsManager = new ShellSettingsManager(Vsix.Instance);
            var store           = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);

#if VS2013
            store.CreateCollection(Statics.QmlClassifierPath);
            store.SetBoolean(Statics.QmlClassifierPath, Statics.QmlClassifierKey,
                             EnableQmlClassifier);
#else
            store.CreateCollection(Statics.QmlTextMatePath);
            store.SetBoolean(Statics.QmlTextMatePath, Statics.QmlTextMateKey, EnableQmlTextMate);
#endif
        }
Ejemplo n.º 4
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);
                }
            }
        }
Ejemplo n.º 5
0
        public static void loadAssistant()
        {
            string qtVersion = null;

            QtVersionManager vm = QtVersionManager.The(HelperFunctions.GetSolutionPlaformName(Connect._applicationObject.Solution));

            Project prj = HelperFunctions.GetSelectedQtProject(Connect._applicationObject);

            if (prj != null)
            {
                vm.SetPlatform(prj.ConfigurationManager.ActiveConfiguration.PlatformName);
                qtVersion = vm.GetProjectQtVersion(prj);
                if (qtVersion == null)
                {
                    qtVersion = vm.GetSolutionQtVersion(Connect._applicationObject.Solution);
                }
            }
            else
            {
                prj = HelperFunctions.GetSelectedProject(Connect._applicationObject);
                if (prj != null && HelperFunctions.IsQMakeProject(prj))
                {
                    string qmakeQtDir = HelperFunctions.GetQtDirFromQMakeProject(prj);
                    qtVersion = vm.GetQtVersionFromInstallDir(qmakeQtDir);
                }
                if (qtVersion == null)
                {
                    qtVersion = vm.GetSolutionQtVersion(Connect._applicationObject.Solution);
                }
            }

            string qtDir = HelperFunctions.FindQtDirWithTools("assistant", qtVersion);

            if (qtDir == null || qtDir.Length == 0)
            {
                MessageBox.Show(SR.GetString("NoDefaultQtVersionError"),
                                Resources.msgBoxCaption);
                return;
            }

            try
            {
                string workingDir = qtDir;
                string arguments  = null;
                string options    = QtVSIPSettings.GetAssistantOptions(prj);
                if (options != null && options != "")
                {
                    arguments = options;
                }
                System.Diagnostics.Process tmp = getQtApplicationProcess("assistant", arguments, workingDir, qtDir);
                tmp.Start();
            }
            catch
            {
                MessageBox.Show(SR.GetString("QtAppNotFoundErrorMessage", "Qt Assistant"),
                                SR.GetString("QtAppNotFoundErrorTitle", "Assistant"));
            }
        }
Ejemplo n.º 6
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;
                }
            }
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
0
 public VSQtSettings()
 {
     newMocDir                    = QtVSIPSettings.GetMocDirectory();
     newMocOptions                = QtVSIPSettings.GetMocOptions();
     newRccDir                    = QtVSIPSettings.GetRccDirectory();
     newUicDir                    = QtVSIPSettings.GetUicDirectory();
     newLUpdateOnBuild            = QtVSIPSettings.GetLUpdateOnBuild();
     newLUpdateOptions            = QtVSIPSettings.GetLUpdateOptions();
     newLReleaseOptions           = QtVSIPSettings.GetLReleaseOptions();
     newAskBeforeCheckoutFile     = QtVSIPSettings.GetAskBeforeCheckoutFile();
     newDisableCheckoutFiles      = QtVSIPSettings.GetDisableCheckoutFiles();
     newDisableAutoMOCStepsUpdate = QtVSIPSettings.GetDisableAutoMocStepsUpdate();
 }
Ejemplo n.º 9
0
 public void SaveSettings()
 {
     QtVSIPSettings.SaveMocDirectory(newMocDir);
     QtVSIPSettings.SaveMocOptions(newMocOptions);
     QtVSIPSettings.SaveUicDirectory(newUicDir);
     QtVSIPSettings.SaveRccDirectory(newRccDir);
     QtVSIPSettings.SaveLUpdateOnBuild(newLUpdateOnBuild);
     QtVSIPSettings.SaveLUpdateOptions(newLUpdateOptions);
     QtVSIPSettings.SaveLReleaseOptions(newLReleaseOptions);
     QtVSIPSettings.SaveAskBeforeCheckoutFile(newAskBeforeCheckoutFile);
     QtVSIPSettings.SaveDisableCheckoutFiles(newDisableCheckoutFiles);
     QtVSIPSettings.SaveDisableAutoMocStepsUpdate(newDisableAutoMOCStepsUpdate);
 }
Ejemplo n.º 10
0
 public ProjectQtSettings(EnvDTE.Project proj)
 {
     versionManager     = QtVersionManager.The();
     project            = proj;
     newMocDir          = oldMocDir = QtVSIPSettings.GetMocDirectory(project);
     newMocOptions      = oldMocOptions = QtVSIPSettings.GetMocOptions(project);
     newRccDir          = oldRccDir = QtVSIPSettings.GetRccDirectory(project);
     newUicDir          = oldUicDir = QtVSIPSettings.GetUicDirectory(project);
     newLUpdateOnBuild  = oldLUpdateOnBuild = QtVSIPSettings.GetLUpdateOnBuild(project);
     newLUpdateOptions  = oldLUpdateOptions = QtVSIPSettings.GetLUpdateOptions(project);
     newLReleaseOptions = oldLReleaseOptions = QtVSIPSettings.GetLReleaseOptions(project);
     newQtVersion       = oldQtVersion = versionManager.GetProjectQtVersion(project);
 }
Ejemplo n.º 11
0
        private void CheckoutFileIfNeeded(string fileName, out bool abortOperation)
        {
            abortOperation = false;

            if (QtVSIPSettings.GetDisableCheckoutFiles())
            {
                return;
            }

            SourceControl sourceControl = dte.SourceControl;

            if (sourceControl == null)
            {
                return;
            }

            if (!sourceControl.IsItemUnderSCC(fileName))
            {
                return;
            }

            if (sourceControl.IsItemCheckedOut(fileName))
            {
                return;
            }

            if (QtVSIPSettings.GetAskBeforeCheckoutFile())
            {
                string       shortFileName = System.IO.Path.GetFileName(fileName);
                DialogResult dr            = MessageBox.Show(
                    SR.GetString("QuestionSCCCheckoutOnOpen", shortFileName),
                    Resources.msgBoxCaption, MessageBoxButtons.YesNoCancel,
                    MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (dr == DialogResult.Cancel)
                {
                    abortOperation = true;
                }
                if (dr != DialogResult.Yes)
                {
                    return;
                }
            }

            sourceControl.CheckOutItem(fileName);
        }
Ejemplo n.º 12
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.
        }
Ejemplo n.º 13
0
        public VSQtSettings()
        {
            newMocDir                    = QtVSIPSettings.GetMocDirectory();
            newMocOptions                = QtVSIPSettings.GetMocOptions();
            newRccDir                    = QtVSIPSettings.GetRccDirectory();
            newUicDir                    = QtVSIPSettings.GetUicDirectory();
            newLUpdateOnBuild            = QtVSIPSettings.GetLUpdateOnBuild();
            newLUpdateOptions            = QtVSIPSettings.GetLUpdateOptions();
            newLReleaseOptions           = QtVSIPSettings.GetLReleaseOptions();
            newAskBeforeCheckoutFile     = QtVSIPSettings.GetAskBeforeCheckoutFile();
            newDisableCheckoutFiles      = QtVSIPSettings.GetDisableCheckoutFiles();
            newDisableAutoMOCStepsUpdate = QtVSIPSettings.GetDisableAutoMocStepsUpdate();

            var settingsManager = new ShellSettingsManager(Vsix.Instance);
            var store           = settingsManager.GetReadOnlySettingsStore(SettingsScope.UserSettings);

#if VS2013
            EnableQmlClassifier = store.GetBoolean(Statics.QmlClassifierPath,
                                                   Statics.QmlClassifierKey, true);
#else
            EnableQmlTextMate = store.GetBoolean(Statics.QmlTextMatePath,
                                                 Statics.QmlTextMateKey, true);
#endif
        }
Ejemplo n.º 14
0
        public void DocumentSaved(Document document)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var qtPro = QtProject.Create(document.ProjectItem.ContainingProject);

            if (!HelperFunctions.IsQtProject(qtPro.VCProject))
            {
                return;
            }

            var file = (VCFile)((IVCCollection)qtPro.VCProject.Files).Item(document.FullName);

            if (HelperFunctions.IsUicFile(file.Name))
            {
                if (QtVSIPSettings.AutoUpdateUicSteps() && !QtProject.HasUicStep(file))
                {
                    qtPro.AddUic4BuildStep(file);
                }
                return;
            }

            if (!HelperFunctions.IsSourceFile(file.Name) && !HelperFunctions.IsHeaderFile(file.Name))
            {
                return;
            }

            if (HelperFunctions.HasQObjectDeclaration(file))
            {
                if (!qtPro.HasMocStep(file))
                {
                    qtPro.AddMocStep(file);
                }
            }
            else
            {
                if (qtPro.HasMocStep(file))
                {
                    qtPro.RemoveMocStep(file);
                }
            }

            if (HelperFunctions.IsSourceFile(file.Name))
            {
                var moccedFileName = "moc_" + file.Name;

                if (qtPro.IsMoccedFileIncluded(file))
                {
                    foreach (var moccedFile in qtPro.GetFilesFromProject(moccedFileName))
                    {
                        QtProject.ExcludeFromAllBuilds(moccedFile);
                    }
                }
                else
                {
                    var moccedFiles = qtPro.GetFilesFromProject(moccedFileName);
                    if (moccedFiles.Any())
                    {
                        var hasDifferentMocFilesPerConfig   = QtVSIPSettings.HasDifferentMocFilePerConfig(qtPro.Project);
                        var hasDifferentMocFilesPerPlatform = QtVSIPSettings.HasDifferentMocFilePerPlatform(qtPro.Project);
                        var generatedFiles = qtPro.FindFilterFromGuid(Filters.GeneratedFiles().UniqueIdentifier);
                        foreach (VCFile fileInFilter in (IVCCollection)generatedFiles.Files)
                        {
                            if (fileInFilter.Name == moccedFileName)
                            {
                                foreach (VCFileConfiguration config in (IVCCollection)fileInFilter.FileConfigurations)
                                {
                                    var exclude  = true;
                                    var vcConfig = config.ProjectConfiguration as VCConfiguration;
                                    if (hasDifferentMocFilesPerConfig && hasDifferentMocFilesPerPlatform)
                                    {
                                        var platform = vcConfig.Platform as VCPlatform;
                                        if (fileInFilter.RelativePath.ToLower().Contains(vcConfig.ConfigurationName.ToLower()) &&
                                            fileInFilter.RelativePath.ToLower().Contains(platform.Name.ToLower()))
                                        {
                                            exclude = false;
                                        }
                                    }
                                    else if (hasDifferentMocFilesPerConfig)
                                    {
                                        if (fileInFilter.RelativePath.ToLower().Contains(vcConfig.ConfigurationName.ToLower()))
                                        {
                                            exclude = false;
                                        }
                                    }
                                    else if (hasDifferentMocFilesPerPlatform)
                                    {
                                        var platform     = vcConfig.Platform as VCPlatform;
                                        var platformName = platform.Name;
                                        if (fileInFilter.RelativePath.ToLower().Contains(platformName.ToLower()))
                                        {
                                            exclude = false;
                                        }
                                    }
                                    else
                                    {
                                        exclude = false;
                                    }
                                    if (config.ExcludedFromBuild != exclude)
                                    {
                                        config.ExcludedFromBuild = exclude;
                                    }
                                }
                            }
                        }
                        foreach (VCFilter filt in (IVCCollection)generatedFiles.Filters)
                        {
                            foreach (VCFile f in (IVCCollection)filt.Files)
                            {
                                if (f.Name == moccedFileName)
                                {
                                    foreach (VCFileConfiguration config in (IVCCollection)f.FileConfigurations)
                                    {
                                        var vcConfig        = config.ProjectConfiguration as VCConfiguration;
                                        var filterToLookFor = string.Empty;
                                        if (hasDifferentMocFilesPerConfig)
                                        {
                                            filterToLookFor = vcConfig.ConfigurationName;
                                        }
                                        if (hasDifferentMocFilesPerPlatform)
                                        {
                                            var platform = vcConfig.Platform as VCPlatform;
                                            if (!string.IsNullOrEmpty(filterToLookFor))
                                            {
                                                filterToLookFor += '_';
                                            }
                                            filterToLookFor += platform.Name;
                                        }
                                        if (filt.Name == filterToLookFor)
                                        {
                                            if (config.ExcludedFromBuild)
                                            {
                                                config.ExcludedFromBuild = false;
                                            }
                                        }
                                        else
                                        {
                                            if (!config.ExcludedFromBuild)
                                            {
                                                config.ExcludedFromBuild = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 15
0
        static void Legacy_RunTranslation(
            BuildAction buildAction,
            QtProject qtProject,
            string tsFile,
            ref string tempFile)
        {
            var qtVersion     = qtProject.GetQtVersion();
            var qtInstallPath = QtVersionManager.The().GetInstallPath(qtVersion);

            if (string.IsNullOrEmpty(qtInstallPath))
            {
                Messages.Print("translation: Error accessing Qt installation");
                return;
            }

            var procInfo = new ProcessStartInfo
            {
                WorkingDirectory       = qtProject.ProjectDir,
                CreateNoWindow         = true,
                UseShellExecute        = false,
                RedirectStandardError  = true,
                RedirectStandardOutput = true,
                Arguments = ""
            };

            switch (buildAction)
            {
            case BuildAction.Update:
                Messages.Print("\r\n--- (lupdate) file: " + tsFile);
                procInfo.FileName = Path.Combine(qtInstallPath, "bin", "lupdate.exe");
                var options = QtVSIPSettings.GetLUpdateOptions();
                if (!string.IsNullOrEmpty(options))
                {
                    procInfo.Arguments += options + " ";
                }
                if (tempFile == null)
                {
                    var inputFiles = GetProjectFiles(qtProject.Project, FilesToList.FL_HFiles)
                                     .Union(GetProjectFiles(qtProject.Project, FilesToList.FL_CppFiles))
                                     .Union(GetProjectFiles(qtProject.Project, FilesToList.FL_UiFiles))
                                     .Union(GetProjectFiles(qtProject.Project, FilesToList.FL_QmlFiles));
                    tempFile = Path.GetTempFileName();
                    File.WriteAllLines(tempFile, inputFiles);
                }
                procInfo.Arguments += string.Format("\"@{0}\" -ts \"{1}\"", tempFile, tsFile);
                break;

            case BuildAction.Release:
                Messages.Print("\r\n--- (lrelease) file: " + tsFile);
                procInfo.FileName = Path.Combine(qtInstallPath, "bin", "lrelease.exe");
                options           = QtVSIPSettings.GetLReleaseOptions();
                if (!string.IsNullOrEmpty(options))
                {
                    procInfo.Arguments += options + " ";
                }
                procInfo.Arguments += string.Format("\"{0}\"", tsFile);
                break;
            }
            using (var proc = Process.Start(procInfo)) {
                proc.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
                {
                    if (!string.IsNullOrEmpty(e.Data))
                    {
                        Messages.Print(e.Data);
                    }
                };
                proc.ErrorDataReceived += (object sender, DataReceivedEventArgs e) =>
                {
                    if (!string.IsNullOrEmpty(e.Data))
                    {
                        Messages.Print(e.Data);
                    }
                };
                proc.BeginOutputReadLine();
                proc.BeginErrorReadLine();
                proc.WaitForExit();
                switch (proc.ExitCode)
                {
                case 0:
                    Messages.Print("translation: ok");
                    break;

                default:
                    Messages.Print(string.Format("translation: ERROR {0}", proc.ExitCode));
                    break;
                }
            }
        }
Ejemplo n.º 16
0
        public static bool RunlUpdate(VCFile vcFile, EnvDTE.Project pro)
        {
            if (vcFile == null || pro == null)
            {
                return(false);
            }

            if (!HelperFunctions.IsQtProject(pro))
            {
                return(false);
            }

            var cmdLine = string.Empty;
            var options = QtVSIPSettings.GetLUpdateOptions(pro);

            if (!string.IsNullOrEmpty(options))
            {
                cmdLine += options + " ";
            }
            var headers = HelperFunctions.GetProjectFiles(pro, FilesToList.FL_HFiles);
            var sources = HelperFunctions.GetProjectFiles(pro, FilesToList.FL_CppFiles);
            var uifiles = HelperFunctions.GetProjectFiles(pro, FilesToList.FL_UiFiles);

            StringBuilder fileNames = new StringBuilder();

            foreach (var file in headers)
            {
                fileNames.AppendLine(file);
            }

            foreach (var file in sources)
            {
                fileNames.AppendLine(file);
            }

            foreach (var file in uifiles)
            {
                fileNames.AppendLine(file);
            }

            var lstFilePath = Path.GetTempFileName();

            File.WriteAllText(lstFilePath, fileNames.ToString());
            cmdLine += string.Format("\"@{0}\" ", lstFilePath);
            cmdLine += "-ts " + vcFile.RelativePath.Quoute();

            var success = true;

            try {
                Messages.PaneMessage(pro.DTE, "--- (lupdate) file: " + vcFile.FullPath);
                StartProcess(Resources.lupdateCommand, cmdLine, (vcFile.project as VCProject)
                             .ProjectDirectory, pro);
            } catch (QtVSException e) {
                success = false;
                Messages.DisplayErrorMessage(e.Message);
            }

            if (File.Exists(lstFilePath))
            {
                File.Delete(lstFilePath);
            }

            return(success);
        }
Ejemplo n.º 17
0
        public void loadDesigner(string fileName)
        {
            string qtVersion = null;

            QtVersionManager vm = QtVersionManager.The(HelperFunctions.GetSolutionPlaformName(Connect._applicationObject.Solution));

            Project prj = HelperFunctions.GetSelectedQtProject(Connect._applicationObject);

            if (prj != null)
            {
                vm.SetPlatform(prj.ConfigurationManager.ActiveConfiguration.PlatformName);
                qtVersion = vm.GetProjectQtVersion(prj);
                if (qtVersion == null)
                {
                    qtVersion = vm.GetSolutionQtVersion(Connect._applicationObject.Solution);
                }
            }
            else
            {
                prj = HelperFunctions.GetSelectedProject(Connect._applicationObject);
                if (prj != null && HelperFunctions.IsQMakeProject(prj))
                {
                    string qmakeQtDir = HelperFunctions.GetQtDirFromQMakeProject(prj);
                    qtVersion = vm.GetQtVersionFromInstallDir(qmakeQtDir);
                }
                if (qtVersion == null)
                {
                    qtVersion = vm.GetSolutionQtVersion(Connect._applicationObject.Solution);
                }
            }

            string qtDir = HelperFunctions.FindQtDirWithTools("designer", qtVersion);

            if (qtDir == null || qtDir.Length == 0)
            {
                MessageBox.Show(SR.GetString("NoDefaultQtVersionError"),
                                Resources.msgBoxCaption);
                return;
            }

            try
            {
                if (!designerDict.ContainsKey(qtDir) || designerDict[qtDir].process.HasExited)
                {
                    string workingDir, formFile;
                    if (fileName == null)
                    {
                        formFile   = "";
                        workingDir = (prj == null) ? null : Path.GetDirectoryName(prj.FullName);
                    }
                    else
                    {
                        formFile   = fileName;
                        workingDir = Path.GetDirectoryName(fileName);
                        if (!formFile.StartsWith("\""))
                        {
                            formFile = "\"" + formFile;
                        }
                        if (!formFile.EndsWith("\""))
                        {
                            formFile += "\"";
                        }
                    }

                    string options   = QtVSIPSettings.GetDesignerOptions(prj);
                    string launchCMD = "-server " + formFile;
                    if (options != null && options != "")
                    {
                        launchCMD = options + " " + launchCMD;
                    }
                    System.Diagnostics.Process tmp = getQtApplicationProcess("designer", launchCMD, workingDir, qtDir);
                    tmp.StartInfo.UseShellExecute        = false;
                    tmp.StartInfo.RedirectStandardOutput = true;
                    tmp.OutputDataReceived += new DataReceivedEventHandler(designerOutputHandler);
                    tmp.Start();
                    tmp.BeginOutputReadLine();
                    try
                    {
                        portFound.WaitOne(5000, false);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }
                    tmp.WaitForInputIdle();
                    DesignerData data;
                    data.process = tmp;
                    data.port    = designerPort;
                    portFound.Reset();
                    designerDict[qtDir] = data;
                }
                else if (fileName != null)
                {
                    try
                    {
                        TcpClient c = new TcpClient("127.0.0.1", designerDict[qtDir].port);
                        System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
                        byte[] bArray = enc.GetBytes(fileName + "\n");
                        Stream stream = c.GetStream();
                        stream.Write(bArray, 0, bArray.Length);
                        c.Close();
                        stream.Close();
                    }
                    catch
                    {
                        Messages.DisplayErrorMessage(SR.GetString("DesignerAddError"));
                    }
                }
            }
            catch
            {
                MessageBox.Show(SR.GetString("QtAppNotFoundErrorMessage", "Qt Designer"),
                                SR.GetString("QtAppNotFoundErrorTitle", "Designer"));
                return;
            }
            try
            {
                if ((int)designerDict[qtDir].process.MainWindowHandle == 0)
                {
                    System.Diagnostics.Process prc = System.Diagnostics.Process.GetProcessById(designerDict[qtDir].process.Id);
                    if ((int)prc.MainWindowHandle != 0)
                    {
                        DesignerData data;
                        data.process        = prc;
                        data.port           = designerDict[qtDir].port;
                        designerDict[qtDir] = data;
                    }
                }
                SwitchToThisWindow(designerDict[qtDir].process.MainWindowHandle, true);
            }
            catch
            {
                // silent
            }
        }
Ejemplo n.º 18
0
        public void DocumentSaved(EnvDTE.Document document)
        {
            QtProject qtPro = QtProject.Create(document.ProjectItem.ContainingProject);

            if (!HelperFunctions.IsQtProject(qtPro.VCProject))
            {
                return;
            }

            VCFile file = (VCFile)((IVCCollection)qtPro.VCProject.Files).Item(document.FullName);

            if (file.Extension == ".ui")
            {
                if (QtVSIPSettings.AutoUpdateUicSteps() && !QtProject.HasUicStep(file))
                {
                    qtPro.AddUic4BuildStep(file);
                }
                return;
            }

            if (!HelperFunctions.HasSourceFileExtension(file.Name) && !HelperFunctions.HasHeaderFileExtension(file.Name))
            {
                return;
            }

            if (HelperFunctions.HasQObjectDeclaration(file))
            {
                if (!qtPro.HasMocStep(file))
                {
                    qtPro.AddMocStep(file);
                }
            }
            else
            {
                qtPro.RemoveMocStep(file);
            }

            if (HelperFunctions.HasSourceFileExtension(file.Name))
            {
                string moccedFileName = "moc_" + file.Name;

                if (qtPro.IsMoccedFileIncluded(file))
                {
                    // exclude moc_foo.cpp from build
//#if (VS2012 || VS2013 || VS2015)
                    // Code copied here from 'GetFilesFromProject'
                    // For some reason error CS1771 was generated from function call
                    List <VCFile> tmpList = new System.Collections.Generic.List <VCFile>();
                    moccedFileName = HelperFunctions.NormalizeRelativeFilePath(moccedFileName);

                    FileInfo fi = new FileInfo(moccedFileName);
                    foreach (VCFile f in (IVCCollection)qtPro.VCProject.Files)
                    {
                        if (f.Name.ToLower() == fi.Name.ToLower())
                        {
                            tmpList.Add(f);
                        }
                    }
                    foreach (VCFile moccedFile in tmpList)
                    {
                        QtProject.ExcludeFromAllBuilds(moccedFile);
                    }
//#else
///                    foreach (VCFile moccedFile in qtPro.GetFilesFromProject(moccedFileName))
//                        QtProject.ExcludeFromAllBuilds(moccedFile);
//#endif
                }
                else
                {
                    // make sure that moc_foo.cpp isn't excluded from build
//#if (VS2012 || VS2013 || VS2015)
                    // Code copied here from 'GetFilesFromProject'
                    // For some reason error CS1771 was generated from function call
                    List <VCFile> moccedFiles = new System.Collections.Generic.List <VCFile>();
                    moccedFileName = HelperFunctions.NormalizeRelativeFilePath(moccedFileName);

                    FileInfo fi = new FileInfo(moccedFileName);
                    foreach (VCFile f in (IVCCollection)qtPro.VCProject.Files)
                    {
                        if (f.Name.ToLower() == fi.Name.ToLower())
                        {
                            moccedFiles.Add(f);
                        }
                    }
//#else
//                    List<VCFile> moccedFiles = qtPro.GetFilesFromProject(moccedFileName);
//#endif
                    if (moccedFiles.Count > 0)
                    {
                        bool     hasDifferentMocFilesPerConfig   = QtVSIPSettings.HasDifferentMocFilePerConfig(qtPro.Project);
                        bool     hasDifferentMocFilesPerPlatform = QtVSIPSettings.HasDifferentMocFilePerPlatform(qtPro.Project);
                        VCFilter generatedFiles = qtPro.FindFilterFromGuid(Filters.GeneratedFiles().UniqueIdentifier);
                        foreach (VCFile fileInFilter in (IVCCollection)generatedFiles.Files)
                        {
                            if (fileInFilter.Name == moccedFileName)
                            {
                                foreach (VCFileConfiguration config in (IVCCollection)fileInFilter.FileConfigurations)
                                {
                                    bool            exclude  = true;
                                    VCConfiguration vcConfig = config.ProjectConfiguration as VCConfiguration;
                                    if (hasDifferentMocFilesPerConfig && hasDifferentMocFilesPerPlatform)
                                    {
                                        VCPlatform platform     = vcConfig.Platform as VCPlatform;
                                        string     platformName = platform.Name;
                                        if (fileInFilter.RelativePath.ToLower().Contains(vcConfig.ConfigurationName.ToLower()) &&
                                            fileInFilter.RelativePath.ToLower().Contains(platform.Name.ToLower()))
                                        {
                                            exclude = false;
                                        }
                                    }
                                    else if (hasDifferentMocFilesPerConfig)
                                    {
                                        if (fileInFilter.RelativePath.ToLower().Contains(vcConfig.ConfigurationName.ToLower()))
                                        {
                                            exclude = false;
                                        }
                                    }
                                    else if (hasDifferentMocFilesPerPlatform)
                                    {
                                        VCPlatform platform     = vcConfig.Platform as VCPlatform;
                                        string     platformName = platform.Name;
                                        if (fileInFilter.RelativePath.ToLower().Contains(platformName.ToLower()))
                                        {
                                            exclude = false;
                                        }
                                    }
                                    else
                                    {
                                        exclude = false;
                                    }
                                    if (config.ExcludedFromBuild != exclude)
                                    {
                                        config.ExcludedFromBuild = exclude;
                                    }
                                }
                            }
                        }
                        foreach (VCFilter filt in (IVCCollection)generatedFiles.Filters)
                        {
                            foreach (VCFile f in (IVCCollection)filt.Files)
                            {
                                if (f.Name == moccedFileName)
                                {
                                    foreach (VCFileConfiguration config in (IVCCollection)f.FileConfigurations)
                                    {
                                        VCConfiguration vcConfig        = config.ProjectConfiguration as VCConfiguration;
                                        string          filterToLookFor = "";
                                        if (hasDifferentMocFilesPerConfig)
                                        {
                                            filterToLookFor = vcConfig.ConfigurationName;
                                        }
                                        if (hasDifferentMocFilesPerPlatform)
                                        {
                                            VCPlatform platform = vcConfig.Platform as VCPlatform;
                                            if (!string.IsNullOrEmpty(filterToLookFor))
                                            {
                                                filterToLookFor += '_';
                                            }
                                            filterToLookFor += platform.Name;
                                        }
                                        if (filt.Name == filterToLookFor)
                                        {
                                            if (config.ExcludedFromBuild)
                                            {
                                                config.ExcludedFromBuild = false;
                                            }
                                        }
                                        else
                                        {
                                            if (!config.ExcludedFromBuild)
                                            {
                                                config.ExcludedFromBuild = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 19
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.GUISystem | (data.CreateStaticLibrary
                ? TemplateType.StaticLibrary : TemplateType.DynamicLibrary);

            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());
            }

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

            qtProject.AddDefine(projectDefine, BuildConfig.Both);
            if (data.CreateStaticLibrary)
            {
                qtProject.AddDefine("BUILD_STATIC", BuildConfig.Both);
            }

            qtProject.SetQtEnvironment(qtVersion);
            qtProject.Finish(); // Collapses all project nodes.
        }
Ejemplo n.º 20
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.
        }
Ejemplo n.º 21
0
        public static bool RunlUpdate(VCFile vcFile, EnvDTE.Project pro)
        {
            if (!HelperFunctions.IsQtProject(pro))
            {
                return(false);
            }

            string cmdLine = "";
            string options = QtVSIPSettings.GetLUpdateOptions(pro);

            if (!string.IsNullOrEmpty(options))
            {
                cmdLine += options + " ";
            }
            List <string> headers = HelperFunctions.GetProjectFiles(pro, FilesToList.FL_HFiles);
            List <string> sources = HelperFunctions.GetProjectFiles(pro, FilesToList.FL_CppFiles);
            List <string> uifiles = HelperFunctions.GetProjectFiles(pro, FilesToList.FL_UiFiles);

            foreach (string file in headers)
            {
                cmdLine += file + " ";
            }

            foreach (string file in sources)
            {
                cmdLine += file + " ";
            }

            foreach (string file in uifiles)
            {
                cmdLine += file + " ";
            }

            cmdLine += "-ts " + vcFile.RelativePath;

            int    cmdLineLength    = cmdLine.Length + Resources.lupdateCommand.Length + 1;
            string temporaryProFile = null;

            if (cmdLineLength > HelperFunctions.GetMaximumCommandLineLength())
            {
                string codec = "";
                if (!string.IsNullOrEmpty(options))
                {
                    int cc4tr_location = options.IndexOf("-codecfortr", System.StringComparison.CurrentCultureIgnoreCase);
                    if (cc4tr_location != -1)
                    {
                        codec = options.Substring(cc4tr_location).Split(' ')[1];
                        string remove_this = options.Substring(cc4tr_location, "-codecfortr".Length + 1 + codec.Length);
                        options = options.Replace(remove_this, "");
                    }
                }
                VCProject vcPro = (VCProject)pro.Object;
                temporaryProFile = System.IO.Path.GetTempFileName();
                temporaryProFile = System.IO.Path.GetDirectoryName(temporaryProFile) + "\\" +
                                   System.IO.Path.GetFileNameWithoutExtension(temporaryProFile) + ".pro";
                if (System.IO.File.Exists(temporaryProFile))
                {
                    System.IO.File.Delete(temporaryProFile);
                }
                System.IO.StreamWriter sw = new System.IO.StreamWriter(temporaryProFile);
                writeFilesToPro(sw, "HEADERS",
                                ProjectExporter.ConvertFilesToFullPath(headers, vcPro.ProjectDirectory));
                writeFilesToPro(sw, "SOURCES",
                                ProjectExporter.ConvertFilesToFullPath(sources, vcPro.ProjectDirectory));
                writeFilesToPro(sw, "FORMS",
                                ProjectExporter.ConvertFilesToFullPath(uifiles, vcPro.ProjectDirectory));

                List <string> tsFiles = new List <string>(1);
                tsFiles.Add(vcFile.FullPath);
                writeFilesToPro(sw, "TRANSLATIONS", tsFiles);

                if (!string.IsNullOrEmpty(codec))
                {
                    sw.WriteLine("CODECFORTR = " + codec);
                }
                sw.Close();

                cmdLine = "";
                if (!string.IsNullOrEmpty(options))
                {
                    cmdLine += options + " ";
                }
                cmdLine += "\"" + temporaryProFile + "\"";
            }

            bool success = true;

            try
            {
                Messages.PaneMessage(pro.DTE, "--- (lupdate) file: " + vcFile.FullPath);

                HelperFunctions.StartExternalQtApplication(Resources.lupdateCommand, cmdLine,
                                                           ((VCProject)vcFile.project).ProjectDirectory, pro, true, null);
            }
            catch (QtVSException e)
            {
                success = false;
                Messages.DisplayErrorMessage(e.Message);
            }

            if (temporaryProFile != null && System.IO.File.Exists(temporaryProFile))
            {
                System.IO.File.Delete(temporaryProFile);
                temporaryProFile  = temporaryProFile.Substring(0, temporaryProFile.Length - 3);
                temporaryProFile += "TMP";
                if (System.IO.File.Exists(temporaryProFile))
                {
                    System.IO.File.Delete(temporaryProFile);
                }
            }

            return(success);
        }