mirror of
https://github.com/microsoft/PowerToys
synced 2025-09-01 23:15:18 +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
|
list.Add(new ContextMenuResult
|
||||||
{
|
{
|
||||||
AcceleratorKey = Key.Enter,
|
AcceleratorKey = Key.Enter,
|
||||||
|
AcceleratorModifiers = ModifierKeys.Control,
|
||||||
Action = _ => TryToOpenInRegistryEditor(entry),
|
Action = _ => TryToOpenInRegistryEditor(entry),
|
||||||
FontFamily = "Segoe MDL2 Assets",
|
FontFamily = "Segoe MDL2 Assets",
|
||||||
Glyph = "\xE8A7", // E8A7 => Symbol: OpenInNewWindow
|
Glyph = "\xE8A7", // E8A7 => Symbol: OpenInNewWindow
|
||||||
PluginName = assemblyName,
|
PluginName = assemblyName,
|
||||||
Title = $"{Resources.OpenKeyInRegistryEditor} (Enter)",
|
Title = $"{Resources.OpenKeyInRegistryEditor} (Ctrl+Enter)",
|
||||||
});
|
});
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
|
@@ -9,6 +9,7 @@ using System.Diagnostics;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.ServiceProcess;
|
using System.ServiceProcess;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.PowerToys.Run.Plugin.Service.Properties;
|
using Microsoft.PowerToys.Run.Plugin.Service.Properties;
|
||||||
using Wox.Infrastructure;
|
using Wox.Infrastructure;
|
||||||
using Wox.Plugin;
|
using Wox.Plugin;
|
||||||
@@ -18,18 +19,41 @@ namespace Microsoft.PowerToys.Run.Plugin.Service.Helpers
|
|||||||
{
|
{
|
||||||
public static class ServiceHelper
|
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();
|
var services = ServiceController.GetServices();
|
||||||
|
|
||||||
return services
|
return services
|
||||||
.Where(s => s.DisplayName.StartsWith(search, StringComparison.OrdinalIgnoreCase) || s.ServiceName.StartsWith(search, StringComparison.OrdinalIgnoreCase))
|
.Where(s => s.DisplayName.StartsWith(search, StringComparison.OrdinalIgnoreCase) || s.ServiceName.StartsWith(search, StringComparison.OrdinalIgnoreCase))
|
||||||
.Select(s => new Result
|
.Select(s =>
|
||||||
{
|
{
|
||||||
Title = GetResultTitle(s),
|
ServiceResult serviceResult = new ServiceResult(s);
|
||||||
SubTitle = GetResultSubTitle(s),
|
Func<ActionContext, bool> serviceAction;
|
||||||
IcoPath = icoPath,
|
if (serviceResult.IsRunning)
|
||||||
ContextData = new ServiceResult(s),
|
{
|
||||||
|
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",
|
Glyph = "\xE71A",
|
||||||
FontFamily = "Segoe MDL2 Assets",
|
FontFamily = "Segoe MDL2 Assets",
|
||||||
AcceleratorKey = Key.Enter,
|
AcceleratorKey = Key.Enter,
|
||||||
|
AcceleratorModifiers = ModifierKeys.Control,
|
||||||
Action = _ =>
|
Action = _ =>
|
||||||
{
|
{
|
||||||
Task.Run(() => ServiceHelper.ChangeStatus(serviceResult, Action.Stop, _context.API));
|
Task.Run(() => ServiceHelper.ChangeStatus(serviceResult, Action.Stop, _context.API));
|
||||||
@@ -84,6 +85,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Service
|
|||||||
Glyph = "\xEDB5",
|
Glyph = "\xEDB5",
|
||||||
FontFamily = "Segoe MDL2 Assets",
|
FontFamily = "Segoe MDL2 Assets",
|
||||||
AcceleratorKey = Key.Enter,
|
AcceleratorKey = Key.Enter,
|
||||||
|
AcceleratorModifiers = ModifierKeys.Control,
|
||||||
Action = _ =>
|
Action = _ =>
|
||||||
{
|
{
|
||||||
Task.Run(() => ServiceHelper.ChangeStatus(serviceResult, Action.Start, _context.API));
|
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)
|
public List<Result> Query(Query query)
|
||||||
{
|
{
|
||||||
var search = query?.Search ?? string.Empty;
|
var search = query?.Search ?? string.Empty;
|
||||||
return ServiceHelper.Search(search, _icoPath).ToList();
|
return ServiceHelper.Search(search, _icoPath, _context).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetTranslatedPluginTitle()
|
public string GetTranslatedPluginTitle()
|
||||||
|
@@ -58,14 +58,25 @@ namespace PowerLauncher
|
|||||||
if (listView.SelectedItem != null)
|
if (listView.SelectedItem != null)
|
||||||
{
|
{
|
||||||
ListBoxItem listBoxItem = (ListBoxItem)listView.ItemContainerGenerator.ContainerFromItem(listView.SelectedItem);
|
ListBoxItem listBoxItem = (ListBoxItem)listView.ItemContainerGenerator.ContainerFromItem(listView.SelectedItem);
|
||||||
ContentPresenter contentPresenter = FindVisualChild<ContentPresenter>(listBoxItem);
|
if (listBoxItem != null)
|
||||||
DataTemplate dataTemplate = contentPresenter.ContentTemplate;
|
{
|
||||||
Button button = (Button)dataTemplate.FindName("commandButton", contentPresenter);
|
ContentPresenter contentPresenter = FindVisualChild<ContentPresenter>(listBoxItem);
|
||||||
ToolTip tooltip = button.ToolTip as ToolTip;
|
DataTemplate dataTemplate = contentPresenter.ContentTemplate;
|
||||||
tooltip.PlacementTarget = button;
|
Button button = (Button)dataTemplate.FindName("commandButton", contentPresenter);
|
||||||
tooltip.Placement = System.Windows.Controls.Primitives.PlacementMode.Right;
|
ToolTip tooltip = button.ToolTip as ToolTip;
|
||||||
tooltip.PlacementRectangle = new Rect(0, button.Height, 0, 0);
|
tooltip.PlacementTarget = button;
|
||||||
tooltip.IsOpen = true;
|
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