WPF: Adjust log panel, fix #222

This commit is contained in:
Genteure 2021-08-01 18:02:46 +08:00
parent 7df5bce368
commit 9a51bf04de
5 changed files with 172 additions and 28 deletions

View File

@ -1,14 +1,19 @@
<UserControl x:Class="BililiveRecorder.WPF.Controls.LogPanel" <UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" x:Class="BililiveRecorder.WPF.Controls.LogPanel"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BililiveRecorder.WPF.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:models="clr-namespace:BililiveRecorder.WPF.Models" xmlns:l="https://github.com/XAMLMarkupExtensions/WPFLocalizationExtension"
mc:Ignorable="d" l:LocalizeDictionary.DesignCulture=""
d:DesignHeight="450" d:DesignWidth="800"> l:ResxLocalizationProvider.DefaultAssembly="BililiveRecorder.WPF"
<ListView ItemsSource="{Binding}" SizeChanged="ListView_SizeChanged" l:ResxLocalizationProvider.DefaultDictionary="Strings"
VirtualizingPanel.VirtualizationMode="Recycling" xmlns:local="clr-namespace:BililiveRecorder.WPF.Controls"
xmlns:models="clr-namespace:BililiveRecorder.WPF.Models"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<ListView x:Name="logView" ItemsSource="{Binding}" SizeChanged="ListView_SizeChanged"
VirtualizingPanel.VirtualizationMode="Recycling"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"> ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListView.DataContext> <ListView.DataContext>
<models:LogModel/> <models:LogModel/>
@ -22,13 +27,22 @@
</ListView.Resources> </ListView.Resources>
<ListView.View> <ListView.View>
<GridView AllowsColumnReorder="False"> <GridView AllowsColumnReorder="False">
<GridViewColumn DisplayMemberBinding="{Binding Timestamp,StringFormat=HH:mm:ss.ffff}"/> <GridViewColumn Header="{l:Loc LogPanel_Header_Timestamp}" DisplayMemberBinding="{Binding Timestamp,StringFormat=HH:mm:ss.ffff}"/>
<GridViewColumn DisplayMemberBinding="{Binding Level}"/> <GridViewColumn Header="{l:Loc LogPanel_Header_Level}">
<GridViewColumn DisplayMemberBinding="{Binding RoomId}"/>
<GridViewColumn>
<GridViewColumn.CellTemplate> <GridViewColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="{Binding Message}" TextWrapping="Wrap"/> <TextBlock l:ResxLocalizationProvider.DefaultDictionary="Strings"
Text="{l:Loc {Binding Path=Level, StringFormat=LogPanel_Level_{0}}}"
TextWrapping="NoWrap"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="{l:Loc LogPanel_Header_RoomId}" DisplayMemberBinding="{Binding RoomId}"/>
<GridViewColumn Header="{l:Loc LogPanel_Header_Message}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock l:ResxLocalizationProvider.DefaultDictionary="Strings"
Text="{Binding Message}" TextWrapping="Wrap"/>
</DataTemplate> </DataTemplate>
</GridViewColumn.CellTemplate> </GridViewColumn.CellTemplate>
</GridViewColumn> </GridViewColumn>

View File

@ -1,5 +1,8 @@
using System;
using System.Collections.Specialized;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media;
#nullable enable #nullable enable
namespace BililiveRecorder.WPF.Controls namespace BililiveRecorder.WPF.Controls
@ -12,6 +15,22 @@ namespace BililiveRecorder.WPF.Controls
public LogPanel() public LogPanel()
{ {
this.InitializeComponent(); this.InitializeComponent();
((INotifyCollectionChanged)this.logView.Items).CollectionChanged += this.LogView_CollectionChanged;
}
private void LogView_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
try
{
if (!this.logView.IsMouseOver && VisualTreeHelper.GetChildrenCount(this.logView) > 0)
{
var border = (Border)VisualTreeHelper.GetChild(this.logView, 0);
var scrollViewer = (ScrollViewer)VisualTreeHelper.GetChild(border, 0);
scrollViewer.ScrollToBottom();
}
}
catch (Exception)
{ }
} }
private void ListView_SizeChanged(object sender, SizeChangedEventArgs e) private void ListView_SizeChanged(object sender, SizeChangedEventArgs e)

View File

