mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
[QuickAccent] Add description of current selected letter (#20587)
* Adding unicode names and adjusting UI (WIP) * Added changing letter names * Add optioins to hide description (WIP) * WIP * Change to binding property * Adress PR comments * Set TextBlock in border * * Added to settings * Fixed string showing/not showing one time after switching character * Removed unneccessairy command in SettingsService.cs * Moved showdescription enum to settings.ui * Adding Fluent design :) * Fix merge errors * Center list * Fixed code not working. Accepted some code style changes. * Merge main in branch #2 * [Quick Accent] support unicode description for UTF-16 surrogate pairs * [Quick Accent] fix check-spelling-bot errors * [check-spelling] accept LANGID as correct word * [Quick Accent] fix delay when calling ShowToolbar for the first time * [Quick Accent] use toggle switch to turn off/on Unicode description * [Quick Accent] fix after merge * [Quick Accent] add UnicodeInformation.dll to installer Co-authored-by: Niels Laute <niels.laute@live.nl>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -17,12 +17,14 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.0" />
|
||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />
|
||||
<PackageReference Include="UnicodeInformation" Version="2.6.0" />
|
||||
<PackageReference Include="Vanara.PInvoke.User32" Version="3.4.11" />
|
||||
<PackageReference Include="Vanara.PInvoke.Shell32" Version="3.4.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
|
||||
<ProjectReference Include="..\..\..\common\GPOWrapper\GPOWrapper.vcxproj" />
|
||||
<ProjectReference Include="..\..\..\settings-ui\Settings.UI.Library\Settings.UI.Library.csproj" />
|
||||
<ProjectReference Include="..\PowerAccentKeyboardService\PowerAccentKeyboardService.vcxproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
// 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.Globalization;
|
||||
using System.Text;
|
||||
using System.Unicode;
|
||||
using System.Windows;
|
||||
using PowerAccent.Core.Services;
|
||||
using PowerAccent.Core.Tools;
|
||||
@@ -13,20 +16,31 @@ public class PowerAccent : IDisposable
|
||||
{
|
||||
private readonly SettingsService _settingService;
|
||||
|
||||
// Keys that show a description (like dashes) when ShowCharacterInfoSetting is 1
|
||||
private readonly LetterKey[] _letterKeysShowingDescription = new LetterKey[] { LetterKey.VK_O };
|
||||
|
||||
private bool _visible;
|
||||
|
||||
private string[] _characters = Array.Empty<string>();
|
||||
|
||||
private string[] _characterDescriptions = Array.Empty<string>();
|
||||
private int _selectedIndex = -1;
|
||||
private bool _showUnicodeDescription;
|
||||
|
||||
public LetterKey[] LetterKeysShowingDescription => _letterKeysShowingDescription;
|
||||
|
||||
public bool ShowUnicodeDescription => _showUnicodeDescription;
|
||||
|
||||
public string[] CharacterDescriptions => _characterDescriptions;
|
||||
|
||||
public event Action<bool, string[]> OnChangeDisplay;
|
||||
|
||||
public event Action<int, string> OnSelectCharacter;
|
||||
|
||||
private KeyboardListener _keyboardListener;
|
||||
private readonly KeyboardListener _keyboardListener;
|
||||
|
||||
public PowerAccent()
|
||||
{
|
||||
LoadUnicodeInfoCache();
|
||||
|
||||
_keyboardListener = new KeyboardListener();
|
||||
_keyboardListener.InitHook();
|
||||
_settingService = new SettingsService(_keyboardListener);
|
||||
@@ -34,6 +48,11 @@ public class PowerAccent : IDisposable
|
||||
SetEvents();
|
||||
}
|
||||
|
||||
private void LoadUnicodeInfoCache()
|
||||
{
|
||||
UnicodeInfo.GetCharInfo(0);
|
||||
}
|
||||
|
||||
private void SetEvents()
|
||||
{
|
||||
_keyboardListener.SetShowToolbarEvent(new PowerToys.PowerAccentKeyboardService.ShowToolbar((LetterKey letterKey) =>
|
||||
@@ -70,14 +89,79 @@ public class PowerAccent : IDisposable
|
||||
{
|
||||
_visible = true;
|
||||
_characters = (WindowsFunctions.IsCapsLockState() || WindowsFunctions.IsShiftState()) ? ToUpper(Languages.GetDefaultLetterKey(letterKey, _settingService.SelectedLang)) : Languages.GetDefaultLetterKey(letterKey, _settingService.SelectedLang);
|
||||
_characterDescriptions = GetCharacterDescriptions(_characters);
|
||||
|
||||
_showUnicodeDescription = _settingService.ShowUnicodeDescription;
|
||||
|
||||
Task.Delay(_settingService.InputTime).ContinueWith(
|
||||
t =>
|
||||
t =>
|
||||
{
|
||||
if (_visible)
|
||||
{
|
||||
if (_visible)
|
||||
{
|
||||
OnChangeDisplay?.Invoke(true, _characters);
|
||||
}
|
||||
}, TaskScheduler.FromCurrentSynchronizationContext());
|
||||
OnChangeDisplay?.Invoke(true, _characters);
|
||||
}
|
||||
}, TaskScheduler.FromCurrentSynchronizationContext());
|
||||
}
|
||||
|
||||
private string GetCharacterDescription(string character)
|
||||
{
|
||||
List<UnicodeCharInfo> unicodeList = new List<UnicodeCharInfo>();
|
||||
foreach (var codePoint in character.AsCodePointEnumerable())
|
||||
{
|
||||
unicodeList.Add(UnicodeInfo.GetCharInfo(codePoint));
|
||||
}
|
||||
|
||||
if (unicodeList.Count == 0)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
var description = new StringBuilder();
|
||||
if (unicodeList.Count == 1)
|
||||
{
|
||||
var unicode = unicodeList.First();
|
||||
var charUnicodeNumber = unicode.CodePoint.ToString("X4", CultureInfo.InvariantCulture);
|
||||
description.AppendFormat(CultureInfo.InvariantCulture, "(U+{0}) {1} ", charUnicodeNumber, unicode.Name);
|
||||
|
||||
return description.ToString();
|
||||
}
|
||||
|
||||
var displayTextAndCodes = new StringBuilder();
|
||||
var names = new StringBuilder();
|
||||
foreach (var unicode in unicodeList)
|
||||
{
|
||||
var charUnicodeNumber = unicode.CodePoint.ToString("X4", CultureInfo.InvariantCulture);
|
||||
if (displayTextAndCodes.Length > 0)
|
||||
{
|
||||
displayTextAndCodes.Append(" - ");
|
||||
}
|
||||
|
||||
displayTextAndCodes.AppendFormat(CultureInfo.InvariantCulture, "{0}: (U+{1})", unicode.GetDisplayText(), charUnicodeNumber);
|
||||
|
||||
if (names.Length > 0)
|
||||
{
|
||||
names.Append(", ");
|
||||
}
|
||||
|
||||
names.Append(unicode.Name);
|
||||
}
|
||||
|
||||
description.Append(displayTextAndCodes);
|
||||
description.Append(": ");
|
||||
description.Append(names);
|
||||
|
||||
return description.ToString();
|
||||
}
|
||||
|
||||
private string[] GetCharacterDescriptions(string[] characters)
|
||||
{
|
||||
string[] charInfoCollection = Array.Empty<string>();
|
||||
foreach (string character in characters)
|
||||
{
|
||||
charInfoCollection = charInfoCollection.Append<string>(GetCharacterDescription(character)).ToArray<string>();
|
||||
}
|
||||
|
||||
return charInfoCollection;
|
||||
}
|
||||
|
||||
private void SendInputAndHideToolbar(InputType inputType)
|
||||
@@ -212,14 +296,7 @@ public class PowerAccent : IDisposable
|
||||
string[] result = new string[array.Length];
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
if (array[i].Contains('ß'))
|
||||
{
|
||||
result[i] = "ẞ";
|
||||
}
|
||||
else
|
||||
{
|
||||
result[i] = array[i].ToUpper(System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
result[i] = array[i].Contains('ß') ? "ẞ" : array[i].ToUpper(System.Globalization.CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -10,6 +10,7 @@ using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using PowerToys.PowerAccentKeyboardService;
|
||||
using System.IO.Abstractions;
|
||||
using System.Text.Json;
|
||||
using static Vanara.PInvoke.LANGID;
|
||||
|
||||
public class SettingsService
|
||||
{
|
||||
@@ -91,6 +92,8 @@ public class SettingsService
|
||||
Position = Position.Center;
|
||||
break;
|
||||
}
|
||||
|
||||
ShowUnicodeDescription = settings.Properties.ShowUnicodeDescription;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -175,6 +178,21 @@ public class SettingsService
|
||||
_selectedLang = value;
|
||||
}
|
||||
}
|
||||
|
||||
private bool _showUnicodeDescription;
|
||||
|
||||
public bool ShowUnicodeDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
return _showUnicodeDescription;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_showUnicodeDescription = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum Position
|
||||
|
||||
Reference in New Issue
Block a user