From 25f93e8b94f3433f3aeedcf4d50cc4950817305d Mon Sep 17 00:00:00 2001 From: Arjun Balgovind <32061677+arjunbalgovind@users.noreply.github.com> Date: Mon, 14 Sep 2020 13:12:02 -0700 Subject: [PATCH] Fix for issue 3886 (#6585) --- .../launcher/PowerLauncher/MainWindow.xaml | 2 +- .../launcher/PowerLauncher/MainWindow.xaml.cs | 2 +- .../PowerLauncher/ViewModel/MainViewModel.cs | 105 +++++++++++------- 3 files changed, 65 insertions(+), 44 deletions(-) diff --git a/src/modules/launcher/PowerLauncher/MainWindow.xaml b/src/modules/launcher/PowerLauncher/MainWindow.xaml index 78f14c64eb..74f908974a 100644 --- a/src/modules/launcher/PowerLauncher/MainWindow.xaml +++ b/src/modules/launcher/PowerLauncher/MainWindow.xaml @@ -98,7 +98,7 @@ - + diff --git a/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs b/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs index ba18902ed6..a97cb6a4d8 100644 --- a/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs +++ b/src/modules/launcher/PowerLauncher/MainWindow.xaml.cs @@ -110,7 +110,7 @@ namespace PowerLauncher if (result is ResultViewModel resultVM) { _viewModel.Results.SelectedItem = resultVM; - _viewModel.OpenResultCommand.Execute(null); + _viewModel.OpenResultWithMouseCommand.Execute(null); } } } diff --git a/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs b/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs index 36130cd7e8..2b308d76bd 100644 --- a/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs +++ b/src/modules/launcher/PowerLauncher/ViewModel/MainViewModel.cs @@ -118,6 +118,60 @@ namespace PowerLauncher.ViewModel } } + private void OpenResultsEvent(object index, bool isMouseClick) + { + var results = SelectedResults; + + if (index != null) + { + results.SelectedIndex = int.Parse(index.ToString(), CultureInfo.InvariantCulture); + } + + if (results.SelectedItem != null) + { + bool executeResultRequired = false; + + if (isMouseClick) + { + executeResultRequired = true; + } + else + { + // If there is a context button selected fire the action for that button instead, and the main command will not be executed + executeResultRequired = !results.SelectedItem.ExecuteSelectedContextButton(); + } + + if (executeResultRequired) + { + var result = results.SelectedItem.Result; + + // SelectedItem returns null if selection is empty. + if (result != null && result.Action != null) + { + MainWindowVisibility = Visibility.Collapsed; + + Application.Current.Dispatcher.Invoke(() => + { + result.Action(new ActionContext + { + SpecialKeyState = KeyboardHelper.CheckModifiers(), + }); + }); + + if (SelectedIsFromQueryResults()) + { + _userSelectedRecord.Add(result); + _history.Add(result.OriginQuery.RawQuery); + } + else + { + SelectedResults = Results; + } + } + } + } + } + private void InitializeKeyCommands() { IgnoreCommand = new RelayCommand(_ => { }); @@ -181,49 +235,14 @@ namespace PowerLauncher.ViewModel Process.Start("https://aka.ms/PowerToys/"); }); - OpenResultCommand = new RelayCommand(index => + OpenResultWithKeyboardCommand = new RelayCommand(index => { - var results = SelectedResults; + OpenResultsEvent(index, false); + }); - if (index != null) - { - results.SelectedIndex = int.Parse(index.ToString(), CultureInfo.InvariantCulture); - } - - if (results.SelectedItem != null) - { - // If there is a context button selected fire the action for that button before the main command. - bool didExecuteContextButton = results.SelectedItem.ExecuteSelectedContextButton(); - - if (!didExecuteContextButton) - { - var result = results.SelectedItem.Result; - - // SelectedItem returns null if selection is empty. - if (result != null && result.Action != null) - { - MainWindowVisibility = Visibility.Collapsed; - - Application.Current.Dispatcher.Invoke(() => - { - result.Action(new ActionContext - { - SpecialKeyState = KeyboardHelper.CheckModifiers(), - }); - }); - - if (SelectedIsFromQueryResults()) - { - _userSelectedRecord.Add(result); - _history.Add(result.OriginQuery.RawQuery); - } - else - { - SelectedResults = Results; - } - } - } - } + OpenResultWithMouseCommand = new RelayCommand(index => + { + OpenResultsEvent(index, true); }); LoadContextMenuCommand = new RelayCommand(_ => @@ -391,7 +410,9 @@ namespace PowerLauncher.ViewModel public ICommand LoadHistoryCommand { get; set; } - public ICommand OpenResultCommand { get; set; } + public ICommand OpenResultWithKeyboardCommand { get; set; } + + public ICommand OpenResultWithMouseCommand { get; set; } public ICommand ClearQueryCommand { get; set; }