mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-30 00:46:20 +01:00
Compare commits
1 Commits
search-cle
...
leilzh/bgc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3cde0b2a68 |
@@ -8,7 +8,6 @@
|
||||
xmlns:cpcontrols="using:Microsoft.CmdPal.UI.Controls"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
x:Name="RootSearchBar"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<UserControl.Resources>
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Windows.Input;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using CommunityToolkit.WinUI;
|
||||
using Microsoft.CmdPal.Core.ViewModels;
|
||||
@@ -38,9 +36,6 @@ public sealed partial class SearchBar : UserControl,
|
||||
private string? _lastText;
|
||||
private string? _deletedSuggestion;
|
||||
|
||||
// An ICommand for clearing the search box, allowing the DeleteButton to invoke this logic via MVVM command binding.
|
||||
public ICommand ClearSearchCommand { get; }
|
||||
|
||||
public PageViewModel? CurrentPageViewModel
|
||||
{
|
||||
get => (PageViewModel?)GetValue(CurrentPageViewModelProperty);
|
||||
@@ -80,11 +75,6 @@ public sealed partial class SearchBar : UserControl,
|
||||
WeakReferenceMessenger.Default.Register<GoHomeMessage>(this);
|
||||
WeakReferenceMessenger.Default.Register<FocusSearchBoxMessage>(this);
|
||||
WeakReferenceMessenger.Default.Register<UpdateSuggestionMessage>(this);
|
||||
|
||||
// Attach a keydown event handler Clear Button within the FilterBox to trigger search clearing logic.
|
||||
FilterBox.AddHandler(Button.KeyDownEvent, new KeyEventHandler(DeleteButton_KeyDown), true);
|
||||
|
||||
ClearSearchCommand = new RelayCommand(() => ExecuteDeleteButtonAction());
|
||||
}
|
||||
|
||||
public void ClearSearch()
|
||||
@@ -102,36 +92,6 @@ public sealed partial class SearchBar : UserControl,
|
||||
}));
|
||||
}
|
||||
|
||||
private Button? GetDeleteButton()
|
||||
{
|
||||
// Try to find the DeleteButton in the FilterBox's template
|
||||
return FilterBox?.FindName("DeleteButton") as Button;
|
||||
}
|
||||
|
||||
private bool IsDeleteButtonFocused()
|
||||
{
|
||||
var deleteButton = GetDeleteButton();
|
||||
var focusedElement = FocusManager.GetFocusedElement() as Button;
|
||||
return deleteButton != null && focusedElement == deleteButton;
|
||||
}
|
||||
|
||||
public void DeleteButton_KeyDown(object sender, KeyRoutedEventArgs e)
|
||||
{
|
||||
if (IsDeleteButtonFocused())
|
||||
{
|
||||
if (e.Key == VirtualKey.Enter)
|
||||
{
|
||||
ExecuteDeleteButtonAction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteDeleteButtonAction()
|
||||
{
|
||||
ClearSearch();
|
||||
FilterBox.Focus(Microsoft.UI.Xaml.FocusState.Programmatic);
|
||||
}
|
||||
|
||||
public void SelectSearch()
|
||||
{
|
||||
// TODO GH #239 switch back when using the new MD text block
|
||||
|
||||
@@ -434,7 +434,4 @@ Right-click to remove the key combination, thereby deactivating the shortcut.</v
|
||||
<data name="StatusMessagesButton.[using:Microsoft.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
|
||||
<value>Show status messages</value>
|
||||
</data>
|
||||
<data name="DeleteButton.AutomationProperties.Name" xml:space="preserve">
|
||||
<value>Clears the search box</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -14,11 +14,6 @@
|
||||
EmptyValue="Visible"
|
||||
NotEmptyValue="Collapsed" />
|
||||
|
||||
<converters:StringVisibilityConverter
|
||||
x:Key="StringVisibilityConverter"
|
||||
EmptyValue="Collapsed"
|
||||
NotEmptyValue="Visible" />
|
||||
|
||||
<Style x:Key="SearchTextBoxStyle" TargetType="TextBox">
|
||||
<Setter Property="Foreground" Value="{ThemeResource TextControlForeground}" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
@@ -171,21 +166,18 @@
|
||||
Visibility="{Binding Description, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ReverseStringVisibilityConverter}, Mode=OneWay}" />
|
||||
<Button
|
||||
x:Name="DeleteButton"
|
||||
x:Uid="DeleteButton"
|
||||
Grid.Column="2"
|
||||
Margin="0,0,8,0"
|
||||
Padding="4"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center"
|
||||
AutomationProperties.AccessibilityView="Content"
|
||||
AutomationProperties.AccessibilityView="Raw"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Command="{Binding ClearSearchCommand, ElementName=RootSearchBar}"
|
||||
CornerRadius="{TemplateBinding CornerRadius}"
|
||||
FontSize="{TemplateBinding FontSize}"
|
||||
IsTabStop="True"
|
||||
KeyDown="DeleteButton_KeyDown"
|
||||
IsTabStop="False"
|
||||
Style="{StaticResource DeleteButtonStyle}"
|
||||
Visibility="{Binding Text, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource StringVisibilityConverter}, Mode=OneWay}" />
|
||||
Visibility="Collapsed" />
|
||||
<TextBlock
|
||||
x:Name="DescriptionPresenter"
|
||||
Grid.Column="1"
|
||||
|
||||
Reference in New Issue
Block a user