Changeset 1526
- Timestamp:
- 1/14/2010 10:58:24 AM (3 years ago)
- File:
-
- 1 edited
-
branches/eraser6/CodeReview/Eraser/LogForm.cs (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/CodeReview/Eraser/LogForm.cs
r1450 r1526 27 27 using System.Text; 28 28 using System.Windows.Forms; 29 using System.Globalization; 30 using System.IO; 29 31 30 32 using Eraser.Manager; 31 using System.Globalization;32 33 using Eraser.Util; 33 using System.IO;34 34 35 35 namespace Eraser … … 56 56 57 57 //Display the log entries 58 this.task = task;58 Task = task; 59 59 RefreshMessages(); 60 60 EnableButtons(); 61 61 62 62 //Register our event handler to get live log messages 63 task.Log.Logged += task_Logged;64 task.Log.NewSession += task_NewSession;63 Task.Log.Logged += task_Logged; 64 Task.Log.NewSession += task_NewSession; 65 65 } 66 66 67 67 private void LogForm_FormClosed(object sender, FormClosedEventArgs e) 68 68 { 69 task.Log.Logged -= task_Logged; 69 Task.Log.NewSession -= task_NewSession; 70 Task.Log.Logged -= task_Logged; 70 71 } 71 72 … … 83 84 } 84 85 85 filterSessionCombobox.Items.Add( task.Log.LastSession);86 filterSessionCombobox.Items.Add(Task.Log.LastSession); 86 87 } 87 88 … … 98 99 //display this entry when the session in question is the last one. 99 100 if (filterSessionCombobox.SelectedItem == null || 100 (DateTime)filterSessionCombobox.SelectedItem != task.Log.LastSession ||101 (DateTime)filterSessionCombobox.SelectedItem != Task.Log.LastSession || 101 102 !MeetsCriteria(e.LogEntry)) 102 103 { … … 105 106 106 107 //Add it to the cache and increase our virtual list size. 107 entryCache.Add(e.LogEntry);108 EntryCache.Add(e.LogEntry); 108 109 ++log.VirtualListSize; 109 110 … … 114 115 private void log_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e) 115 116 { 116 LogEntry entry = entryCache[e.ItemIndex];117 LogEntry entry = EntryCache[e.ItemIndex]; 117 118 e.Item = new ListViewItem(entry.Timestamp.ToString("F", CultureInfo.CurrentCulture)); 118 119 e.Item.SubItems.Add(entry.Level.ToString()); … … 137 138 if (e.IsSelected) 138 139 { 139 if (!selectedEntries.ContainsKey(e.ItemIndex)) 140 selectedEntries.Add(e.ItemIndex, null); 140 SelectedEntries.Add(e.ItemIndex, EntryCache[e.ItemIndex]); 141 141 } 142 142 else 143 143 { 144 selectedEntries.Remove(e.ItemIndex);144 SelectedEntries.Remove(e.ItemIndex); 145 145 } 146 146 } … … 152 152 if (e.IsSelected) 153 153 { 154 if (!selectedEntries.ContainsKey(i)) 155 selectedEntries.Add(i, null); 154 SelectedEntries.Add(i, EntryCache[i]); 156 155 } 157 156 else 158 157 { 159 selectedEntries.Remove(i);158 SelectedEntries.Remove(i); 160 159 } 161 160 } … … 164 163 private void log_ItemActivate(object sender, EventArgs e) 165 164 { 166 if (selectedEntries.Count < 1) 167 return; 168 169 int currentEntryIndex = 0; 170 LogEntry selectedEntry = new LogEntry(); 171 foreach (LogEntry entry in task.Log.Entries[(DateTime)filterSessionCombobox.SelectedItem]) 172 { 173 //Only copy entries which meet the display criteria and that they are selected 174 if (!MeetsCriteria(entry)) 175 continue; 176 if (!selectedEntries.ContainsKey(currentEntryIndex++)) 177 continue; 178 179 selectedEntry = entry; 180 break; 181 } 182 183 //Decide on the icon 165 if (SelectedEntries.Count < 1) 166 return; 167 168 //Get the selected entry from the entry cache. 169 LogEntry selectedEntry = SelectedEntries.Values[0]; 170 171 //Decide on the icon. 184 172 MessageBoxIcon icon = MessageBoxIcon.None; 185 173 switch (selectedEntry.Level) … … 205 193 private void logContextMenuStrip_Opening(object sender, CancelEventArgs e) 206 194 { 207 copySelectedEntriesToolStripMenuItem.Enabled = selectedEntries.Count != 0;195 copySelectedEntriesToolStripMenuItem.Enabled = SelectedEntries.Count != 0; 208 196 } 209 197 … … 211 199 { 212 200 //Ensure we've got stuff to copy. 213 if ( selectedEntries.Count == 0)201 if (SelectedEntries.Count == 0) 214 202 return; 215 203 216 204 StringBuilder csvText = new StringBuilder(); 217 205 StringBuilder rawText = new StringBuilder(); 218 LogSessionDictionary logEntries = task.Log.Entries;206 LogSessionDictionary logEntries = Task.Log.Entries; 219 207 220 208 DateTime sessionTime = (DateTime)filterSessionCombobox.SelectedItem; … … 222 210 rawText.AppendLine(S._("Session: {0:F}", sessionTime)); 223 211 224 int currentEntryIndex = 0; 225 foreach (LogEntry entry in logEntries[sessionTime]) 226 { 227 //Only copy entries which meet the display criteria and that they are selected 228 if (!MeetsCriteria(entry)) 229 continue; 230 if (!selectedEntries.ContainsKey(currentEntryIndex++)) 231 continue; 232 212 foreach (LogEntry entry in SelectedEntries.Values) 213 { 214 //Append the entry's contents to our buffer. 233 215 string timeStamp = entry.Timestamp.ToString("F", CultureInfo.CurrentCulture); 234 216 string message = entry.Message; … … 259 241 { 260 242 //Clear the backing store 261 task.Log.Clear();243 Task.Log.Clear(); 262 244 263 245 //Reset the list of sessions … … 266 248 //And reset the list-view control 267 249 log.VirtualListSize = 0; 268 selectedEntries.Clear();269 entryCache.Clear();250 SelectedEntries.Clear(); 251 EntryCache.Clear(); 270 252 271 253 //Finally update the UI state. … … 314 296 { 315 297 //Check if we have a task 316 if ( task == null)298 if (Task == null) 317 299 return; 318 300 319 301 Application.UseWaitCursor = true; 320 LogSessionDictionary log = task.Log.Entries;321 entryCache.Clear();322 selectedEntries.Clear();302 LogSessionDictionary log = Task.Log.Entries; 303 EntryCache.Clear(); 304 SelectedEntries.Clear(); 323 305 324 306 //Iterate over every key … … 334 316 //Check if the entry meets the criteria for viewing 335 317 if (MeetsCriteria(entry)) 336 entryCache.Add(entry);318 EntryCache.Add(entry); 337 319 } 338 320 } 339 321 340 322 //Set the list view size and update all the control states 341 this.log.VirtualListSize = entryCache.Count;323 this.log.VirtualListSize = EntryCache.Count; 342 324 this.log.Refresh(); 343 325 EnableButtons(); … … 350 332 private void EnableButtons() 351 333 { 352 clear.Enabled = task.Log.Entries.Count > 0;334 clear.Enabled = Task.Log.Entries.Count > 0; 353 335 } 354 336 … … 356 338 /// The task which this log is displaying entries for 357 339 /// </summary> 358 private Task task;340 private Task Task; 359 341 360 342 /// <summary> 361 343 /// Stores all log entries fulfilling the current criteria for rapid access. 362 344 /// </summary> 363 private List<LogEntry> entryCache = new List<LogEntry>(); 364 365 /// <summary> 366 /// Stores all currently selected list view entry indices. 367 /// </summary> 368 private SortedList<int, object> selectedEntries = new SortedList<int, object>(); 345 private List<LogEntry> EntryCache = new List<LogEntry>(); 346 347 /// <summary> 348 /// Stores all currently selected list view entry indices. The key is the 349 /// index which is selected. 350 /// </summary> 351 private SortedList<int, LogEntry> SelectedEntries = new SortedList<int, LogEntry>(); 369 352 } 370 353 }
Note: See TracChangeset
for help on using the changeset viewer.
