diff --git a/src/common/Common.UI/SettingsDeepLink.cs b/src/common/Common.UI/SettingsDeepLink.cs index 87cc631047..1a154f0a82 100644 --- a/src/common/Common.UI/SettingsDeepLink.cs +++ b/src/common/Common.UI/SettingsDeepLink.cs @@ -27,6 +27,7 @@ namespace Common.UI MeasureTool, PowerOCR, RegistryPreview, + CropAndLock, } private static string SettingsWindowNameToString(SettingsWindow value) @@ -65,6 +66,8 @@ namespace Common.UI return "PowerOCR"; case SettingsWindow.RegistryPreview: return "RegistryPreview"; + case SettingsWindow.CropAndLock: + return "CropAndLock"; default: { return string.Empty; diff --git a/src/common/interop/interop.cpp b/src/common/interop/interop.cpp index 77d896b398..aebf044f21 100644 --- a/src/common/interop/interop.cpp +++ b/src/common/interop/interop.cpp @@ -254,5 +254,13 @@ public static String ^ ShowHostsAdminSharedEvent() { return gcnew String(CommonSharedConstants::SHOW_HOSTS_ADMIN_EVENT); } + + static String ^ CropAndLockThumbnailEvent() { + return gcnew String(CommonSharedConstants::CROP_AND_LOCK_THUMBNAIL_EVENT); + } + + static String ^ CropAndLockReparentEvent() { + return gcnew String(CommonSharedConstants::CROP_AND_LOCK_REPARENT_EVENT); + } }; } diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/Utility.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/Utility.cs index 85a60b94b8..8fd8529fef 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/Utility.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/Utility.cs @@ -2,6 +2,7 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using System.Collections.Generic; using System.Threading; using System.Windows.Input; @@ -15,17 +16,20 @@ namespace Microsoft.PowerToys.Run.Plugin.PowerToys.Components { public class Utility { - public UtilityKey Key { get; } + public UtilityKey Key { get; private set; } - public string Name { get; } + public string Name { get; private set; } public bool Enabled { get; private set; } - public Utility(UtilityKey key, string name, bool enabled) + public Func Action { get; private set; } + + public Utility(UtilityKey key, string name, bool enabled, Func action) { Key = key; Name = name; Enabled = enabled; + Action = action; } public Result CreateResult(MatchResult matchResult) @@ -35,7 +39,7 @@ namespace Microsoft.PowerToys.Run.Plugin.PowerToys.Components Title = Name, SubTitle = Resources.Subtitle_Powertoys_Utility, IcoPath = UtilityHelper.GetIcoPath(Key), - Action = UtilityHelper.GetAction(Key), + Action = Action, ContextData = this, Score = matchResult.Score, TitleHighlightData = matchResult.MatchData, diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityHelper.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityHelper.cs index 621ef44c6a..3d495479a9 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityHelper.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityHelper.cs @@ -2,11 +2,7 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Threading; using Common.UI; -using interop; -using Wox.Plugin; namespace Microsoft.PowerToys.Run.Plugin.PowerToys.Components { @@ -23,6 +19,7 @@ namespace Microsoft.PowerToys.Run.Plugin.PowerToys.Components UtilityKey.PowerOCR => "Images/PowerOcr.png", UtilityKey.ShortcutGuide => "Images/ShortcutGuide.png", UtilityKey.RegistryPreview => "Images/RegistryPreview.png", + UtilityKey.CropAndLock => "Images/CropAndLock.png", _ => null, }; } @@ -38,78 +35,9 @@ namespace Microsoft.PowerToys.Run.Plugin.PowerToys.Components UtilityKey.PowerOCR => SettingsDeepLink.SettingsWindow.PowerOCR, UtilityKey.ShortcutGuide => SettingsDeepLink.SettingsWindow.ShortcutGuide, UtilityKey.RegistryPreview => SettingsDeepLink.SettingsWindow.RegistryPreview, + UtilityKey.CropAndLock => SettingsDeepLink.SettingsWindow.CropAndLock, _ => null, }; } - - public static Func GetAction(UtilityKey key) - { - return (context) => - { - switch (key) - { - case UtilityKey.ColorPicker: // Launch ColorPicker - using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowColorPickerSharedEvent())) - { - eventHandle.Set(); - } - - break; - case UtilityKey.FancyZones: // Launch FancyZones Editor - using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.FZEToggleEvent())) - { - eventHandle.Set(); - } - - break; - - case UtilityKey.Hosts: // Launch Hosts - { - using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowHostsSharedEvent())) - { - eventHandle.Set(); - } - } - - break; - - case UtilityKey.MeasureTool: // Launch Screen Ruler - using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.MeasureToolTriggerEvent())) - { - eventHandle.Set(); - } - - break; - case UtilityKey.PowerOCR: // Launch Text Extractor - using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowPowerOCRSharedEvent())) - { - eventHandle.Set(); - } - - break; - - case UtilityKey.ShortcutGuide: // Launch Shortcut Guide - using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShortcutGuideTriggerEvent())) - { - eventHandle.Set(); - } - - break; - - case UtilityKey.RegistryPreview: // Launch Registry Preview - using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.RegistryPreviewTriggerEvent())) - { - eventHandle.Set(); - } - - break; - - default: - break; - } - - return true; - }; - } } } diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityKey.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityKey.cs index 4276e0988b..33cb97b4a6 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityKey.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityKey.cs @@ -13,5 +13,6 @@ namespace Microsoft.PowerToys.Run.Plugin.PowerToys.Components PowerOCR = 4, ShortcutGuide = 5, RegistryPreview = 6, + CropAndLock = 7, } } diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityProvider.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityProvider.cs index 314a81728e..59fc0c82f5 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityProvider.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Components/UtilityProvider.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading; +using interop; using Microsoft.PowerToys.Run.Plugin.PowerToys.Components; using Microsoft.PowerToys.Run.Plugin.PowerToys.Properties; using Microsoft.PowerToys.Settings.UI.Library; @@ -32,37 +33,141 @@ namespace Microsoft.PowerToys.Run.Plugin.PowerToys if (GPOWrapper.GetConfiguredColorPickerEnabledValue() != GpoRuleConfigured.Disabled) { - _utilities.Add(new Utility(UtilityKey.ColorPicker, Resources.Color_Picker, generalSettings.Enabled.ColorPicker)); + _utilities.Add(new Utility( + UtilityKey.ColorPicker, + Resources.Color_Picker, + generalSettings.Enabled.ColorPicker, + (_) => + { + using var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowColorPickerSharedEvent()); + eventHandle.Set(); + return true; + })); } if (GPOWrapper.GetConfiguredFancyZonesEnabledValue() != GpoRuleConfigured.Disabled) { - _utilities.Add(new Utility(UtilityKey.FancyZones, Resources.FancyZones_Editor, generalSettings.Enabled.FancyZones)); + _utilities.Add(new Utility( + UtilityKey.FancyZones, + Resources.FancyZones_Editor, + generalSettings.Enabled.FancyZones, + (_) => + { + using var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.FZEToggleEvent()); + eventHandle.Set(); + return true; + })); } if (GPOWrapper.GetConfiguredHostsFileEditorEnabledValue() != GpoRuleConfigured.Disabled) { - _utilities.Add(new Utility(UtilityKey.Hosts, Resources.Hosts_File_Editor, generalSettings.Enabled.Hosts)); + _utilities.Add(new Utility( + UtilityKey.Hosts, + Resources.Hosts_File_Editor, + generalSettings.Enabled.Hosts, + (_) => + { + using var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowHostsSharedEvent()); + eventHandle.Set(); + return true; + })); } if (GPOWrapper.GetConfiguredScreenRulerEnabledValue() != GpoRuleConfigured.Disabled) { - _utilities.Add(new Utility(UtilityKey.MeasureTool, Resources.Screen_Ruler, generalSettings.Enabled.MeasureTool)); + _utilities.Add(new Utility( + UtilityKey.MeasureTool, + Resources.Screen_Ruler, + generalSettings.Enabled.MeasureTool, + (_) => + { + using var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.MeasureToolTriggerEvent()); + eventHandle.Set(); + return true; + })); } if (GPOWrapper.GetConfiguredTextExtractorEnabledValue() != GpoRuleConfigured.Disabled) { - _utilities.Add(new Utility(UtilityKey.PowerOCR, Resources.Text_Extractor, generalSettings.Enabled.PowerOCR)); + _utilities.Add(new Utility( + UtilityKey.PowerOCR, + Resources.Text_Extractor, + generalSettings.Enabled.PowerOCR, + (_) => + { + using var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShowPowerOCRSharedEvent()); + eventHandle.Set(); + return true; + })); } if (GPOWrapper.GetConfiguredShortcutGuideEnabledValue() != GpoRuleConfigured.Disabled) { - _utilities.Add(new Utility(UtilityKey.ShortcutGuide, Resources.Shortcut_Guide, generalSettings.Enabled.ShortcutGuide)); + _utilities.Add(new Utility( + UtilityKey.ShortcutGuide, + Resources.Shortcut_Guide, + generalSettings.Enabled.ShortcutGuide, + (_) => + { + using var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.ShortcutGuideTriggerEvent()); + eventHandle.Set(); + return true; + })); } if (GPOWrapper.GetConfiguredRegistryPreviewEnabledValue() != GpoRuleConfigured.Disabled) { - _utilities.Add(new Utility(UtilityKey.RegistryPreview, Resources.Registry_Preview, generalSettings.Enabled.RegistryPreview)); + _utilities.Add(new Utility( + UtilityKey.RegistryPreview, + Resources.Registry_Preview, + generalSettings.Enabled.RegistryPreview, + (_) => + { + using var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.RegistryPreviewTriggerEvent()); + eventHandle.Set(); + return true; + })); + } + + if (GPOWrapper.GetConfiguredCropAndLockEnabledValue() != GpoRuleConfigured.Disabled) + { + _utilities.Add(new Utility( + UtilityKey.CropAndLock, + Resources.Crop_And_Lock_Thumbnail, + generalSettings.Enabled.CropAndLock, + (_) => + { + // Wait for the Launcher window to be hidden and activate Crop And Lock in the correct window + var timer = new System.Timers.Timer(TimeSpan.FromMilliseconds(500)); + timer.Elapsed += (_, _) => + { + timer.Stop(); + using var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.CropAndLockThumbnailEvent()); + eventHandle.Set(); + }; + + timer.Start(); + return true; + })); + + _utilities.Add(new Utility( + UtilityKey.CropAndLock, + Resources.Crop_And_Lock_Reparent, + generalSettings.Enabled.CropAndLock, + (_) => + { + // Wait for the Launcher window to be hidden and activate Crop And Lock in the correct window + var timer = new System.Timers.Timer(TimeSpan.FromMilliseconds(500)); + timer.Elapsed += (_, _) => + { + timer.Stop(); + using var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, Constants.CropAndLockReparentEvent()); + eventHandle.Set(); + }; + + timer.Start(); + return true; + })); } _watcher = new FileSystemWatcher @@ -108,6 +213,7 @@ namespace Microsoft.PowerToys.Run.Plugin.PowerToys case UtilityKey.MeasureTool: u.Enable(generalSettings.Enabled.MeasureTool); break; case UtilityKey.ShortcutGuide: u.Enable(generalSettings.Enabled.ShortcutGuide); break; case UtilityKey.RegistryPreview: u.Enable(generalSettings.Enabled.RegistryPreview); break; + case UtilityKey.CropAndLock: u.Enable(generalSettings.Enabled.CropAndLock); break; } } diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ColorPicker.png b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ColorPicker.png deleted file mode 100644 index 7fed152227..0000000000 Binary files a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ColorPicker.png and /dev/null differ diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/FancyZones.png b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/FancyZones.png deleted file mode 100644 index 1d70bbb959..0000000000 Binary files a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/FancyZones.png and /dev/null differ diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/Hosts.png b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/Hosts.png deleted file mode 100644 index ce81ac6dda..0000000000 Binary files a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/Hosts.png and /dev/null differ diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/PowerOcr.png b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/PowerOcr.png deleted file mode 100644 index 3f5dcb1a9e..0000000000 Binary files a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/PowerOcr.png and /dev/null differ diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/RegistryPreview.png b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/RegistryPreview.png deleted file mode 100644 index 887c42a182..0000000000 Binary files a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/RegistryPreview.png and /dev/null differ diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ScreenRuler.png b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ScreenRuler.png deleted file mode 100644 index bc93c7e113..0000000000 Binary files a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ScreenRuler.png and /dev/null differ diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ShortcutGuide.png b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ShortcutGuide.png deleted file mode 100644 index dbdfc2c687..0000000000 Binary files a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Images/ShortcutGuide.png and /dev/null differ diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Microsoft.PowerToys.Run.Plugin.PowerToys.csproj b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Microsoft.PowerToys.Run.Plugin.PowerToys.csproj index d55c416f4f..0f9ff24d78 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Microsoft.PowerToys.Run.Plugin.PowerToys.csproj +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Microsoft.PowerToys.Run.Plugin.PowerToys.csproj @@ -66,33 +66,45 @@ - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - PreserveNewest PreserveNewest - + + + Images\ColorPicker.png PreserveNewest - - + + + Images\FancyZones.png PreserveNewest - - + + + Images\CropAndLock.png PreserveNewest - + + + Images\Hosts.png + PreserveNewest + + + Images\PowerOcr.png + PreserveNewest + + + Images\RegistryPreview.png + PreserveNewest + + + Images\ScreenRuler.png + PreserveNewest + + + Images\ShortcutGuide.png + PreserveNewest + diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Properties/Resources.Designer.cs b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Properties/Resources.Designer.cs index be8e3664d0..05d0f47ec5 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Properties/Resources.Designer.cs +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Properties/Resources.Designer.cs @@ -87,6 +87,24 @@ namespace Microsoft.PowerToys.Run.Plugin.PowerToys.Properties { } } + /// + /// Looks up a localized string similar to Crop And Lock (Reparent). + /// + internal static string Crop_And_Lock_Reparent { + get { + return ResourceManager.GetString("Crop_And_Lock_Reparent", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Crop And Lock (Thumbnail). + /// + internal static string Crop_And_Lock_Thumbnail { + get { + return ResourceManager.GetString("Crop_And_Lock_Thumbnail", resourceCulture); + } + } + /// /// Looks up a localized string similar to FancyZones Editor. /// diff --git a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Properties/Resources.resx b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Properties/Resources.resx index 53eb6605be..cbc299caa9 100644 --- a/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Properties/Resources.resx +++ b/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.PowerToys/Properties/Resources.resx @@ -127,6 +127,14 @@ Color Picker "Color Picker" is the name of the utility + + Crop And Lock (Reparent) + "Crop And Lock" is the name of the utility, "Reparent" is the activation mode + + + Crop And Lock (Thumbnail) + "Crop And Lock" is the name of the utility, "Thumbnail" is the activation mode + FancyZones Editor "FancyZones" is the name of the utility diff --git a/src/runner/settings_window.cpp b/src/runner/settings_window.cpp index 0371eca889..f2bf54b585 100644 --- a/src/runner/settings_window.cpp +++ b/src/runner/settings_window.cpp @@ -685,6 +685,8 @@ std::string ESettingsWindowNames_to_string(ESettingsWindowNames value) return "PowerOCR"; case ESettingsWindowNames::RegistryPreview: return "RegistryPreview"; + case ESettingsWindowNames::CropAndLock: + return "CropAndLock"; default: { Logger::error(L"Can't convert ESettingsWindowNames value={} to string", static_cast(value)); @@ -760,6 +762,10 @@ ESettingsWindowNames ESettingsWindowNames_from_string(std::string value) { return ESettingsWindowNames::RegistryPreview; } + else if (value == "CropAndLock") + { + return ESettingsWindowNames::CropAndLock; + } else { Logger::error(L"Can't convert string value={} to ESettingsWindowNames", winrt::to_hstring(value)); diff --git a/src/runner/settings_window.h b/src/runner/settings_window.h index 0601237256..2a14ec46e0 100644 --- a/src/runner/settings_window.h +++ b/src/runner/settings_window.h @@ -20,6 +20,7 @@ enum class ESettingsWindowNames MeasureTool, PowerOCR, RegistryPreview, + CropAndLock, }; std::string ESettingsWindowNames_to_string(ESettingsWindowNames value); diff --git a/src/settings-ui/Settings.UI/SettingsXAML/App.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/App.xaml.cs index a96e73d674..6026718d7c 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/App.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/App.xaml.cs @@ -401,6 +401,7 @@ namespace Microsoft.PowerToys.Settings.UI case "RegistryPreview": return typeof(RegistryPreviewPage); case "PastePlain": return typeof(PastePlainPage); case "Peek": return typeof(PeekPage); + case "CropAndLock": return typeof(CropAndLockPage); default: // Fallback to general Debug.Assert(false, "Unexpected SettingsWindow argument value");