Skip to content
This repository has been archived by the owner on Dec 26, 2020. It is now read-only.

Commit

Permalink
Custom filters all done!
Browse files Browse the repository at this point in the history
  • Loading branch information
pipe01 committed Jan 7, 2017
1 parent 087f4d8 commit 0617bce
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 73 deletions.
2 changes: 1 addition & 1 deletion AB+ Log Viewer/CustomFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class CustomFilter
public string Regex;
public string Name = "Change me";
public Color ForeColor, BackColor;
public bool ForeEnable, BackEnable, Visible;
public bool ForeEnable, BackEnable, Visible, Enabled;
}
}
136 changes: 77 additions & 59 deletions AB+ Log Viewer/frmCustomFilters.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 49 additions & 7 deletions AB+ Log Viewer/frmCustomFilters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public frmCustomFilters()
InitializeComponent();
}

private CustomFilter Selected
{
get
{
return Config.Inst.CustomFilters[lbFilters.SelectedIndex];
}
}

public void LoadFilters()
{
lbFilters.Items.Clear();
Expand All @@ -28,7 +36,7 @@ public void LoadFilters()

public void LoadSelected()
{
var sel = Config.Inst.CustomFilters[lbFilters.SelectedIndex];
var sel = Selected;

txtRegex.Text = sel.Regex;

Expand Down Expand Up @@ -77,30 +85,64 @@ private void lbFilters_SelectedIndexChanged(object sender, EventArgs e)
{
if (lbFilters.SelectedItems.Count == 1)
{
panel1.Enabled = false;
panel1.Enabled = true;
LoadSelected();

}
else
{
panel1.Enabled = true;
panel1.Enabled = false;
}
}

private void txtRegex_TextChanged(object sender, EventArgs e)
{
var sel = Config.Inst.CustomFilters[lbFilters.SelectedIndex];
sel.Regex = txtRegex.Text;
Selected.Regex = txtRegex.Text;
}

private void chkVisible_CheckedChanged(object sender, EventArgs e)
{
var sel = Config.Inst.CustomFilters[lbFilters.SelectedIndex];
sel.Visible = chkVisible.Checked;
Selected.Visible = chkVisible.Checked;
}

private void btnColor_Click(object sender, EventArgs e)
{
colorChooser.Color = btnColor.ForeColor;
if (colorChooser.ShowDialog() == DialogResult.OK)
{
Selected.ForeColor = colorChooser.Color;
btnColor.BackColor = colorChooser.Color;
}
}

private void btnBColor_Click(object sender, EventArgs e)
{
colorChooser.Color = btnColor.BackColor;
if (colorChooser.ShowDialog() == DialogResult.OK)
{
Selected.BackColor = colorChooser.Color;
btnBColor.BackColor = colorChooser.Color;
}
}

private void chkColor_CheckedChanged(object sender, EventArgs e)
{
Selected.ForeEnable = chkColor.Checked;
}

private void chkBColor_CheckedChanged(object sender, EventArgs e)
{
Selected.BackEnable = chkBColor.Checked;
}

private void chkEnabled_CheckedChanged(object sender, EventArgs e)
{
Selected.Enabled = chkEnabled.Checked;
}

private void frmCustomFilters_FormClosing(object sender, FormClosingEventArgs e)
{
frmMain.Instance.Reload();
}
}
}
4 changes: 2 additions & 2 deletions AB+ Log Viewer/frmMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 32 additions & 4 deletions AB+ Log Viewer/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

Expand All @@ -16,8 +17,11 @@ public partial class frmMain : Form
public frmMain()
{
InitializeComponent();
Instance = this; //Unsafe, dirty and whatever you want, but meh
}

public static frmMain Instance;

private string[] LastLines = new string[0];

private string LogPath
Expand Down Expand Up @@ -112,7 +116,6 @@ private void LoadChanges()
string[] lines = new string[0];
try
{
//string p = "C:/Users/pipe_/Documents/My Games/Binding of Isaac Afterbirth+/log.txt";
string p = Path.Combine(LogPath, "log.txt");
using (var stream = new FileStream(p, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
Expand Down Expand Up @@ -142,10 +145,30 @@ private void LoadChanges()
bool error = IsErrorLine(item);
bool debug = IsDebugLine(item);
bool info = IsInfoLine(item);
bool visible = ShouldSee(item);

itm.ForeColor = error ? Color.Red : debug ? Color.DarkOrange : Color.Black;

if (!((error && !chkError.Checked) || (debug && !chkDebug.Checked) || (info && !chkInfo.Checked)))
if (info)
{
foreach (var filter in Config.Inst.CustomFilters)
{
if (filter.Enabled && Regex.IsMatch(item, filter.Regex))
{
visible = filter.Visible;
if (filter.BackEnable)
{
itm.BackColor = filter.BackColor;
}
if (filter.ForeEnable)
{
itm.ForeColor = filter.ForeColor;
}
}
}
}

if (visible)
{
lvLog.Items.Add(itm);
}
Expand All @@ -158,6 +181,12 @@ private void LoadChanges()
}
}

public void Reload()
{
ClearAll();
LoadChanges();
}

public void ClearAll()
{
LastLines = new string[0];
Expand All @@ -181,8 +210,7 @@ public bool IsInfoLine(string line)

public bool ShouldSee(string line)
{
//return !((IsErrorLine(line) && !chkError.Checked) || (IsDebugLine(line) && !chkDebug.Checked) || (IsInfoLine(line) && !chkInfo.Checked));
return true;
return !((IsErrorLine(line) && !chkError.Checked) || (IsDebugLine(line) && !chkDebug.Checked) || (IsInfoLine(line) && !chkInfo.Checked));
}

private void chkInfo_CheckedChanged(object sender, EventArgs e)
Expand Down

0 comments on commit 0617bce

Please sign in to comment.