From f7ed043446cef95063d1e5d5afeca04d31efcfeb Mon Sep 17 00:00:00 2001 From: Hao Liu Date: Tue, 4 Mar 2025 19:09:28 +0800 Subject: [PATCH] [FHL] New static UX for Keyboard Manager Editor (#37747) * Set up static new UX for Keyboard Manager Editor * Improve the formatting and performance * fix spelling --- .../KeyboardManagerEditorUI/App.xaml | 3 +- .../KeyboardManagerEditorUI/App.xaml.cs | 47 +++- .../Assets/FluentIconsKeyboardManager.png | Bin 0 -> 3386 bytes .../KeyboardManagerEditorUI/Assets/kbm.jpg | Bin 0 -> 5034 bytes .../Helpers/Remapping.cs | 25 ++ .../Helpers/URLShortcut.cs | 19 ++ .../KeyboardManagerEditorUI.csproj | 56 +++++ .../KeyboardManagerEditorUI/MainWindow.xaml | 139 +++++------ .../MainWindow.xaml.cs | 75 +----- .../Pages/ExistingUI.xaml | 96 ++++++++ .../Pages/ExistingUI.xaml.cs | 102 ++++++++ .../Pages/Programs.xaml | 230 ++++++++++++++++++ .../Pages/Programs.xaml.cs | 46 ++++ .../Pages/Shortcuts.xaml | 191 +++++++++++++++ .../Pages/Shortcuts.xaml.cs | 57 +++++ .../KeyboardManagerEditorUI/Pages/Text.xaml | 180 ++++++++++++++ .../Pages/Text.xaml.cs | 53 ++++ .../KeyboardManagerEditorUI/Pages/URLs.xaml | 172 +++++++++++++ .../Pages/URLs.xaml.cs | 54 ++++ .../Styles/CommonStyle.xaml | 203 ++++++++++++++++ .../Styles/InputControl.xaml | 104 ++++++++ .../Styles/InputControl.xaml.cs | 80 ++++++ .../Styles/KeyVisual.cs | 198 +++++++++++++++ .../Styles/KeyVisual.xaml | 156 ++++++++++++ 24 files changed, 2136 insertions(+), 150 deletions(-) create mode 100644 src/modules/keyboardmanager/KeyboardManagerEditorUI/Assets/FluentIconsKeyboardManager.png create mode 100644 src/modules/keyboardmanager/KeyboardManagerEditorUI/Assets/kbm.jpg create mode 100644 src/modules/keyboardmanager/KeyboardManagerEditorUI/Helpers/Remapping.cs create mode 100644 src/modules/keyboardmanager/KeyboardManagerEditorUI/Helpers/URLShortcut.cs create mode 100644 src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/ExistingUI.xaml create mode 100644 src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/ExistingUI.xaml.cs create mode 100644 src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Programs.xaml create mode 100644 src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Programs.xaml.cs create mode 100644 src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Shortcuts.xaml create mode 100644 src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Shortcuts.xaml.cs create mode 100644 src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Text.xaml create mode 100644 src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Text.xaml.cs create mode 100644 src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/URLs.xaml create mode 100644 src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/URLs.xaml.cs create mode 100644 src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/CommonStyle.xaml create mode 100644 src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/InputControl.xaml create mode 100644 src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/InputControl.xaml.cs create mode 100644 src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/KeyVisual.cs create mode 100644 src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/KeyVisual.xaml diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorUI/App.xaml b/src/modules/keyboardmanager/KeyboardManagerEditorUI/App.xaml index 21a8eb12e1..b5119bcf57 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorUI/App.xaml +++ b/src/modules/keyboardmanager/KeyboardManagerEditorUI/App.xaml @@ -8,7 +8,8 @@ - + + diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorUI/App.xaml.cs b/src/modules/keyboardmanager/KeyboardManagerEditorUI/App.xaml.cs index 88b7f7996c..d013209292 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorUI/App.xaml.cs +++ b/src/modules/keyboardmanager/KeyboardManagerEditorUI/App.xaml.cs @@ -7,7 +7,10 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; +using System.Threading.Tasks; using ManagedCommon; +using Microsoft.UI; +using Microsoft.UI.Dispatching; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls.Primitives; @@ -35,8 +38,14 @@ namespace KeyboardManagerEditorUI public App() { this.InitializeComponent(); - Logger.InitializeLogger("\\Keyboard Manager\\WinUI3Editor\\Logs"); - Logger.LogInfo("keyboard-manager WinUI3 editor logger is initialized"); + + Task.Run(() => + { + Logger.InitializeLogger("\\Keyboard Manager\\WinUI3Editor\\Logs"); + Logger.LogInfo("keyboard-manager WinUI3 editor logger is initialized"); + }); + + UnhandledException += App_UnhandledException; } /// @@ -46,10 +55,42 @@ namespace KeyboardManagerEditorUI protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args) { window = new MainWindow(); - window.Activate(); + + var appWindow = window.AppWindow; + var titleBar = appWindow.TitleBar; + + titleBar.ExtendsContentIntoTitleBar = true; + titleBar.BackgroundColor = Colors.Transparent; + + var windowSize = new Windows.Graphics.SizeInt32(960, 600); + appWindow.Resize(windowSize); + + Task.Run(() => + { + App.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() + { + Source = new Uri("ms-appx:///Styles/CommonStyle.xaml"), + }); + }).ContinueWith(_ => + { + window.DispatcherQueue.TryEnqueue(() => + { + window.Activate(); + window.DispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, () => + { + (window.Content as FrameworkElement)?.UpdateLayout(); + }); + }); + }); + Logger.LogInfo("keyboard-manager WinUI3 editor window is launched"); } + private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e) + { + Logger.LogError("Unhandled exception", e.Exception); + } + private Window? window; } } diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorUI/Assets/FluentIconsKeyboardManager.png b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Assets/FluentIconsKeyboardManager.png new file mode 100644 index 0000000000000000000000000000000000000000..2d6db29ff15ee3334b29e74572c65701394599e1 GIT binary patch literal 3386 zcmbVP2~-o;8V(3HO4&4h0*b_d8Z051EIk zFCvSw6jTIM5Ue1rR>WE@P}ER2L{KBr3KUmVcoRiV`;J{s=bV|jbMNaT3lz$*Ul0;53umoh zfUwY!!-ZoZM}<&~piw9{4~3WmCO|T5EW{Ux+;KzA-{P!x5J1VTv0!77A_A}K@Rj(f+;K-Ri#A`bfwB1>?`dFm8m!&!k? zFIWO$og7I7kVK+ko#~E%6O~3MIbg{oGKmO~i6lA!02nl929=7Pyl{v%375wR@?Jiv z3;A-##mQu129YS2%N^wuM_9rq0(3f^NFo!-WCDU9NR=WPM?nxtZ9g!0LsC#85X%Ix z2&-e{#KK83cN}8rdl!V_DO!Pipga3qj>i7=|kkGPNQ#w9si%>YFLMrpwfVeRkkdLCJAxbes41%O^ zk_3c&HXvr&>bwy%yd)4u21`O}u$#6L`&fkK$AcF@>gdD_S zfsn(8h++{Rhn)%|!wXJ?C5U3gI?C_&{k^;bB`{Brh#W|Re3@8(A1^0>?&L&3e0*mv zi^cF4No5=n2>E-v5!UJf8SQ5aY#UdPZD*c1}Dv1DTK~Cbo z=Fv5#u67uH0x6PJ{huZ8&rSbBo&FosC&LQHaYTFwnW;pa z&KaU^`n*pH@&EJn?(BDy>H{1Zf4b$=+(ka7CO0HPs3pi;KDbQmfI>}w>+kIu629%% zeYcL9y?Hz*TKg{?b@+ra5_LMkX+8ZX27zCcHuMA?4~*Gt^D+RvC3jWHwIhu*#n1+( zb>Eqb5j&apio6nbNo#E@84lMLXd=#_yHfRQPPFyD1spoV6NbB5EJxBzXq7aDc1PKx zypzxS&t7Dr9zbhEOa8Mn`bkQ6bmp8zduI^ejQNWc_)>abjNJl0)C1_-O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P>t`hg~zL88}GZJ3dX=^w;>7FSpZkk_^sVfYOwSoqv_K`lQ4a z9M!t%&|)8(cNz_OH8)!DM5pLvVnHk-~0|5z_x0_j!` zniYOdo!t$S1Nj>!V)zA2;uml#>*ne0{7t9L74Slb`Vd)314pheRln-6C$hkLgOgsj8{#=u}m# zcxCo7!xP^j#I9}?ipTsbyK5zaH|8=vOxLI^fJ=YUDeux8Bc4%}%Nf`GYW41o{+82-Z937j|IeXB{J8Iogz>1&cakK&%C#sW)u+mb1gFB>V(ucF~^(bu}!M^ zYk5uZ)TL!1!`Y<5lPKu>42^{g)$gH~F{k#TfOobB8iDKlf?3eZN`JwkvK*^R9ea(J zU&_2^U(&UT?BMDZx&n8!6fe2!Dm(g;uIdJwv!f^3&~tsMe2B3@V7zvvcS~meYF;xF zE?x4srQ<`ro7nlpU!nY;Ue(n=W6Z+5k%`T33gmXdzapD7Nv zUpWW`_ACx7la)BVhU_ceiwzDFgA8(-h`R2_70%z=Y~6{1p`k5%HRXG8*Dm+hTX5!e z&{I>M4Ewab+GLQpXY*m4*T(ha@(c9*q)5v?29a&5+Be^_FPq4=ooU=4vR!8yR3bZY zwqeR4P<1QfCfl!;U#3TTbZ_-b&8KIkB OriginalKeys { get; set; } = new List(); + + public List RemappedKeys { get; set; } = new List(); + + public bool IsAllApps { get; set; } = true; + + public string AppName { get; set; } = "All apps"; + + public bool IsEnabled { get; set; } = true; + } +} diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorUI/Helpers/URLShortcut.cs b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Helpers/URLShortcut.cs new file mode 100644 index 0000000000..b961b3bc1b --- /dev/null +++ b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Helpers/URLShortcut.cs @@ -0,0 +1,19 @@ +// 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.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KeyboardManagerEditorUI.Helpers +{ + public class URLShortcut + { + public List Shortcut { get; set; } = new List(); + + public string URL { get; set; } = string.Empty; + } +} diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorUI/KeyboardManagerEditorUI.csproj b/src/modules/keyboardmanager/KeyboardManagerEditorUI/KeyboardManagerEditorUI.csproj index eace63f59e..58f7a1e829 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEditorUI/KeyboardManagerEditorUI.csproj +++ b/src/modules/keyboardmanager/KeyboardManagerEditorUI/KeyboardManagerEditorUI.csproj @@ -18,6 +18,22 @@ ..\..\..\..\$(Platform)\$(Configuration)\$(MSBuildProjectName) + + true + true + + + + + + + + + + + + + @@ -42,6 +58,46 @@ + + + MSBuild:Compile + + + + + MSBuild:Compile + + + + + MSBuild:Compile + + + + + MSBuild:Compile + + + + + MSBuild:Compile + + + + + MSBuild:Compile + + + + + MSBuild:Compile + + + + + MSBuild:Compile + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Programs.xaml.cs b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Programs.xaml.cs new file mode 100644 index 0000000000..c0410222fb --- /dev/null +++ b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Programs.xaml.cs @@ -0,0 +1,46 @@ +// 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.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using KeyboardManagerEditorUI.Helpers; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Navigation; +using Windows.Foundation; +using Windows.Foundation.Collections; + +namespace KeyboardManagerEditorUI.Pages +{ + public sealed partial class Programs : Page + { + public ObservableCollection Shortcuts { get; set; } + + public Programs() + { + this.InitializeComponent(); + + Shortcuts = new ObservableCollection(); + Shortcuts.Add(new URLShortcut() { Shortcut = new List() { "Win", "U", }, URL = "https://www.bing.com" }); + } + + private async void NewShortcutBtn_Click(object sender, RoutedEventArgs e) + { + await KeyDialog.ShowAsync(); + } + + private async void ListView_ItemClick(object sender, ItemClickEventArgs e) + { + await KeyDialog.ShowAsync(); + } + } +} diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Shortcuts.xaml b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Shortcuts.xaml new file mode 100644 index 0000000000..62a6f01376 --- /dev/null +++ b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Shortcuts.xaml @@ -0,0 +1,191 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Shortcuts.xaml.cs b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Shortcuts.xaml.cs new file mode 100644 index 0000000000..02d7346a96 --- /dev/null +++ b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Shortcuts.xaml.cs @@ -0,0 +1,57 @@ +// 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.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using KeyboardManagerEditorUI.Helpers; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Navigation; +using Windows.Foundation; +using Windows.Foundation.Collections; + +namespace KeyboardManagerEditorUI.Pages +{ + public sealed partial class Shortcuts : Page + { + public ObservableCollection RemappedShortcuts { get; set; } + + public Shortcuts() + { + this.InitializeComponent(); + + RemappedShortcuts = new ObservableCollection(); + RemappedShortcuts.Add(new Remapping() { OriginalKeys = new List() { "Ctrl", "Shift", "F" }, RemappedKeys = new List() { "Shift", "F" }, IsAllApps = true }); + RemappedShortcuts.Add(new Remapping() { OriginalKeys = new List() { "Ctrl (Left)" }, RemappedKeys = new List() { "Ctrl (Right)" }, IsAllApps = true }); + RemappedShortcuts.Add(new Remapping() { OriginalKeys = new List() { "Shift", "M" }, RemappedKeys = new List() { "Ctrl", "M" }, IsAllApps = true }); + RemappedShortcuts.Add(new Remapping() { OriginalKeys = new List() { "Shift", "Alt", "B" }, RemappedKeys = new List() { "Alt", "B" }, IsAllApps = false, AppName = "outlook.exe" }); + RemappedShortcuts.Add(new Remapping() { OriginalKeys = new List() { "Numpad 1" }, RemappedKeys = new List() { "Ctrl", "F" }, IsAllApps = true }); + RemappedShortcuts.Add(new Remapping() { OriginalKeys = new List() { "Numpad 2" }, RemappedKeys = new List() { "Alt", "F" }, IsAllApps = true, AppName = "outlook.exe" }); + } + + private async void NewShortcutBtn_Click(object sender, RoutedEventArgs e) + { + await KeyDialog.ShowAsync(); + } + + private async void ListView_ItemClick(object sender, ItemClickEventArgs e) + { + if (e.ClickedItem is Remapping selectedShortcut) + { + ShortcutControl.SetOriginalKeys(selectedShortcut.OriginalKeys); + ShortcutControl.SetRemappedKeys(selectedShortcut.RemappedKeys); + ShortcutControl.SetApp(!selectedShortcut.IsAllApps, selectedShortcut.AppName); + await KeyDialog.ShowAsync(); + } + } + } +} diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Text.xaml b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Text.xaml new file mode 100644 index 0000000000..4ccffe69b4 --- /dev/null +++ b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Text.xaml @@ -0,0 +1,180 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Text.xaml.cs b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Text.xaml.cs new file mode 100644 index 0000000000..1a9ae16ee3 --- /dev/null +++ b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/Text.xaml.cs @@ -0,0 +1,53 @@ +// 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.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using KeyboardManagerEditorUI.Helpers; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Navigation; +using Windows.Foundation; +using Windows.Foundation.Collections; + +namespace KeyboardManagerEditorUI.Pages +{ + /// + /// An empty page that can be used on its own or navigated to within a Frame. + /// + public sealed partial class Text : Page + { + public ObservableCollection Shortcuts { get; set; } + + public Text() + { + this.InitializeComponent(); + + Shortcuts = new ObservableCollection(); + Shortcuts.Add(new URLShortcut() { Shortcut = new List() { "Shift", "Win", "M" }, URL = "Hello" }); + Shortcuts.Add(new URLShortcut() { Shortcut = new List() { "Win", "P", }, URL = "Nice!" }); + Shortcuts.Add(new URLShortcut() { Shortcut = new List() { "Shift", "Win", "M" }, URL = "I like it" }); + Shortcuts.Add(new URLShortcut() { Shortcut = new List() { "Win", "U", }, URL = "Yes" }); + Shortcuts.Add(new URLShortcut() { Shortcut = new List() { "Ctrl", "P" }, URL = "OK" }); + } + + private async void NewShortcutBtn_Click(object sender, RoutedEventArgs e) + { + await KeyDialog.ShowAsync(); + } + + private async void ListView_ItemClick(object sender, ItemClickEventArgs e) + { + await KeyDialog.ShowAsync(); + } + } +} diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/URLs.xaml b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/URLs.xaml new file mode 100644 index 0000000000..06a2fbed00 --- /dev/null +++ b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/URLs.xaml @@ -0,0 +1,172 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/URLs.xaml.cs b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/URLs.xaml.cs new file mode 100644 index 0000000000..05a0b60040 --- /dev/null +++ b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Pages/URLs.xaml.cs @@ -0,0 +1,54 @@ +// 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.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using KeyboardManagerEditorUI.Helpers; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Navigation; +using Windows.Foundation; +using Windows.Foundation.Collections; + +namespace KeyboardManagerEditorUI.Pages +{ + /// + /// An empty page that can be used on its own or navigated to within a Frame. + /// + public sealed partial class URLs : Page + { + public ObservableCollection Shortcuts { get; set; } + + public URLs() + { + this.InitializeComponent(); + + Shortcuts = new ObservableCollection(); + Shortcuts.Add(new URLShortcut() { Shortcut = new List() { "Shift", "Win", "M" }, URL = "https://www.microsoft.com" }); + Shortcuts.Add(new URLShortcut() { Shortcut = new List() { "Win", "P", }, URL = "https://www.bing.com" }); + Shortcuts.Add(new URLShortcut() { Shortcut = new List() { "Shift", "Win", "M" }, URL = "https://www.windows.com" }); + Shortcuts.Add(new URLShortcut() { Shortcut = new List() { "Win", "U", }, URL = "https://www.bing.com" }); + Shortcuts.Add(new URLShortcut() { Shortcut = new List() { "Ctrl", "P" }, URL = "https://www.surface.com" }); + Shortcuts.Add(new URLShortcut() { Shortcut = new List() { "Alt", "Ctrl", "Shift" }, URL = "https://www.bing.com" }); + } + + private async void NewShortcutBtn_Click(object sender, RoutedEventArgs e) + { + await KeyDialog.ShowAsync(); + } + + private async void ListView_ItemClick(object sender, ItemClickEventArgs e) + { + await KeyDialog.ShowAsync(); + } + } +} diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/CommonStyle.xaml b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/CommonStyle.xaml new file mode 100644 index 0000000000..0cc49d716b --- /dev/null +++ b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/CommonStyle.xaml @@ -0,0 +1,203 @@ + + + + 960 + + + diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/InputControl.xaml b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/InputControl.xaml new file mode 100644 index 0000000000..4b29a1af5a --- /dev/null +++ b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/InputControl.xaml @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/InputControl.xaml.cs b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/InputControl.xaml.cs new file mode 100644 index 0000000000..5b319e9c5a --- /dev/null +++ b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/InputControl.xaml.cs @@ -0,0 +1,80 @@ +// 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.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Input; +using Microsoft.UI.Xaml.Media; +using Microsoft.UI.Xaml.Navigation; +using Windows.Foundation; +using Windows.Foundation.Collections; + +namespace KeyboardManagerEditorUI.Styles +{ + public sealed partial class InputControl : UserControl + { + public InputControl() + { + this.InitializeComponent(); + } + + public void SetOriginalKeys(List keys) + { + OriginalKeys.ItemsSource = keys; + } + + public void SetRemappedKeys(List keys) + { + RemappedKeys.ItemsSource = keys; + } + + private void OriginalToggleBtn_Checked(object sender, RoutedEventArgs e) + { + RemappedToggleBtn.IsChecked = false; + } + + private void RemappedToggleBtn_Checked(object sender, RoutedEventArgs e) + { + OriginalToggleBtn.IsChecked = false; + } + + public void SetApp(bool isSpecificApp, string appName) + { + if (isSpecificApp) + { + AllAppsCheckBox.IsChecked = true; + AppNameTextBox.Text = appName; + AppNameTextBox.Visibility = Visibility.Visible; + } + else + { + AllAppsCheckBox.IsChecked = false; + AppNameTextBox.Visibility = Visibility.Collapsed; + } + } + + private void AllAppsCheckBox_Checked(object sender, RoutedEventArgs e) + { + AppNameTextBox.Visibility = Visibility.Visible; + } + + private void AllAppsCheckBox_Unchecked(object sender, RoutedEventArgs e) + { + AppNameTextBox.Visibility = Visibility.Collapsed; + } + + private void UserControl_Loaded(object sender, RoutedEventArgs e) + { + AllAppsCheckBox.Checked += AllAppsCheckBox_Checked; + AllAppsCheckBox.Unchecked += AllAppsCheckBox_Unchecked; + } + } +} diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/KeyVisual.cs b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/KeyVisual.cs new file mode 100644 index 0000000000..058377d1ce --- /dev/null +++ b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/KeyVisual.cs @@ -0,0 +1,198 @@ +// 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.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Data; +using Microsoft.UI.Xaml.Markup; +using Microsoft.UI.Xaml.Media; +using Windows.System; + +namespace KeyboardManagerEditorUI.Styles +{ + [TemplatePart(Name = KeyPresenter, Type = typeof(ContentPresenter))] + [TemplateVisualState(Name = "Normal", GroupName = "CommonStates")] + [TemplateVisualState(Name = "Disabled", GroupName = "CommonStates")] + [TemplateVisualState(Name = "Default", GroupName = "StateStates")] + [TemplateVisualState(Name = "Error", GroupName = "StateStates")] + public sealed partial class KeyVisual : Control + { + private const string KeyPresenter = "KeyPresenter"; + private KeyVisual? _keyVisual; + private ContentPresenter? _keyPresenter; + + public object Content + { + get => (object)GetValue(ContentProperty); + set => SetValue(ContentProperty, value); + } + + public static readonly DependencyProperty ContentProperty = DependencyProperty.Register("Content", typeof(object), typeof(KeyVisual), new PropertyMetadata(default(string), OnContentChanged)); + + public VisualType VisualType + { + get => (VisualType)GetValue(VisualTypeProperty); + set => SetValue(VisualTypeProperty, value); + } + + public static readonly DependencyProperty VisualTypeProperty = DependencyProperty.Register("VisualType", typeof(VisualType), typeof(KeyVisual), new PropertyMetadata(default(VisualType), OnSizeChanged)); + + public bool IsError + { + get => (bool)GetValue(IsErrorProperty); + set => SetValue(IsErrorProperty, value); + } + + public static readonly DependencyProperty IsErrorProperty = DependencyProperty.Register("IsError", typeof(bool), typeof(KeyVisual), new PropertyMetadata(false, OnIsErrorChanged)); + + public KeyVisual() + { + this.DefaultStyleKey = typeof(KeyVisual); + this.Style = GetStyleSize("TextKeyVisualStyle"); + } + + protected override void OnApplyTemplate() + { + IsEnabledChanged -= KeyVisual_IsEnabledChanged; + _keyVisual = (KeyVisual)this; + _keyPresenter = (ContentPresenter)_keyVisual.GetTemplateChild(KeyPresenter); + Update(); + SetEnabledState(); + SetErrorState(); + IsEnabledChanged += KeyVisual_IsEnabledChanged; + base.OnApplyTemplate(); + } + + private static void OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((KeyVisual)d).Update(); + } + + private static void OnSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((KeyVisual)d).Update(); + } + + private static void OnIsErrorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + ((KeyVisual)d).SetErrorState(); + } + + private void Update() + { + if (_keyVisual == null || _keyVisual._keyPresenter == null) + { + return; + } + + if (_keyVisual.Content != null) + { + if (_keyVisual.Content.GetType() == typeof(string)) + { + _keyVisual.Style = GetStyleSize("TextKeyVisualStyle"); + _keyVisual._keyPresenter.Content = _keyVisual.Content; + } + else + { + _keyVisual.Style = GetStyleSize("IconKeyVisualStyle"); + + switch ((int)_keyVisual.Content) + { + /* We can enable other glyphs in the future + case 13: // The Enter key or button. + _keyVisual._keyPresenter.Content = "\uE751"; break; + + case 8: // The Back key or button. + _keyVisual._keyPresenter.Content = "\uE750"; break; + + case 16: // The right Shift key or button. + case 160: // The left Shift key or button. + case 161: // The Shift key or button. + _keyVisual._keyPresenter.Content = "\uE752"; break; */ + + case 38: _keyVisual._keyPresenter.Content = "\uE0E4"; break; // The Up Arrow key or button. + case 40: _keyVisual._keyPresenter.Content = "\uE0E5"; break; // The Down Arrow key or button. + case 37: _keyVisual._keyPresenter.Content = "\uE0E2"; break; // The Left Arrow key or button. + case 39: _keyVisual._keyPresenter.Content = "\uE0E3"; break; // The Right Arrow key or button. + + case 91: // The left Windows key + case 92: // The right Windows key + PathIcon winIcon = (PathIcon)XamlReader.Load(@"") as PathIcon; + Viewbox winIconContainer = new Viewbox(); + winIconContainer.Child = winIcon; + winIconContainer.HorizontalAlignment = HorizontalAlignment.Center; + winIconContainer.VerticalAlignment = VerticalAlignment.Center; + + double iconDimensions = GetIconSize(); + winIconContainer.Height = iconDimensions; + winIconContainer.Width = iconDimensions; + _keyVisual._keyPresenter.Content = winIconContainer; + break; + default: _keyVisual._keyPresenter.Content = ((VirtualKey)_keyVisual.Content).ToString(); break; + } + } + } + } + + public Style GetStyleSize(string styleName) + { + if (VisualType == VisualType.Small) + { + return (Style)App.Current.Resources["Small" + styleName]; + } + else if (VisualType == VisualType.SmallOutline) + { + return (Style)App.Current.Resources["SmallOutline" + styleName]; + } + else if (VisualType == VisualType.LargeOutline) + { + return (Style)App.Current.Resources["LargeOutline" + styleName]; + } + else + { + return (Style)App.Current.Resources["Default" + styleName]; + } + } + + public double GetIconSize() + { + if (VisualType == VisualType.Small || VisualType == VisualType.SmallOutline) + { + return (double)App.Current.Resources["SmallIconSize"]; + } + else + { + return (double)App.Current.Resources["DefaultIconSize"]; + } + } + + private void KeyVisual_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e) + { + SetEnabledState(); + } + + private void SetErrorState() + { + VisualStateManager.GoToState(this, IsError ? "Error" : "Default", true); + } + + private void SetEnabledState() + { + VisualStateManager.GoToState(this, IsEnabled ? "Normal" : "Disabled", true); + } + } + + public enum VisualType + { + Small, + SmallOutline, + Large, + LargeOutline, + } +} diff --git a/src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/KeyVisual.xaml b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/KeyVisual.xaml new file mode 100644 index 0000000000..5bb67875cc --- /dev/null +++ b/src/modules/keyboardmanager/KeyboardManagerEditorUI/Styles/KeyVisual.xaml @@ -0,0 +1,156 @@ + + + + 16 + 12 + + + + + + + + + + + + + + + +