Skip to content

Commit b5fe07a

Browse files
Add Copy Function for Log Pages
Signed-off-by: Littlenine <LittlenineEnnea@gmail.com>
1 parent 2b349e3 commit b5fe07a

2 files changed

Lines changed: 44 additions & 32 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,43 @@
1+
using System.Collections.Specialized;
12
using QCEDL.GUI.Services;
3+
using ReactiveUI;
24

35
namespace QCEDL.GUI.ViewModels;
46

57
public sealed class LogsViewModel : ViewModelBase
68
{
9+
private string _text = string.Empty;
10+
711
public LogsViewModel(ObservableLogSink sink)
812
{
913
ArgumentNullException.ThrowIfNull(sink);
1014
Sink = sink;
15+
Sink.Entries.CollectionChanged += OnEntriesChanged;
16+
UpdateText();
1117
}
1218

1319
public ObservableLogSink Sink { get; }
1420

21+
public string Text
22+
{
23+
get => _text;
24+
private set => this.RaiseAndSetIfChanged(ref _text, value);
25+
}
26+
1527
public void Clear()
1628
{
1729
Sink.Clear();
30+
UpdateText();
31+
}
32+
33+
private void OnEntriesChanged(object? sender, NotifyCollectionChangedEventArgs e)
34+
{
35+
UpdateText();
36+
}
37+
38+
private void UpdateText()
39+
{
40+
// Format each log entry as "Time Level Message" and join them with new lines
41+
Text = string.Join(Environment.NewLine, Sink.Entries.Select(entry => $"{entry.TimeText} {entry.LevelText} {entry.Message}"));
1842
}
1943
}

QCEDL.GUI/Views/LogsView.axaml

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,27 @@
11
<UserControl xmlns="https://github.com/avaloniaui"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3-
xmlns:vm="clr-namespace:QCEDL.GUI.ViewModels"
4-
xmlns:svc="clr-namespace:QCEDL.GUI.Services"
5-
xmlns:l="clr-namespace:QCEDL.GUI.Markup"
6-
x:Class="QCEDL.GUI.Views.LogsView"
7-
x:DataType="vm:LogsViewModel">
8-
<StackPanel Spacing="16" MaxWidth="1040">
9-
<StackPanel Spacing="6">
10-
<TextBlock Classes="label" Text="{l:Localize Logs_Label}" />
11-
<TextBlock Classes="h1" Text="{l:Localize Logs_Heading}" />
12-
<TextBlock Classes="body" Text="{l:Localize Logs_Body}" />
3+
xmlns:vm="using:QCEDL.GUI.ViewModels"
4+
xmlns:svc="using:QCEDL.GUI.Services"
5+
x:Class="QCEDL.GUI.Views.LogsView" x:DataType="vm:LogsViewModel">
6+
<StackPanel Spacing="16">
7+
<StackPanel Orientation="Horizontal" Spacing="8">
8+
<Button Content="Clear Logs" Command="{Binding Clear}" />
139
</StackPanel>
1410

1511
<Border Classes="card dark" Padding="16">
16-
<Grid RowDefinitions="*,Auto">
17-
<ScrollViewer Grid.Row="0" HorizontalScrollBarVisibility="Auto" Height="420">
18-
<ItemsControl ItemsSource="{Binding Sink.Entries}">
19-
<ItemsControl.ItemTemplate>
20-
<DataTemplate DataType="svc:LogEntry">
21-
<Grid ColumnDefinitions="90,60,*" Margin="0,1">
22-
<TextBlock Grid.Column="0" FontFamily="{DynamicResource FontMono}"
23-
Foreground="{DynamicResource BrushTextOnDark}"
24-
FontSize="12" Text="{Binding TimeText}" />
25-
<TextBlock Grid.Column="1" FontFamily="{DynamicResource FontMono}"
26-
Foreground="{DynamicResource BrushCoral}"
27-
FontSize="12" Text="{Binding LevelText}" />
28-
<TextBlock Grid.Column="2" FontFamily="{DynamicResource FontMono}"
29-
Foreground="{DynamicResource BrushTextInverse}"
30-
FontSize="12" TextWrapping="Wrap" Text="{Binding Message}" />
31-
</Grid>
32-
</DataTemplate>
33-
</ItemsControl.ItemTemplate>
34-
</ItemsControl>
35-
</ScrollViewer>
36-
</Grid>
12+
<TextBox
13+
Height="420"
14+
FontFamily="{DynamicResource FontMono}"
15+
FontSize="12"
16+
TextWrapping="NoWrap"
17+
AcceptsReturn="True"
18+
IsReadOnly="True"
19+
ScrollViewer.HorizontalScrollBarVisibility="Auto"
20+
ScrollViewer.VerticalScrollBarVisibility="Auto"
21+
Foreground="{DynamicResource BrushTextInverse}"
22+
Background="Transparent"
23+
BorderThickness="0"
24+
Text="{Binding Text, Mode=OneWay}" />
3725
</Border>
3826
</StackPanel>
39-
</UserControl>
27+
</UserControl>

0 commit comments

Comments
 (0)