Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. public ICommand FindAllToolsCommand
  2. => _findAllToolsCommand ?? (_findAllToolsCommand = new RelayCommand<object>(() =>
  3. {
  4. Regex toolSearchRegex = new Regex(ToolRegex);
  5. Regex commentRegex = new Regex(CommentRegex);
  6. string firstComment = "";
  7. string secondComment = "";
  8. string thirdComment = "";
  9. ProgramToolList.Clear();
  10. foreach (Match match in toolSearchRegex.Matches(CurrentEditor.Text))
  11. {
  12. var line = CurrentEditor.Document.GetLineByOffset(match.Index);
  13. if (CheckForComments(line,match.Index))
  14. {
  15. continue;
  16. }
  17. secondComment = SearchInLine(GetLineText(line.Offset), commentRegex);
  18. if (line.PreviousLine != null)
  19. {
  20. firstComment = SearchInLine(GetLineText(line.PreviousLine.Offset), commentRegex);
  21. }
  22. if (line.NextLine != null)
  23. {
  24. thirdComment = SearchInLine(GetLineText(line.NextLine.Offset), commentRegex);
  25. }
  26. ProgramToolList.Add(new ToolLine(match.Index, match.Value, string.Concat(firstComment,secondComment,thirdComment)));
  27. }
  28. }));
  29.  
  30. private bool CheckForComments(DocumentLine line, int toolOffset)
  31. {
  32. var lineText = GetLineText(toolOffset);
  33. var leftBracketIndex = lineText.IndexOf("(");
  34. if (leftBracketIndex<0)
  35. {
  36. return false;
  37. }
  38. if (leftBracketIndex + line.Offset < toolOffset)
  39. {
  40. if (lineText.IndexOf(")") + line.Offset > toolOffset)
  41. {
  42. return true;
  43. }
  44. }
  45. return false;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement