[QuickAccent]Fix unstable language loading (#36721)

This commit is contained in:
Jaime Bernardo 2025-01-13 15:13:50 +00:00 коммит произвёл GitHub
Родитель df48a33bb9
Коммит 4951a63352
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 11 добавлений и 0 удалений

Просмотреть файл

@ -63,8 +63,15 @@ namespace Microsoft.PowerToys.Settings.UI.Views
this.QuickAccent_Language_Select.DeselectAll(); this.QuickAccent_Language_Select.DeselectAll();
} }
private bool loadingLanguageListDontTriggerSelectionChanged;
private void QuickAccent_SelectedLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e) private void QuickAccent_SelectedLanguage_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
if (loadingLanguageListDontTriggerSelectionChanged)
{
return;
}
var listView = sender as ListView; var listView = sender as ListView;
ViewModel.SelectedLanguageOptions = listView.SelectedItems ViewModel.SelectedLanguageOptions = listView.SelectedItems
@ -76,10 +83,13 @@ namespace Microsoft.PowerToys.Settings.UI.Views
private void QuickAccent_Language_Select_Loaded(object sender, RoutedEventArgs e) private void QuickAccent_Language_Select_Loaded(object sender, RoutedEventArgs e)
{ {
loadingLanguageListDontTriggerSelectionChanged = true;
foreach (var languageOption in ViewModel.SelectedLanguageOptions) foreach (var languageOption in ViewModel.SelectedLanguageOptions)
{ {
this.QuickAccent_Language_Select.SelectedItems.Add(languageOption); this.QuickAccent_Language_Select.SelectedItems.Add(languageOption);
} }
loadingLanguageListDontTriggerSelectionChanged = false;
} }
} }
} }

Просмотреть файл

@ -115,6 +115,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{ {
SelectedLanguageOptions = _powerAccentSettings.Properties.SelectedLang.Value.Split(',') SelectedLanguageOptions = _powerAccentSettings.Properties.SelectedLang.Value.Split(',')
.Select(l => Languages.Find(lang => lang.LanguageCode == l)) .Select(l => Languages.Find(lang => lang.LanguageCode == l))
.Where(l => l != null) // Wrongly typed languages will appear as null after find. We want to remove those to avoid crashes.
.ToArray(); .ToArray();
} }
else if (_powerAccentSettings.Properties.SelectedLang.Value.Contains("ALL")) else if (_powerAccentSettings.Properties.SelectedLang.Value.Contains("ALL"))