Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public sealed class Localization : INotifyPropertyChanged
["QuickDisk"] = "Disk / SSD / NVMe", ["QuickNtfs"] = "NTFS / file system", ["QuickUsb"] = "USB / USB-C / UCSI",
["QuickDevice"] = "Device / Kernel-PnP", ["QuickDriver"] = "Drivers", ["QuickWhea"] = "Hardware / WHEA",
["QuickNetwork"] = "Network", ["QuickUpdate"] = "Windows Update", ["QuickPower"] = "Power / unexpected shutdown",
["ActiveFilters"] = "Active filters: {0}", ["FilterKeyword"] = "Keyword: {0}", ["FilterProvider"] = "Provider: {0}",
["FilterChannels"] = "Channels: {0}", ["FilterSort"] = "Sort: {0}",
["SearchPossibleCauses"] = "Search possible causes", ["EventId"] = "Event ID", ["ColumnSeverity"] = "Severity", ["ColumnProblem"] = "Problem",
["ColumnCount"] = "Count", ["ColumnSource"] = "Source", ["ColumnLastSeen"] = "Last seen",
["ProblemDetails"] = "Problem details", ["GroupedEvents"] = "Group Events", ["ColumnTime"] = "Time",
Expand Down Expand Up @@ -93,6 +95,8 @@ public sealed class Localization : INotifyPropertyChanged
["QuickDisk"] = "磁碟 / SSD / NVMe", ["QuickNtfs"] = "NTFS / 檔案系統", ["QuickUsb"] = "USB / USB-C / UCSI",
["QuickDevice"] = "裝置 / Kernel-PnP", ["QuickDriver"] = "驅動程式", ["QuickWhea"] = "硬體 / WHEA",
["QuickNetwork"] = "網路", ["QuickUpdate"] = "Windows Update", ["QuickPower"] = "電源 / 異常關機",
["ActiveFilters"] = "啟用篩選:{0}", ["FilterKeyword"] = "關鍵字:{0}", ["FilterProvider"] = "Provider:{0}",
["FilterChannels"] = "Channel:{0}", ["FilterSort"] = "排序:{0}",
["SearchPossibleCauses"] = "使用搜尋引擎查詢可能原因", ["EventId"] = "Event ID", ["ColumnSeverity"] = "等級", ["ColumnProblem"] = "問題",
["ColumnCount"] = "次數", ["ColumnSource"] = "來源", ["ColumnLastSeen"] = "最後發生",
["ProblemDetails"] = "問題詳細資料", ["GroupedEvents"] = "群組事件", ["ColumnTime"] = "時間",
Expand Down
67 changes: 46 additions & 21 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
xmlns:local="clr-namespace:EventFast"
Title="EventFast" Icon="Assets/EventFast.ico" Height="760" Width="1180" MinHeight="560" MinWidth="820"
Background="#F4F6F8" PreviewKeyDown="Window_PreviewKeyDown" AllowDrop="True" Drop="Window_Drop">
<Window.Resources>
<Style x:Key="ActiveFilterControl" TargetType="{x:Type Control}">
<Setter Property="Background" Value="#E5F1FB" />
<Setter Property="Foreground" Value="#003B66" />
<Setter Property="BorderBrush" Value="#0078D4" />
<Setter Property="BorderThickness" Value="2" />
<Setter Property="FontWeight" Value="SemiBold" />
</Style>
<Style x:Key="ActiveQuickButton" TargetType="Button">
<Setter Property="Background" Value="#005A9E" />
<Setter Property="Foreground" Value="White" />
<Setter Property="BorderBrush" Value="#003B66" />
<Setter Property="BorderThickness" Value="2" />
<Setter Property="FontWeight" Value="SemiBold" />
</Style>
</Window.Resources>
<Grid Margin="16">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
Expand All @@ -25,9 +41,10 @@
<ComboBoxItem Tag="selected" Content="{local:Loc ExportSelected}" />
<ComboBoxItem Tag="all" Content="{local:Loc ExportAll}" />
</ComboBox>
<CheckBox x:Name="IncludeXmlBox" DockPanel.Dock="Right" Content="{local:Loc IncludeXml}" VerticalAlignment="Center" />
<CheckBox x:Name="IncludeXmlBox" DockPanel.Dock="Right" Content="{local:Loc IncludeXml}" VerticalAlignment="Center"
Checked="Filter_Changed" Unchecked="Filter_Changed" />
<TextBox x:Name="SearchBox" Height="34" VerticalContentAlignment="Center"
ToolTip="{local:Loc SearchTip}" />
ToolTip="{local:Loc SearchTip}" TextChanged="ManualFilter_Changed" />
</DockPanel>

<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0,12">
Expand All @@ -46,19 +63,21 @@
<ComboBoxItem Tag="all" Content="{local:Loc AllTime}" />
</ComboBox>
<StackPanel x:Name="CustomTimePanel" Orientation="Horizontal" Visibility="Collapsed" Margin="8,0,0,0">
<DatePicker x:Name="FromDate" Width="120" />
<DatePicker x:Name="FromDate" Width="120" SelectedDateChanged="Filter_Changed" />
<TextBlock Text="{local:Loc To}" VerticalAlignment="Center" Margin="4,0" />
<DatePicker x:Name="ToDate" Width="120" />
<DatePicker x:Name="ToDate" Width="120" SelectedDateChanged="Filter_Changed" />
</StackPanel>
<TextBlock Text="{local:Loc Level}" VerticalAlignment="Center" Margin="20,0,0,0" />
<ComboBox x:Name="LevelBox" Width="120" SelectedIndex="2">
<ComboBox x:Name="LevelBox" Width="120" SelectedIndex="2" SelectionChanged="Filter_Changed">
<ComboBoxItem Tag="1" Content="{local:Loc CriticalOnly}" />
<ComboBoxItem Tag="2" Content="{local:Loc ErrorsAndAbove}" />
<ComboBoxItem Tag="3" Content="{local:Loc WarningsAndAbove}" />
<ComboBoxItem Tag="0" Content="{local:Loc All}" />
</ComboBox>
<CheckBox x:Name="SystemBox" Content="System" IsChecked="True" Margin="24,0,12,0" VerticalAlignment="Center" />
<CheckBox x:Name="ApplicationBox" Content="Application" IsChecked="True" VerticalAlignment="Center" />
<CheckBox x:Name="SystemBox" Content="System" IsChecked="True" Margin="24,0,12,0" VerticalAlignment="Center"
Checked="ManualFilter_Changed" Unchecked="ManualFilter_Changed" />
<CheckBox x:Name="ApplicationBox" Content="Application" IsChecked="True" VerticalAlignment="Center"
Checked="ManualFilter_Changed" Unchecked="ManualFilter_Changed" />
<Button x:Name="AdminButton" Content="{local:Loc RestartAdmin}" Visibility="Collapsed" Margin="16,0,0,0" Click="Admin_Click" />
<TextBlock Text="{local:Loc Sort}" VerticalAlignment="Center" Margin="20,0,0,0" />
<ComboBox x:Name="SortBox" Width="100" SelectedIndex="0" SelectionChanged="Sort_Changed">
Expand All @@ -77,20 +96,26 @@
<TextBlock x:Name="StatusText" Margin="24,0,0,0" VerticalAlignment="Center" Foreground="#40566C" />
</StackPanel>

<WrapPanel Grid.Row="2" Margin="0,0,0,12">
<Button Tag="all" Content="{local:Loc QuickAll}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="system" Content="{local:Loc QuickSystem}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="crash" Content="{local:Loc QuickCrash}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="disk" Content="{local:Loc QuickDisk}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="ntfs" Content="{local:Loc QuickNtfs}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="usb" Content="{local:Loc QuickUsb}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="device" Content="{local:Loc QuickDevice}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="driver" Content="{local:Loc QuickDriver}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="whea" Content="{local:Loc QuickWhea}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="network" Content="{local:Loc QuickNetwork}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="update" Content="{local:Loc QuickUpdate}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="power" Content="{local:Loc QuickPower}" Click="Quick_Click" Margin="0,0,6,6" />
</WrapPanel>
<StackPanel Grid.Row="2" Margin="0,0,0,12">
<WrapPanel x:Name="QuickFilterPanel">
<Button Tag="all" Content="{local:Loc QuickAll}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="system" Content="{local:Loc QuickSystem}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="crash" Content="{local:Loc QuickCrash}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="disk" Content="{local:Loc QuickDisk}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="ntfs" Content="{local:Loc QuickNtfs}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="usb" Content="{local:Loc QuickUsb}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="device" Content="{local:Loc QuickDevice}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="driver" Content="{local:Loc QuickDriver}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="whea" Content="{local:Loc QuickWhea}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="network" Content="{local:Loc QuickNetwork}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="update" Content="{local:Loc QuickUpdate}" Click="Quick_Click" Margin="0,0,6,6" />
<Button Tag="power" Content="{local:Loc QuickPower}" Click="Quick_Click" Margin="0,0,6,6" />
</WrapPanel>
<Border Background="#E5F1FB" BorderBrush="#8AB8DA" BorderThickness="1" CornerRadius="3" Padding="8,5">
<TextBlock x:Name="ActiveFiltersText" Foreground="#003B66" TextWrapping="Wrap"
AutomationProperties.LiveSetting="Polite" />
</Border>
</StackPanel>

<DataGrid x:Name="EventsGrid" Grid.Row="3" IsReadOnly="True" AutoGenerateColumns="False"
EnableRowVirtualization="True" EnableColumnVirtualization="True"
Expand Down
75 changes: 74 additions & 1 deletion MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ internal MainWindow(StartupOptions? options = null)
options ??= new();
_eventFile = options.EventFile;
_providerFilter = options.Provider;
_quickQuery = options.Quick;
if (options.From is { } from && options.To is { } to)
{
FromDate.SelectedDate = from;
Expand Down Expand Up @@ -80,19 +79,23 @@ internal MainWindow(StartupOptions? options = null)
if (!options.HasTimeRange)
TimeBox.SelectedIndex = TimeBox.Items.Count - 1;
}
_quickQuery = options.Quick;
UpdateFilterVisuals();
if (options.AutoRun)
Loaded += (_, _) => Dispatcher.BeginInvoke(() => _ = RunQueryAsync(_quickQuery is null ? null : EventQuery.QuickQueries[_quickQuery]));
}

private async void Search_Click(object sender, RoutedEventArgs e)
{
_quickQuery = null;
UpdateFilterVisuals();
await RunQueryAsync(null);
}

private async void Quick_Click(object sender, RoutedEventArgs e)
{
_quickQuery = (string)((Button)sender).Tag;
UpdateFilterVisuals();
await RunQueryAsync(EventQuery.QuickQueries[_quickQuery]);
}

Expand Down Expand Up @@ -228,6 +231,7 @@ private async void Window_Drop(object sender, DragEventArgs e)
Title = $"EventFast — {Path.GetFileName(_eventFile)}";
SystemBox.IsEnabled = ApplicationBox.IsEnabled = false;
TimeBox.SelectedIndex = TimeBox.Items.Count - 1;
UpdateFilterVisuals();
await RunQueryAsync(null);
}

Expand Down Expand Up @@ -350,6 +354,7 @@ private void Sort_Changed(object sender, SelectionChangedEventArgs e)
return;

ApplySort();
UpdateFilterVisuals();
}

private void ApplySort()
Expand Down Expand Up @@ -443,6 +448,73 @@ private void Time_Changed(object sender, SelectionChangedEventArgs e)
{
if (CustomTimePanel is not null && TimeBox.SelectedItem is ComboBoxItem item)
CustomTimePanel.Visibility = item.Tag.ToString() == "custom" ? Visibility.Visible : Visibility.Collapsed;
UpdateFilterVisuals();
}

private void Filter_Changed(object sender, RoutedEventArgs e) => UpdateFilterVisuals();

