ToolTips.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. using FastColoredTextBoxNS;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. namespace MPE
  5. {
  6. static class ToolTips
  7. {
  8. static Dictionary<string, int> break_points = new Dictionary<string, int>();
  9. static Dictionary<string, int> go_to_break_points = new Dictionary<string, int>();
  10. static Dictionary<string, List<int>> lines_of_go_to_break_points = new Dictionary<string, List<int>>();
  11. public static void getToolTip(ref object sender, ref ToolTipNeededEventArgs e)
  12. {
  13. Range range = DataHelper.field.GetLine(e.Place.iLine);
  14. Regex rgx = new Regex(@"\$?[a-zA-Z_]*" + e.HoveredWord + @"[a-zA-Z_\d]*");
  15. Match mc = rgx.Match(range.Text);
  16. string hoveredWord = "";
  17. if (mc.Success) hoveredWord = mc.Value;
  18. string bp = range.GetFragment("[^\n]").Text;
  19. Match mch = DataHelper.GO_TO_BREAK_POINT.Match(bp), mch1 = DataHelper.BREAK_POINT.Match(bp);
  20. if (mch.Success || mch1.Success)
  21. {
  22. break_points.Clear(); lines_of_go_to_break_points.Clear(); go_to_break_points.Clear();
  23. get_all_bp(ref sender);
  24. }
  25. bool nextTip = false;
  26. if (mch.Success)
  27. {// Навели на параметр функции GO_TO_BREAK_POINT => возвращаем номер строки где объявлена точка возврата
  28. string str = bp.Remove(0, mch.Value.Length);
  29. string[] split = str.Split(new char[] { ']' });
  30. if (split.Length > 0)
  31. {
  32. if (split.Length == 1)
  33. {
  34. if (break_points.TryGetValue(split[0].Remove(0, 1), out int line))
  35. e.ToolTipText = $"Метка возврата обьявлена на {line + 1} строке";
  36. else e.ToolTipText = "Не удалось найти обьявление этой метки возврата";
  37. }
  38. else if (split.Length == 2)
  39. {
  40. if (break_points.TryGetValue(hoveredWord, out int line))
  41. e.ToolTipText = $"Метка возврата обьявлена на {line + 1} строке";
  42. nextTip = true;
  43. }
  44. }
  45. if (!nextTip) return;
  46. }
  47. else
  48. {
  49. if (mch1.Success && !(e.HoveredWord.Contains("BREAK") || e.HoveredWord.Contains("POINT")))
  50. {
  51. string str = bp.Remove(0, mch1.Length).Remove(0, 1);
  52. str = str.Split(new char[] { ']' })[0];
  53. if (lines_of_go_to_break_points.TryGetValue(str, out List<int> lines))
  54. {
  55. string output = "";
  56. for (int i = 0; i < lines.Count; i++) output += $"\n {lines[i]}";
  57. e.ToolTipText = $"Метка имеет {lines.Count} вызова на строках {output}";
  58. }
  59. else e.ToolTipText = "Метка не имеет вызовов";
  60. return;
  61. }
  62. }
  63. if (e.HoveredWord.Length == 0) return;
  64. Match match = Regex.Match(hoveredWord, @"(\[*[A-Z]*.*\]*)+");//Очистка от мусора
  65. Match indent = DataHelper.currentIndent_rgx.Match(match.Value);
  66. string clearedHoveredWord = match.Value;
  67. if (indent.Value.Length > 0) clearedHoveredWord = match.Value.Remove(0, indent.Value.Length);//Удаляем лишнии отступы в начале
  68. if (match.Success)
  69. {
  70. string[] split = clearedHoveredWord.Split(new string[] { "]" }, System.StringSplitOptions.None);
  71. clearedHoveredWord = split.Length > 1 ? split[0] + "]" : split[0];
  72. }
  73. if (clearedHoveredWord.Contains(e.HoveredWord))
  74. {
  75. toolTipsValues.TryGetValue(clearedHoveredWord.Replace(" ", ""), out string tooltip);
  76. if (tooltip != null && tooltip.Length > 0)
  77. { e.ToolTipTitle = clearedHoveredWord; e.ToolTipText = tooltip; }
  78. else
  79. {
  80. toolTipsValues.TryGetValue("[" + clearedHoveredWord.Replace(" ", "") + "]", out tooltip);
  81. if (tooltip != null && tooltip.Length > 0)
  82. { e.ToolTipTitle = clearedHoveredWord; e.ToolTipText = tooltip; }
  83. }
  84. }
  85. }
  86. public static string getToolTipForItem(string item)
  87. {
  88. toolTipsValues.TryGetValue(item, out string tooltip);
  89. return tooltip != null && tooltip.Length > 0 ? tooltip : "";
  90. }
  91. static void get_all_bp(ref object field)
  92. {
  93. FastColoredTextBox range = (field as FastColoredTextBox);
  94. for (int i = 0; i < range.LinesCount; i++)
  95. {
  96. Range line = range.GetLine(i);
  97. Match mch = DataHelper.BREAK_POINT.Match(line.Text);
  98. if (mch.Success)
  99. {
  100. string str = line.Text.Remove(0, mch.Length);
  101. DataHelper.getClearedString(ref str);
  102. if (str.Contains("]")) str = str.Remove(str.Length - 1, 1);
  103. if (str.Contains("[")) str = str.Remove(0, 1);
  104. try { break_points.Add(str, line.ToLine); } catch { }
  105. }
  106. else
  107. {
  108. mch = DataHelper.GO_TO_BREAK_POINT.Match(line.Text);
  109. if (mch.Success)
  110. {
  111. string str = line.Text.Remove(0, mch.Length).Remove(0, 1);
  112. str = str.Split(new char[] { ']' })[0];
  113. if (go_to_break_points.TryGetValue(str, out int value))
  114. { go_to_break_points.Remove(str); go_to_break_points.Add(str, value + 1); }
  115. else go_to_break_points.Add(str, value + 1);
  116. if (lines_of_go_to_break_points.TryGetValue(str, out List<int> li))
  117. { li.Add(line.ToLine + 1); lines_of_go_to_break_points[str] = li; }
  118. else lines_of_go_to_break_points.Add(str, new List<int> { line.ToLine + 1 });
  119. }
  120. }
  121. }
  122. }
  123. static Dictionary<string, string> toolTipsValues;
  124. }
  125. }