Rework BOTWConsole logging

Remove Log in favor of LogStatus, disable timer auto-clear, remove TSCB console
This commit is contained in:
Chev 2021-06-04 20:38:07 -07:00
parent 84026365fc
commit 25d6193aed

View file

@ -1,8 +1,6 @@
using System; using System.Linq;
using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Threading;
namespace BOTWToolset.Debugging namespace BOTWToolset.Debugging
{ {
@ -11,51 +9,48 @@ namespace BOTWToolset.Debugging
/// </summary> /// </summary>
static class BOTWConsole static class BOTWConsole
{ {
private readonly static TextBox _console; private static readonly Label _status;
private readonly static Label _status;
private static DispatcherTimer ClearStatusTimer; // Timer which automatically clears the status bar - currently unused
//private static DispatcherTimer ClearStatusTimer;
static BOTWConsole() static BOTWConsole()
{ {
var dashboard = Application.Current.Windows.OfType<Dashboard>().ToArray()[0]; var dashboard = Application.Current.Windows.OfType<Dashboard>().ToArray()[0];
// Get the TSCB control
var tabControl = Dashboard.toolsetTabs[0];
_console = ((Control.TabTSCB)tabControl).TSCBConsole;
_status = dashboard.LabelStatus; _status = dashboard.LabelStatus;
} }
public static void Log(object text) /// <summary>
/// Sets the status bar text.
/// </summary>
/// <param name="text">The text to display.</param>
public static void LogStatus(object text)
{ {
_console.Text += text.ToString() + "\n"; /*if (ClearStatusTimer != null)
_console.ScrollToEnd(); // After adding the new text, scroll to the end ClearStatusTimer.Stop();*/
}
_status.Content = text.ToString();
/*ClearStatusTimer = new DispatcherTimer();
ClearStatusTimer.Tick += (src, e) => { ClearStatus(); };
ClearStatusTimer.Interval = new TimeSpan(0, 0, 4);
ClearStatusTimer.Start();*/
}
public static void LogWarning(object text) public static void LogWarning(object text)
{ {
Log("[Warning]" + text); LogStatus("[Warning]" + text);
} }
public static void LogError(object text) public static void LogError(object text)
{ {
Log("[ERROR]" + text); LogStatus("[ERROR]" + text);
} }
public static void LogStatus(object text) /// <summary>
{ /// Clears the status bar text.
if (ClearStatusTimer != null) /// </summary>
ClearStatusTimer.Stop(); public static void ClearStatus()
_status.Content = text.ToString();
ClearStatusTimer = new DispatcherTimer();
ClearStatusTimer.Tick += ClearStatus;
ClearStatusTimer.Interval = new TimeSpan(0, 0, 4);
ClearStatusTimer.Start();
}
public static void ClearStatus(object src, EventArgs e)
{ {
_status.Content = ""; _status.Content = "";
} }