added copy button and inverse-filter

This commit is contained in:
PaulKoudelka 2026-07-21 15:02:27 +02:00
parent d72b7c558e
commit 3f93847810
2 changed files with 58 additions and 2 deletions

View File

@ -60,7 +60,11 @@
<MudButton Variant="Variant.Text" Color="Color.Default" StartIcon="@Icons.Material.Filled.Clear" Disabled="@(!this.HasActiveFilter)" OnClick="@this.ClearFilters">
@T("Clear")
</MudButton>
<MudButton Variant="Variant.Text" Color="Color.Default" StartIcon="@Icons.Material.Filled.ContentCopy" Disabled="@(!this.CanCopyDisplayedLines)" OnClick="@this.CopyDisplayedLines">
@T("Copy visible lines")
</MudButton>
<MudCheckBox T="bool" @bind-Value="@this.FilterOnly" Label="@T("Filter only")" Color="Color.Primary" />
<MudCheckBox T="bool" @bind-Value="@this.InvertFilters" Label="@T("Invert filters")" Color="Color.Primary" />
</MudStack>
<MudText Typo="Typo.body2" Class="log-viewer-path mb-1">

View File

@ -60,6 +60,7 @@ public partial class AssistantLogViewer : MSGComponentBase
private bool isLoading;
private bool autoRefresh;
private bool filterOnly = true;
private bool invertFilters;
private bool showTimestamps = true;
private int maxLines = DEFAULT_MAX_LINES;
private int totalLineCount;
@ -72,7 +73,11 @@ public partial class AssistantLogViewer : MSGComponentBase
private bool HasDropdownFilter => this.selectedLogLevels.Count > 0 || this.selectedLoggers.Count > 0 || this.selectedSourceDetails.Count > 0;
private bool HasActiveFilter => !string.IsNullOrWhiteSpace(this.filterText) || this.HasDropdownFilter;
private bool HasActiveFilter => !string.IsNullOrWhiteSpace(this.filterText) || this.HasDropdownFilter || this.invertFilters;
private bool HasActiveVisibilityFilter => this.HasDropdownFilter || (this.filterOnly && this.activeSearchTerms.Length > 0);
private bool CanCopyDisplayedLines => this.displayLines.Count > 0;
private string FilterText
{
@ -100,6 +105,19 @@ public partial class AssistantLogViewer : MSGComponentBase
}
}
private bool InvertFilters
{
get => this.invertFilters;
set
{
if (this.invertFilters == value)
return;
this.invertFilters = value;
this.RefreshDisplayLines();
}
}
private bool ShowTimestamps
{
get => this.showTimestamps;
@ -208,6 +226,12 @@ public partial class AssistantLogViewer : MSGComponentBase
await this.RefreshLogAsync();
}
private async Task CopyDisplayedLines()
{
var text = string.Join(Environment.NewLine, this.displayLines.Select(this.GetPlainRenderedLine));
await this.RustService.CopyText2Clipboard(this.Snackbar, text);
}
private async Task OpenCurrentLogInFileManager()
{
try
@ -276,6 +300,7 @@ public partial class AssistantLogViewer : MSGComponentBase
this.selectedLogLevels.Clear();
this.selectedLoggers.Clear();
this.selectedSourceDetails.Clear();
this.invertFilters = false;
this.RefreshDisplayLines();
}
@ -386,6 +411,14 @@ public partial class AssistantLogViewer : MSGComponentBase
}
private bool LineMatchesFilters(LogLine line)
{
if (this.invertFilters && this.HasActiveVisibilityFilter)
return !this.LineMatchesAnyActiveFilter(line);
return this.LineMatchesActiveFilters(line);
}
private bool LineMatchesActiveFilters(LogLine line)
{
if (!MatchesSelection(line.Segments.Level, this.selectedLogLevels))
return false;
@ -402,6 +435,20 @@ public partial class AssistantLogViewer : MSGComponentBase
return MatchesSearchTerms(this.GetPlainRenderedLine(line), this.activeSearchTerms);
}
private bool LineMatchesAnyActiveFilter(LogLine line)
{
if (ActiveSelectionMatches(line.Segments.Level, this.selectedLogLevels))
return true;
if (ActiveSelectionMatches(line.Segments.Logger, this.selectedLoggers))
return true;
if (ActiveSelectionMatches(line.Segments.SourceDetails, this.selectedSourceDetails))
return true;
return this.filterOnly && this.activeSearchTerms.Length > 0 && MatchesSearchTerms(this.GetPlainRenderedLine(line), this.activeSearchTerms);
}
private string RenderLine(LogLine line)
{
var text = this.GetPlainRenderedLine(line);
@ -687,9 +734,14 @@ public partial class AssistantLogViewer : MSGComponentBase
}
private static bool MatchesSelection(string? value, HashSet<string> selectedValues)
{
return selectedValues.Count == 0 || ActiveSelectionMatches(value, selectedValues);
}
private static bool ActiveSelectionMatches(string? value, HashSet<string> selectedValues)
{
if (selectedValues.Count == 0)
return true;
return false;
var normalizedValue = string.IsNullOrWhiteSpace(value) ? OTHER_OPTION_VALUE : value;
return selectedValues.Contains(normalizedValue);