shortcutguide, and ocr

This commit is contained in:
kaitao-ms
2025-12-01 16:51:36 +08:00
parent 8cf6ed6de5
commit 0fc3fbc40e
5 changed files with 140 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation
// 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 Microsoft.CommandPalette.Extensions.Toolkit;
using PowerToysExtension.Helpers;
namespace PowerToysExtension.Commands;
/// <summary>
/// Toggles the Shortcut Guide UI via the shared trigger event.
/// </summary>
internal sealed partial class ToggleShortcutGuideCommand : InvokableCommand
{
public ToggleShortcutGuideCommand()
{
Name = "Toggle Shortcut Guide";
}
public override CommandResult Invoke()
{
try
{
using var evt = new EventWaitHandle(false, EventResetMode.AutoReset, PowerToysEventNames.ShortcutGuideTrigger);
evt.Set();
return CommandResult.Dismiss();
}
catch (Exception ex)
{
return CommandResult.ShowToast($"Failed to toggle Shortcut Guide: {ex.Message}");
}
}
}

View File

@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation
// 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 Microsoft.CommandPalette.Extensions.Toolkit;
using PowerToysExtension.Helpers;
namespace PowerToysExtension.Commands;
/// <summary>
/// Triggers the Text Extractor UI via the existing show event.
/// </summary>
internal sealed partial class ToggleTextExtractorCommand : InvokableCommand
{
public ToggleTextExtractorCommand()
{
Name = "Toggle Text Extractor";
}
public override CommandResult Invoke()
{
try
{
using var evt = new EventWaitHandle(false, EventResetMode.AutoReset, PowerToysEventNames.PowerOcrShow);
evt.Set();
return CommandResult.Dismiss();
}
catch (Exception ex)
{
return CommandResult.ShowToast($"Failed to toggle Text Extractor: {ex.Message}");
}
}
}

View File

@@ -25,6 +25,8 @@ internal static class ModuleCommandCatalog
new LightSwitchModuleCommandProvider(), new LightSwitchModuleCommandProvider(),
new PowerToysRunModuleCommandProvider(), new PowerToysRunModuleCommandProvider(),
new ScreenRulerModuleCommandProvider(), new ScreenRulerModuleCommandProvider(),
new ShortcutGuideModuleCommandProvider(),
new TextExtractorModuleCommandProvider(),
new ColorPickerModuleCommandProvider(), new ColorPickerModuleCommandProvider(),
]; ];

View File

@@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation
// 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.Collections.Generic;
using Microsoft.CommandPalette.Extensions.Toolkit;
using PowerToysExtension.Commands;
using PowerToysExtension.Helpers;
using static Common.UI.SettingsDeepLink;
namespace PowerToysExtension.Modules;
internal sealed class ShortcutGuideModuleCommandProvider : ModuleCommandProvider
{
public override IEnumerable<ListItem> BuildCommands()
{
var title = SettingsWindow.ShortcutGuide.ModuleDisplayName();
var icon = SettingsWindow.ShortcutGuide.ModuleIcon();
yield return new ListItem(new ToggleShortcutGuideCommand())
{
Title = "Toggle Shortcut Guide",
Subtitle = "Show or hide Shortcut Guide",
Icon = icon,
};
yield return new ListItem(new OpenInSettingsCommand(SettingsWindow.ShortcutGuide, title))
{
Title = title,
Subtitle = "Open Shortcut Guide settings",
Icon = icon,
};
}
}

View File

@@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation
// 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.Collections.Generic;
using Microsoft.CommandPalette.Extensions.Toolkit;
using PowerToysExtension.Commands;
using PowerToysExtension.Helpers;
using static Common.UI.SettingsDeepLink;
namespace PowerToysExtension.Modules;
internal sealed class TextExtractorModuleCommandProvider : ModuleCommandProvider
{
public override IEnumerable<ListItem> BuildCommands()
{
var title = SettingsWindow.PowerOCR.ModuleDisplayName();
var icon = SettingsWindow.PowerOCR.ModuleIcon();
yield return new ListItem(new ToggleTextExtractorCommand())
{
Title = "Toggle Text Extractor",
Subtitle = "Start or close Text Extractor",
Icon = icon,
};
yield return new ListItem(new OpenInSettingsCommand(SettingsWindow.PowerOCR, title))
{
Title = title,
Subtitle = "Open Text Extractor settings",
Icon = icon,
};
}
}