/// <summary> /// Handler for a removed item by other editor /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void my_RemovedItem(object sender, ItemRemovedEventArgs e) { CoProFilterProvider.MySide = false; if (e.IsDeleted) { EnvDTE.Projects ps = gobj.DTE2.Solution.Projects; foreach (EnvDTE.Project p in ps) { string pname = p.Name; if (p.Name.Contains(e.Project)) { p.ProjectItems.Item(e.Name).Delete(); break; } } } else { EnvDTE.Projects ps = gobj.DTE2.Solution.Projects; foreach (EnvDTE.Project p in ps) { string pname = p.Name; if (p.Name.Contains(e.Project)) { p.ProjectItems.Item(e.Name).Remove(); break; } } } CoProFilterProvider.MySide = true; }
// Deprecated: remove when old project parsing is retired public static List <String> GetSolutionProjectsFullNames(DTE dte) { List <String> projectNames = new List <String>(); EnvDTE.Solution solution = dte.Solution; EnvDTE.Projects projects = solution.Projects; List <Guid> guids = new List <Guid>(); foreach (EnvDTE.Project project in projects) { guids.Add(ProjectUtility.ReloadProject(project)); } projects = solution.Projects; foreach (EnvDTE.Project project in projects) { projectNames.Add(project.FullName); } foreach (Guid guid in guids) { ProjectUtility.UnloadProject(guid, dte); } return(projectNames); }
/// <summary> /// loads all classes in solution /// </summary> /// <param name="projects">All projects in the solution</param> /// <param name="editor">The textbox to display progress</param> /// <param name="withProperties">True if you only want classes with properties only. False if you want classes with Functions</param> /// <returns></returns> public static List <CodeClass> ClassSearch(EnvDTE.Projects projects, FastColoredTextBox editor) { var projs = CodeDiscoverer.Projects(); var foundClasses = new List <CodeClass>(); editor.Text = "Loading projects\r\n"; foreach (var proj in projs) { if (proj == null) { continue; } editor.AppendText("\r\n" + proj.Name); if (proj.ProjectItems == null || proj.CodeModel == null) { continue; } // var timer = new Stopwatch(); // timer.Start(); var projectItems = GetProjectItems(proj.ProjectItems).Where(v => v.Name.Contains(".cs")); // foundClasses.AddRange(projectItems.Where(c => c.FileCodeModel != null).SelectMany(x => x.FileCodeModel.CodeElements.OfType<CodeNamespace>().SelectMany(xx => xx.Members.OfType<CodeClass>()))); Parallel.ForEach(projectItems, (c) => { if (c == null || c.FileCodeModel == null) { return; } //foundClasses.AddRange(c.FileCodeModel.CodeElements.OfType<CodeNamespace>().SelectMany(x => x.Members.OfType<CodeClass>())); foreach (var ns in c.FileCodeModel.CodeElements.OfType <CodeNamespace>()) { foreach (var member in ns.Members.OfType <CodeClass>()) { if (member == null || member.Kind != vsCMElement.vsCMElementClass) { continue; } foundClasses.Add(member); } } }); //timer.Stop(); // editor.AppendText("\r\n" + proj.Name + "- " + timer.ElapsedMilliseconds + "ms"); } if (foundClasses == null || foundClasses.Count == 0) { throw new Exception("Could not find any classes"); } foundClasses.Sort((x, y) => x.FullName.CompareTo(y.FullName)); return(foundClasses); }
public static SolutionStructure GetProjectStructureRecursive(DTE dte) { EnvDTE.Solution solution = dte.Solution; EnvDTE.Projects solutionProjects = solution.Projects; List <Guid> guids = new List <Guid>(); SolutionStructure projectStructure = new SolutionStructure(); foreach (Project project in solutionProjects) { try { if (project.Kind == EnvDTE.Constants.vsProjectKindUnmodeled) // not loaded { continue; } // check it's a c/c++ project if (project.CodeModel != null) { if (project.CodeModel.Language != CodeModelLanguageConstants.vsCMLanguageVC) { continue; } } if (project.Kind == "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") { SolutionStructure.ProjectNode projectNode = new SolutionStructure.ProjectNode(); projectNode.Name = project.Name; projectNode.Project = project; projectNode.Include = false; projectStructure.Nodes.Add(projectNode); } else { SolutionStructure.Node folderNode = GetSubProjects(project); if (folderNode != null) { projectStructure.Nodes.Add(folderNode); } else { Logging.Logging.LogWarning("Subnode was NULL"); } } } catch (Exception e) { Logging.Logging.LogError("Exception: " + e.Message); } } return(projectStructure); }
public static void WalkProjects(EnvDTE.Projects projects) { foreach (EnvDTE.Project proj in projects) { doProject(proj); foreach (EnvDTE.ProjectItem projItem in proj.ProjectItems) { doProjectItem(projItem); WalkFileCodeModel(projItem.FileCodeModel, ""); } WalkCodeModel(proj.CodeModel, ""); } }
public static void PutTextToCS(string text) { ThreadHelper.ThrowIfNotOnUIThread(); EnvDTE.Solution solution = DTE.Solution; EnvDTE.Projects _projects = solution.Projects; string s = string.Empty; var projects = _projects.GetEnumerator(); while (projects.MoveNext()) { var items = ((Project)projects.Current).ProjectItems.GetEnumerator(); while (items.MoveNext()) { ProjectItem item = (ProjectItem)items.Current; //Recursion to get all ProjectItems s += item.Name + Environment.NewLine; //ExamineItem(item); if (item.Name.EndsWith("cs")) { Window x = item.Open(); x.Visible = true; var document = x.Document; document.ReadOnly = false; TextDocument editDoc = document.Object("TextDocument") as TextDocument; string x1 = editDoc.ToString(); EditPoint objEditPt = editDoc.CreateEditPoint(); editDoc.Selection.Insert(text + Environment.NewLine); System.Windows.Forms.SendKeys.SendWait("^k"); System.Windows.Forms.SendKeys.SendWait("^d"); //objEditPt.StartOfDocument(); //while (!objEditPt.AtEndOfDocument) //{ // //objEditPt.Delete(objEditPt.LineLength); // objEditPt.LineDown(1); //} //objEditPt.Insert(text); //objEditPt.DeleteWhitespace(vsWhitespaceOptions.vsWhitespaceOptionsHorizontal); //objEditPt.DeleteWhitespace(vsWhitespaceOptions.vsWhitespaceOptionsVertical); Console.WriteLine("saving file {0}", document.FullName); //document.Save(document.FullName); } } } }
/// <summary> /// Handler for item added by other editor /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void my_ItemAdded(object sender, NewItemAddedEventArgs e) { File.WriteAllBytes(cb.ProjPath + e.RelPath, e.Content); CoProFilterProvider.MySide = false; EnvDTE.Projects ps = gobj.DTE2.Solution.Projects; foreach (EnvDTE.Project p in ps) { string pname = p.Name; if (p.Name.Contains(e.Project)) { p.ProjectItems.AddFromTemplate(cb.ProjPath + e.RelPath, e.Name); break; } } CoProFilterProvider.MySide = true; }
private IEnumerable <EnvDTE.Project> EnumerateProjects(EnvDTE.Projects vsSolution) { foreach (var project in vsSolution.OfType <EnvDTE.Project>()) { if (project.Kind == FolderKind /* Folder */) { foreach (var subProject in EnumSubProjects(project)) { yield return(subProject); } } else { yield return(project); } } }
public bool FindProjectItem(string projectName, string name) { bool found = false; EnvDTE.Projects vsProjects = dte.Solution.Projects; foreach (EnvDTE.Project vsProject in vsProjects) { if (vsProject.Name.Equals(projectName)) { EnvDTE.ProjectItem item = vsProject.ProjectItems.Item(name); if (item != null) { found = true; } } } return(found); }
public static string GetProjectName(string fileName) { ThreadHelper.ThrowIfNotOnUIThread(); EnvDTE.Solution solution = DTE.Solution; EnvDTE.Projects _projects = solution.Projects; string result = null; if (DTE != null && DTE.Solution != null) { ProjectItem prj = DTE.Solution.FindProjectItem(fileName); var x = prj.ProjectItems; if (prj != null) { result = prj.ContainingProject.Name; } } return(result); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void Execute(object sender, EventArgs e) { ThreadHelper.ThrowIfNotOnUIThread(); EnvDTE.DTE dte = (EnvDTE.DTE) this.ServiceProvider.GetServiceAsync(typeof(EnvDTE.DTE)).Result; EnvDTE.Projects projects = dte.Solution.Projects; string props = ""; foreach (SelectedItem selectedItem in dte.SelectedItems) { foreach (EnvDTE.Property property in selectedItem.Project.Properties) { try { props += property.Name + ":\t" + property.Value.ToString() + '\n'; } catch (Exception) { } if (property.Name == "Kind" && property.Value.ToString() != "VCProject") { throw new Exception("Wrong project type, needs to be a C++ project"); } if (property.Name == "ShowAllFiles") { property.Value = "True"; } else if (property.Name == "ProjectFile") { string vcxfilepath = property.Value.ToString(); VCXProjFileHandler.ModifyVCXProj(vcxfilepath); } else if (property.Name == "ProjectDirectory") { string projFilePath = property.Value.ToString(); Directory.CreateDirectory(projFilePath + "\\src"); using (FileStream writer = new FileStream(projFilePath + "\\src\\pch.cpp", FileMode.Create)) { byte[] arr = Encoding.ASCII.GetBytes("#include \"pch.h\"\n\n\n"); writer.Write(arr, 0, 19); } using (FileStream writer = new FileStream(projFilePath + "\\src\\pch.h", FileMode.Create)) { byte[] arr = Encoding.ASCII.GetBytes("#ifndef PCH_H\n#define PCH_H\n\n\n#endif"); writer.Write(arr, 0, 15); } using (FileStream writer = new FileStream(projFilePath + "\\src\\main.cpp", FileMode.Create)) { byte[] arr = Encoding.ASCII.GetBytes("#include \"pch.h\"\n\n\n\nint main(int argc, char** argv)\n{\n\t\n}\n\n"); writer.Write(arr, 0, 59); } } } } }
/// <summary>实现 IDTCommandTarget 接口的 Exec 方法。此方法在调用该命令时调用。</summary> /// <param term='commandName'>要执行的命令的名称。</param> /// <param term='executeOption'>描述该命令应如何运行。</param> /// <param term='varIn'>从调用方传递到命令处理程序的参数。</param> /// <param term='varOut'>从命令处理程序传递到调用方的参数。</param> /// <param term='handled'>通知调用方此命令是否已被处理。</param> /// <seealso class='Exec' /> public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled) { handled = false; if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault) { if (commandName == "ThkDevEnc.Connect.ProeAttach" || commandName == "ThkDevEnc.Connect.CatiaAttach") { handled = true; bool bCatia = false; if (commandName == "ThkDevEnc.Connect.CatiaAttach") { bCatia = true; } ArrayList procList = new ArrayList(); foreach (Process proc in _applicationObject.Debugger.LocalProcesses) { string strname = proc.Name; strname = strname.ToLower(); if (bCatia) { if (strname.Contains("cnext.exe")) { procList.Add(proc); } } else { if (strname.Contains("xtop.exe")) { procList.Add(proc); } } } int iNum = procList.Count; if (iNum > 0) { if (iNum > 1) { SelForm sel = new SelForm(); sel.DebugCatia = bCatia; if (sel.ShowDialog() == System.Windows.Forms.DialogResult.OK) { AttachProcess(sel.PROCESSES); } } else { //Engine[] eng = new Engine[2]; //Debugger3 dbg = (Debugger3)_applicationObject.Debugger; //Transport tras = dbg.Transports.Item("default"); //eng[0] = tras.Engines.Item("native"); //eng[1] = tras.Engines.Item("Managed"); ((Process)procList[0]).Attach(); } } else { if (bCatia) { MessageBox.Show("当前没有运行Catia程序"); } else { MessageBox.Show("当前没有运行PROE/CREO程序"); } } return; } if (commandName == "ThkDevEnc.Connect.ProUnlock") { handled = true; ProUnLock pu = new ProUnLock(); pu.m_envcfgs = m_envcfgs; pu.ShowDialog(); return; } if (commandName == "ThkDevEnc.Connect.CopyFile") { handled = true; LP_SC.FileCopyForm fm = new LP_SC.FileCopyForm(_applicationObject); fm.ResetTree(); fm.ShowDialog(); return; } if (commandName == "ThkDevEnc.Connect.DevEnvCfg") { handled = true; EncSet sel = new EncSet(); if (DialogResult.OK == sel.ShowDialog()) { m_envcfgs.LoadConfig(); EnvDTE.Projects curprj = _applicationObject.DTE.Solution.Projects; if (curprj == null || curprj.Count == 0) { return; } for (int i = 0; i < curprj.Count; i++) { EnvDTE.Project prj = curprj.Item(i); } } return; } if (commandName == "ThkDevEnc.Connect.VCSet") { handled = true; VcInfoSet sel = new VcInfoSet(); sel.ShowDialog(); return; } if (commandName == "ThkDevEnc.Connect.UnAttach") { handled = true; if (_applicationObject.Debugger.CurrentMode == dbgDebugMode.dbgDesignMode) { return; } _applicationObject.Debugger.DetachAll(); //try //{ // Project prj; // Configuration config; // OutputGroups outPGs; // Properties props; // if (_applicationObject.Solution.Projects.Count > 0) // { // prj = _applicationObject.Solution.Projects.Item(1); // config = prj.ConfigurationManager.ActiveConfiguration; // // Return a collection of OutputGroup objects that contain // // the names of files that are outputs for the project. // outPGs = config.OutputGroups; // MessageBox.Show(outPGs.Count.ToString()); // // Returns the project for the config. // MessageBox.Show(((Project)config.Owner).Name); // // Returning the platform name for the Configuration. // MessageBox.Show(config.PlatformName); // // Returning all properties for Configuration object. // props = config.Properties; // string p = ""; // foreach (Property prop in props) // { // p = p + prop.Name + "<:>"+prop.Value+"\n"; // } // MessageBox.Show(p); // } //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message); //} return; } } }
// Run on Mono public bool TestInMono() { // Registry Helper Obj Mfconsulting.Vsprj2make.RegistryHelper regH = new RegistryHelper(); // MonoLaunchHelper Mfconsulting.Vsprj2make.MonoLaunchHelper launchHlpr = new MonoLaunchHelper(); // Web bool isWebProject = false; string aciveFileSharePath = @"C:\inetpub\wwwroot"; string startPage = "index.aspx"; string portForXsp = "8189"; // Other string startUpProject = ""; string projectOutputFileName = ""; string projectOutputPathFromBase = ""; int projectOutputType = 0; string projectOutputWorkingDirectory = ""; EnvDTE.Solution thisSln = applicationObject.Solution; // Run in Mono Process System.Diagnostics.ProcessStartInfo procInfo = new ProcessStartInfo(); System.Diagnostics.Process monoLauncC = new System.Diagnostics.Process(); monoLauncC.StartInfo = procInfo; // Get the Solution's startup project startUpProject = thisSln.Properties.Item(5).Value.ToString(); // Run in Mono EnvDTE.Projects projs = thisSln.Projects; foreach (EnvDTE.Project proj in projs) { if (startUpProject.CompareTo(proj.Name) == 0) { foreach (EnvDTE.Property prop in proj.Properties) { if (prop.Name.CompareTo("ProjectType") == 0) { if (Convert.ToInt32(prop.Value) == 1) { isWebProject = true; portForXsp = regH.Port.ToString(); } } // Web Root for XSP if (prop.Name.CompareTo("ActiveFileSharePath") == 0) { aciveFileSharePath = prop.Value.ToString(); } if (prop.Name.CompareTo("OutputType") == 0) { projectOutputType = Convert.ToInt32(prop.Value); } if (prop.Name.CompareTo("OutputFileName") == 0) { projectOutputFileName = prop.Value.ToString(); } if (prop.Name.CompareTo("LocalPath") == 0) { projectOutputWorkingDirectory = prop.Value.ToString(); } } // Active Configuration Properties foreach (EnvDTE.Property prop in proj.ConfigurationManager.ActiveConfiguration.Properties) { // XSP startup page if (prop.Name.CompareTo("StartPage") == 0) { startPage = prop.Value.ToString(); } // Output path for non web projects if (prop.Name.CompareTo("OutputPath") == 0) { projectOutputPathFromBase = prop.Value.ToString(); } } // If is an Executable and not a DLL or web project // then launch it with monoLaunchC if (isWebProject == false && (projectOutputType == 0 || projectOutputType == 1)) { monoLauncC.StartInfo.FileName = launchHlpr.MonoLaunchCPath; monoLauncC.StartInfo.WorkingDirectory = System.IO.Path.Combine( projectOutputWorkingDirectory, projectOutputPathFromBase); monoLauncC.StartInfo.Arguments = projectOutputFileName; monoLauncC.Start(); return(true); } // Web Project execution and launching of XSP if (isWebProject == true) { string startURL = String.Format( "http://localhost:{0}/{1}", portForXsp, startPage); System.Diagnostics.ProcessStartInfo procInfo1 = new ProcessStartInfo(); System.Diagnostics.Process launchStartPage = new System.Diagnostics.Process(); launchStartPage.StartInfo = procInfo1; monoLauncC.StartInfo.FileName = launchHlpr.MonoLaunchCPath; monoLauncC.StartInfo.WorkingDirectory = aciveFileSharePath; monoLauncC.StartInfo.Arguments = String.Format( "{0} --root . --port {1} --applications /:.", launchHlpr.GetXspExePath(regH.XspExeSelection), portForXsp ); // Actually start XSP monoLauncC.Start(); launchStartPage.StartInfo.UseShellExecute = true; launchStartPage.StartInfo.Verb = "open"; launchStartPage.StartInfo.FileName = startURL; // Do a little delay so XSP can launch System.Threading.Thread.Sleep(1500); launchStartPage.Start(); } } } /* * string strSLNFile = applicationObject.Solution.FileName; * * applicationObject.StatusBar.Clear(); * outputWindowPane.OutputString("--------------------------------------\nCompile and Run in Mono: "); * outputWindowPane.OutputString(String.Format("Solution: {0}\n", strSLNFile)); * * applicationObject.StatusBar.Text = "Attemp to build in Mono..."; * outputWindowPane.OutputString("\tAttemp to build in Mono...\n"); * * // Build for Mono * * applicationObject.StatusBar.Text = "Launch in Mono..."; * outputWindowPane.OutputString("\tLaunch in Mono...\n"); * * // Lanunch in Mono */ return(true); }