mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
Fix for issue 3886 (#6585)
This commit is contained in:
@@ -98,7 +98,7 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
<Window.InputBindings>
|
<Window.InputBindings>
|
||||||
<KeyBinding Key="Escape" Command="{Binding EscCommand}" />
|
<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}" />
|
<KeyBinding Modifiers="Alt" Key="F4" Command="{Binding IgnoreCommand}" />
|
||||||
</Window.InputBindings>
|
</Window.InputBindings>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ namespace PowerLauncher
|
|||||||
if (result is ResultViewModel resultVM)
|
if (result is ResultViewModel resultVM)
|
||||||
{
|
{
|
||||||
_viewModel.Results.SelectedItem = 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()
|
private void InitializeKeyCommands()
|
||||||
{
|
{
|
||||||
IgnoreCommand = new RelayCommand(_ => { });
|
IgnoreCommand = new RelayCommand(_ => { });
|
||||||
@@ -181,49 +235,14 @@ namespace PowerLauncher.ViewModel
|
|||||||
Process.Start("https://aka.ms/PowerToys/");
|
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())
|
OpenResultWithMouseCommand = new RelayCommand(index =>
|
||||||
{
|
{
|
||||||
_userSelectedRecord.Add(result);
|
OpenResultsEvent(index, true);
|
||||||
_history.Add(result.OriginQuery.RawQuery);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SelectedResults = Results;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
LoadContextMenuCommand = new RelayCommand(_ =>
|
LoadContextMenuCommand = new RelayCommand(_ =>
|
||||||
@@ -391,7 +410,9 @@ namespace PowerLauncher.ViewModel
|
|||||||
|
|
||||||
public ICommand LoadHistoryCommand { get; set; }
|
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; }
|
public ICommand ClearQueryCommand { get; set; }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user