/// <summary> /// Recursive enumeration of all solution items. /// </summary> private static bool InternalEnumeration(ProjectItem item, IList <CodeNamespace> codeNamespaces, IList <CodeClass> codeClasses, IList <CodeStruct> codeStructs, IList <CodeFunction> codeFunctions, IClassFinder classFinder, IStructFinder structFinder, IFunctionFinder functionFinder) { IList <CodeNamespace> interNamespaces; IList <CodeClass> interClasses; IList <CodeStruct> interStructs; IList <CodeFunction> internalFunctions; CodeElements elements; // enumerate through all namespaces: if (codeNamespaces != null) { foreach (CodeNamespace n in codeNamespaces) { elements = n.Members; interNamespaces = EditorHelper.GetList <CodeNamespace>(elements, vsCMElement.vsCMElementNamespace); interClasses = classFinder != null?EditorHelper.GetList <CodeClass>(elements, vsCMElement.vsCMElementClass) : null; interStructs = structFinder != null?EditorHelper.GetList <CodeStruct>(elements, vsCMElement.vsCMElementStruct) : null; internalFunctions = EditorHelper.GetList <CodeFunction>(elements, vsCMElement.vsCMElementFunction); if (InternalEnumeration(item, interNamespaces, interClasses, interStructs, internalFunctions, classFinder, structFinder, functionFinder)) { return(true); } } } // enumerate classes: if (codeClasses != null && classFinder != null) { foreach (CodeClass c in codeClasses) { if (classFinder.MatchCriteria(c)) { Window w = item.Open(Constants.vsViewKindTextView); TextSelection sel = w.Selection as TextSelection; classFinder.Activate(item, c, w, sel); return(true); } interClasses = EditorHelper.GetList <CodeClass>(c.Members, vsCMElement.vsCMElementClass); if (codeStructs != null) { interStructs = EditorHelper.GetList <CodeStruct>(c.Members, vsCMElement.vsCMElementStruct); } else { interStructs = null; } if (InternalEnumeration(item, null, interClasses, interStructs, null, classFinder, structFinder, null)) { return(true); } } } // enumerate structures: if (codeStructs != null && structFinder != null) { foreach (CodeStruct s in codeStructs) { if (structFinder.MatchCriteria(s)) { Window w = item.Open(Constants.vsViewKindTextView); TextSelection sel = w.Selection as TextSelection; structFinder.Activate(item, s, w, sel); return(true); } if (classFinder != null) { interClasses = EditorHelper.GetList <CodeClass>(s.Members, vsCMElement.vsCMElementClass); } else { interClasses = null; } interStructs = EditorHelper.GetList <CodeStruct>(s.Members, vsCMElement.vsCMElementStruct); if (InternalEnumeration(item, null, interClasses, interStructs, null, classFinder, structFinder, null)) { return(true); } } } // enumerate all global functions: if (codeFunctions != null && functionFinder != null) { foreach (CodeFunction f in codeFunctions) { if (functionFinder.MatchCriteria(f)) { Window w = item.Open(Constants.vsViewKindTextView); TextSelection sel = w.Selection as TextSelection; functionFinder.Activate(item, f, w, sel); return(true); } } } return(false); }
private static bool ValidateItem(ProjectItem item, IClassFinder classFinder, IStructFinder structFinder, IFunctionFinder functionFinder) { IList <CodeNamespace> codeNamespaces; IList <CodeClass> codeClasses; IList <CodeStruct> codeStructs; IList <CodeFunction> codeFunctions; FileCodeModel fcm = item.FileCodeModel; CodeElements elements = null; if (fcm != null) { elements = fcm.CodeElements; } codeNamespaces = fcm != null?EditorHelper.GetList <CodeNamespace>(elements, vsCMElement.vsCMElementNamespace) : null; codeClasses = classFinder != null && fcm != null ? EditorHelper.GetList <CodeClass>(elements, vsCMElement.vsCMElementClass) : null; codeStructs = structFinder != null && fcm != null ? EditorHelper.GetList <CodeStruct>(elements, vsCMElement.vsCMElementStruct) : null; codeFunctions = (classFinder != null || structFinder != null) && fcm != null ? EditorHelper.GetList <CodeFunction>(elements, vsCMElement.vsCMElementFunction) : null; return(InternalEnumeration(item, codeNamespaces, codeClasses, codeStructs, codeFunctions, classFinder, structFinder, functionFinder)); }
private static bool InternalEnumeration(ProjectItem item, IClassFinder classFinder, IStructFinder structFinder, IFunctionFinder functionFinder) { ProjectItems subItems; if (item != null) { if (ValidateItem(item, classFinder, structFinder, functionFinder)) { return(true); } subItems = item.ProjectItems; if (subItems != null && subItems.Count > 0) { foreach (ProjectItem x in subItems) { if (ValidateItem(x, classFinder, structFinder, functionFinder)) { return(true); } } } } return(false); }
/// <summary> /// Open code editor window and set the cursor at the start of particular class or structure. /// Returns 'true' if editor opened, otherwise 'false'. /// </summary> public static bool Activate(IList <Project> projects, IClassFinder classFinder, IStructFinder structFinder, IFunctionFinder functionFinder) { // nothing to do: if ((classFinder == null && structFinder == null) || projects == null || projects.Count == 0) { return(false); } foreach (Project prj in projects) { ProjectItems pi = prj.ProjectItems; for (int i = 1; i < pi.Count; i++) { ProjectItem f = pi.Item(i); if (InternalEnumeration(f, classFinder, structFinder, functionFinder)) { return(true); } } } return(false); }