|
| 1 | +/* |
| 2 | + * COPYRIGHT: See COPYING in the top level directory |
| 3 | + * PROJECT: CoreBuilder.UI |
| 4 | + * FILE: LogWindow.xaml.cs |
| 5 | + * PURPOSE: Basic log window for displaying messages. |
| 6 | + * PROGRAMMER: Peter Geinitz (Wayfarer) |
| 7 | + */ |
| 8 | + |
| 9 | +using System; |
| 10 | +using System.Windows; |
| 11 | + |
| 12 | +namespace CoreBuilder.UI |
| 13 | +{ |
| 14 | + /// <summary> |
| 15 | + /// Simple Display window for logging messages |
| 16 | + /// </summary> |
| 17 | + public partial class LogWindow |
| 18 | + { |
| 19 | + /// <summary> |
| 20 | + /// Initializes a new instance of the <see cref="LogWindow"/> class. |
| 21 | + /// </summary> |
| 22 | + public LogWindow() |
| 23 | + { |
| 24 | + InitializeComponent(); |
| 25 | + } |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// Appends the specified message. |
| 29 | + /// </summary> |
| 30 | + /// <param name="message">The message.</param> |
| 31 | + public void Append(string message) |
| 32 | + { |
| 33 | + Dispatcher.Invoke(() => |
| 34 | + { |
| 35 | + if (ShowTimestampCheck.IsChecked == true) |
| 36 | + { |
| 37 | + var ts = DateTime.Now.ToString("HH:mm:ss.fff"); |
| 38 | + message = $"[{ts}] {message}"; |
| 39 | + } |
| 40 | + |
| 41 | + LogText.Text += message + Environment.NewLine; |
| 42 | + |
| 43 | + if (AutoScrollCheck.IsChecked == true) |
| 44 | + ScrollToBottom(); |
| 45 | + }); |
| 46 | + } |
| 47 | + |
| 48 | + /// <summary> |
| 49 | + /// Scrolls to bottom. |
| 50 | + /// </summary> |
| 51 | + private void ScrollToBottom() |
| 52 | + { |
| 53 | + ScrollViewer.ScrollToEnd(); |
| 54 | + } |
| 55 | + |
| 56 | + /// <summary> |
| 57 | + /// Scrolls to top. |
| 58 | + /// </summary> |
| 59 | + private void ScrollToTop() |
| 60 | + { |
| 61 | + ScrollViewer.ScrollToHome(); |
| 62 | + } |
| 63 | + |
| 64 | + // Menu Handlers |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Handles the Click event of the ClearLog control. |
| 68 | + /// </summary> |
| 69 | + /// <param name="sender">The source of the event.</param> |
| 70 | + /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> |
| 71 | + private void ClearLog_Click(object sender, RoutedEventArgs e) |
| 72 | + => LogText.Text = string.Empty; |
| 73 | + |
| 74 | + /// <summary> |
| 75 | + /// Handles the Click event of the GoTop control. |
| 76 | + /// </summary> |
| 77 | + /// <param name="sender">The source of the event.</param> |
| 78 | + /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> |
| 79 | + private void GoTop_Click(object sender, RoutedEventArgs e) |
| 80 | + => ScrollToTop(); |
| 81 | + |
| 82 | + /// <summary> |
| 83 | + /// Handles the Click event of the GoBottom control. |
| 84 | + /// </summary> |
| 85 | + /// <param name="sender">The source of the event.</param> |
| 86 | + /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> |
| 87 | + private void GoBottom_Click(object sender, RoutedEventArgs e) |
| 88 | + => ScrollToBottom(); |
| 89 | + } |
| 90 | +} |
0 commit comments