botw-toolset/Debugging/BOTWConsole.cs
2021-05-30 19:20:03 -07:00

63 lines
1.7 KiB
C#

using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;
namespace BOTWToolset.Debugging
{
/// <summary>
/// Allows for printing debug info to an in-app console.
/// </summary>
static class BOTWConsole
{
private readonly static TextBox _console;
private readonly static Label _status;
private static DispatcherTimer ClearStatusTimer;
static BOTWConsole()
{
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;
}
public static void Log(object text)
{
_console.Text += text.ToString() + "\n";
_console.ScrollToEnd(); // After adding the new text, scroll to the end
}
public static void LogWarning(object text)
{
Log("[Warning]" + text);
}
public static void LogError(object text)
{
Log("[ERROR]" + text);
}
public static void LogStatus(object text)
{
if (ClearStatusTimer != null)
ClearStatusTimer.Stop();
_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 = "";
}
}
}