diff --git a/src/modules/poweraccent/PowerAccent.Core/Languages.cs b/src/modules/poweraccent/PowerAccent.Core/Languages.cs index d02afd2c85c..2838fe95889 100644 --- a/src/modules/poweraccent/PowerAccent.Core/Languages.cs +++ b/src/modules/poweraccent/PowerAccent.Core/Languages.cs @@ -10,7 +10,7 @@ namespace PowerAccent.Core { public enum Language { - ALL, + SPECIAL, BG, CA, CRH, @@ -54,52 +54,68 @@ public enum Language internal sealed class Languages { - public static string[] GetDefaultLetterKey(LetterKey letter, Language lang) - { - return lang switch - { - Language.ALL => GetDefaultLetterKeyALL(letter), // All - Language.BG => GetDefaultLetterKeyBG(letter), // Bulgarian - Language.CA => GetDefaultLetterKeyCA(letter), // Catalan - Language.CRH => GetDefaultLetterKeyCRH(letter), // Crimean Tatar - Language.CUR => GetDefaultLetterKeyCUR(letter), // Currency - Language.CY => GetDefaultLetterKeyCY(letter), // Welsh - Language.CZ => GetDefaultLetterKeyCZ(letter), // Czech - Language.DK => GetDefaultLetterKeyDK(letter), // Danish - Language.GA => GetDefaultLetterKeyGA(letter), // Gaeilge (Irish) - Language.GD => GetDefaultLetterKeyGD(letter), // Gàidhlig (Scottish Gaelic) - Language.DE => GetDefaultLetterKeyDE(letter), // German - Language.EL => GetDefaultLetterKeyEL(letter), // Greek - Language.EST => GetDefaultLetterKeyEST(letter), // Estonian - Language.EPO => GetDefaultLetterKeyEPO(letter), // Esperanto - Language.FI => GetDefaultLetterKeyFI(letter), // Finnish - Language.FR => GetDefaultLetterKeyFR(letter), // French - Language.HR => GetDefaultLetterKeyHR(letter), // Croatian - Language.HE => GetDefaultLetterKeyHE(letter), // Hebrew - Language.HU => GetDefaultLetterKeyHU(letter), // Hungarian - Language.IS => GetDefaultLetterKeyIS(letter), // Iceland - Language.IPA => GetDefaultLetterKeyIPA(letter), // IPA (International phonetic alphabet) - Language.IT => GetDefaultLetterKeyIT(letter), // Italian - Language.KU => GetDefaultLetterKeyKU(letter), // Kurdish - Language.LT => GetDefaultLetterKeyLT(letter), // Lithuanian - Language.MK => GetDefaultLetterKeyMK(letter), // Macedonian - Language.MI => GetDefaultLetterKeyMI(letter), // Maori - Language.NL => GetDefaultLetterKeyNL(letter), // Dutch - Language.NO => GetDefaultLetterKeyNO(letter), // Norwegian - Language.PI => GetDefaultLetterKeyPI(letter), // Pinyin - Language.PL => GetDefaultLetterKeyPL(letter), // Polish - Language.PT => GetDefaultLetterKeyPT(letter), // Portuguese - Language.RO => GetDefaultLetterKeyRO(letter), // Romanian - Language.ROM => GetDefaultLetterKeyROM(letter), // Middle Eastern Romanization - Language.SK => GetDefaultLetterKeySK(letter), // Slovak - Language.SL => GetDefaultLetterKeySL(letter), // Slovenian - Language.SP => GetDefaultLetterKeySP(letter), // Spain - Language.SR => GetDefaultLetterKeySR(letter), // Serbian - Language.SR_CYRL => GetDefaultLetterKeySRCyrillic(letter), // Serbian Cyrillic - Language.SV => GetDefaultLetterKeySV(letter), // Swedish - Language.TK => GetDefaultLetterKeyTK(letter), // Turkish - _ => throw new ArgumentException("The language {0} is not known in this context", lang.ToString()), - }; + public static string[] GetDefaultLetterKey(LetterKey letter, Language[] langs) + { + if (langs.Length == Enum.GetValues(typeof(Language)).Length) + { + return GetDefaultLetterKeyALL(letter); + } + + if (langs.Length == 0) + { + return Array.Empty(); + } + + var characters = new List(); + foreach (var lang in langs) + { + characters.AddRange(lang switch + { + Language.SPECIAL => GetDefaultLetterKeySPECIAL(letter), // Special Characters + Language.BG => GetDefaultLetterKeyBG(letter), // Bulgarian + Language.CA => GetDefaultLetterKeyCA(letter), // Catalan + Language.CRH => GetDefaultLetterKeyCRH(letter), // Crimean Tatar + Language.CUR => GetDefaultLetterKeyCUR(letter), // Currency + Language.CY => GetDefaultLetterKeyCY(letter), // Welsh + Language.CZ => GetDefaultLetterKeyCZ(letter), // Czech + Language.DK => GetDefaultLetterKeyDK(letter), // Danish + Language.GA => GetDefaultLetterKeyGA(letter), // Gaeilge (Irish) + Language.GD => GetDefaultLetterKeyGD(letter), // Gàidhlig (Scottish Gaelic) + Language.DE => GetDefaultLetterKeyDE(letter), // German + Language.EL => GetDefaultLetterKeyEL(letter), // Greek + Language.EST => GetDefaultLetterKeyEST(letter), // Estonian + Language.EPO => GetDefaultLetterKeyEPO(letter), // Esperanto + Language.FI => GetDefaultLetterKeyFI(letter), // Finnish + Language.FR => GetDefaultLetterKeyFR(letter), // French + Language.HR => GetDefaultLetterKeyHR(letter), // Croatian + Language.HE => GetDefaultLetterKeyHE(letter), // Hebrew + Language.HU => GetDefaultLetterKeyHU(letter), // Hungarian + Language.IS => GetDefaultLetterKeyIS(letter), // Iceland + Language.IPA => GetDefaultLetterKeyIPA(letter), // IPA (International phonetic alphabet) + Language.IT => GetDefaultLetterKeyIT(letter), // Italian + Language.KU => GetDefaultLetterKeyKU(letter), // Kurdish + Language.LT => GetDefaultLetterKeyLT(letter), // Lithuanian + Language.MK => GetDefaultLetterKeyMK(letter), // Macedonian + Language.MI => GetDefaultLetterKeyMI(letter), // Maori + Language.NL => GetDefaultLetterKeyNL(letter), // Dutch + Language.NO => GetDefaultLetterKeyNO(letter), // Norwegian + Language.PI => GetDefaultLetterKeyPI(letter), // Pinyin + Language.PL => GetDefaultLetterKeyPL(letter), // Polish + Language.PT => GetDefaultLetterKeyPT(letter), // Portuguese + Language.RO => GetDefaultLetterKeyRO(letter), // Romanian + Language.ROM => GetDefaultLetterKeyROM(letter), // Middle Eastern Romanization + Language.SK => GetDefaultLetterKeySK(letter), // Slovak + Language.SL => GetDefaultLetterKeySL(letter), // Slovenian + Language.SP => GetDefaultLetterKeySP(letter), // Spain + Language.SR => GetDefaultLetterKeySR(letter), // Serbian + Language.SR_CYRL => GetDefaultLetterKeySRCyrillic(letter), // Serbian Cyrillic + Language.SV => GetDefaultLetterKeySV(letter), // Swedish + Language.TK => GetDefaultLetterKeyTK(letter), // Turkish + _ => throw new ArgumentException("The language {0} is not known in this context", lang.ToString()), + }); + } + + return characters.Distinct().ToArray(); } // Store the computed letters for each key, so that subsequent calls don't take as long. @@ -149,7 +165,7 @@ private static string[] GetDefaultLetterKeyALL(LetterKey letter) .Union(GetDefaultLetterKeySRCyrillic(letter)) .Union(GetDefaultLetterKeySV(letter)) .Union(GetDefaultLetterKeyTK(letter)) - .Union(GetDefaultLetterKeyAllLanguagesOnly(letter)) + .Union(GetDefaultLetterKeySPECIAL(letter)) .ToArray(); _allLanguagesCache[letter] = cachedValue; @@ -160,7 +176,7 @@ private static string[] GetDefaultLetterKeyALL(LetterKey letter) // Contains all characters that should be shown in all languages but currently don't belong to any of the single languages available for that letter. // These characters can be removed from this list after they've been added to one of the other languages for that specific letter. - private static string[] GetDefaultLetterKeyAllLanguagesOnly(LetterKey letter) + private static string[] GetDefaultLetterKeySPECIAL(LetterKey letter) { return letter switch { diff --git a/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs b/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs index a745d83bc91..cd9ab476d84 100644 --- a/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs +++ b/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs @@ -66,7 +66,10 @@ private void ReadSettings() ExcludedApps = settings.Properties.ExcludedApps.Value; _keyboardListener.UpdateExcludedApps(ExcludedApps); - SelectedLang = Enum.TryParse(settings.Properties.SelectedLang.Value, out Language selectedLangValue) ? selectedLangValue : Language.ALL; + SelectedLang = settings.Properties.SelectedLang.Value + .Split(',', StringSplitOptions.RemoveEmptyEntries) + .Select(lang => Enum.TryParse(lang, out Language selectedLangValue) ? selectedLangValue : Language.SPECIAL) + .ToArray(); switch (settings.Properties.ToolbarPosition.Value) { @@ -187,9 +190,9 @@ public string ExcludedApps } } - private Language _selectedLang; + private Language[] _selectedLang; - public Language SelectedLang + public Language[] SelectedLang { get { diff --git a/src/settings-ui/Settings.UI.Library/PowerAccentLanguageGroupModel.cs b/src/settings-ui/Settings.UI.Library/PowerAccentLanguageGroupModel.cs new file mode 100644 index 00000000000..8033782bd7c --- /dev/null +++ b/src/settings-ui/Settings.UI.Library/PowerAccentLanguageGroupModel.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.Collections.Generic; + +namespace Microsoft.PowerToys.Settings.UI.Library +{ + public class PowerAccentLanguageGroupModel : List + { + public PowerAccentLanguageGroupModel(List languages, string group) + : base(languages) + { + this.Group = group; + } + + public string Group { get; init; } + } +} diff --git a/src/settings-ui/Settings.UI.Library/PowerAccentLanguageModel.cs b/src/settings-ui/Settings.UI.Library/PowerAccentLanguageModel.cs new file mode 100644 index 00000000000..13de2ac653d --- /dev/null +++ b/src/settings-ui/Settings.UI.Library/PowerAccentLanguageModel.cs @@ -0,0 +1,11 @@ +// 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 Microsoft.PowerToys.Settings.UI.Library +{ + public record PowerAccentLanguageModel(string LanguageCode, string LanguageResourceID, string GroupResourceID) + { + public string Language { get; set; } + } +} diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml index 77c96b15f69..790d8182b3d 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml @@ -1,7 +1,8 @@ - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml.cs index 91e57b8105e..c0e78d3e87c 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml.cs @@ -1,10 +1,12 @@ // 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.Linq; +using CommunityToolkit.WinUI; using Microsoft.PowerToys.Settings.UI.Helpers; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.ViewModels; +using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; namespace Microsoft.PowerToys.Settings.UI.Views @@ -19,11 +21,65 @@ public PowerAccentPage() ViewModel = new PowerAccentViewModel(settingsUtils, SettingsRepository.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage); DataContext = ViewModel; this.InitializeComponent(); + this.InitializeControlsStates(); } public void RefreshEnabledState() { ViewModel.RefreshEnabledState(); } + + private void InitializeControlsStates() + { + SetCheckBoxStatus(); + } + + private void SetCheckBoxStatus() + { + if (ViewModel.SelectedLanguageOptions.Length == 0) + { + this.QuickAccent_SelectedLanguage_All.IsChecked = false; + this.QuickAccent_SelectedLanguage_All.IsThreeState = false; + } + else if (ViewModel.AllSelected) + { + this.QuickAccent_SelectedLanguage_All.IsChecked = true; + this.QuickAccent_SelectedLanguage_All.IsThreeState = false; + } + else + { + this.QuickAccent_SelectedLanguage_All.IsThreeState = true; + this.QuickAccent_SelectedLanguage_All.IsChecked = null; + } + } + + private void QuickAccent_SelectedLanguage_SelectAll(object sender, RoutedEventArgs e) + { + this.QuickAccent_Language_Select.SelectAllSafe(); + } + + private void QuickAccent_SelectedLanguage_UnselectAll(object sender, RoutedEventArgs e) + { + this.QuickAccent_Language_Select.DeselectAll(); + } + + private void QuickAccent_SelectedLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + var listView = sender as ListView; + + ViewModel.SelectedLanguageOptions = listView.SelectedItems + .Select(item => item as PowerAccentLanguageModel) + .ToArray(); + + SetCheckBoxStatus(); + } + + private void QuickAccent_Language_Select_Loaded(object sender, RoutedEventArgs e) + { + foreach (var languageOption in ViewModel.SelectedLanguageOptions) + { + this.QuickAccent_Language_Select.SelectedItems.Add(languageOption); + } + } } } diff --git a/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw b/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw index 781a89ae880..59626edce64 100644 --- a/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw +++ b/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw @@ -1,4 +1,4 @@ - +