Skip to content

Commit ad9929a

Browse files
author
Wayfarer
committed
add a wpf window
1 parent acb3181 commit ad9929a

8 files changed

Lines changed: 184 additions & 9 deletions

File tree

CoreBuilder/CoreBuilder.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
<PropertyGroup>
44
<TargetFramework>net9.0-windows</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<UseWPF>true</UseWPF>
57
</PropertyGroup>
68

79
<ItemGroup>

CoreBuilder/FileManager/FileObserverCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
using System;
1212
using System.IO;
13-
using CoreBuilder.Helper;
1413
using CoreBuilder.Interface;
14+
using CoreBuilder.UI;
1515
using Weaver;
1616
using Weaver.Interfaces;
1717
using Weaver.Messages;
@@ -61,7 +61,7 @@ public sealed class FileObserverCommand : ICommand
6161
/// <param name="output">The side channel for output.</param>
6262
public FileObserverCommand(IEventOutput? output = null)
6363
{
64-
_output = output ?? new ConsoleEventOutput();
64+
_output = output ?? new WpfEventOutput();
6565
}
6666

6767
/// <inheritdoc />

CoreBuilder/FileManager/LogTailCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
using System;
1212
using System.IO;
13-
using CoreBuilder.Helper;
1413
using CoreBuilder.Interface;
14+
using CoreBuilder.UI;
1515
using Weaver;
1616
using Weaver.Interfaces;
1717
using Weaver.Messages;
@@ -61,7 +61,7 @@ public sealed class LogTailCommand : ICommand
6161
/// <param name="output">The output.</param>
6262
public LogTailCommand(IEventOutput? output = null)
6363
{
64-
_output = output ?? new ConsoleEventOutput();
64+
_output = output ?? new WpfEventOutput();
6565
}
6666

6767
/// <inheritdoc />

CoreBuilder/Interface/IEventOutput.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ public interface IEventOutput
2121
/// <param name="message">The message.</param>
2222
void Write(string message);
2323
}
24-
2524
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* COPYRIGHT: See COPYING in the top level directory
3-
* PROJECT: CoreBuilder.Helper
3+
* PROJECT: CoreBuilder.UI
44
* FILE: ConsoleEventOutput.cs
55
* PURPOSE: Sample console side channel for event output.
66
* PROGRAMMER: Peter Geinitz (Wayfarer)
@@ -9,17 +9,16 @@
99
using System;
1010
using CoreBuilder.Interface;
1111

12-
namespace CoreBuilder.Helper
12+
namespace CoreBuilder.UI
1313
{
1414
/// <inheritdoc />
1515
/// <summary>
1616
/// Console side channel for event output.
1717
/// </summary>
18-
/// <seealso cref="CoreBuilder.Interface.IEventOutput" />
18+
/// <seealso cref="IEventOutput" />
1919
public sealed class ConsoleEventOutput : IEventOutput
2020
{
2121
/// <inheritdoc />
2222
public void Write(string message) => Console.WriteLine(message);
2323
}
24-
2524
}

CoreBuilder/UI/LogWindow.xaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<Window x:Class="CoreBuilder.UI.LogWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:CoreBuilder.UI"
7+
mc:Ignorable="d"
8+
Title="Log Window" Height="450" Width="800">
9+
<DockPanel>
10+
<!-- Menu Bar -->
11+
<Menu DockPanel.Dock="Top">
12+
<MenuItem Header="_Actions">
13+
<MenuItem Header="Clear Log" Click="ClearLog_Click"/>
14+
<Separator />
15+
<MenuItem Header="Go to Top" Click="GoTop_Click"/>
16+
<MenuItem Header="Go to Bottom" Click="GoBottom_Click"/>
17+
</MenuItem>
18+
19+
<MenuItem Header="_Options">
20+
<MenuItem>
21+
<CheckBox x:Name="AutoScrollCheck"
22+
Content="Auto Scroll"
23+
IsChecked="True"/>
24+
</MenuItem>
25+
<MenuItem>
26+
<CheckBox x:Name="ShowTimestampCheck"
27+
Content="Show Timestamp"
28+
IsChecked="False"/>
29+
</MenuItem>
30+
</MenuItem>
31+
</Menu>
32+
33+
<!-- Log Area -->
34+
<ScrollViewer x:Name="ScrollViewer"
35+
VerticalScrollBarVisibility="Auto">
36+
<TextBlock x:Name="LogText"
37+
FontFamily="Consolas"
38+
TextWrapping="Wrap"
39+
Margin="10"/>
40+
</ScrollViewer>
41+
</DockPanel>
42+
</Window>

CoreBuilder/UI/LogWindow.xaml.cs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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+
}

CoreBuilder/UI/WpfEventOutput.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* COPYRIGHT: See COPYING in the top level directory
3+
* PROJECT: CoreBuilder.UI
4+
* FILE: WpfEventOutput.cs
5+
* PURPOSE: Sample wpf side channel for event output.
6+
* PROGRAMMER: Peter Geinitz (Wayfarer)
7+
*/
8+
9+
using CoreBuilder.Interface;
10+
11+
namespace CoreBuilder.UI
12+
{
13+
/// <inheritdoc />
14+
/// <summary>
15+
/// Logging output that displays messages in a WPF window.
16+
/// </summary>
17+
/// <seealso cref="CoreBuilder.Interface.IEventOutput" />
18+
public sealed class WpfEventOutput : IEventOutput
19+
{
20+
/// <summary>
21+
/// The window
22+
/// </summary>
23+
private readonly LogWindow _window;
24+
25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="WpfEventOutput"/> class.
27+
/// </summary>
28+
public WpfEventOutput()
29+
{
30+
_window = new LogWindow();
31+
_window.Show();
32+
}
33+
34+
/// <summary>
35+
/// Writes the specified message.
36+
/// </summary>
37+
/// <param name="message">The message.</param>
38+
public void Write(string message)
39+
{
40+
_window.Append(message);
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)