@ -340,6 +340,96 @@ namespace BililiveRecorder.WPF.Properties {
} }
} }
/// <summary>
/// Looks up a localized string similar to 级别.
/// </summary>
public static string LogPanel_Header_Level {
get {
return ResourceManager.GetString("LogPanel_Header_Level", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 消息.
/// </summary>
public static string LogPanel_Header_Message {
get {
return ResourceManager.GetString("LogPanel_Header_Message", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 房间号.
/// </summary>
public static string LogPanel_Header_RoomId {
get {
return ResourceManager.GetString("LogPanel_Header_RoomId", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 时间.
/// </summary>
public static string LogPanel_Header_Timestamp {
get {
return ResourceManager.GetString("LogPanel_Header_Timestamp", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 调试.
/// </summary>
public static string LogPanel_Level_Debug {
get {
return ResourceManager.GetString("LogPanel_Level_Debug", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 错误.
/// </summary>
public static string LogPanel_Level_Error {
get {
return ResourceManager.GetString("LogPanel_Level_Error", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 致命.
/// </summary>
public static string LogPanel_Level_Fatal {
get {
return ResourceManager.GetString("LogPanel_Level_Fatal", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 信息.
/// </summary>
public static string LogPanel_Level_Information {
get {
return ResourceManager.GetString("LogPanel_Level_Information", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 详细.
/// </summary>
public static string LogPanel_Level_Verbose {
get {
return ResourceManager.GetString("LogPanel_Level_Verbose", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 警告.
/// </summary>
public static string LogPanel_Level_Warning {
get {
return ResourceManager.GetString("LogPanel_Level_Warning", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to 回放剪辑(正在处理中的数量). /// Looks up a localized string similar to 回放剪辑(正在处理中的数量).
/// </summary> /// </summary>

View File

@ -196,6 +196,36 @@
<data name="LogPage_RightClickCopyToolTip" xml:space="preserve"> <data name="LogPage_RightClickCopyToolTip" xml:space="preserve">
<value>右键点击可以复制单行日志</value> <value>右键点击可以复制单行日志</value>
</data> </data>
<data name="LogPanel_Header_Level" xml:space="preserve">
<value>级别</value>
</data>
<data name="LogPanel_Header_Message" xml:space="preserve">
<value>消息</value>
</data>
<data name="LogPanel_Header_RoomId" xml:space="preserve">
<value>房间号</value>
</data>
<data name="LogPanel_Header_Timestamp" xml:space="preserve">
<value>时间</value>
</data>
<data name="LogPanel_Level_Debug" xml:space="preserve">
<value>调试</value>
</data>
<data name="LogPanel_Level_Error" xml:space="preserve">
<value>错误</value>
</data>
<data name="LogPanel_Level_Fatal" xml:space="preserve">
<value>致命</value>
</data>
<data name="LogPanel_Level_Information" xml:space="preserve">
<value>信息</value>
</data>
<data name="LogPanel_Level_Verbose" xml:space="preserve">
<value>详细</value>
</data>
<data name="LogPanel_Level_Warning" xml:space="preserve">
<value>警告</value>
</data>
<data name="RoomCard_ClipButton_Tooltip" xml:space="preserve"> <data name="RoomCard_ClipButton_Tooltip" xml:space="preserve">
<value>回放剪辑(正在处理中的数量)</value> <value>回放剪辑(正在处理中的数量)</value>
<comment>This feature is off by default, and will be removed in the future.</comment> <comment>This feature is off by default, and will be removed in the future.</comment>

View File

@ -11,7 +11,7 @@ namespace BililiveRecorder.WPF
{ {
internal class WpfLogEventSink : ILogEventSink internal class WpfLogEventSink : ILogEventSink
{ {
private const int MAX_LINE = 60; private const int MAX_LINE = 150;
internal static object _lock = new object(); internal static object _lock = new object();
internal static ObservableCollection<LogModel> Logs = new ObservableCollection<LogModel>(); internal static ObservableCollection<LogModel> Logs = new ObservableCollection<LogModel>();
@ -26,16 +26,7 @@ namespace BililiveRecorder.WPF
var m = new LogModel var m = new LogModel
{ {
Timestamp = logEvent.Timestamp, Timestamp = logEvent.Timestamp,
Level = logEvent.Level switch Level = logEvent.Level,
{
LogEventLevel.Verbose => "Verbose",
LogEventLevel.Debug => "Debug",
LogEventLevel.Information => "Info",
LogEventLevel.Warning => "Warn",
LogEventLevel.Error => "Error",
LogEventLevel.Fatal => "Fatal",
_ => string.Empty,
},
Message = msg, Message = msg,
}; };
@ -69,7 +60,7 @@ namespace BililiveRecorder.WPF
{ {
public DateTimeOffset Timestamp { get; set; } public DateTimeOffset Timestamp { get; set; }
public string Level { get; set; } = string.Empty; public LogEventLevel Level { get; set; }
public string RoomId { get; set; } = string.Empty; public string RoomId { get; set; } = string.Empty;