Winify
/trunk/Winify/LogViewForm.cs |
@@ -0,0 +1,72 @@ |
using System.Collections.Specialized; |
using System.Threading; |
using System.Windows.Forms; |
using Winify; |
using Winify.Utilities; |
|
namespace Winify |
{ |
public partial class LogViewForm : Form |
{ |
private readonly CancellationToken _cancellationToken; |
|
private readonly MainForm _mainForm; |
|
private readonly LogMemorySink _memorySink; |
|
public LogViewForm() |
{ |
InitializeComponent(); |
} |
|
public LogViewForm(MainForm mainForm) : this() |
{ |
_mainForm = mainForm; |
_mainForm.MemorySinkEnabled = true; |
} |
|
public LogViewForm(MainForm mainForm, LogMemorySink memorySink, CancellationToken cancellationToken) : |
this(mainForm) |
{ |
_memorySink = memorySink; |
_memorySink.Events.CollectionChanged += Events_CollectionChanged; |
|
_cancellationToken = cancellationToken; |
} |
|
/// <summary> |
/// Clean up any resources being used. |
/// </summary> |
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> |
protected override void Dispose(bool disposing) |
{ |
if (disposing && components != null) |
{ |
components.Dispose(); |
} |
|
_memorySink.Events.CollectionChanged -= Events_CollectionChanged; |
|
_mainForm.MemorySinkEnabled = false; |
_memorySink.Clear(); |
|
base.Dispose(disposing); |
} |
|
private void Events_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) |
{ |
switch (e.Action) |
{ |
case NotifyCollectionChangedAction.Add: |
foreach (var item in e.NewItems) |
{ |
var line = (string)item; |
|
textBox1.InvokeIfRequired(textbox => { textbox.Text += line; }); |
} |
|
break; |
} |
} |
} |
} |