mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
Refactoring
This commit is contained in:
@@ -21,7 +21,7 @@ namespace ShortcutGuide.IndexYmlGenerator
|
||||
// Todo: Exception handling
|
||||
public static void CreateIndexYmlFile()
|
||||
{
|
||||
string path = ManifestInterpreter.GetPathOfIntepretations();
|
||||
string path = ManifestInterpreter.GetPathOfInterpretations();
|
||||
if (File.Exists(Path.Combine(path, "index.yml")))
|
||||
{
|
||||
File.Delete(Path.Combine(path, "index.yml"));
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
// 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.
|
||||
|
||||
namespace ShortcutGuide.Exceptions
|
||||
{
|
||||
internal sealed class InvalidYamlFileException : System.Exception
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -2,30 +2,29 @@
|
||||
// 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 Windows.Foundation;
|
||||
using WinUIEx;
|
||||
|
||||
namespace ShortcutGuide.Helpers
|
||||
{
|
||||
public static partial class DisplayHelper
|
||||
public static class DisplayHelper
|
||||
{
|
||||
private enum MonitorFromWindowDwFlags : int
|
||||
private enum MonitorFromWindowDwFlags
|
||||
{
|
||||
MONITOR_DEFAULTTONEAREST = 2,
|
||||
}
|
||||
|
||||
public static Rect GetWorkAreaForDisplayWithWindow(nint hwnd)
|
||||
{
|
||||
foundMonitorIndex = -1;
|
||||
monitorIndex = 0;
|
||||
_foundMonitorIndex = -1;
|
||||
_monitorIndex = 0;
|
||||
var monitor = NativeMethods.MonitorFromWindow(hwnd, (int)MonitorFromWindowDwFlags.MONITOR_DEFAULTTONEAREST);
|
||||
NativeMethods.EnumDisplayMonitors(nint.Zero, nint.Zero, MonitorEnumProc, new NativeMethods.LPARAM(monitor));
|
||||
return MonitorInfo.GetDisplayMonitors()[foundMonitorIndex].RectWork;
|
||||
return MonitorInfo.GetDisplayMonitors()[_foundMonitorIndex].RectWork;
|
||||
}
|
||||
|
||||
private static int foundMonitorIndex = -1;
|
||||
private static int monitorIndex;
|
||||
private static int _foundMonitorIndex = -1;
|
||||
private static int _monitorIndex;
|
||||
|
||||
private static bool MonitorEnumProc(nint hMonitor, nint hdcMonitor, ref NativeMethods.RECT lprcMonitor, nint dwData)
|
||||
{
|
||||
@@ -33,11 +32,11 @@ namespace ShortcutGuide.Helpers
|
||||
|
||||
if (hMonitor == targetMonitor)
|
||||
{
|
||||
foundMonitorIndex = monitorIndex;
|
||||
_foundMonitorIndex = _monitorIndex;
|
||||
return false;
|
||||
}
|
||||
|
||||
monitorIndex++;
|
||||
_monitorIndex++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace ShortcutGuide.Helpers
|
||||
{
|
||||
// This class is rewritten from C++ to C# from the measure tool project
|
||||
internal static partial class DpiHelper
|
||||
internal static class DpiHelper
|
||||
{
|
||||
#pragma warning disable SA1310 // Field names should not contain underscore
|
||||
private const int DEFAULT_DPI = 96;
|
||||
|
||||
@@ -22,14 +22,15 @@ namespace ShortcutGuide.Helpers
|
||||
|
||||
public static ShortcutFile GetShortcutsOfApplication(string applicationName)
|
||||
{
|
||||
string path = GetPathOfIntepretations();
|
||||
string path = GetPathOfInterpretations();
|
||||
IEnumerable<string> files = Directory.EnumerateFiles(path, applicationName + ".*.yml") ??
|
||||
throw new FileNotFoundException($"The file for the application '{applicationName}' was not found in '{path}'.");
|
||||
|
||||
return files.Any(f => f.EndsWith($".{Language}.yml", StringComparison.InvariantCulture))
|
||||
IEnumerable<string> filesEnumerable = files as string[] ?? files.ToArray();
|
||||
return filesEnumerable.Any(f => f.EndsWith($".{Language}.yml", StringComparison.InvariantCulture))
|
||||
? YamlToShortcutList(File.ReadAllText(Path.Combine(path, applicationName + $".{Language}.yml")))
|
||||
: files.Any(f => f.EndsWith(".en-US.yml", StringComparison.InvariantCulture))
|
||||
? YamlToShortcutList(File.ReadAllText(files.First(f => f.EndsWith(".en-US.yml", StringComparison.InvariantCulture))))
|
||||
: filesEnumerable.Any(f => f.EndsWith(".en-US.yml", StringComparison.InvariantCulture))
|
||||
? YamlToShortcutList(File.ReadAllText(filesEnumerable.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'.");
|
||||
}
|
||||
|
||||
@@ -39,14 +40,14 @@ namespace ShortcutGuide.Helpers
|
||||
return deserializer.Deserialize<ShortcutFile>(content);
|
||||
}
|
||||
|
||||
public static string GetPathOfIntepretations()
|
||||
public static string GetPathOfInterpretations()
|
||||
{
|
||||
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft", "WinGet", "KeyboardShortcuts");
|
||||
}
|
||||
|
||||
public static IndexFile GetIndexYamlFile()
|
||||
{
|
||||
string path = GetPathOfIntepretations();
|
||||
string path = GetPathOfInterpretations();
|
||||
string content = File.ReadAllText(Path.Combine(path, "index.yml"));
|
||||
Deserializer deserializer = new();
|
||||
return deserializer.Deserialize<IndexFile>(content);
|
||||
@@ -58,15 +59,7 @@ namespace ShortcutGuide.Helpers
|
||||
|
||||
List<string> applicationIds = [];
|
||||
|
||||
static bool IsMatch(string input, string filter)
|
||||
{
|
||||
input = input.ToLower(CultureInfo.InvariantCulture);
|
||||
filter = filter.ToLower(CultureInfo.InvariantCulture);
|
||||
string regexPattern = "^" + Regex.Escape(filter).Replace("\\*", ".*") + "$";
|
||||
return Regex.IsMatch(input, regexPattern);
|
||||
}
|
||||
|
||||
var processes = Process.GetProcesses();
|
||||
Process[] processes = Process.GetProcesses();
|
||||
|
||||
if (NativeMethods.GetWindowThreadProcessId(handle, out uint processId) > 0)
|
||||
{
|
||||
@@ -115,11 +108,14 @@ namespace ShortcutGuide.Helpers
|
||||
}
|
||||
|
||||
return [.. applicationIds];
|
||||
}
|
||||
|
||||
public static ShortcutFile GetShortcutsOfDefaultShell()
|
||||
{
|
||||
return GetShortcutsOfApplication(GetIndexYamlFile().DefaultShellName);
|
||||
static bool IsMatch(string input, string filter)
|
||||
{
|
||||
input = input.ToLower(CultureInfo.InvariantCulture);
|
||||
filter = filter.ToLower(CultureInfo.InvariantCulture);
|
||||
string regexPattern = "^" + Regex.Escape(filter).Replace("\\*", ".*") + "$";
|
||||
return Regex.IsMatch(input, regexPattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,15 +7,14 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using ShortcutGuide.Helpers;
|
||||
|
||||
namespace ShortcutGuide
|
||||
namespace ShortcutGuide.Helpers
|
||||
{
|
||||
internal sealed partial class PowerToysShortcutsPopulator
|
||||
{
|
||||
public static void Populate()
|
||||
{
|
||||
string path = Path.Combine(ManifestInterpreter.GetPathOfIntepretations(), $"Microsoft.PowerToys.{ManifestInterpreter.Language}.yml");
|
||||
string path = Path.Combine(ManifestInterpreter.GetPathOfInterpretations(), $"Microsoft.PowerToys.{ManifestInterpreter.Language}.yml");
|
||||
|
||||
string content = File.ReadAllText(path);
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// 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 Microsoft.Windows.ApplicationModel.Resources;
|
||||
|
||||
namespace ShortcutGuide.Helpers
|
||||
{
|
||||
internal static class ResourceLoaderInstance
|
||||
{
|
||||
internal static ResourceLoader ResourceLoader { get; private set; }
|
||||
|
||||
static ResourceLoaderInstance()
|
||||
{
|
||||
ResourceLoader = new ResourceLoader("PowerToys.ShortcutGuide.pri");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,12 @@
|
||||
// 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.Runtime.InteropServices;
|
||||
using TasklistButton = NativeMethods.TasklistButton;
|
||||
using TasklistButton = ShortcutGuide.NativeMethods.TasklistButton;
|
||||
|
||||
namespace ShortcutGuide.Helpers
|
||||
{
|
||||
internal sealed partial class TasklistPositions
|
||||
internal sealed class TasklistPositions
|
||||
{
|
||||
public static TasklistButton[] GetButtons()
|
||||
{
|
||||
|
||||
@@ -75,6 +75,7 @@ namespace ShortcutGuide.Models
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +87,7 @@ namespace ShortcutGuide.Models
|
||||
shortcutStackPanel.Orientation = Orientation.Horizontal;
|
||||
|
||||
// If any entry is blank, we skip the whole shortcut
|
||||
if (!shortcutEntry.Ctrl && !shortcutEntry.Alt && !shortcutEntry.Shift && !shortcutEntry.Win && shortcutEntry.Keys.Length == 0)
|
||||
if (shortcutEntry is { Ctrl: false, Alt: false, Shift: false, Win: false, Keys.Length: 0 })
|
||||
{
|
||||
return new ShortcutTemplateDataObject(shortcut.Name, shortcut.Description ?? string.Empty, shortcutStackPanel, shortcut);
|
||||
}
|
||||
@@ -103,21 +104,18 @@ namespace ShortcutGuide.Models
|
||||
shortcutStackPanel.Children.Add(shortcutIndexTextBlock);
|
||||
}
|
||||
|
||||
void AddNewTextToStackPanel(string text)
|
||||
{
|
||||
shortcutStackPanel.Children.Add(new TextBlock { Text = text, Margin = new Thickness(3), VerticalAlignment = VerticalAlignment.Center });
|
||||
}
|
||||
|
||||
if (shortcutEntry.Win)
|
||||
{
|
||||
PathIcon winIcon = (XamlReader.Load(@"<PathIcon xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" Data=""M683 1229H0V546h683v683zm819 0H819V546h683v683zm-819 819H0v-683h683v683zm819 0H819v-683h683v683z"" />") as PathIcon)!;
|
||||
Viewbox winIconContainer = new();
|
||||
winIconContainer.Child = winIcon;
|
||||
winIconContainer.HorizontalAlignment = HorizontalAlignment.Center;
|
||||
winIconContainer.VerticalAlignment = VerticalAlignment.Center;
|
||||
winIconContainer.Height = 24;
|
||||
winIconContainer.Width = 24;
|
||||
winIconContainer.Margin = new Thickness(3);
|
||||
Viewbox winIconContainer = new()
|
||||
{
|
||||
Child = winIcon,
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
Height = 24,
|
||||
Width = 24,
|
||||
Margin = new Thickness(3),
|
||||
};
|
||||
shortcutStackPanel.Children.Add(winIconContainer);
|
||||
}
|
||||
|
||||
@@ -136,7 +134,7 @@ namespace ShortcutGuide.Models
|
||||
AddNewTextToStackPanel("Shift");
|
||||
}
|
||||
|
||||
foreach (object key in shortcutEntry.Keys)
|
||||
foreach (string key in shortcutEntry.Keys)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
@@ -208,18 +206,10 @@ namespace ShortcutGuide.Models
|
||||
shortcutStackPanel.Children.Add(arrowUDTextBlock);
|
||||
AnimateTextBlock(arrowUDTextBlock, "↑↓", 1000);
|
||||
break;
|
||||
case string name when name.StartsWith('<') && name.EndsWith('>'):
|
||||
case { } name when name.StartsWith('<') && name.EndsWith('>'):
|
||||
AddNewTextToStackPanel(name[1..^1]);
|
||||
break;
|
||||
case int num:
|
||||
if (num == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
AddNewTextToStackPanel(Helper.GetKeyName((uint)num));
|
||||
break;
|
||||
case string num when int.TryParse(num, out int parsedNum):
|
||||
case { } num when int.TryParse(num, out int parsedNum):
|
||||
if (parsedNum == 0)
|
||||
{
|
||||
break;
|
||||
@@ -228,55 +218,76 @@ namespace ShortcutGuide.Models
|
||||
AddNewTextToStackPanel(Helper.GetKeyName((uint)parsedNum));
|
||||
break;
|
||||
default:
|
||||
AddNewTextToStackPanel((string)key);
|
||||
AddNewTextToStackPanel(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
|
||||
void AddNewTextToStackPanel(string text)
|
||||
{
|
||||
shortcutStackPanel.Children.Add(new TextBlock { Text = text, Margin = new Thickness(3), VerticalAlignment = VerticalAlignment.Center });
|
||||
}
|
||||
}
|
||||
|
||||
StackPanel stackPanelToReturn = shortcutStackPanels[0];
|
||||
|
||||
if (shortcutStackPanels.Count == 0)
|
||||
switch (shortcutStackPanels.Count)
|
||||
{
|
||||
return new ShortcutTemplateDataObject(shortcut.Name, shortcut.Description ?? string.Empty, new StackPanel(), shortcut);
|
||||
}
|
||||
else if (shortcutStackPanels.Count > 1)
|
||||
{
|
||||
stackPanelToReturn = new StackPanel();
|
||||
|
||||
stackPanelToReturn.Orientation = Orientation.Vertical;
|
||||
foreach (StackPanel panel in shortcutStackPanels)
|
||||
case 0:
|
||||
return new ShortcutTemplateDataObject(shortcut.Name, shortcut.Description ?? string.Empty, new StackPanel(), shortcut);
|
||||
case <= 1:
|
||||
return new ShortcutTemplateDataObject(shortcut.Name, shortcut.Description ?? string.Empty, stackPanelToReturn, shortcut);
|
||||
default:
|
||||
{
|
||||
panel.Visibility = Visibility.Collapsed;
|
||||
stackPanelToReturn.Children.Add(panel);
|
||||
}
|
||||
|
||||
shortcutStackPanels[0].Visibility = Visibility.Visible;
|
||||
for (int i = 1; i < shortcutStackPanels.Count; i++)
|
||||
{
|
||||
shortcutStackPanels[i].Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
async void AnimateStackPanels(StackPanel[] panels, int delay = 2000)
|
||||
{
|
||||
int index = 0;
|
||||
while (!ShortcutView.AnimationCancellationTokenSource.Token.IsCancellationRequested)
|
||||
{
|
||||
foreach (StackPanel panel in panels)
|
||||
stackPanelToReturn = new StackPanel
|
||||
{
|
||||
Orientation = Orientation.Vertical,
|
||||
};
|
||||
|
||||
foreach (StackPanel panel in shortcutStackPanels)
|
||||
{
|
||||
panel.Visibility = Visibility.Collapsed;
|
||||
stackPanelToReturn.Children.Add(panel);
|
||||
}
|
||||
|
||||
panels[index].Visibility = Visibility.Visible;
|
||||
index = (index + 1) % panels.Length;
|
||||
await Task.Delay(delay);
|
||||
shortcutStackPanels[0].Visibility = Visibility.Visible;
|
||||
for (int i = 1; i < shortcutStackPanels.Count; i++)
|
||||
{
|
||||
shortcutStackPanels[i].Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
async void AnimateStackPanels(StackPanel[] panels, int delay = 2000)
|
||||
{
|
||||
try
|
||||
{
|
||||
int index = 0;
|
||||
while (!ShortcutView.AnimationCancellationTokenSource.Token.IsCancellationRequested)
|
||||
{
|
||||
foreach (StackPanel panel in panels)
|
||||
{
|
||||
panel.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
panels[index].Visibility = Visibility.Visible;
|
||||
index = (index + 1) % panels.Length;
|
||||
await Task.Delay(delay);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
AnimateStackPanels([.. shortcutStackPanels]);
|
||||
}
|
||||
|
||||
return new ShortcutTemplateDataObject(shortcut.Name, shortcut.Description ?? string.Empty, stackPanelToReturn, shortcut);
|
||||
}
|
||||
|
||||
AnimateStackPanels([.. shortcutStackPanels]);
|
||||
}
|
||||
|
||||
return new ShortcutTemplateDataObject(shortcut.Name, shortcut.Description ?? string.Empty, stackPanelToReturn, shortcut);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,10 @@ using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Windows.Graphics;
|
||||
|
||||
namespace ShortcutGuide;
|
||||
|
||||
internal static partial class NativeMethods
|
||||
{
|
||||
internal static readonly IntPtr HWND_TOPMOST = new(-1);
|
||||
internal const uint SWP_NOSIZE = 0x0001;
|
||||
internal const uint SWP_NOMOVE = 0x0002;
|
||||
internal const uint SWP_NOACTIVATE = 0x0010;
|
||||
internal const uint SWP_SHOWWINDOW = 0x0040;
|
||||
internal const int GWL_STYLE = -16;
|
||||
internal const int WS_CAPTION = 0x00C00000;
|
||||
|
||||
@@ -29,9 +26,6 @@ internal static partial class NativeMethods
|
||||
[LibraryImport("user32.dll", StringMarshalling = StringMarshalling.Utf16)]
|
||||
internal static partial IntPtr FindWindowA(in string lpClassName, in string? lpWindowName);
|
||||
|
||||
[LibraryImport("user32.dll", StringMarshalling = StringMarshalling.Utf16)]
|
||||
internal static partial IntPtr FindWindowExA(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
|
||||
|
||||
[LibraryImport("User32.dll")]
|
||||
internal static partial IntPtr MonitorFromWindow(IntPtr hwnd, int dwFlags);
|
||||
|
||||
|
||||
@@ -32,16 +32,16 @@ namespace ShortcutGuide
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Directory.Exists(ManifestInterpreter.GetPathOfIntepretations()))
|
||||
if (!Directory.Exists(ManifestInterpreter.GetPathOfInterpretations()))
|
||||
{
|
||||
Directory.CreateDirectory(ManifestInterpreter.GetPathOfIntepretations());
|
||||
Directory.CreateDirectory(ManifestInterpreter.GetPathOfInterpretations());
|
||||
}
|
||||
|
||||
// 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);
|
||||
File.Copy(Path.GetDirectoryName(Environment.ProcessPath) + "\\Assets\\ShortcutGuide\\" + file, ManifestInterpreter.GetPathOfInterpretations() + "\\" + file, true);
|
||||
}
|
||||
|
||||
Process.Start(Path.GetDirectoryName(Environment.ProcessPath) + "\\PowerToys.ShortcutGuide.IndexYmlGenerator.exe");
|
||||
@@ -68,8 +68,6 @@ namespace ShortcutGuide
|
||||
|
||||
// Something prevents the process from exiting, so we need to kill it manually.
|
||||
Process.GetCurrentProcess().Kill();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ShortcutGuide.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resource {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resource() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ShortcutGuide.Properties.Resource", typeof(Resource).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Error displaying the application's shortcuts.
|
||||
/// </summary>
|
||||
internal static string ErrorInAppParsing {
|
||||
get {
|
||||
return ResourceManager.GetString("ErrorInAppParsing", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to There has been an error displaying this category.
|
||||
/// </summary>
|
||||
internal static string ErrorInCategoryParsing {
|
||||
get {
|
||||
return ResourceManager.GetString("ErrorInCategoryParsing", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to No shortcuts pinned or recommended.
|
||||
/// </summary>
|
||||
internal static string NoShortcutsInOverview {
|
||||
get {
|
||||
return ResourceManager.GetString("NoShortcutsInOverview", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Overview.
|
||||
/// </summary>
|
||||
internal static string Overview {
|
||||
get {
|
||||
return ResourceManager.GetString("Overview", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Pin.
|
||||
/// </summary>
|
||||
internal static string PinShortcut {
|
||||
get {
|
||||
return ResourceManager.GetString("PinShortcut", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to No results found.
|
||||
/// </summary>
|
||||
internal static string SearchBlank {
|
||||
get {
|
||||
return ResourceManager.GetString("SearchBlank", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Shortcut Guide.
|
||||
/// </summary>
|
||||
internal static string Title {
|
||||
get {
|
||||
return ResourceManager.GetString("Title", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Unpin.
|
||||
/// </summary>
|
||||
internal static string UnpinShortcut {
|
||||
get {
|
||||
return ResourceManager.GetString("UnpinShortcut", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,19 +100,6 @@
|
||||
<ProjectReference Include="..\..\..\settings-ui\Settings.UI.Library\Settings.UI.Library.csproj" />
|
||||
<ProjectReference Include="..\ShortcutGuide.CPPProject\ShortcutGuide.CPPProject.vcxproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resource.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resource.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\Resource.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resource.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Update="ShortcutGuideXAML\ShortcutView.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
<Application
|
||||
x:Class="ShortcutGuide.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:ShortcutGuide">
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
|
||||
@@ -6,7 +6,7 @@ using Microsoft.UI.Xaml;
|
||||
|
||||
namespace ShortcutGuide
|
||||
{
|
||||
public partial class App : Application
|
||||
public partial class App
|
||||
{
|
||||
public App()
|
||||
{
|
||||
@@ -17,7 +17,7 @@ namespace ShortcutGuide
|
||||
{
|
||||
_window = new MainWindow();
|
||||
_window.Activate();
|
||||
_window.Closed += (s, e) =>
|
||||
_window.Closed += (_, _) =>
|
||||
{
|
||||
_window = null;
|
||||
Current.Exit();
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
x:Class="ShortcutGuide.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:ShortcutGuide"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
// 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.Globalization;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.UI;
|
||||
using Microsoft.UI.Windowing;
|
||||
@@ -16,18 +14,17 @@ using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using ShortcutGuide.Helpers;
|
||||
using ShortcutGuide.Models;
|
||||
using ShortcutGuide.Properties;
|
||||
using Windows.Foundation;
|
||||
using Windows.Graphics;
|
||||
using WinUIEx;
|
||||
using static NativeMethods;
|
||||
using static ShortcutGuide.NativeMethods;
|
||||
|
||||
namespace ShortcutGuide
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty window that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
public sealed partial class MainWindow : WindowEx
|
||||
public sealed partial class MainWindow
|
||||
{
|
||||
private readonly string[] _currentApplicationIds;
|
||||
|
||||
@@ -41,7 +38,7 @@ namespace ShortcutGuide
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
Title = Resource.ResourceManager.GetString("Title", CultureInfo.InvariantCulture)!;
|
||||
Title = ResourceLoaderInstance.ResourceLoader.GetString("Title")!;
|
||||
|
||||
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
|
||||
WindowHwnd = hwnd;
|
||||
@@ -92,7 +89,7 @@ namespace ShortcutGuide
|
||||
_appWindow = AppWindow.GetFromWindowId(windowId);
|
||||
|
||||
GetCursorPos(out POINT lpPoint);
|
||||
_appWindow.Move(lpPoint with { Y = lpPoint.Y - ((int)Height / 2), X = lpPoint.X - ((int)Width / 2) });
|
||||
_appWindow.Move(new POINT { Y = lpPoint.Y - ((int)Height / 2), X = lpPoint.X - ((int)Width / 2) });
|
||||
|
||||
float dpiScale = DpiHelper.GetDPIScaleForWindow((int)hwnd);
|
||||
|
||||
@@ -104,13 +101,15 @@ namespace ShortcutGuide
|
||||
_setPosition = true;
|
||||
AppWindow.Changed += (_, a) =>
|
||||
{
|
||||
if (a.DidPresenterChange)
|
||||
if (!a.DidPresenterChange)
|
||||
{
|
||||
Rect monitorRect = DisplayHelper.GetWorkAreaForDisplayWithWindow(hwnd);
|
||||
float dpiScale = DpiHelper.GetDPIScaleForWindow((int)hwnd);
|
||||
this.SetWindowSize(monitorRect.Width / dpiScale, monitorRect.Height / dpiScale / 2);
|
||||
_appWindow.Move(new PointInt32((int)monitorRect.X, (int)(monitorRect.Y + (int)(monitorRect.Height / 2))));
|
||||
return;
|
||||
}
|
||||
|
||||
Rect monitorRect = DisplayHelper.GetWorkAreaForDisplayWithWindow(hwnd);
|
||||
float dpiScale = DpiHelper.GetDPIScaleForWindow((int)hwnd);
|
||||
this.SetWindowSize(monitorRect.Width / dpiScale, monitorRect.Height / dpiScale / 2);
|
||||
_appWindow.Move(new PointInt32((int)monitorRect.X, (int)(monitorRect.Y + (int)(monitorRect.Height / 2))));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
<TextBlock x:Name="ErrorMessage" Style="{StaticResource SubheaderTextBlockStyle}" Grid.Row="1" Margin="6,0,6,0"></TextBlock>
|
||||
<ScrollViewer Grid.Row="1" HorizontalScrollMode="Enabled" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Disabled" VerticalScrollMode="Disabled">
|
||||
<Grid>
|
||||
<StackPanel Height="{Binding ContentHeight}" Orientation="Horizontal" Grid.Row="1" x:Name="OverviewStackPanel">
|
||||
<StackPanel Height="{Binding ContentHeight}" Orientation="Horizontal" x:Name="OverviewStackPanel">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
@@ -54,7 +54,7 @@
|
||||
<GridView Grid.Row="1" SelectionMode="None" x:Name="PinnedListElement" ItemTemplate="{StaticResource ShortcutTemplate}">
|
||||
<GridView.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<ItemsWrapGrid x:Name="MaxItemsWrapGrid" Orientation="Vertical"/>
|
||||
<ItemsWrapGrid Orientation="Vertical"/>
|
||||
</ItemsPanelTemplate>
|
||||
</GridView.ItemsPanel>
|
||||
</GridView>
|
||||
@@ -64,16 +64,16 @@
|
||||
<GridView SelectionMode="None" x:Name="RecommendedListElement" ItemTemplate="{StaticResource ShortcutTemplate}">
|
||||
<GridView.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<ItemsWrapGrid x:Name="MaxItemsWrapGrid" Orientation="Vertical"/>
|
||||
<ItemsWrapGrid Orientation="Vertical"/>
|
||||
</ItemsPanelTemplate>
|
||||
</GridView.ItemsPanel>
|
||||
</GridView>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
<GridView HorizontalContentAlignment="Left" HorizontalAlignment="Left" Height="{Binding ContentHeight}" SelectionMode="None" x:Name="ShortcutListElement" Grid.Row="1" ItemTemplate="{StaticResource ShortcutTemplate}">
|
||||
<GridView HorizontalContentAlignment="Left" HorizontalAlignment="Left" Height="{Binding ContentHeight}" SelectionMode="None" x:Name="ShortcutListElement" ItemTemplate="{StaticResource ShortcutTemplate}">
|
||||
<GridView.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<ItemsWrapGrid HorizontalAlignment="Left" x:Name="MaxItemsWrapGrid" Orientation="Vertical"/>
|
||||
<ItemsWrapGrid HorizontalAlignment="Left" Orientation="Vertical"/>
|
||||
</ItemsPanelTemplate>
|
||||
</GridView.ItemsPanel>
|
||||
</GridView>
|
||||
|
||||
@@ -16,17 +16,16 @@ using Microsoft.UI.Xaml.Media.Animation;
|
||||
using Microsoft.UI.Xaml.Shapes;
|
||||
using ShortcutGuide.Helpers;
|
||||
using ShortcutGuide.Models;
|
||||
using ShortcutGuide.Properties;
|
||||
using Windows.Foundation;
|
||||
|
||||
namespace ShortcutGuide
|
||||
{
|
||||
public sealed partial class ShortcutView : Page, INotifyPropertyChanged
|
||||
public sealed partial class ShortcutView : INotifyPropertyChanged
|
||||
{
|
||||
private readonly DispatcherTimer _taskbarUpdateTimer = new() { Interval = TimeSpan.FromMilliseconds(500) };
|
||||
private readonly bool _showTaskbarShortcuts;
|
||||
public static readonly CancellationTokenSource AnimationCancellationTokenSource = new();
|
||||
private ShortcutFile shortcutList = ManifestInterpreter.GetShortcutsOfApplication(ShortcutPageParameters.CurrentPageName);
|
||||
private readonly ShortcutFile _shortcutList = ManifestInterpreter.GetShortcutsOfApplication(ShortcutPageParameters.CurrentPageName);
|
||||
|
||||
public ShortcutView()
|
||||
{
|
||||
@@ -40,20 +39,20 @@ namespace ShortcutGuide
|
||||
{
|
||||
CategorySelector.Items.Add(new SelectorBarItem()
|
||||
{
|
||||
Text = Resource.ResourceManager.GetString("Overview", CultureInfo.CurrentUICulture),
|
||||
Text = ResourceLoaderInstance.ResourceLoader.GetString("Overview"),
|
||||
Name = i.ToString(CultureInfo.InvariantCulture),
|
||||
});
|
||||
|
||||
i++;
|
||||
|
||||
foreach (var category in shortcutList.Shortcuts)
|
||||
foreach (var category in _shortcutList.Shortcuts)
|
||||
{
|
||||
switch (category.SectionName)
|
||||
{
|
||||
case string name when name.StartsWith("<TASKBAR1-9>", StringComparison.Ordinal):
|
||||
case { } name when name.StartsWith("<TASKBAR1-9>", StringComparison.Ordinal):
|
||||
_showTaskbarShortcuts = true;
|
||||
break;
|
||||
case string name when name.StartsWith('<') && name.EndsWith('>'):
|
||||
case { } name when name.StartsWith('<') && name.EndsWith('>'):
|
||||
break;
|
||||
default:
|
||||
CategorySelector.Items.Add(new SelectorBarItem() { Text = category.SectionName, Name = i.ToString(CultureInfo.InvariantCulture) });
|
||||
@@ -66,7 +65,7 @@ namespace ShortcutGuide
|
||||
CategorySelector.SelectedItem = CategorySelector.Items[0];
|
||||
CategorySelector.SelectionChanged += CategorySelector_SelectionChanged;
|
||||
|
||||
foreach (var shortcut in shortcutList.Shortcuts[0].Properties)
|
||||
foreach (var shortcut in _shortcutList.Shortcuts[0].Properties)
|
||||
{
|
||||
ShortcutListElement.Items.Add((ShortcutTemplateDataObject)shortcut);
|
||||
}
|
||||
@@ -92,10 +91,10 @@ namespace ShortcutGuide
|
||||
{
|
||||
OverviewStackPanel.Visibility = Visibility.Collapsed;
|
||||
ErrorMessage.Visibility = Visibility.Visible;
|
||||
ErrorMessage.Text = Resource.ResourceManager.GetString("ErrorInAppParsing", CultureInfo.CurrentUICulture);
|
||||
ErrorMessage.Text = ResourceLoaderInstance.ResourceLoader.GetString("ErrorInAppParsing");
|
||||
}
|
||||
|
||||
Unloaded += (s, e) =>
|
||||
Unloaded += (_, _) =>
|
||||
{
|
||||
AnimationCancellationTokenSource.Cancel();
|
||||
_taskbarUpdateTimer.Tick -= UpdateTaskbarIndicators;
|
||||
@@ -105,7 +104,7 @@ namespace ShortcutGuide
|
||||
|
||||
private void UpdateTaskbarIndicators(object? sender, object? e)
|
||||
{
|
||||
var buttons = TasklistPositions.GetButtons();
|
||||
NativeMethods.TasklistButton[] buttons = TasklistPositions.GetButtons();
|
||||
Canvas[] canvases = [
|
||||
TaskbarIndicator1,
|
||||
TaskbarIndicator2,
|
||||
@@ -171,7 +170,7 @@ namespace ShortcutGuide
|
||||
set
|
||||
{
|
||||
_contentHeight = value;
|
||||
OnPropertyChanged(nameof(ContentHeight));
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,13 +190,8 @@ namespace ShortcutGuide
|
||||
PinnedListTitle.Visibility = Visibility.Visible;
|
||||
ShortcutListElement.Visibility = Visibility.Collapsed;
|
||||
|
||||
foreach (var list in shortcutList.Shortcuts)
|
||||
foreach (var list in _shortcutList.Shortcuts)
|
||||
{
|
||||
if (list.Properties == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var shortcut in list.Properties)
|
||||
{
|
||||
if (shortcut.Recommended)
|
||||
@@ -228,7 +222,7 @@ namespace ShortcutGuide
|
||||
{
|
||||
OverviewStackPanel.Visibility = Visibility.Collapsed;
|
||||
ErrorMessage.Visibility = Visibility.Visible;
|
||||
ErrorMessage.Text = Resource.ResourceManager.GetString("NoShortcutsInOverview", CultureInfo.CurrentUICulture);
|
||||
ErrorMessage.Text = ResourceLoaderInstance.ResourceLoader.GetString("NoShortcutsInOverview");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,13 +250,8 @@ namespace ShortcutGuide
|
||||
|
||||
OverviewStackPanel.Visibility = Visibility.Collapsed;
|
||||
|
||||
foreach (var list in shortcutList.Shortcuts)
|
||||
foreach (var list in _shortcutList.Shortcuts)
|
||||
{
|
||||
if (list.Properties == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var shortcut in list.Properties)
|
||||
{
|
||||
if (shortcut.Name.Contains(filter, StringComparison.InvariantCultureIgnoreCase))
|
||||
@@ -274,7 +263,7 @@ namespace ShortcutGuide
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var shortcut in shortcutList.Shortcuts[int.Parse(CategorySelector.SelectedItem.Name, CultureInfo.InvariantCulture)].Properties)
|
||||
foreach (var shortcut in _shortcutList.Shortcuts[int.Parse(CategorySelector.SelectedItem.Name, CultureInfo.InvariantCulture)].Properties)
|
||||
{
|
||||
if (shortcut.Name.Contains(filter, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
@@ -283,12 +272,14 @@ namespace ShortcutGuide
|
||||
}
|
||||
}
|
||||
|
||||
if (ShortcutListElement.Items.Count == 0)
|
||||
if (ShortcutListElement.Items.Count != 0)
|
||||
{
|
||||
ShortcutListElement.Visibility = Visibility.Collapsed;
|
||||
ErrorMessage.Visibility = Visibility.Visible;
|
||||
ErrorMessage.Text = Resource.ResourceManager.GetString("SearchBlank", CultureInfo.CurrentUICulture);
|
||||
return;
|
||||
}
|
||||
|
||||
ShortcutListElement.Visibility = Visibility.Collapsed;
|
||||
ErrorMessage.Visibility = Visibility.Visible;
|
||||
ErrorMessage.Text = ResourceLoaderInstance.ResourceLoader.GetString("SearchBlank");
|
||||
}
|
||||
|
||||
public void CategorySelector_SelectionChanged(SelectorBar sender, SelectorBarSelectionChangedEventArgs e)
|
||||
@@ -311,7 +302,7 @@ namespace ShortcutGuide
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var shortcut in shortcutList.Shortcuts[int.Parse(sender.SelectedItem.Name, CultureInfo.InvariantCulture)].Properties)
|
||||
foreach (var shortcut in _shortcutList.Shortcuts[int.Parse(sender.SelectedItem.Name, CultureInfo.InvariantCulture)].Properties)
|
||||
{
|
||||
ShortcutListElement.Items.Add((ShortcutTemplateDataObject)shortcut);
|
||||
}
|
||||
@@ -319,7 +310,7 @@ namespace ShortcutGuide
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
ErrorMessage.Visibility = Visibility.Visible;
|
||||
ErrorMessage.Text = Resource.ResourceManager.GetString("ErrorInCategoryParsing", CultureInfo.CurrentUICulture);
|
||||
ErrorMessage.Text = ResourceLoaderInstance.ResourceLoader.GetString("ErrorInCategoryParsing");
|
||||
}
|
||||
|
||||
FilterBy(_searchFilter);
|
||||
@@ -362,7 +353,7 @@ namespace ShortcutGuide
|
||||
|
||||
bool isItemPinned = ShortcutPageParameters.PinnedShortcuts[ShortcutPageParameters.CurrentPageName].Contains(originalObject);
|
||||
|
||||
pinItem.Text = isItemPinned ? Resource.ResourceManager.GetString("UnpinShortcut", CultureInfo.CurrentUICulture) : Resource.ResourceManager.GetString("PinShortcut", CultureInfo.CurrentUICulture);
|
||||
pinItem.Text = isItemPinned ? ResourceLoaderInstance.ResourceLoader.GetString("UnpinShortcut") : ResourceLoaderInstance.ResourceLoader.GetString("PinShortcut");
|
||||
pinItem.Icon = new SymbolIcon(isItemPinned ? Symbol.UnPin : Symbol.Pin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
Reference in New Issue
Block a user