Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. using System;
  2. using System.ComponentModel;
  3. using System.Linq;
  4. using System.Windows.Forms;
  5. using Microsoft.Vbe.Interop;
  6. using System.Collections.Generic;
  7.  
  8. namespace Rubberduck.ToDoItems
  9. {
  10. public partial class ToDoItemsControl : UserControl
  11. {
  12. private VBE vbe;
  13. private BindingList<ToDoItem> taskList;
  14. private List<Config.ToDoMarker> markers;
  15.  
  16. public ToDoItemsControl(VBE vbe, List<Config.ToDoMarker> markers)
  17. {
  18. this.vbe = vbe;
  19. this.markers = markers;
  20.  
  21. InitializeComponent();
  22.  
  23. RefreshTaskList();
  24. InitializeGrid();
  25.  
  26. }
  27.  
  28. private void InitializeGrid()
  29. {
  30. todoItemsGridView.DataSource = taskList;
  31. var descriptionColumn = todoItemsGridView.Columns["Description"];
  32. if (descriptionColumn != null)
  33. {
  34. descriptionColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
  35. }
  36.  
  37. todoItemsGridView.CellDoubleClick += taskListGridView_CellDoubleClick;
  38. refreshButton.Click += refreshButton_Click;
  39.  
  40. }
  41.  
  42. void taskListGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
  43. {
  44. ToDoItem task = taskList.ElementAt(e.RowIndex);
  45. VBComponent component = vbe.ActiveVBProject.VBComponents.Item(task.Module);
  46.  
  47. component.CodeModule.CodePane.Show();
  48. component.CodeModule.CodePane.SetSelection(task.LineNumber, 1, task.LineNumber, 1);
  49. }
  50.  
  51. private void RefreshGridView()
  52. {
  53. RefreshTaskList();
  54. todoItemsGridView.DataSource = taskList;
  55. todoItemsGridView.Refresh();
  56. }
  57.  
  58. public void RefreshTaskList()
  59. {
  60. this.taskList = new BindingList<ToDoItem>();
  61.  
  62. foreach (VBComponent component in this.vbe.ActiveVBProject.VBComponents)
  63. {
  64. CodeModule module = component.CodeModule;
  65. for (var i = 1; i <= module.CountOfLines; i++)
  66. {
  67. string line = module.get_Lines(i, 1);
  68. Config.ToDoMarker marker;
  69.  
  70. if (TryGetMarker(line, out marker))
  71. {
  72. var priority = (TaskPriority)marker.priority;
  73. this.taskList.Add(new ToDoItem(priority, line, module, i));
  74. }
  75. }
  76. }
  77. }
  78.  
  79. private bool TryGetMarker(string line, out Config.ToDoMarker result)
  80. {
  81. var upCasedLine = line.ToUpper();
  82. foreach (var marker in this.markers)
  83. {
  84. if (upCasedLine.Contains(marker.text))
  85. {
  86. result = marker;
  87. return true;
  88. }
  89. }
  90. result = null;
  91. return false;
  92. }
  93.  
  94. private void refreshButton_Click(object sender, EventArgs e)
  95. {
  96. RefreshGridView();
  97. }
  98. }
  99. }
  100.  
  101. using Microsoft.Vbe.Interop;
  102.  
  103. namespace Rubberduck.ToDoItems
  104. {
  105. internal enum TaskPriority
  106. {
  107. Low,
  108. Medium,
  109. High
  110. }
  111.  
  112. internal class ToDoItem
  113. {
  114. public TaskPriority Priority{ get; set; }
  115. public string Description { get; set; }
  116. public string Module { get; set; }
  117. public int LineNumber { get; set; }
  118.  
  119. public ToDoItem(TaskPriority priority, string description, CodeModule module, int lineNumber)
  120. {
  121. this.Priority = priority;
  122. this.Description = description.Trim();
  123. this.Module = module.Parent.Name;
  124. this.LineNumber = lineNumber;
  125. }
  126. }
  127. }
  128.  
  129. using System.Xml.Serialization;
  130.  
  131. namespace Rubberduck.Config
  132. {
  133. [System.Runtime.InteropServices.ComVisible(false)]
  134. [XmlTypeAttribute(AnonymousType = true)]
  135. public class ToDoListSettings
  136. {
  137.  
  138. [XmlArrayItemAttribute("ToDoMarker", IsNullable = false)]
  139. public ToDoMarker[] ToDoMarkers { get; set; }
  140. }
  141.  
  142. [System.Runtime.InteropServices.ComVisible(false)]
  143. [XmlTypeAttribute(AnonymousType = true)]
  144. public class ToDoMarker
  145. {
  146. [XmlAttributeAttribute()]
  147. public string text { get; set; }
  148.  
  149. [XmlAttributeAttribute()]
  150. public byte priority { get; set; }
  151.  
  152. public ToDoMarker() { }
  153.  
  154. public ToDoMarker(string text, byte priority)
  155. {
  156. this.text = text;
  157. this.priority = priority;
  158. }
  159. }
  160. }
  161.  
  162. var priority = (TaskPriority)marker.priority;
  163.  
  164. upCasedLine.Contains(marker.text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement