Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<UserControl x:Class="QuickLook.Plugin.CsvViewer.Controls.SearchPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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"
d:DesignHeight="35"
d:DesignWidth="300"
mc:Ignorable="d">
<Border Margin="0,-1,16,0"
Padding="2"
HorizontalAlignment="Right"
VerticalAlignment="Top"
Background="{DynamicResource WindowBackground}"
BorderBrush="#102E2E3E"
BorderThickness="1"
CornerRadius="4"
Cursor="Arrow">
<StackPanel Orientation="Horizontal">
<TextBox Name="searchTextBox"
Width="150"
Height="29"
Padding="4,5,0,0"
FocusVisualStyle="{x:Null}"
Focusable="True"
KeyDown="SearchTextBox_KeyDown"
TextChanged="SearchTextBox_TextChanged" />
<TextBlock Name="matchCountText"
Width="50"
Margin="4,0,0,0"
VerticalAlignment="Center"
FontSize="11"
Foreground="{DynamicResource WindowTextForeground}"
Text="" />
<Button Width="24"
Height="24"
Margin="3,3,0,3"
Padding="0"
Click="FindPrevious_Click"
ToolTip="Find Previous (Shift+Enter)">
<!-- ChevronUp -->
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"
FontFamily="{DynamicResource SymbolThemeFontFamily}"
FontSize="12"
Text="&#xe70e;" />
</Button>
<Button Width="24"
Height="24"
Margin="3"
Padding="0"
Click="FindNext_Click"
ToolTip="Find Next (Enter)">
<!-- ChevronDown -->
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"
FontFamily="{DynamicResource SymbolThemeFontFamily}"
FontSize="12"
Text="&#xe70d;" />
</Button>
<CheckBox Name="matchCaseCheckBox"
Margin="3,0"
VerticalAlignment="Center"
Checked="MatchCase_Changed"
Content="Match case"
Unchecked="MatchCase_Changed" />
<Button Width="16"
Height="16"
Padding="0"
HorizontalAlignment="Right"
VerticalAlignment="Top"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Click="CloseSearch_Click"
Focusable="False"
ToolTip="Close (Escape)">
<!-- CalculatorMultiply -->
<TextBlock HorizontalAlignment="Center"
VerticalAlignment="Center"
FontFamily="{DynamicResource SymbolThemeFontFamily}"
FontSize="10"
Text="&#xe947;" />
</Button>
</StackPanel>
</Border>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// Copyright © 2017-2025 QL-Win Contributors
//
// This file is part of QuickLook program.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace QuickLook.Plugin.CsvViewer.Controls;

public partial class SearchPanel : UserControl
{
public event EventHandler<SearchEventArgs> SearchRequested;
public event EventHandler<NavigateEventArgs> NavigateRequested;
public event EventHandler CloseRequested;

public SearchPanel()
{
InitializeComponent();
}

public string SearchText => searchTextBox.Text;
public bool MatchCase => matchCaseCheckBox.IsChecked == true;

public new void Focus()
{
searchTextBox.Focus();
searchTextBox.SelectAll();
}

public void UpdateMatchCount(int totalCount, int currentIndex)
{
if (totalCount == 0)
{
matchCountText.Text = string.IsNullOrEmpty(searchTextBox.Text) ? "" : "0/0";
}
else
{
matchCountText.Text = $"{currentIndex + 1}/{totalCount}";
}
}

private void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
SearchRequested?.Invoke(this, new SearchEventArgs(searchTextBox.Text, MatchCase));
}

private void SearchTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
if (Keyboard.Modifiers == ModifierKeys.Shift)
{
FindPrevious_Click(sender, e);
}
else
{
FindNext_Click(sender, e);
}
e.Handled = true;
}
else if (e.Key == Key.Escape)
{
CloseSearch_Click(sender, e);
e.Handled = true;
}
}

private void FindPrevious_Click(object sender, RoutedEventArgs e)
{
NavigateRequested?.Invoke(this, new NavigateEventArgs(false));
}

private void FindNext_Click(object sender, RoutedEventArgs e)
{
NavigateRequested?.Invoke(this, new NavigateEventArgs(true));
}

private void MatchCase_Changed(object sender, RoutedEventArgs e)
{
SearchRequested?.Invoke(this, new SearchEventArgs(searchTextBox.Text, MatchCase));
}

private void CloseSearch_Click(object sender, RoutedEventArgs e)
{
CloseRequested?.Invoke(this, EventArgs.Empty);
}
}

public class SearchEventArgs : EventArgs
{
public string SearchText { get; }
public bool MatchCase { get; }

public SearchEventArgs(string searchText, bool matchCase)
{
SearchText = searchText;
MatchCase = matchCase;
}
}

public class NavigateEventArgs : EventArgs
{
public bool Forward { get; }

public NavigateEventArgs(bool forward)
{
Forward = forward;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<UserControl x:Class="QuickLook.Plugin.CsvViewer.CsvViewerPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:QuickLook.Plugin.CsvViewer.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:QuickLook.Plugin.CsvViewer"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="csvViewer"
d:DesignHeight="300"
d:DesignWidth="300"
Focusable="True"
mc:Ignorable="d">
<UserControl.Resources>
<ResourceDictionary>
Expand All @@ -30,5 +32,7 @@
ItemsSource="{Binding Path=Rows, ElementName=csvViewer}"
RowBackground="#00FFFFFF"
VerticalGridLinesBrush="#19000000" />
<controls:SearchPanel x:Name="searchPanel"
Visibility="Collapsed" />
</Grid>
</UserControl>
Loading