Skip to content

Commit

Permalink
Changes Language selection UI
Browse files Browse the repository at this point in the history
- Groups languages into two groups
- Sort them by localized language name
- Remove unneeded looping when no languages selected
  • Loading branch information
Sirozha1337 committed Oct 25, 2024
1 parent 714ce45 commit 9c998a9
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 243 deletions.
5 changes: 5 additions & 0 deletions src/modules/poweraccent/PowerAccent.Core/Languages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public static string[] GetDefaultLetterKey(LetterKey letter, Language[] langs)
return GetDefaultLetterKeyALL(letter);
}

if (langs.Length == 0)
{
return Array.Empty<string>();
}

var characters = new List<string>();
foreach (var lang in langs)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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<PowerAccentLanguageModel>
{
public PowerAccentLanguageGroupModel(List<PowerAccentLanguageModel> languages, string group)
: base(languages)
{
this.Group = group;
}

public string Group { get; init; }
}
}
11 changes: 11 additions & 0 deletions src/settings-ui/Settings.UI.Library/PowerAccentLanguageModel.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
144 changes: 22 additions & 122 deletions src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls"
xmlns:ui="using:CommunityToolkit.WinUI"
xmlns:Lib="using:Microsoft.PowerToys.Settings.UI.Library"
AutomationProperties.LandmarkType="Main"
mc:Ignorable="d">

<Page.Resources>
<CollectionViewSource x:Name="LanguagesCVS" IsSourceGrouped="True" Source="{x:Bind ViewModel.LanguageGroups, Mode=OneWay}" />

Check failure on line 14 in src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml

View workflow job for this annotation

GitHub Actions / Spell checking

`CVS` is not a recognized word. (unrecognized-spelling)
<DataTemplate x:Key="LanguageViewTemplate" x:DataType="Lib:PowerAccentLanguageModel">
<TextBlock Text="{x:Bind Language}" />
</DataTemplate>
</Page.Resources>

<controls:SettingsPageControl
x:Uid="QuickAccent"
IsTabStop="False"
Expand Down Expand Up @@ -75,6 +82,9 @@
ScrollViewer.VerticalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollMode="Enabled"
SelectionChanged="QuickAccent_SelectedLanguage_SelectionChanged"
ItemsSource="{x:Bind LanguagesCVS.View, Mode=OneWay}"

Check failure on line 85 in src/settings-ui/Settings.UI/SettingsXAML/Views/PowerAccentPage.xaml

View workflow job for this annotation

GitHub Actions / Spell checking

`CVS` is not a recognized word. (unrecognized-spelling)
ItemTemplate="{StaticResource LanguageViewTemplate}"
Loaded="QuickAccent_Language_Select_Loaded"
SelectionMode="Multiple">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
Expand Down Expand Up @@ -119,127 +129,17 @@
</Setter>
</Style>
</ListView.ItemContainerStyle>
<!-- These should be in the same order as the array items in PowerAccentViewModel.cs -->
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Special" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Bulgarian" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Catalan" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Crimean" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Currency" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Croatian" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Czech" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Danish" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Gaeilge" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Gaidhlig" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Dutch" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Greek" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Estonian" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Esperanto" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Finnish" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_French" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_German" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Hebrew" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Hungarian" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Icelandic" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_IPA" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Italian" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Kurdish" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Lithuanian" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Macedonian" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Maori" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Norwegian" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Pinyin" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Polish" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Portuguese" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Romanian" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Romanization" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Slovak" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Slovenian" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Spanish" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Serbian" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Serbian_Cyrillic" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Swedish" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Turkish" />
</ListViewItem>
<ListViewItem>
<TextBlock x:Uid="QuickAccent_SelectedLanguage_Welsh" />
</ListViewItem>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate x:DataType="Lib:PowerAccentLanguageGroupModel">
<Border AutomationProperties.AccessibilityView="Raw">
<TextBlock Text="{x:Bind Group}" Style="{ThemeResource SubtitleTextBlockStyle}" AutomationProperties.AccessibilityView="Raw"/>
</Border>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
</tkcontrols:SettingsCard>
</tkcontrols:SettingsExpander.Items>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
}
Loading

0 comments on commit 9c998a9

Please sign in to comment.