public APINode Search(string text) { if (Name.ToLower().Trim().Contains(text)) { return(this); } foreach (APINode nd in Children) { APINode n = nd.Search(text); if (n != null) { return(n); } } return(null); }
public APIDocumentation() { if (root_ == null) { string dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); dir = System.IO.Path.Combine(System.IO.Path.Combine(dir, "bin"), "ScriptAPI.dox"); if (!System.IO.File.Exists(dir)) { //\todo, do something about the case where it doesn't exist? invoke the script API } string[] lines = File.ReadAllLines(dir); APINode current = new APINode { Name = "Root" }; APINode lastPage = null; APINode lastSection = null; APINode lastSubsection = null; foreach (string line in lines) { if (line.StartsWith("\\page")) { string[] words = line.Split(' '); APINode nd = new APINode { Name = string.Join(" ", words, 2, words.Length - 2) }; current.Children.Add(nd); nd.Parent = current; lastPage = nd; lastSection = null; lastSubsection = null; } else if (line.StartsWith("\\section")) { string[] words = line.Split(' '); APINode nd = new APINode { Name = string.Join(" ", words, 2, words.Length - 2) }; if (lastSection != null) { lastSection.Children.Add(nd); nd.Parent = lastSection; } else { lastPage.Children.Add(nd); nd.Parent = lastPage; } lastSubsection = nd; } else if (line.StartsWith("## ")) { APINode nd = new APINode { Name = line.Replace("## ", "").Replace("%", "") }; lastSection = nd; lastPage.Children.Add(nd); nd.Parent = lastPage; } else if (line.StartsWith("### ")) { APINode nd = new APINode { Name = line.Replace("### ", "").Replace("%", "") }; if (lastSection == null) { lastPage.Children.Add(nd); nd.Parent = lastPage; } else { lastSection.Children.Add(nd); nd.Parent = lastSection; } lastSubsection = nd; } else if (line.StartsWith("- ")) { APILeaf leaf = new APILeaf { Name = line.Replace("- ", "").Replace("%", "") }; if (leaf.Name.Contains(":")) { leaf.TypeAnnote = leaf.Name.Substring(leaf.Name.IndexOf(':') + 2); } lastSubsection.Children.Add(leaf); leaf.Parent = lastSubsection; } } //current.Prune(); DocumentNode = current; } }
private void tree_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e) { TreeViewItem treeViewItem = VisualUpwardSearch(e.OriginalSource as DependencyObject); if (treeViewItem != null) { treeViewItem.Focus(); //e.Handled = true; API.APINode nd = treeViewItem.DataContext as API.APINode; if (nd.ParentCount >= 3 && CommandText != null && CommandText.Length > 0) { ContextMenu cmenu = new ContextMenu(); TextBlock os = e.OriginalSource as TextBlock; string[] CmdText = null; string[] FmtText = null; if (nd.ParentCount == 3) { CmdText = CommandText; FmtText = CommandFormats; } else if (nd.ParentCount == 4) { CmdText = LowerText; FmtText = LowerCommands; } if (CmdText != null && FmtText != null) { for (int i = 0; i < CmdText.Length; ++i) { int idx = i; cmenu.Items.Add(new MenuItem { Header = CmdText[idx], Command = new RelayCommand(p => { string txt = FmtText[idx]; if (os.Text.Contains(":")) { string annote = os.Text.Substring(os.Text.IndexOf(':') + 2); if (annote.Contains("pointer")) //pointers are a special case { System.Windows.Clipboard.SetText(string.Format(txt, os.Text.Substring(0, os.Text.IndexOf(":")).Trim(), RemapAnnotes["pointer"])); } else if (RemapAnnotes.ContainsKey(annote)) { System.Windows.Clipboard.SetText(string.Format(txt, os.Text.Substring(0, os.Text.IndexOf(":")).Trim(), RemapAnnotes[annote])); } else { System.Windows.Clipboard.SetText(string.Format(txt, os.Text.Substring(0, os.Text.IndexOf(":")).Trim(), "")); } } else { System.Windows.Clipboard.SetText(string.Format(txt, os.Text.Trim())); } }) }); } treeViewItem.ContextMenu = cmenu; } } } }