Horizon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 using System.Collections.Specialized;
2 using System.Threading;
3 using System.Windows.Forms;
4 using Horizon.Utilities;
5  
6 namespace Horizon
7 {
8 public partial class LogViewForm : Form
9 {
10 private readonly CancellationToken _cancellationToken;
11  
12 private readonly MainForm _mainForm;
13  
14 private readonly LogMemorySink _memorySink;
15  
16 public LogViewForm()
17 {
18 InitializeComponent();
19 Utilities.WindowState.FormTracker.Track(this);
20 }
21  
22 public LogViewForm(MainForm mainForm) : this()
23 {
24 _mainForm = mainForm;
25 _mainForm.MemorySinkEnabled = true;
26 }
27  
28 public LogViewForm(MainForm mainForm, LogMemorySink memorySink, CancellationToken cancellationToken) :
29 this(mainForm)
30 {
31 _memorySink = memorySink;
32 _memorySink.Events.CollectionChanged += Events_CollectionChanged;
33  
34 _cancellationToken = cancellationToken;
35 }
36  
37 /// <summary>
38 /// Clean up any resources being used.
39 /// </summary>
40 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
41 protected override void Dispose(bool disposing)
42 {
43 if (disposing && components != null)
44 {
45 components.Dispose();
46 }
47  
48 _memorySink.Events.CollectionChanged -= Events_CollectionChanged;
49  
50 _mainForm.MemorySinkEnabled = false;
51 _memorySink.Clear();
52  
53 base.Dispose(disposing);
54 }
55  
56 private void Events_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
57 {
58 switch (e.Action)
59 {
60 case NotifyCollectionChangedAction.Add:
61 foreach (var item in e.NewItems)
62 {
63 var line = (string)item;
64  
65 textBox1.InvokeIfRequired(textbox => { textbox.AppendText(line); });
66 }
67  
68 break;
69 }
70 }
71 }
72 }