Skip to content

Commit

Permalink
- fix issue when no character
Browse files Browse the repository at this point in the history
- apply multiple countries in the selection
  • Loading branch information
Damien LEROY committed Jan 16, 2024
1 parent 1a9e7c0 commit ad27476
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 17 deletions.
61 changes: 51 additions & 10 deletions PowerAccent.Core/Languages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,47 @@ public enum Language

internal static class Languages
{
public static char[] GetMultipleLetterKey(LetterKey letter, Language[] langs)
{
var multipleLetterKey = new List<char[]>();
foreach (var lang in langs)
{
multipleLetterKey.Add(GetDefaultLetterKey(letter, lang));
}

var result = new List<char>();
for (int i = 0; i < multipleLetterKey.Max(x => x.Length); i++)
{
for (int j = 0; j < multipleLetterKey.Count; j++)
{
if (i < multipleLetterKey[j].Length)
{
result.Add(multipleLetterKey[j][i]);
}

if (j > multipleLetterKey.Count)
j = 0;
}
}

// remove duplicate
int index = 0;
while (index < result.Count)
{
int index2 = result.FindIndex(index + 1, x => x == result[index]);
if (index2 != -1)
{
result.RemoveAt(index);
}
else
{
index++;
}
}

return result.ToArray();
}

public static char[] GetDefaultLetterKey(LetterKey letter, Language lang)
{
switch (lang)
Expand Down Expand Up @@ -200,7 +241,7 @@ private static char[] GetDefaultLetterKeyHR(LetterKey letter)
{
switch (letter)
{

case LetterKey.C:
return new char[] { 'ć', 'č' };
case LetterKey.D:
Expand Down Expand Up @@ -492,7 +533,7 @@ private static char[] GetDefaultLetterKeySK(LetterKey letter)

return Array.Empty<char>();
}

// Czech
private static char[] GetDefaultLetterKeyCZ(LetterKey letter)
{
Expand Down Expand Up @@ -528,7 +569,7 @@ private static char[] GetDefaultLetterKeyCZ(LetterKey letter)

return Array.Empty<char>();
}

// Germany
private static char[] GetDefaultLetterKeyDE(LetterKey letter)
{
Expand Down Expand Up @@ -615,7 +656,7 @@ private static char[] GetDefaultLetterKeyJP(LetterKey letter)
case LetterKey.A:
return new char[] { 'ā', 'â' };
case LetterKey.E:
return new char[] { 'ē', 'ê'};
return new char[] { 'ē', 'ê' };
case LetterKey.I:
return new char[] { 'ī', 'î' };
case LetterKey.O:
Expand All @@ -634,17 +675,17 @@ private static char[] GetDefaultLetterKeyCY(LetterKey letter)
{
switch (letter)
{
case LetterKey.A:
case LetterKey.A:
return new char[] { 'â' };
case LetterKey.E:
case LetterKey.E:
return new char[] { 'ê' };
case LetterKey.I:
case LetterKey.I:
return new char[] { 'î' };
case LetterKey.O:
case LetterKey.O:
return new char[] { 'ô' };
case LetterKey.U:
case LetterKey.U:
return new char[] { 'û' };
case LetterKey.Y:
case LetterKey.Y:
return new char[] { 'ŷ' };
case LetterKey.W:
return new char[] { 'ŵ' };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override bool InvokeKeyDown(uint key)
: SettingsService.GetLetterKey(Options.LetterPressed.Value);
}

if (Options.Characters == Array.Empty<char>())
if (Options.Characters.Length == 0)
{
Debug.WriteLine($"InvokeKeyDown StrokeSpaceModuleHandler - No characters found for {Options.LetterPressed.Value}");
Options.Reset();
Expand Down
4 changes: 2 additions & 2 deletions PowerAccent.Core/Services/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ public char[] GetLetterKey(LetterKey letter)
if (this.PropertyValues.Cast<SettingsPropertyValue>().Any(s => s.Name == key) && this[key] != null)
return (char[])this[key];

return Languages.GetDefaultLetterKey(letter, SelectedLanguage);
return Languages.GetMultipleLetterKey(letter, SelectedLanguages);
}

public char[] GetDefaultLetterKey(LetterKey key)
{
return Languages.GetDefaultLetterKey(key, SelectedLanguage);
return Languages.GetMultipleLetterKey(key, SelectedLanguages);
}

private void AddingProperty(string key)
Expand Down
1 change: 0 additions & 1 deletion PowerAccent.UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Size = PowerAccent.Core.Size;
using Application = System.Windows.Application;
using System.Collections.Generic;
using System.Diagnostics;

namespace PowerAccent.UI;

Expand Down
4 changes: 1 addition & 3 deletions PowerAccent.UI/Selector.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using PowerAccent.Core.Services;
using PowerAccent.Core;
using System.Windows;
using System.Windows;

namespace PowerAccent.UI;

Expand Down

0 comments on commit ad27476

Please sign in to comment.