Fix for issue 3886 (#6585)

This commit is contained in:
Arjun Balgovind 2020-09-14 13:12:02 -07:00 committed by GitHub
parent 7328aa7df5
commit 25f93e8b94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 44 deletions

View File

@ -98,7 +98,7 @@
</Grid>
<Window.InputBindings>
<KeyBinding Key="Escape" Command="{Binding EscCommand}" />
<KeyBinding Key="Enter" Command="{Binding OpenResultCommand}" />
<KeyBinding Key="Enter" Command="{Binding OpenResultWithKeyboardCommand}" />
<KeyBinding Modifiers="Alt" Key="F4" Command="{Binding IgnoreCommand}" />
</Window.InputBindings>
</Window>

View File

@ -110,7 +110,7 @@ namespace PowerLauncher
if (result is ResultViewModel resultVM)
{
_viewModel.Results.SelectedItem = resultVM;
_viewModel.OpenResultCommand.Execute(null);
_viewModel.OpenResultWithMouseCommand.Execute(null);
}
}
}

View File

@ -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; }