From 9ecf82d2ead2d15d42e397da2b2281859265c5d5 Mon Sep 17 00:00:00 2001 From: Aaron Junker Date: Wed, 11 Jun 2025 15:26:34 +0200 Subject: [PATCH] Add copying keyboard manifests and other improvements --- Directory.Packages.props | 2 +- .../IndexYmlGenerator.cs | 75 ++ .../ShortcutGuide.IndexYmlGenerator.csproj | 24 + .../+WindowsNT.Notepad.en-US.yml | 247 ++++++ .../ShortcutGuide/+WindowsNT.Shell.en-US.yml | 778 ++++++++++++++++++ .../+WindowsNT.WindowsExplorer.en-US.yml | 3 + .../Microsoft.PowerToys.en-US.yml | 165 ++++ .../ShortcutGuide.Ui/ManifestInterpreter.cs | 65 +- .../{ShortcutList.cs => ShortcutFile.cs} | 2 +- .../PowerToysShortcutsPopulator.cs | 2 +- .../ShortcutGuide.Ui/Program.cs | 22 + .../ShortcutGuide.Ui/ShortcutGuide.Ui.csproj | 3 + .../ShortcutGuideXAML/MainWindow.xaml | 3 +- .../ShortcutGuideXAML/MainWindow.xaml.cs | 6 +- .../ShortcutGuideXAML/ShortcutView.xaml.cs | 2 +- 15 files changed, 1366 insertions(+), 33 deletions(-) create mode 100644 src/modules/ShortcutGuideV2/ShortcutGuide.IndexYmlGenerator/ShortcutGuide.IndexYmlGenerator/IndexYmlGenerator.cs create mode 100644 src/modules/ShortcutGuideV2/ShortcutGuide.IndexYmlGenerator/ShortcutGuide.IndexYmlGenerator/ShortcutGuide.IndexYmlGenerator.csproj create mode 100644 src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Assets/ShortcutGuide/+WindowsNT.Notepad.en-US.yml create mode 100644 src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Assets/ShortcutGuide/+WindowsNT.Shell.en-US.yml create mode 100644 src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Assets/ShortcutGuide/+WindowsNT.WindowsExplorer.en-US.yml create mode 100644 src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Assets/ShortcutGuide/Microsoft.PowerToys.en-US.yml rename src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Models/{ShortcutList.cs => ShortcutFile.cs} (94%) diff --git a/Directory.Packages.props b/Directory.Packages.props index e951a1d451..61cb71ec8e 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -107,7 +107,7 @@ - + diff --git a/src/modules/ShortcutGuideV2/ShortcutGuide.IndexYmlGenerator/ShortcutGuide.IndexYmlGenerator/IndexYmlGenerator.cs b/src/modules/ShortcutGuideV2/ShortcutGuide.IndexYmlGenerator/ShortcutGuide.IndexYmlGenerator/IndexYmlGenerator.cs new file mode 100644 index 0000000000..caf9f344cc --- /dev/null +++ b/src/modules/ShortcutGuideV2/ShortcutGuide.IndexYmlGenerator/ShortcutGuide.IndexYmlGenerator/IndexYmlGenerator.cs @@ -0,0 +1,75 @@ +// 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 System.IO; +using ShortcutGuide.Models; +using YamlDotNet.Serialization; + +// This should all be outsourced to WinGet in the future +namespace ShortcutGuide.IndexYmlGenerator +{ + public class IndexYmlGenerator + { + public static void Main() + { + CreateIndexYmlFile(); + } + + // Todo: Exception handling + public static void CreateIndexYmlFile() + { + string path = ManifestInterpreter.GetPathOfIntepretations(); + if (File.Exists(Path.Combine(path, "index.yml"))) + { + File.Delete(Path.Combine(path, "index.yml")); + } + + IndexFile indexFile = new() { }; + Dictionary<(string WindowFilter, bool BackgroundProcess), List> processes = []; + + foreach (string file in Directory.EnumerateFiles(path, "*.yml")) + { + string content = File.ReadAllText(file); + Deserializer deserializer = new(); + ShortcutFile shortcutFile = deserializer.Deserialize(content); + if (processes.TryGetValue((shortcutFile.WindowFilter, shortcutFile.BackgroundProcess), out List? apps)) + { + if (apps.Contains(shortcutFile.PackageName)) + { + continue; + } + + apps.Add(shortcutFile.PackageName); + continue; + } + + processes[(shortcutFile.WindowFilter, shortcutFile.BackgroundProcess)] = [shortcutFile.PackageName]; + } + + indexFile.Index = []; + + foreach (var item in processes) + { + indexFile.Index = + [ + .. indexFile.Index, + new IndexFile.IndexItem + { + WindowFilter = item.Key.WindowFilter, + BackgroundProcess = item.Key.BackgroundProcess, + Apps = [.. item.Value], + }, + ]; + } + + // Todo: Take the default shell name from the settings or environment variable, default to "+WindowsNT.Shell" + indexFile.DefaultShellName = "+WindowsNT.Shell"; + + Serializer serializer = new(); + string yamlContent = serializer.Serialize(indexFile); + File.WriteAllText(Path.Combine(path, "index.yml"), yamlContent); + } + } +} diff --git a/src/modules/ShortcutGuideV2/ShortcutGuide.IndexYmlGenerator/ShortcutGuide.IndexYmlGenerator/ShortcutGuide.IndexYmlGenerator.csproj b/src/modules/ShortcutGuideV2/ShortcutGuide.IndexYmlGenerator/ShortcutGuide.IndexYmlGenerator/ShortcutGuide.IndexYmlGenerator.csproj new file mode 100644 index 0000000000..2d497a237d --- /dev/null +++ b/src/modules/ShortcutGuideV2/ShortcutGuide.IndexYmlGenerator/ShortcutGuide.IndexYmlGenerator/ShortcutGuide.IndexYmlGenerator.csproj @@ -0,0 +1,24 @@ + + + + + + + WinExe + ShortcutGuide.IndexYmlGenerator + enable + false + false + ..\..\..\..\..\$(Platform)\$(Configuration)\WinUI3Apps + PowerToys.ShortcutGuide.IndexYmlGenerator + + + + + + + + + + + diff --git a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Assets/ShortcutGuide/+WindowsNT.Notepad.en-US.yml b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Assets/ShortcutGuide/+WindowsNT.Notepad.en-US.yml new file mode 100644 index 0000000000..d0d607253c --- /dev/null +++ b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Assets/ShortcutGuide/+WindowsNT.Notepad.en-US.yml @@ -0,0 +1,247 @@ +PackageName: +WindowsNT.Notepad +Name: Notepad +WindowFilter: "Notepad.exe" +BackgroundProcess: false +Shortcuts: + - SectionName: File + Properties: + - Name: New tab + Recommended: true + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - N + - Name: New window + Shortcut: + - Win: false + Ctrl: true + Shift: true + Alt: false + Keys: + - N + - Name: Open + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - O + - Name: Save + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - S + - Name: Save As + Shortcut: + - Win: false + Ctrl: true + Shift: true + Alt: false + Keys: + - S + - Name: Save all + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: true + Keys: + - S + - Name: Print + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - P + - Name: Close tab + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - W + - Name: Close window + Shortcut: + - Win: false + Ctrl: true + Shift: true + Alt: false + Keys: + - W + - SectionName: Edit + Properties: + - Name: Undo + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - Z + - Name: Redo + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: true + Keys: + - Z + - Name: Cut + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - X + - Name: Copy + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - C + - Name: Paste + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - V + - Name: Search with Bing + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - E + - Name: Find + Recommended: true + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - F + - Name: Find next + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: false + Keys: + - F3 + - Name: Find previous + Shortcut: + - Win: false + Ctrl: false + Shift: true + Alt: false + Keys: + - F3 + - Name: Replace + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - H + - Name: Go to + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - G + - Name: Select all + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - A + - Name: Time/Date + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - F5 + - SectionName: View + Properties: + - Name: Zoom in + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - Plus + - Name: Zoom out + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - Minus + - Name: Reset zoom + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - 0 + - SectionName: Formatting + Properties: + - Name: Bold + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - B + - Name: Italic + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - I + - Name: Insert link + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - K + - Name: Clear formatting + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - Space \ No newline at end of file diff --git a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Assets/ShortcutGuide/+WindowsNT.Shell.en-US.yml b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Assets/ShortcutGuide/+WindowsNT.Shell.en-US.yml new file mode 100644 index 0000000000..cf7aa4b240 --- /dev/null +++ b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Assets/ShortcutGuide/+WindowsNT.Shell.en-US.yml @@ -0,0 +1,778 @@ +PackageName: +WindowsNT.Shell +WindowFilter: "*" +BackgroundProcess: true +Shortcuts: + - SectionName: Desktop Shortcuts + Properties: + - Name: Close active window + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: true + Keys: + - F4 + - Name: Open shutdown box + Description: When no windows are open + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: true + Keys: + - F4 + - Name: Cycle through open Windows + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: true + Keys: + - Esc + - Win: false + Ctrl: false + Shift: false + Alt: true + Keys: + - Esc + - Name: Reveal typed password + Description: On sign-in screen + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: true + Keys: + - F8 + - Name: Go back + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: true + Keys: + - "" + - Name: Go forward + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: true + Keys: + - "" + - Name: Move up one screen + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: true + Keys: + - "" + - Name: Move down one screen + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: true + Keys: + - "" + - Name: Window context menu + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: true + Keys: + - Space + - Name: Switch between open apps + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: true + Keys: + - Tab + Description: While pressing Tab multiple times + - Name: Run command + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: true + Keys: + - "" + Description: for the underlined letter in the app + - Name: View open apps + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: true + Keys: + - Tab + - Name: Change start menu size + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - "" + - Name: Move cursor + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - "" + Description: To the beginning or end of a word + - Name: Switch keyboard layout + Shortcut: + - Win: false + Ctrl: true + Shift: true + Alt: false + Keys: + - "" + - Name: Select block of text + Shortcut: + - Win: false + Ctrl: true + Shift: true + Alt: false + Keys: + - "" + - Name: Open Task Manager + Shortcut: + - Win: false + Ctrl: true + Shift: true + Alt: false + Keys: + - Esc + - Name: Enable/Disable Chinese IME + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - Space + - Name: Open context menu + Shortcut: + - Win: false + Ctrl: false + Shift: true + Alt: false + Keys: + - F10 + Description: For the selected item + - SectionName: Virtual desktop + Properties: + - Name: Open task view + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - Tab + - Name: Add a virtual desktop + Shortcut: + - Win: true + Ctrl: true + Shift: false + Alt: false + Keys: + - D + - Name: Close current desktop + Shortcut: + - Win: true + Ctrl: true + Shift: false + Alt: false + Keys: + - F4 + Recommended: true + - Name: Switch desktop + Shortcut: + - Win: true + Ctrl: true + Shift: false + Alt: false + Keys: + - "" + - SectionName: "Windows key" + Properties: + - Name: Open start menu + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "" + Recommended: true + - Name: Open Action Center + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "A" + - Name: Open Date and Time + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: true + Keys: + - "D" + - Name: Focus on the notification area + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "B" + - Name: Open narrator + Shortcut: + - Win: true + Ctrl: true + Shift: false + Alt: false + Keys: + - "Enter" + - Name: Open domain search + Shortcut: + - Win: true + Ctrl: true + Shift: false + Alt: false + Keys: + - "F" + - Name: Open Quick Assist + Shortcut: + - Win: true + Ctrl: true + Shift: false + Alt: false + Keys: + - "Q" + - Name: Wake up device + Shortcut: + - Win: true + Ctrl: true + Shift: true + Alt: false + Keys: + - "B" + Description: When black or a blank screen. + - Name: Change input option + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "Space" + Description: To next option + - Name: Change input option + Shortcut: + - Win: true + Ctrl: true + Shift: false + Alt: false + Keys: + - "Space" + Description: To previous option + - Name: Display/Hide desktop + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "D" + - Name: Minimize the active window + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "Down" + - Name: Open file Explorer + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "E" + - Name: Close Magnifier + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "Esc" + - Name: Open Feedback Hub + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "F" + - Name: Start IME reconversion + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "/" + - Name: Open Gamebar + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "G" + - Name: Open voice dictation + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "H" + - Name: Minimize or restore all other windows + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "" + - Name: Open Settings + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "I" + - Name: Set focus to a Windows tip + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "J" + - Name: Open Cast + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "K" + - Name: Lock the device + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "L" + - Name: Snap the window + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "" + - Name: Minimize all windows + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "M" + - Name: Zoom out Magnifier + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "-" + - Name: Zoom in Magnifier + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "=" + - Name: Open notification center + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "N" + - Name: Lock the device orientation + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "O" + - Name: Open project Settings + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "P" + - Name: Open Settings about Page + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "" + - Name: Open the emoji panel + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "." + - Name: Open the emoji panel + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - ";" + - Name: Capture a screenshot + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "" + Description: Save to the pictures folder + - Name: Open search + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "Q" + - Name: Open search + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "S" + - Name: Open Run dialog + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "R" + - Name: Restore window + Description: If a window is snapped or maximized + Shortcut: + - Win: true + Ctrl: false + Shift: true + Alt: false + Keys: + - "" + - Name: Make UWP app full screen + Shortcut: + - Win: true + Ctrl: false + Shift: true + Alt: false + Keys: + - "" + - Name: Move window to monitor + Shortcut: + - Win: true + Ctrl: false + Shift: true + Alt: false + Keys: + - "" + - Name: Open Snipping Tool + Shortcut: + - Win: true + Ctrl: false + Shift: true + Alt: false + Keys: + - "S" + - Name: Stretch window + Description: To the top and bottom of the screen + Shortcut: + - Win: true + Ctrl: false + Shift: true + Alt: false + Keys: + - "" + - Name: Open task view + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "Tab" + - Name: Open Accessibility Settings + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "U" + - Name: Maximize the active window + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "" + - Name: Open the clipboard history + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "V" + - Name: Open widgets + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "W" + - Name: Open Quick Link menu + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "X" + - Name: Open snap layouts + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "Z" + - SectionName: Clipboard + Properties: + - Name: Copy + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - "C" + - Name: Cut + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - "X" + - Name: Paste + Shortcut: + - Win: false + Ctrl: true + Shift: false + Alt: false + Keys: + - "V" + - Name: Paste + Shortcut: + - Win: false + Ctrl: false + Shift: true + Alt: false + Keys: + - "" + Description: Paste as plain text + - SectionName: Taskbar Shortcuts + Properties: + - Name: Open app in Taskbar + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: false + Keys: + - "" + - Name: Open jump list + Shortcut: + - Win: true + Ctrl: false + Shift: false + Alt: true + Keys: + - "" + - Name: Switch to last active window + Shortcut: + - Win: true + Ctrl: true + Shift: false + Alt: false + Keys: + - "" + - Name: Open as administrator + Shortcut: + - Win: true + Ctrl: true + Shift: true + Alt: false + Keys: + - "" + - SectionName: Copilot key + Properties: + - Name: Open Copilot + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: false + Keys: + - '' + Description: When copilot is available + - Name: Open Windows search + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: false + Keys: + - '' + Description: When copilot is not available + - SectionName: Office key + Properties: + - Name: Open Word + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: false + Keys: + - "" + - "W" + - Name: Open Excel + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: false + Keys: + - "" + - "X" + - Name: Open PowerPoint + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: false + Keys: + - "" + - "P" + - Name: Open Outlook + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: false + Keys: + - "" + - "O" + - Name: Open Microsoft Teams + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: false + Keys: + - "" + - "T" + - Name: Open OneNote + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: false + Keys: + - "" + - "N" + - Name: Open OneDrive + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: false + Keys: + - "" + - "D" + - Name: Open Yammer + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: false + Keys: + - "" + - "Y" + - Name: Open LinkedIn + Shortcut: + - Win: false + Ctrl: false + Shift: false + Alt: false + Keys: + - "" + - "L" \ No newline at end of file diff --git a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Assets/ShortcutGuide/+WindowsNT.WindowsExplorer.en-US.yml b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Assets/ShortcutGuide/+WindowsNT.WindowsExplorer.en-US.yml new file mode 100644 index 0000000000..19ae44f559 --- /dev/null +++ b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Assets/ShortcutGuide/+WindowsNT.WindowsExplorer.en-US.yml @@ -0,0 +1,3 @@ +PackageName: +WindowsNT.WindowsExplorer +WindowFilter: "explorer.exe" +Shortcuts: \ No newline at end of file diff --git a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Assets/ShortcutGuide/Microsoft.PowerToys.en-US.yml b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Assets/ShortcutGuide/Microsoft.PowerToys.en-US.yml new file mode 100644 index 0000000000..3d4f539ce7 --- /dev/null +++ b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Assets/ShortcutGuide/Microsoft.PowerToys.en-US.yml @@ -0,0 +1,165 @@ +PackageName: Microsoft.PowerToys +Name: PowerToys +BackgroundProcess: True +WindowFilter: "powertoys.exe" +Shortcuts: + - SectionName: General + Properties: +# + - Name: Advanced Paste + Shortcut: + - Win: True + Ctrl: False + Alt: False + Shift: True + Keys: + - 86 + Description: Open Advanced Paste window + - Name: Advanced Paste + Shortcut: + - Win: True + Ctrl: True + Alt: True + Shift: False + Keys: + - 86 + Description: Paste as plain text directly + - Name: Advanced Paste + Shortcut: + - Win: False + Ctrl: False + Alt: False + Shift: False + Keys: + - 0 + Description: Paste as markdown directly + - Name: Advanced Paste + Shortcut: + - Win: False + Ctrl: False + Alt: False + Shift: False + Keys: + - 0 + Description: Paste as JSON directly + - Name: Always On Top + Shortcut: + - Win: True + Ctrl: True + Alt: False + Shift: False + Keys: + - 84 + Description: Pin a window + - Name: Color Picker + Shortcut: + - Win: True + Ctrl: False + Alt: False + Shift: True + Keys: + - 67 + Description: Pick a color + - Name: Crop And Lock + Shortcut: + - Win: True + Ctrl: True + Alt: False + Shift: True + Keys: + - 84 + Description: Thumbnail + - Name: Crop And Lock + Shortcut: + - Win: True + Ctrl: True + Alt: False + Shift: True + Keys: + - 82 + Description: Reparent + - Name: FancyZones + Shortcut: + - Win: True + Ctrl: False + Alt: False + Shift: True + Keys: + - 192 + Description: Open editor + - Name: Mouse Highlight + Shortcut: + - Win: True + Ctrl: False + Alt: False + Shift: True + Keys: + - 72 + Description: Highlight clicks + - Name: Mouse Jump + Shortcut: + - Win: True + Ctrl: False + Alt: False + Shift: True + Keys: + - 68 + Description: Quickly move the mouse pointer + - Name: Mouse Pointer Crosshairs + Shortcut: + - Win: True + Ctrl: False + Alt: True + Shift: False + Keys: + - 80 + Description: Show crosshairs + - Name: Peek + Shortcut: + - Win: False + Ctrl: True + Alt: False + Shift: False + Keys: + - 32 + - Name: PowerToys Run + Shortcut: + - Win: False + Ctrl: False + Alt: True + Shift: False + Keys: + - 32 + - Name: Screen Ruler + Shortcut: + - Win: True + Ctrl: True + Alt: False + Shift: True + Keys: + - 77 + - Name: Shortcut Guide + Shortcut: + - Win: True + Ctrl: False + Alt: False + Shift: True + Keys: + - 191 + - Name: Text Extractor + Shortcut: + - Win: True + Ctrl: False + Alt: False + Shift: True + Keys: + - 84 + - Name: Workspaces + Shortcut: + - Win: True + Ctrl: True + Alt: False + Shift: False + Keys: + - 192 +# \ No newline at end of file diff --git a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ManifestInterpreter.cs b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ManifestInterpreter.cs index a01204748c..6dbc040056 100644 --- a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ManifestInterpreter.cs +++ b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ManifestInterpreter.cs @@ -17,17 +17,32 @@ namespace ShortcutGuide { public class ManifestInterpreter { - public static ShortcutList GetShortcutsOfApplication(string applicationName) + // Todo: Get language from settings or environment variable, default to "en-US" + public static string Language => "en-US"; + + public static ShortcutFile GetShortcutsOfApplication(string applicationName) { string path = GetPathOfIntepretations(); - string content = File.ReadAllText(Path.Combine(path, applicationName + ".yml")); - return YamlToShortcutList(content); + IEnumerable files = Directory.EnumerateFiles(path, applicationName + ".*.yml") ?? + throw new FileNotFoundException($"The file for the application '{applicationName}' was not found in '{path}'."); + + if (files.Any(f => f.EndsWith($".{Language}.yml", StringComparison.InvariantCulture))) + { + return YamlToShortcutList(File.ReadAllText(Path.Combine(path, applicationName + $".{Language}.yml"))); + } + + if (files.Any(f => f.EndsWith(".en-US.yml", StringComparison.InvariantCulture))) + { + return YamlToShortcutList(File.ReadAllText(files.First(f => f.EndsWith(".en-US.yml", StringComparison.InvariantCulture)))); + } + + throw new FileNotFoundException($"The file for the application '{applicationName}' was not found in '{path}' with the language '{Language}' or 'en-US'."); } - public static ShortcutList YamlToShortcutList(string content) + public static ShortcutFile YamlToShortcutList(string content) { Deserializer deserializer = new(); - return deserializer.Deserialize(content); + return deserializer.Deserialize(content); } public static string GetPathOfIntepretations() @@ -59,6 +74,25 @@ namespace ShortcutGuide var processes = Process.GetProcesses(); + if (NativeMethods.GetWindowThreadProcessId(handle, out uint processId) > 0) + { + string? name = Process.GetProcessById((int)processId).MainModule?.ModuleName; + + if (name is not null) + { + try + { + foreach (var item in GetIndexYamlFile().Index.First((s) => !s.BackgroundProcess && IsMatch(name, s.WindowFilter)).Apps) + { + applicationIds.Add(item); + } + } + catch (InvalidOperationException) + { + } + } + } + foreach (var item in GetIndexYamlFile().Index.Where((s) => s.BackgroundProcess)) { try @@ -86,29 +120,10 @@ namespace ShortcutGuide } } - if (NativeMethods.GetWindowThreadProcessId(handle, out uint processId) > 0) - { - string? name = Process.GetProcessById((int)processId).MainModule?.ModuleName; - - if (name is not null) - { - try - { - foreach (var item in GetIndexYamlFile().Index.First((s) => !s.BackgroundProcess && IsMatch(name, s.WindowFilter)).Apps) - { - applicationIds.Add(item); - } - } - catch (InvalidOperationException) - { - } - } - } - return [.. applicationIds]; } - public static ShortcutList GetShortcutsOfDefaultShell() + public static ShortcutFile GetShortcutsOfDefaultShell() { return GetShortcutsOfApplication(GetIndexYamlFile().DefaultShellName); } diff --git a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Models/ShortcutList.cs b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Models/ShortcutFile.cs similarity index 94% rename from src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Models/ShortcutList.cs rename to src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Models/ShortcutFile.cs index dd80a4d218..46c114d645 100644 --- a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Models/ShortcutList.cs +++ b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Models/ShortcutFile.cs @@ -4,7 +4,7 @@ namespace ShortcutGuide.Models { - public struct ShortcutList + public struct ShortcutFile { public string PackageName { get; set; } diff --git a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/PowerToysShortcutsPopulator.cs b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/PowerToysShortcutsPopulator.cs index 770d4b4a8c..b26ccf0034 100644 --- a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/PowerToysShortcutsPopulator.cs +++ b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/PowerToysShortcutsPopulator.cs @@ -14,7 +14,7 @@ namespace ShortcutGuide { public static void Populate() { - string path = Path.Combine(ManifestInterpreter.GetPathOfIntepretations(), "Microsoft.PowerToys.yml"); + string path = Path.Combine(ManifestInterpreter.GetPathOfIntepretations(), $"Microsoft.PowerToys.{ManifestInterpreter.Language}.yml"); string content = File.ReadAllText(path); diff --git a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Program.cs b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Program.cs index f50e668659..628887adf9 100644 --- a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Program.cs +++ b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/Program.cs @@ -3,6 +3,8 @@ // See the LICENSE file in the project root for more information. using System; +using System.Diagnostics; +using System.IO; using System.Threading; using ManagedCommon; using Microsoft.UI.Dispatching; @@ -12,9 +14,29 @@ namespace ShortcutGuide { public sealed class Program { + private static readonly string[] InbuiltManifestFiles = [ + "+WindowsNT.Shell.en-US.yml", + "+WindowsNT.WindowsExplorer.en-US.yml", + "+WindowsNT.Notepad.en-US.yml", + "Microsoft.PowerToys.en-US.yml", + ]; + [STAThread] public static void Main() { + if (!Directory.Exists(ManifestInterpreter.GetPathOfIntepretations())) + { + Directory.CreateDirectory(ManifestInterpreter.GetPathOfIntepretations()); + } + + // Todo: Only copy files after an update. + // Todo: Handle error + foreach (var file in InbuiltManifestFiles) + { + File.Copy(Path.GetDirectoryName(Environment.ProcessPath) + "\\Assets\\ShortcutGuide\\" + file, ManifestInterpreter.GetPathOfIntepretations() + "\\" + file, true); + } + + Process.Start(Path.GetDirectoryName(Environment.ProcessPath) + "\\PowerToys.ShortcutGuide.IndexYmlGenerator.exe"); PowerToysShortcutsPopulator.Populate(); Logger.InitializeLogger("\\ShortcutGuide\\Logs"); diff --git a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ShortcutGuide.Ui.csproj b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ShortcutGuide.Ui.csproj index 63d4ab0a61..cba7566b17 100644 --- a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ShortcutGuide.Ui.csproj +++ b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ShortcutGuide.Ui.csproj @@ -24,6 +24,9 @@ + + + diff --git a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ShortcutGuideXAML/MainWindow.xaml b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ShortcutGuideXAML/MainWindow.xaml index 75966a4384..5209b21e4d 100644 --- a/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ShortcutGuideXAML/MainWindow.xaml +++ b/src/modules/ShortcutGuideV2/ShortcutGuide.Ui/ShortcutGuideXAML/MainWindow.xaml @@ -20,8 +20,7 @@ - - +