diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Helper/ContextMenuHelper.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Helper/ContextMenuHelper.cs index 9572d6b677..a5c2409dfc 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Helper/ContextMenuHelper.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Registry/Helper/ContextMenuHelper.cs @@ -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; diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Service/Helpers/ServiceHelper.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Service/Helpers/ServiceHelper.cs index 3c3dd7be07..d4dcdcc9bc 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Service/Helpers/ServiceHelper.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Service/Helpers/ServiceHelper.cs @@ -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 Search(string search, string icoPath) + public static IEnumerable 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 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, + }; }); } diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Service/Main.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Service/Main.cs index 77400479aa..28d3db512a 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Service/Main.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.Service/Main.cs @@ -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 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() diff --git a/src/modules/launcher/PowerLauncher/ResultList.xaml.cs b/src/modules/launcher/PowerLauncher/ResultList.xaml.cs index 858b2b39c2..564890bbc9 100644 --- a/src/modules/launcher/PowerLauncher/ResultList.xaml.cs +++ b/src/modules/launcher/PowerLauncher/ResultList.xaml.cs @@ -58,14 +58,25 @@ namespace PowerLauncher if (listView.SelectedItem != null) { ListBoxItem listBoxItem = (ListBoxItem)listView.ItemContainerGenerator.ContainerFromItem(listView.SelectedItem); - ContentPresenter contentPresenter = FindVisualChild(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(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(); } }