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