diff --git a/src/modules/poweraccent/PowerAccent.Core/Languages.cs b/src/modules/poweraccent/PowerAccent.Core/Languages.cs index 0edf936dffb..2838fe95889 100644 --- a/src/modules/poweraccent/PowerAccent.Core/Languages.cs +++ b/src/modules/poweraccent/PowerAccent.Core/Languages.cs @@ -61,6 +61,11 @@ public static string[] GetDefaultLetterKey(LetterKey letter, Language[] langs) return GetDefaultLetterKeyALL(letter); } + if (langs.Length == 0) + { + return Array.Empty(); + } + var characters = new List(); foreach (var lang in langs) { diff --git a/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs b/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs index 9a35460a43a..cd9ab476d84 100644 --- a/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs +++ b/src/modules/poweraccent/PowerAccent.Core/Services/SettingsService.cs @@ -67,7 +67,7 @@ private void ReadSettings() _keyboardListener.UpdateExcludedApps(ExcludedApps); SelectedLang = settings.Properties.SelectedLang.Value - .Split(',') + .Split(',', StringSplitOptions.RemoveEmptyEntries) .Select(lang => Enum.TryParse(lang, out Language selectedLangValue) ? selectedLangValue : Language.SPECIAL) .ToArray(); 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 fbb88b67342..790d8182b3d 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml @@ -2,6 +2,7 @@ x:Class="Microsoft.PowerToys.Settings.UI.Views.PowerAccentPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:Lib="using:Microsoft.PowerToys.Settings.UI.Library" xmlns:controls="using:Microsoft.PowerToys.Settings.UI.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" @@ -9,6 +10,15 @@ xmlns:ui="using:CommunityToolkit.WinUI" AutomationProperties.LandmarkType="Main" mc:Ignorable="d"> + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + 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 3e124046200..c0e78d3e87c 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml.cs @@ -31,25 +31,12 @@ public void RefreshEnabledState() private void InitializeControlsStates() { - SetListViewSelected(); SetCheckBoxStatus(); } - private void SetListViewSelected() - { - foreach (var languageIndex in ViewModel.SelectedLangIndexes) - { - var item = this.QuickAccent_Language_Select.Items.ElementAtOrDefault(languageIndex); - if (item != null) - { - this.QuickAccent_Language_Select.SelectedItems.Add(item); - } - } - } - private void SetCheckBoxStatus() { - if (ViewModel.SelectedLangIndexes.Length == 0) + if (ViewModel.SelectedLanguageOptions.Length == 0) { this.QuickAccent_SelectedLanguage_All.IsChecked = false; this.QuickAccent_SelectedLanguage_All.IsThreeState = false; @@ -79,10 +66,20 @@ private void QuickAccent_SelectedLanguage_UnselectAll(object sender, RoutedEvent private void QuickAccent_SelectedLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e) { var listView = sender as ListView; - var indexes = listView.SelectedItems.Select(listView.Items.IndexOf).ToArray(); - ViewModel.SelectedLangIndexes = indexes; + + 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 01dc78b00cf..59626edce64 100644 --- a/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw +++ b/src/settings-ui/Settings.UI/Strings/en-us/Resources.resw @@ -3540,130 +3540,136 @@ Activate by holding the key for the character you want to add an accent to, then Show only accented characters common to the selected set - + All available - + + Special sets + + + Language sets + + Special Characters - + Bulgarian - + Catalan - + Crimean Tatar - + Currency - + Croatian - + Czech - + Danish - + Gaeilge Gaelic language spoken in Ireland - + Gàidhlig Scottish Gaelic - + German - + Greek - + Hebrew - + French - + Finnish - + Estonian - + Esperanto - + IPA International Phonetic Alphabet - + Lithuanian - + Macedonian - + Maori - + Middle Eastern Romanization - + Dutch - + Norwegian - + Pinyin - + Polish - + Portuguese - + Slovak - + Slovenian - + Spanish - + Swedish - + Turkish - + Icelandic - + Romanian - + Serbian - + Serbian Cyrillic - + Hungarian - + Italian - + Kurdish - + Welsh diff --git a/src/settings-ui/Settings.UI/ViewModels/PowerAccentViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/PowerAccentViewModel.cs index 7947f47a52d..0c4f9db6509 100644 --- a/src/settings-ui/Settings.UI/ViewModels/PowerAccentViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/PowerAccentViewModel.cs @@ -3,10 +3,11 @@ // See the LICENSE file in the project root for more information. using System; +using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; - using global::PowerToys.GPOWrapper; +using Microsoft.PowerToys.Settings.UI.Helpers; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Enumerations; using Microsoft.PowerToys.Settings.UI.Library.Helpers; @@ -22,50 +23,53 @@ public class PowerAccentViewModel : Observable private readonly ISettingsUtils _settingsUtils; - // These should be in the same order as the ComboBoxItems in PowerAccentPage.xaml - private readonly string[] _languageOptions = - { - "SPECIAL", - "BG", - "CA", - "CRH", - "CUR", - "HR", - "CZ", - "DK", - "GA", - "GD", - "NL", - "EL", - "EST", - "EPO", - "FI", - "FR", - "DE", - "HE", - "HU", - "IS", - "IPA", - "IT", - "KU", - "LT", - "MK", - "MI", - "NO", - "PI", - "PL", - "PT", - "RO", - "ROM", - "SK", - "SL", - "SP", - "SR", - "SR_CYRL", - "SV", - "TK", - "CY", - }; + private const string SpecialGroup = "QuickAccent_Group_Special"; + private const string LanguageGroup = "QuickAccent_Group_Language"; + + public List Languages { get; } = [ + new PowerAccentLanguageModel("SPECIAL", "QuickAccent_SelectedLanguage_Special", SpecialGroup), + new PowerAccentLanguageModel("BG", "QuickAccent_SelectedLanguage_Bulgarian", LanguageGroup), + new PowerAccentLanguageModel("CA", "QuickAccent_SelectedLanguage_Catalan", LanguageGroup), + new PowerAccentLanguageModel("CRH", "QuickAccent_SelectedLanguage_Crimean", LanguageGroup), + new PowerAccentLanguageModel("CUR", "QuickAccent_SelectedLanguage_Currency", SpecialGroup), + new PowerAccentLanguageModel("HR", "QuickAccent_SelectedLanguage_Croatian", LanguageGroup), + new PowerAccentLanguageModel("CZ", "QuickAccent_SelectedLanguage_Czech", LanguageGroup), + new PowerAccentLanguageModel("DK", "QuickAccent_SelectedLanguage_Danish", LanguageGroup), + new PowerAccentLanguageModel("GA", "QuickAccent_SelectedLanguage_Gaeilge", LanguageGroup), + new PowerAccentLanguageModel("GD", "QuickAccent_SelectedLanguage_Gaidhlig", LanguageGroup), + new PowerAccentLanguageModel("NL", "QuickAccent_SelectedLanguage_Dutch", LanguageGroup), + new PowerAccentLanguageModel("EL", "QuickAccent_SelectedLanguage_Greek", LanguageGroup), + new PowerAccentLanguageModel("EST", "QuickAccent_SelectedLanguage_Estonian", LanguageGroup), + new PowerAccentLanguageModel("EPO", "QuickAccent_SelectedLanguage_Esperanto", LanguageGroup), + new PowerAccentLanguageModel("FI", "QuickAccent_SelectedLanguage_Finnish", LanguageGroup), + new PowerAccentLanguageModel("FR", "QuickAccent_SelectedLanguage_French", LanguageGroup), + new PowerAccentLanguageModel("DE", "QuickAccent_SelectedLanguage_German", LanguageGroup), + new PowerAccentLanguageModel("HE", "QuickAccent_SelectedLanguage_Hebrew", LanguageGroup), + new PowerAccentLanguageModel("HU", "QuickAccent_SelectedLanguage_Hungarian", LanguageGroup), + new PowerAccentLanguageModel("IS", "QuickAccent_SelectedLanguage_Icelandic", LanguageGroup), + new PowerAccentLanguageModel("IPA", "QuickAccent_SelectedLanguage_IPA", SpecialGroup), + new PowerAccentLanguageModel("IT", "QuickAccent_SelectedLanguage_Italian", LanguageGroup), + new PowerAccentLanguageModel("KU", "QuickAccent_SelectedLanguage_Kurdish", LanguageGroup), + new PowerAccentLanguageModel("LT", "QuickAccent_SelectedLanguage_Lithuanian", LanguageGroup), + new PowerAccentLanguageModel("MK", "QuickAccent_SelectedLanguage_Macedonian", LanguageGroup), + new PowerAccentLanguageModel("MI", "QuickAccent_SelectedLanguage_Maori", LanguageGroup), + new PowerAccentLanguageModel("NO", "QuickAccent_SelectedLanguage_Norwegian", LanguageGroup), + new PowerAccentLanguageModel("PI", "QuickAccent_SelectedLanguage_Pinyin", LanguageGroup), + new PowerAccentLanguageModel("PL", "QuickAccent_SelectedLanguage_Polish", LanguageGroup), + new PowerAccentLanguageModel("PT", "QuickAccent_SelectedLanguage_Portuguese", LanguageGroup), + new PowerAccentLanguageModel("RO", "QuickAccent_SelectedLanguage_Romanian", LanguageGroup), + new PowerAccentLanguageModel("ROM", "QuickAccent_SelectedLanguage_Romanization", SpecialGroup), + new PowerAccentLanguageModel("SK", "QuickAccent_SelectedLanguage_Slovak", LanguageGroup), + new PowerAccentLanguageModel("SL", "QuickAccent_SelectedLanguage_Slovenian", LanguageGroup), + new PowerAccentLanguageModel("SP", "QuickAccent_SelectedLanguage_Spanish", LanguageGroup), + new PowerAccentLanguageModel("SR", "QuickAccent_SelectedLanguage_Serbian", LanguageGroup), + new PowerAccentLanguageModel("SR_CYRL", "QuickAccent_SelectedLanguage_Serbian_Cyrillic", LanguageGroup), + new PowerAccentLanguageModel("SV", "QuickAccent_SelectedLanguage_Swedish", LanguageGroup), + new PowerAccentLanguageModel("TK", "QuickAccent_SelectedLanguage_Turkish", LanguageGroup), + new PowerAccentLanguageModel("CY", "QuickAccent_SelectedLanguage_Welsh", LanguageGroup), + ]; + + public PowerAccentLanguageGroupModel[] LanguageGroups { get; private set; } private readonly string[] _toolbarOptions = { @@ -91,6 +95,7 @@ public PowerAccentViewModel(ISettingsUtils settingsUtils, ISettingsRepository Array.IndexOf(_languageOptions, l)).ToArray(); + SelectedLanguageOptions = _powerAccentSettings.Properties.SelectedLang.Value.Split(',') + .Select(l => Languages.Find(lang => lang.LanguageCode == l)) + .ToArray(); + } + else if (_powerAccentSettings.Properties.SelectedLang.Value.Contains("ALL")) + { + SelectedLanguageOptions = Languages.ToArray(); } else { - SelectedLangIndexes = Enumerable.Range(0, _languageOptions.Length).ToArray(); + SelectedLanguageOptions = Array.Empty(); } _toolbarPositionIndex = Array.IndexOf(_toolbarOptions, _powerAccentSettings.Properties.ToolbarPosition.Value); @@ -135,6 +146,23 @@ private void InitializeEnabledValue() } } + /// + /// Adds Localized Language Name, sorts by it and splits languages into two groups. + /// + private void InitializeLanguages() + { + foreach (var item in Languages) + { + item.Language = ResourceLoaderInstance.ResourceLoader.GetString(item.LanguageResourceID); + } + + Languages.Sort((x, y) => string.Compare(x.Language, y.Language, StringComparison.Ordinal)); + LanguageGroups = Languages + .GroupBy(language => language.GroupResourceID) + .Select(grp => new PowerAccentLanguageGroupModel(grp.ToList(), ResourceLoaderInstance.ResourceLoader.GetString(grp.Key))) + .ToArray(); + } + public bool IsEnabled { get => _isEnabled; @@ -261,27 +289,18 @@ public int ToolbarPositionIndex } } - public bool AllSelected => _selectedLanguages.Length == _languageOptions.Length; + public bool AllSelected => _selectedLanguageOptions.Length == Languages.Count; - private string[] _selectedLanguages; + private PowerAccentLanguageModel[] _selectedLanguageOptions; - private int[] _selectedLangIndexes; - - public int[] SelectedLangIndexes + public PowerAccentLanguageModel[] SelectedLanguageOptions { - get => _selectedLangIndexes; + get => _selectedLanguageOptions; set { - if (_selectedLangIndexes == value) - { - return; - } - - _selectedLangIndexes = value; - _selectedLanguages = _selectedLangIndexes.Select(s => _languageOptions[s]).ToArray(); - - _powerAccentSettings.Properties.SelectedLang.Value = string.Join(',', _selectedLanguages); - RaisePropertyChanged(nameof(SelectedLangIndexes)); + _selectedLanguageOptions = value; + _powerAccentSettings.Properties.SelectedLang.Value = string.Join(',', _selectedLanguageOptions.Select(l => l.LanguageCode)); + RaisePropertyChanged(nameof(SelectedLanguageOptions)); } }