Skip to content

Commit

Permalink
minor UI and accessibility fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
davidegiacometti committed Dec 15, 2024
1 parent f19a34d commit bf3183c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/modules/PowerOCR/PowerOCR/OCROverlay.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<Border
x:Name="TopButtonsStackPanel"
Margin="12"
Padding="4,8,12,8"
Padding="4,8,4,8"
HorizontalAlignment="Center"
VerticalAlignment="Top"
d:Visibility="Visible"
Expand All @@ -116,7 +116,6 @@
Orientation="Horizontal">
<ComboBox
x:Name="LanguagesComboBox"
Height="32"
Margin="4,0"
AutomationProperties.Name="{x:Static p:Resources.SelectedLang}"
SelectionChanged="LanguagesComboBox_SelectionChanged">
Expand Down Expand Up @@ -156,6 +155,7 @@
</Button>
<Button
x:Name="CancelButton"
AutomationProperties.Name="{x:Static p:Resources.Cancel}"
Click="CancelMenuItem_Click"
ToolTip="{x:Static p:Resources.CancelShortcut}">
<ui:SymbolIcon FontSize="18" Symbol="Dismiss24" />
Expand Down
30 changes: 24 additions & 6 deletions src/modules/PowerOCR/PowerOCR/OCROverlay.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows;
Expand Down Expand Up @@ -76,7 +77,7 @@ private void PopulateLanguageMenu()
if (string.IsNullOrEmpty(selectedLanguageName))
{
selectedLanguage = ImageMethods.GetOCRLanguage();
selectedLanguageName = selectedLanguage?.DisplayName;
selectedLanguageName = selectedLanguage?.NativeName;
}

List<Language> possibleOcrLanguages = OcrEngine.AvailableRecognizerLanguages.ToList();
Expand All @@ -85,10 +86,10 @@ private void PopulateLanguageMenu()

foreach (Language language in possibleOcrLanguages)
{
MenuItem menuItem = new() { Header = language.NativeName, Tag = language, IsCheckable = true };
menuItem.IsChecked = language.DisplayName.Equals(selectedLanguageName, StringComparison.Ordinal);
LanguagesComboBox.Items.Add(language);
if (language.DisplayName.Equals(selectedLanguageName, StringComparison.Ordinal))
MenuItem menuItem = new() { Header = EnsureStartUpper(language.NativeName), Tag = language, IsCheckable = true };
menuItem.IsChecked = language.NativeName.Equals(selectedLanguageName, StringComparison.OrdinalIgnoreCase);
LanguagesComboBox.Items.Add(new ComboBoxItem { Content = EnsureStartUpper(language.NativeName), Tag = language });
if (language.NativeName.Equals(selectedLanguageName, StringComparison.OrdinalIgnoreCase))
{
selectedLanguage = language;
LanguagesComboBox.SelectedIndex = count;
Expand Down Expand Up @@ -358,7 +359,12 @@ private void LanguagesComboBox_SelectionChanged(object sender, SelectionChangedE

// TODO: Set the preferred language based upon what was chosen here
int selection = languageComboBox.SelectedIndex;
selectedLanguage = languageComboBox.SelectedItem as Language;
selectedLanguage = (languageComboBox.SelectedItem as ComboBoxItem)?.Tag as Language;

if (selectedLanguage == null)
{
return;
}

Logger.LogError($"Changed language to {selectedLanguage?.LanguageTag}");

Expand Down Expand Up @@ -499,4 +505,16 @@ public System.Drawing.Rectangle GetScreenRectangle()
{
return screenRectangle;
}

private string EnsureStartUpper(string input)
{
if (string.IsNullOrEmpty(input))
{
return input;
}

var inputArray = input.ToCharArray();
inputArray[0] = char.ToUpper(inputArray[0], CultureInfo.CurrentCulture);
return new string(inputArray);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
x:Uid="EditButton"
Width="40"
Height="36"
AutomationProperties.HelpText="{x:Bind Name, Mode=OneWay}"
Content="&#xE70F;"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
Style="{StaticResource SubtleButtonStyle}">
Expand Down Expand Up @@ -164,6 +165,7 @@
x:Uid="RemoveButton"
Width="40"
Height="36"
AutomationProperties.HelpText="{x:Bind Name, Mode=OneWay}"
Click="DeleteCustomSize"
CommandParameter="{Binding Id}"
Content="&#xE74D;"
Expand Down
16 changes: 14 additions & 2 deletions src/settings-ui/Settings.UI/ViewModels/PowerOcrViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public int LanguageIndex
_languageIndex = value;
if (_powerOcrSettings != null && _languageIndex < possibleOcrLanguages.Count && _languageIndex >= 0)
{
_powerOcrSettings.Properties.PreferredLanguage = possibleOcrLanguages[_languageIndex].DisplayName;
_powerOcrSettings.Properties.PreferredLanguage = possibleOcrLanguages[_languageIndex].NativeName;
NotifySettingsChanged();
}

Expand Down Expand Up @@ -186,7 +186,7 @@ internal void UpdateLanguages()
systemLanguageIndex = AvailableLanguages.Count;
}

AvailableLanguages.Add(language.NativeName);
AvailableLanguages.Add(EnsureStartUpper(language.NativeName));
}

// if the previously stored preferred language is not available (has been deleted or this is the first run with language preference)
Expand Down Expand Up @@ -264,5 +264,17 @@ public void Dispose()
Dispose(disposing: true);
GC.SuppressFinalize(this);
}

private string EnsureStartUpper(string input)
{
if (string.IsNullOrEmpty(input))
{
return input;
}

var inputArray = input.ToCharArray();
inputArray[0] = char.ToUpper(inputArray[0], CultureInfo.CurrentCulture);
return new string(inputArray);
}
}
}

0 comments on commit bf3183c

Please sign in to comment.