void UpdateArguments() { Document doc = App().ActiveDocument; //whats the xml file's path? string xmlpath = ""; bool available = UpdateXml(ref xmlpath); if (!available) { Arguments.Clear(); return; } TextDocument text = (TextDocument)doc.Object(""); VirtualPoint currentpoint = text.Selection.ActivePoint; EditPoint point = currentpoint.CreateEditPoint(); point.EndOfLine(); EditPoint endfound = null; TextRanges found = null; Arguments.Clear(); bool result = point.FindPattern("note[ \t]+{.*}\\({.*}\\)", (int)(vsFindOptions.vsFindOptionsBackwards | vsFindOptions.vsFindOptionsRegularExpression), ref endfound, ref found); if (result) { TextRange fullmatch = found.Item(1); TextRange pathmatch = found.Item(2); TextRange argmatch = found.Item(3); //only want it if the point was in the range if (fullmatch.EndPoint.LessThan(currentpoint) || fullmatch.StartPoint.GreaterThan(currentpoint)) { return; } ArgumentEnd = argmatch.EndPoint; string arguments = argmatch.StartPoint.GetText(argmatch.EndPoint).Trim(); NoteArguments = arguments.Split(','); string notepath = pathmatch.StartPoint.GetText(pathmatch.EndPoint).Trim(); XmlNoteNode note = XmlFile.GetNote(notepath); if (note != null) { Arguments = new List <string>(); foreach (XmlArgumentNode n in note.Arguments) { Arguments.Add(n.Name); } } } }
// Get a desired node. public XmlNoteNode GetNote(string path) { List <string> strings = new List <string>(path.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries)); int size = strings.Count; // Make sure the size is either 3 or 4. if (size != 3 && size != 4) { return(null); } // Grab the category/enumeration. XmlCategoryNode category = Root.Categories.Find(delegate(XmlCategoryNode x) { return(x.Name == strings[0]); }); XmlEnumerationNode enumeration = null; if (category == null) { enumeration = Root.Enumerations.Find(delegate(XmlEnumerationNode x) { return(x.Name == strings[0]); }); if (enumeration == null) { return(null); } } // Grab the location. XmlLocationNode location = null; if (category != null) { location = category.Locations.Find(delegate(XmlLocationNode x) { return(x.Name == strings[1]); }); } else { location = enumeration.Locations.Find(delegate(XmlLocationNode x) { return(x.Name == strings[1]); }); } if (location == null) { return(null); } // If we have 3 strings, it's a note. Otherwise it's a map. if (strings.Count == 3) { // Grab the note. XmlNoteNode note = location.Notes.Find(delegate(XmlNoteNode x) { return(x.Name == strings[2]); }); return(note); } else { // Grab the map. XmlMapNode map = location.Maps.Find(delegate(XmlMapNode x) { return(x.Name == strings[2]); }); if (map == null) { return(null); } // Grab the note. XmlNoteNode note = map.Notes.Find(delegate(XmlNoteNode x) { return(x.Name == strings[3]); }); return(note); } }