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 Nov 13, 2024
1 parent 714ce45 commit 896a856
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 245 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; }
}
}
161 changes: 37 additions & 124 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="LanguagesCustomViewSource" IsSourceGrouped="True" Source="{x:Bind ViewModel.LanguageGroups, Mode=OneWay}" />
<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 LanguagesCustomViewSource.View, Mode=OneWay}"
ItemTemplate="{StaticResource LanguageViewTemplate}"
Loaded="QuickAccent_Language_Select_Loaded"
SelectionMode="Multiple">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
Expand All @@ -92,9 +102,22 @@
<ListViewItemPresenter
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
CheckBoxCornerRadius="{ThemeResource ControlCornerRadius}"
CheckBoxBorderBrush="{ThemeResource CheckBoxBorderThemeBrush}"
CheckBoxBrush="{ThemeResource CheckBoxBackgroundThemeBrush}"
CheckBrush="{ThemeResource CheckBoxForegroundUnchecked}"
CheckBoxPointerOverBorderBrush="{ThemeResource CheckBoxPointerOverBorderThemeBrush}"
CheckBoxPressedBorderBrush="{ThemeResource CheckBoxPressedBorderThemeBrush}"
CheckBoxDisabledBorderBrush="{ThemeResource CheckBoxDisabledBorderThemeBrush}"
CheckBoxBrush="{ThemeResource CheckBoxCheckBackgroundFillUnchecked}"
CheckBoxPointerOverBrush="{ThemeResource CheckBoxCheckBackgroundFillUncheckedPointerOver}"
CheckBoxPressedBrush="{ThemeResource CheckBoxCheckBackgroundFillUncheckedPressed}"
CheckBoxDisabledBrush="{ThemeResource CheckBoxCheckBackgroundFillUncheckedDisabled}"
CheckBoxSelectedBrush="{ThemeResource CheckBoxCheckBackgroundFillChecked}"
CheckBoxSelectedPointerOverBrush="{ThemeResource CheckBoxCheckBackgroundFillCheckedPointerOver}"
CheckBoxSelectedPressedBrush="{ThemeResource CheckBoxCheckBackgroundFillCheckedPressed}"
CheckBoxSelectedDisabledBrush="{ThemeResource CheckBoxCheckBackgroundFillCheckedDisabled}"
CheckBrush="{ThemeResource CheckBoxCheckGlyphForegroundChecked}"
CheckPressedBrush="{ThemeResource CheckBoxCheckGlyphForegroundUncheckedPressed}"
CheckDisabledBrush="{ThemeResource CheckBoxCheckGlyphForegroundCheckedDisabled}"
CheckMode="Inline"
ContentMargin="{TemplateBinding Padding}"
ContentTransitions="{TemplateBinding ContentTransitions}"
Expand All @@ -119,127 +142,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 896a856

Please sign in to comment.