private void ManualFilter_Changed(object sender, RoutedEventArgs e)
{
UpdateFilterVisuals();
}

private void UpdateFilterVisuals()
{
if (ActiveFiltersText is null || SearchBox is null || TimeBox.SelectedItem is not ComboBoxItem timeItem ||
LevelBox.SelectedItem is not ComboBoxItem levelItem || SortBox.SelectedItem is not ComboBoxItem sortItem)
return;

var quick = _quickQuery is not null && EventQuery.QuickQueries.TryGetValue(_quickQuery, out var selectedQuick)
? selectedQuick
: null;
var criteria = quick is null ? EventQuery.Parse(SearchBox.Text, 0, TimeSpan.Zero, _providerFilter) : null;
var channelsOverridden = quick?.Channels is { Length: > 0 };
var channelsEditable = _eventFile is null && !channelsOverridden;
SystemBox.IsEnabled = ApplicationBox.IsEnabled = channelsEditable;
SetFilterActive(SearchBox, criteria?.Keyword is not null || criteria?.EventId is not null);
SetFilterActive(TimeBox, timeItem.Tag.ToString() != "24");
var custom = timeItem.Tag.ToString() == "custom";
SetFilterActive(FromDate, custom);
SetFilterActive(ToDate, custom);
SetFilterActive(LevelBox, levelItem.Tag.ToString() != "3");
SetFilterActive(SystemBox, channelsEditable && SystemBox.IsChecked == true);
SetFilterActive(ApplicationBox, channelsEditable && ApplicationBox.IsChecked == true);
SetFilterActive(SortBox, sortItem.Tag.ToString() != "default");
SetFilterActive(IncludeXmlBox, IncludeXmlBox.IsChecked == true);
foreach (var button in QuickFilterPanel.Children.OfType<Button>())
SetFilterActive(button, button.Tag.ToString() == _quickQuery, quickButton: true);

var parts = new List<string>();
if (quick is not null)
parts.Add(Localization.Text(quick.Name));
if (criteria?.Keyword is { } keyword)
parts.Add(Localization.Format("FilterKeyword", keyword));
if (criteria?.EventId is { } eventId)
parts.Add($"{Localization.Text("EventId")}: {eventId}");
if (criteria?.Providers is { Count: > 0 })
parts.Add(Localization.Format("FilterProvider", string.Join(", ", criteria.Providers)));
parts.Add(timeItem.Content.ToString()!);
if (custom && FromDate.SelectedDate is { } from && ToDate.SelectedDate is { } to)
parts.Add($"{from:yyyy-MM-dd} – {to:yyyy-MM-dd}");
parts.Add(levelItem.Content.ToString()!);
var channels = _eventFile is not null ? [Path.GetFileName(_eventFile)] :
quick?.Channels is { Length: > 0 } ? quick.Channels :
new[] { SystemBox.IsChecked == true ? "System" : null, ApplicationBox.IsChecked == true ? "Application" : null }
.OfType<string>().ToArray();
parts.Add(Localization.Format("FilterChannels", string.Join(" + ", channels)));
if (sortItem.Tag.ToString() != "default")
parts.Add(Localization.Format("FilterSort", sortItem.Content));
if (IncludeXmlBox.IsChecked == true)
parts.Add(IncludeXmlBox.Content.ToString()!);
ActiveFiltersText.Text = Localization.Format("ActiveFilters", string.Join(" · ", parts));
}

private void SetFilterActive(Control control, bool active, bool quickButton = false)
{
if (active)
control.Style = (Style)FindResource(quickButton ? "ActiveQuickButton" : "ActiveFilterControl");
else
control.ClearValue(StyleProperty);
}

private void Language_Changed(object sender, SelectionChangedEventArgs e)
Expand Down Expand Up @@ -496,6 +568,7 @@ internal void ApplyLanguage(string language, bool persist = true)
}
StatusText.ToolTip = null;
StatusText.Text = _operationStatus?.Invoke() ?? Localization.Text("LanguageChanged");
UpdateFilterVisuals();
}

private void EventsGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand Down
Loading
Loading