mirror of
https://github.com/microsoft/PowerToys
synced 2025-08-31 06:25:20 +00:00
[PT Run] Fix some keyboard issues on plugin (#13490)
* Don't use enter for accelerator keys in results Enter is already used to select commands in the context menu in the result entries. * Don't crash when trying to show a tooltip * Clear hanging tooltips when keyboard navigating * Starting/stopping service on Enter
This commit is contained in:
@@ -75,11 +75,12 @@ namespace Microsoft.PowerToys.Run.Plugin.Registry.Helper
|
||||
list.Add(new ContextMenuResult
|
||||
{
|
||||
AcceleratorKey = Key.Enter,
|
||||
AcceleratorModifiers = ModifierKeys.Control,
|
||||
Action = _ => TryToOpenInRegistryEditor(entry),
|
||||
FontFamily = "Segoe MDL2 Assets",
|
||||
Glyph = "\xE8A7", // E8A7 => Symbol: OpenInNewWindow
|
||||
PluginName = assemblyName,
|
||||
Title = $"{Resources.OpenKeyInRegistryEditor} (Enter)",
|
||||
Title = $"{Resources.OpenKeyInRegistryEditor} (Ctrl+Enter)",
|
||||
});
|
||||
|
||||
return list;
|
||||
|
@@ -9,6 +9,7 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.ServiceProcess;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.PowerToys.Run.Plugin.Service.Properties;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Plugin;
|
||||
@@ -18,18 +19,41 @@ namespace Microsoft.PowerToys.Run.Plugin.Service.Helpers
|
||||
{
|
||||
public static class ServiceHelper
|
||||
{
|
||||
public static IEnumerable<Result> Search(string search, string icoPath)
|
||||
public static IEnumerable<Result> Search(string search, string icoPath, PluginInitContext context)
|
||||
{
|
||||
var services = ServiceController.GetServices();
|
||||
|
||||
return services
|
||||
.Where(s => s.DisplayName.StartsWith(search, StringComparison.OrdinalIgnoreCase) || s.ServiceName.StartsWith(search, StringComparison.OrdinalIgnoreCase))
|
||||
.Select(s => new Result
|
||||
.Select(s =>
|
||||
{
|
||||
Title = GetResultTitle(s),
|
||||
SubTitle = GetResultSubTitle(s),
|
||||
IcoPath = icoPath,
|
||||
ContextData = new ServiceResult(s),
|
||||
ServiceResult serviceResult = new ServiceResult(s);
|
||||
Func<ActionContext, bool> serviceAction;
|
||||
if (serviceResult.IsRunning)
|
||||
{
|
||||
serviceAction = _ =>
|
||||
{
|
||||
Task.Run(() => ServiceHelper.ChangeStatus(serviceResult, Action.Stop, context.API));
|
||||
return true;
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
serviceAction = _ =>
|
||||
{
|
||||
Task.Run(() => ServiceHelper.ChangeStatus(serviceResult, Action.Start, context.API));
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
return new Result
|
||||
{
|
||||
Title = ServiceHelper.GetResultTitle(s),
|
||||
SubTitle = ServiceHelper.GetResultSubTitle(s),
|
||||
IcoPath = icoPath,
|
||||
ContextData = serviceResult,
|
||||
Action = serviceAction,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -51,6 +51,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Service
|
||||
Glyph = "\xE71A",
|
||||
FontFamily = "Segoe MDL2 Assets",
|
||||
AcceleratorKey = Key.Enter,
|
||||
AcceleratorModifiers = ModifierKeys.Control,
|
||||
Action = _ =>
|
||||
{
|
||||
Task.Run(() => ServiceHelper.ChangeStatus(serviceResult, Action.Stop, _context.API));
|
||||
@@ -84,6 +85,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Service
|
||||
Glyph = "\xEDB5",
|
||||
FontFamily = "Segoe MDL2 Assets",
|
||||
AcceleratorKey = Key.Enter,
|
||||
AcceleratorModifiers = ModifierKeys.Control,
|
||||
Action = _ =>
|
||||
{
|
||||
Task.Run(() => ServiceHelper.ChangeStatus(serviceResult, Action.Start, _context.API));
|
||||
@@ -114,7 +116,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Service
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
var search = query?.Search ?? string.Empty;
|
||||
return ServiceHelper.Search(search, _icoPath).ToList();
|
||||
return ServiceHelper.Search(search, _icoPath, _context).ToList();
|
||||
}
|
||||
|
||||
public string GetTranslatedPluginTitle()
|
||||
|
@@ -58,14 +58,25 @@ namespace PowerLauncher
|
||||
if (listView.SelectedItem != null)
|
||||
{
|
||||
ListBoxItem listBoxItem = (ListBoxItem)listView.ItemContainerGenerator.ContainerFromItem(listView.SelectedItem);
|
||||
ContentPresenter contentPresenter = FindVisualChild<ContentPresenter>(listBoxItem);
|
||||
DataTemplate dataTemplate = contentPresenter.ContentTemplate;
|
||||
Button button = (Button)dataTemplate.FindName("commandButton", contentPresenter);
|
||||
ToolTip tooltip = button.ToolTip as ToolTip;
|
||||
tooltip.PlacementTarget = button;
|
||||
tooltip.Placement = System.Windows.Controls.Primitives.PlacementMode.Right;
|
||||
tooltip.PlacementRectangle = new Rect(0, button.Height, 0, 0);
|
||||
tooltip.IsOpen = true;
|
||||
if (listBoxItem != null)
|
||||
{
|
||||
ContentPresenter contentPresenter = FindVisualChild<ContentPresenter>(listBoxItem);
|
||||
DataTemplate dataTemplate = contentPresenter.ContentTemplate;
|
||||
Button button = (Button)dataTemplate.FindName("commandButton", contentPresenter);
|
||||
ToolTip tooltip = button.ToolTip as ToolTip;
|
||||
tooltip.PlacementTarget = button;
|
||||
tooltip.Placement = System.Windows.Controls.Primitives.PlacementMode.Right;
|
||||
tooltip.PlacementRectangle = new Rect(0, button.Height, 0, 0);
|
||||
tooltip.IsOpen = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
HideCurrentToolTip();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
HideCurrentToolTip();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user