CommandPalette use FuzzyPanel, Focus search textbox
This commit is contained in:
@@ -12,9 +12,9 @@
|
||||
</UserControl.Styles>
|
||||
<Grid RowDefinitions="Auto,*">
|
||||
<TextBox
|
||||
Focusable="True"
|
||||
KeyDown="Search_OnKeyDown"
|
||||
Text="{Binding SearchText, Mode=TwoWay}" />
|
||||
Text="{Binding SearchText, Mode=TwoWay}"
|
||||
x:Name="SearchTextBox" />
|
||||
<ListBox
|
||||
Classes="CommandPalette"
|
||||
Grid.Row="1"
|
||||
@@ -29,4 +29,4 @@
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
</UserControl>
|
||||
@@ -1,7 +1,9 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using FileTime.App.FrequencyNavigation.ViewModels;
|
||||
using Avalonia.Threading;
|
||||
using FileTime.App.CommandPalette.ViewModels;
|
||||
|
||||
namespace FileTime.GuiApp.Views;
|
||||
|
||||
@@ -10,17 +12,22 @@ public partial class CommandPalette : UserControl
|
||||
public CommandPalette()
|
||||
{
|
||||
InitializeComponent();
|
||||
PropertyChanged += CommandPalette_PropertyChanged;
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
private async void CommandPalette_PropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
if (e.Property.Name == nameof(IsVisible) && IsVisible)
|
||||
{
|
||||
await Task.Delay(10);
|
||||
SearchTextBox.Focus();
|
||||
}
|
||||
}
|
||||
|
||||
private void Search_OnKeyDown(object? sender, KeyEventArgs e)
|
||||
{
|
||||
if (DataContext is not IFrequencyNavigationViewModel viewModel) return;
|
||||
|
||||
if (DataContext is not ICommandPaletteViewModel viewModel) return;
|
||||
|
||||
if (e.Key == Key.Escape)
|
||||
{
|
||||
viewModel.Close();
|
||||
@@ -30,4 +37,9 @@ public partial class CommandPalette : UserControl
|
||||
viewModel.HandleKeyDown(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void Test()
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,27 @@
|
||||
<UserControl
|
||||
Background="{DynamicResource ContainerBackgroundColor}"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
mc:Ignorable="d"
|
||||
x:Class="FileTime.GuiApp.Views.FrequencyNavigation"
|
||||
x:CompileBindings="True"
|
||||
x:DataType="viewModels:IFrequencyNavigationViewModel"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
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:viewModels="clr-namespace:FileTime.App.FrequencyNavigation.ViewModels;assembly=FileTime.App.FrequencyNavigation.Abstractions"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
x:CompileBindings="True"
|
||||
x:DataType="viewModels:IFrequencyNavigationViewModel"
|
||||
Background="{DynamicResource ContainerBackgroundColor}"
|
||||
mc:Ignorable="d">
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<UserControl.Styles>
|
||||
<StyleInclude Source="avares://FileTime.GuiApp/Resources/Styles.axaml" />
|
||||
</UserControl.Styles>
|
||||
<Grid RowDefinitions="Auto,*">
|
||||
<TextBox
|
||||
Focusable="True"
|
||||
KeyDown="Search_OnKeyDown"
|
||||
Text="{Binding SearchText, Mode=TwoWay}" />
|
||||
Text="{Binding SearchText, Mode=TwoWay}"
|
||||
x:Name="SearchTextBox" />
|
||||
<ListBox
|
||||
Grid.Row="1"
|
||||
Classes="CommandPalette"
|
||||
Grid.Row="1"
|
||||
ItemsSource="{Binding FilteredMatches}"
|
||||
SelectedItem="{Binding SelectedItem}">
|
||||
<ListBox.ItemTemplate>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using FileTime.App.FrequencyNavigation.ViewModels;
|
||||
|
||||
namespace FileTime.GuiApp.Views;
|
||||
@@ -10,11 +10,16 @@ public partial class FrequencyNavigation : UserControl
|
||||
public FrequencyNavigation()
|
||||
{
|
||||
InitializeComponent();
|
||||
PropertyChanged += FrequencyNavigation_PropertyChanged;
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
private async void FrequencyNavigation_PropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
AvaloniaXamlLoader.Load(this);
|
||||
if (e.Property.Name == nameof(IsVisible) && IsVisible)
|
||||
{
|
||||
await Task.Delay(100);
|
||||
SearchTextBox.Focus();
|
||||
}
|
||||
}
|
||||
|
||||
private void Search_OnKeyDown(object? sender, KeyEventArgs e)
|
||||
|
||||
@@ -672,7 +672,7 @@
|
||||
IsVisible="{Binding ShowWindow^, FallbackValue=False}"
|
||||
VerticalAlignment="Stretch">
|
||||
<Grid Margin="100">
|
||||
<local:FrequencyNavigation />
|
||||
<local:FrequencyNavigation IsVisible="{Binding ShowWindow^, FallbackValue=False}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
@@ -683,7 +683,7 @@
|
||||
IsVisible="{Binding ShowWindow^, FallbackValue=False}"
|
||||
VerticalAlignment="Stretch">
|
||||
<Grid Margin="100">
|
||||
<local:CommandPalette />
|
||||
<local:CommandPalette IsVisible="{Binding ShowWindow^, FallbackValue=False}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
Reference in New Issue
Block a user