mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-18 14:41:21 +08:00
Fix for issue 3886 (#6585)
This commit is contained in:
parent
7328aa7df5
commit
25f93e8b94
@ -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>
|
||||
|
@ -110,7 +110,7 @@ namespace PowerLauncher
|
||||
if (result is ResultViewModel resultVM)
|
||||
{
|
||||
_viewModel.Results.SelectedItem = resultVM;
|
||||
_viewModel.OpenResultCommand.Execute(null);
|
||||
_viewModel.OpenResultWithMouseCommand.Execute(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user