Merge claudedo/e3c29bf4538e491e9631ab80076b6fb4
This commit is contained in:
@@ -3,6 +3,9 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Input.Platform;
|
||||
using ClaudeDo.Data.Models;
|
||||
using ClaudeDo.Ui.Localization;
|
||||
using ClaudeDo.Ui.Services;
|
||||
@@ -18,7 +21,10 @@ namespace ClaudeDo.Ui.ViewModels.Modals;
|
||||
/// </summary>
|
||||
public sealed partial class LogVisualizerViewModel : ViewModelBase
|
||||
{
|
||||
private const int CopyLastCount = 40;
|
||||
|
||||
private readonly IWorkerClient _worker;
|
||||
private readonly Func<string, Task<bool>> _copyToClipboard;
|
||||
private IReadOnlyList<WorkerLogEntry> _all = Array.Empty<WorkerLogEntry>();
|
||||
|
||||
public ObservableCollection<LogVisualizerRow> Rows { get; } = new();
|
||||
@@ -28,7 +34,14 @@ public sealed partial class LogVisualizerViewModel : ViewModelBase
|
||||
|
||||
public Action? CloseAction { get; set; }
|
||||
|
||||
public LogVisualizerViewModel(IWorkerClient worker) => _worker = worker;
|
||||
public LogVisualizerViewModel(IWorkerClient worker) : this(worker, CopyToClipboardAsync) { }
|
||||
|
||||
internal LogVisualizerViewModel(IWorkerClient worker, Func<string, Task<bool>> copyToClipboard)
|
||||
{
|
||||
_worker = worker;
|
||||
_copyToClipboard = copyToClipboard;
|
||||
Rows.CollectionChanged += (_, _) => CopyLastCommand.NotifyCanExecuteChanged();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public async Task RefreshAsync()
|
||||
@@ -53,6 +66,33 @@ public sealed partial class LogVisualizerViewModel : ViewModelBase
|
||||
}
|
||||
|
||||
[RelayCommand] private void Close() => CloseAction?.Invoke();
|
||||
|
||||
private bool CanCopyLast() => Rows.Count > 0;
|
||||
|
||||
[RelayCommand(CanExecute = nameof(CanCopyLast))]
|
||||
private async Task CopyLastAsync()
|
||||
{
|
||||
var count = Math.Min(Rows.Count, CopyLastCount);
|
||||
var ok = await _copyToClipboard(BuildCopyText());
|
||||
StatusText = ok
|
||||
? Loc.T("modals.logVisualizer.copied", count)
|
||||
: Loc.T("modals.logVisualizer.copyFailed");
|
||||
}
|
||||
|
||||
internal string BuildCopyText() =>
|
||||
string.Join('\n', Rows.Take(CopyLastCount).Reverse()
|
||||
.Select(r => $"{r.Time} {r.Level.ToString().ToUpperInvariant()} {r.Message}"));
|
||||
|
||||
private static async Task<bool> CopyToClipboardAsync(string text)
|
||||
{
|
||||
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop &&
|
||||
desktop.MainWindow?.Clipboard is { } clipboard)
|
||||
{
|
||||
try { await clipboard.SetTextAsync(text); return true; }
|
||||
catch { return false; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record LogVisualizerRow(string Time, string Message, WorkerLogLevel Level);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<ctl:ModalShell Title="{loc:Tr modals.logVisualizer.title}" CloseCommand="{Binding CloseCommand}">
|
||||
<DockPanel LastChildFill="True">
|
||||
<!-- Toolbar: filter · status · refresh -->
|
||||
<Grid DockPanel.Dock="Top" ColumnDefinitions="Auto,*,Auto" Margin="14,10">
|
||||
<Grid DockPanel.Dock="Top" ColumnDefinitions="Auto,*,Auto,Auto" Margin="14,10">
|
||||
<CheckBox Grid.Column="0"
|
||||
Content="{loc:Tr modals.logVisualizer.warnErrorOnly}"
|
||||
IsChecked="{Binding WarnErrorOnly}"
|
||||
@@ -31,7 +31,11 @@
|
||||
Text="{Binding StatusText}"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
Foreground="{DynamicResource TextMuteBrush}"/>
|
||||
<Button Grid.Column="2" Classes="btn"
|
||||
<Button Grid.Column="2" Classes="btn" Margin="0,0,8,0"
|
||||
Content="{loc:Tr modals.logVisualizer.copyLast}"
|
||||
ToolTip.Tip="{loc:Tr modals.logVisualizer.copyLastTooltip}"
|
||||
Command="{Binding CopyLastCommand}"/>
|
||||
<Button Grid.Column="3" Classes="btn"
|
||||
Content="{loc:Tr modals.logVisualizer.refresh}"
|
||||
Command="{Binding RefreshCommand}"/>
|
||||
</Grid>
|
||||
|
||||
Reference in New Issue
Block a user