Winify – Blame information for rev 43
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
43 | office | 1 | using System.Collections.Specialized; |
2 | using System.Threading; |
||
3 | using System.Windows.Forms; |
||
4 | using Winify; |
||
5 | using Winify.Utilities; |
||
6 | |||
7 | namespace Winify |
||
8 | { |
||
9 | public partial class LogViewForm : Form |
||
10 | { |
||
11 | private readonly CancellationToken _cancellationToken; |
||
12 | |||
13 | private readonly MainForm _mainForm; |
||
14 | |||
15 | private readonly LogMemorySink _memorySink; |
||
16 | |||
17 | public LogViewForm() |
||
18 | { |
||
19 | InitializeComponent(); |
||
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.Text += line; }); |
||
66 | } |
||
67 | |||
68 | break; |
||
69 | } |
||
70 | } |
||
71 | } |
||
72 | } |