From 553922bef6788014d99ad7ecf1f7651937443aa4 Mon Sep 17 00:00:00 2001 From: Divyansh Date: Mon, 6 Apr 2020 16:08:31 -0700 Subject: [PATCH] Added query submitted event to handle default action on clicking a list view item --- .../PowerLauncher.UI/LauncherControl.xaml | 4 ++-- .../launcher/PowerLauncher/MainWindow.xaml.cs | 20 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/modules/launcher/PowerLauncher.UI/LauncherControl.xaml b/src/modules/launcher/PowerLauncher.UI/LauncherControl.xaml index ee195d12f3..3e5ca01fde 100644 --- a/src/modules/launcher/PowerLauncher.UI/LauncherControl.xaml +++ b/src/modules/launcher/PowerLauncher.UI/LauncherControl.xaml @@ -422,7 +422,7 @@ - + @@ -442,7 +442,7 @@ - + diff --git a/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs b/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs index bc2802c403..340ee0297f 100644 --- a/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs +++ b/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs @@ -20,6 +20,7 @@ using Microsoft.Toolkit.Wpf.UI.XamlHost; using Windows.UI.Xaml.Controls; using System.Diagnostics; using Wox.Plugin; +using Windows.UI.Xaml.Input; namespace PowerLauncher { @@ -260,9 +261,9 @@ namespace PowerLauncher _launcher = (PowerLauncher.UI.LauncherControl)host.Child; _launcher.DataContext = _viewModel; _launcher.SearchBox.TextChanged += QueryTextBox_TextChanged; - _launcher.SearchBox.SuggestionChosen += SearchBox_SuggestionChosen; + _launcher.SearchBox.SuggestionChosen += AutoSuggestBox_SuggestionChosen; + _launcher.SearchBox.QuerySubmitted += AutoSuggestBox_QuerySubmitted; _launcher.SearchBox.Focus(Windows.UI.Xaml.FocusState.Programmatic); - _viewModel.PropertyChanged += (o, e) => { if (e.PropertyName == nameof(MainViewModel.MainWindowVisibility)) @@ -282,12 +283,21 @@ namespace PowerLauncher }; } - private void SearchBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args) + private void AutoSuggestBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args) { - if (args != null) + if(args != null && args.SelectedItem != null) { ResultViewModel result = (ResultViewModel)args.SelectedItem; - _ = result.Result.Action != null && result.Result.Action(new ActionContext{}); + sender.Text = result.Result.Title; + } + } + + private void AutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args) + { + if (args != null && args.ChosenSuggestion != null) + { + ResultViewModel result = (ResultViewModel)args.ChosenSuggestion; + _ = result.Result.Action != null && result.Result.Action(new ActionContext { }); } }