Skip to content

Commit

Permalink
PowerAccent with multi-language selection
Browse files Browse the repository at this point in the history
- Updated Language enum, method signatures, and settings to support multiple language selections.
- Remove ALL language and added special characters language instead.
- Modified UI to use ListView with checkboxes for language selection, including a "Select All" option.
- Adjusted ViewModel and code-behind to handle multi-selection logic.
- Updated Resources.resw and PowerAccentViewModel.cs to reflect these changes.
  • Loading branch information
Sirozha1337 committed Oct 22, 2024
1 parent 5af2f6f commit e19ee7d
Show file tree
Hide file tree
Showing 6 changed files with 391 additions and 153 deletions.
109 changes: 60 additions & 49 deletions src/modules/poweraccent/PowerAccent.Core/Languages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace PowerAccent.Core
{
public enum Language
{
ALL,
SPECIAL,
BG,
CA,
CRH,
Expand Down Expand Up @@ -54,52 +54,63 @@ 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);
}

var characters = new List<string>();
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.
Expand Down Expand Up @@ -149,7 +160,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;
Expand All @@ -160,7 +171,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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(',')
.Select(lang => Enum.TryParse(lang, out Language selectedLangValue) ? selectedLangValue : Language.SPECIAL)
.ToArray();

switch (settings.Properties.ToolbarPosition.Value)
{
Expand Down Expand Up @@ -187,9 +190,9 @@ public string ExcludedApps
}
}

private Language _selectedLang;
private Language[] _selectedLang;

public Language SelectedLang
public Language[] SelectedLang
{
get
{
Expand Down
Loading

0 comments on commit e19ee7d

Please sign in to comment.