[TextExtractor]Minor UI/Accessibility fixes in the overlay UI (#36356)

minor UI and accessibility fixes
This commit is contained in:
Davide Giacometti 2025-01-02 18:34:58 +01:00 коммит произвёл GitHub
Родитель 2ba5fb75bc
Коммит 1eec678276
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 40 добавлений и 10 удалений

Просмотреть файл

@ -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"
@ -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">
@ -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" />

Просмотреть файл

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows;
@ -76,7 +77,7 @@ public partial class OCROverlay : Window
if (string.IsNullOrEmpty(selectedLanguageName))
{
selectedLanguage = ImageMethods.GetOCRLanguage();
selectedLanguageName = selectedLanguage?.DisplayName;
selectedLanguageName = selectedLanguage?.NativeName;
}
List<Language> possibleOcrLanguages = OcrEngine.AvailableRecognizerLanguages.ToList();
@ -85,10 +86,10 @@ public partial class OCROverlay : Window
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;
@ -358,7 +359,12 @@ public partial class OCROverlay : Window
// 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}");
@ -499,4 +505,16 @@ public partial class OCROverlay : Window
{
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);
}
}

Просмотреть файл

@ -57,7 +57,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
_languageIndex = value;
if (_powerOcrSettings != null && _languageIndex < possibleOcrLanguages.Count && _languageIndex >= 0)
{
_powerOcrSettings.Properties.PreferredLanguage = possibleOcrLanguages[_languageIndex].DisplayName;
_powerOcrSettings.Properties.PreferredLanguage = possibleOcrLanguages[_languageIndex].NativeName;
NotifySettingsChanged();
}
@ -186,7 +186,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
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)
@ -264,5 +264,17 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
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);
}
}
}