Skip to content

Commit 675ce59

Browse files
committed
Add default output format setting for Text Extractor
This adds a new setting to allow users to choose the default output format (None, Single line, or Table) when capturing text with Text Extractor. Fixes #38447
1 parent 9dcddfd commit 675ce59

File tree

7 files changed

+69
-0
lines changed

7 files changed

+69
-0
lines changed

src/modules/PowerOCR/PowerOCR/OCROverlay.xaml.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,25 @@ public OCROverlay(System.Drawing.Rectangle screenRectangleParam, DpiScale dpiSca
6767
Wpf.Ui.Appearance.SystemThemeWatcher.Watch(this, Wpf.Ui.Controls.WindowBackdropType.None);
6868

6969
PopulateLanguageMenu();
70+
ApplyDefaultOutputMode();
71+
}
72+
73+
private void ApplyDefaultOutputMode()
74+
{
75+
// 0 = Default (no mode selected), 1 = SingleLine, 2 = Table
76+
int defaultMode = userSettings.DefaultOutputMode.Value;
77+
switch (defaultMode)
78+
{
79+
case 1:
80+
SingleLineMenuItem.IsChecked = true;
81+
break;
82+
case 2:
83+
TableMenuItem.IsChecked = true;
84+
break;
85+
default:
86+
// Default mode - no pre-selection
87+
break;
88+
}
7089
}
7190

7291
private void PopulateLanguageMenu()

src/modules/PowerOCR/PowerOCR/Settings/IUserSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ public interface IUserSettings
1010

1111
SettingItem<string> PreferredLanguage { get; }
1212

13+
SettingItem<int> DefaultOutputMode { get; }
14+
1315
void SendSettingsTelemetry();
1416
}

src/modules/PowerOCR/PowerOCR/Settings/UserSettings.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public UserSettings(Helpers.IThrottledActionInvoker throttledActionInvoker)
3232
_settingsUtils = new SettingsUtils();
3333
ActivationShortcut = new SettingItem<string>(DefaultActivationShortcut);
3434
PreferredLanguage = new SettingItem<string>(string.Empty);
35+
DefaultOutputMode = new SettingItem<int>(0);
3536

3637
LoadSettingsFromJson();
3738

@@ -43,6 +44,8 @@ public UserSettings(Helpers.IThrottledActionInvoker throttledActionInvoker)
4344

4445
public SettingItem<string> PreferredLanguage { get; private set; }
4546

47+
public SettingItem<int> DefaultOutputMode { get; private set; }
48+
4649
private void LoadSettingsFromJson()
4750
{
4851
// TODO this IO call should by Async, update GetFileWatcher helper to support async
@@ -70,6 +73,7 @@ private void LoadSettingsFromJson()
7073
{
7174
ActivationShortcut.Value = settings.Properties.ActivationShortcut.ToString();
7275
PreferredLanguage.Value = settings.Properties.PreferredLanguage.ToString();
76+
DefaultOutputMode.Value = settings.Properties.DefaultOutputMode;
7377
}
7478

7579
retry = false;

src/settings-ui/Settings.UI.Library/PowerOcrProperties.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ public PowerOcrProperties()
1717
{
1818
ActivationShortcut = DefaultActivationShortcut;
1919
PreferredLanguage = string.Empty;
20+
DefaultOutputMode = 0; // 0 = Default, 1 = SingleLine, 2 = Table
2021
}
2122

2223
public HotkeySettings ActivationShortcut { get; set; }
2324

2425
public string PreferredLanguage { get; set; }
2526

27+
public int DefaultOutputMode { get; set; }
28+
2629
public override string ToString()
2730
=> JsonSerializer.Serialize(this, SettingsSerializationContext.Default.PowerOcrProperties);
2831
}

src/settings-ui/Settings.UI/SettingsXAML/Views/PowerOcrPage.xaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@
6666
Loaded="TextExtractor_ComboBox_Loaded"
6767
SelectedIndex="{x:Bind Path=ViewModel.LanguageIndex, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
6868
</tkcontrols:SettingsCard>
69+
<tkcontrols:SettingsCard Name="TextExtractorDefaultOutputMode" x:Uid="TextExtractor_DefaultOutputMode">
70+
<ComboBox
71+
MinWidth="{StaticResource SettingActionControlMinWidth}"
72+
AutomationProperties.AutomationId="TextExtractorDefaultOutputModeComboBox"
73+
SelectedIndex="{x:Bind Path=ViewModel.DefaultOutputMode, Mode=TwoWay}">
74+
<ComboBoxItem x:Uid="TextExtractor_DefaultOutputMode_None" />
75+
<ComboBoxItem x:Uid="TextExtractor_DefaultOutputMode_SingleLine" />
76+
<ComboBoxItem x:Uid="TextExtractor_DefaultOutputMode_Table" />
77+
</ComboBox>
78+
</tkcontrols:SettingsCard>
6979
</controls:SettingsGroup>
7080
</StackPanel>
7181
</controls:SettingsPageControl.ModuleContent>

src/settings-ui/Settings.UI/Strings/en-us/Resources.resw

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3974,6 +3974,21 @@ Activate by holding the key for the character you want to add an accent to, then
39743974
<data name="TextExtractor_Languages.Header" xml:space="preserve">
39753975
<value>Preferred language</value>
39763976
</data>
3977+
<data name="TextExtractor_DefaultOutputMode.Header" xml:space="preserve">
3978+
<value>Default output format</value>
3979+
</data>
3980+
<data name="TextExtractor_DefaultOutputMode.Description" xml:space="preserve">
3981+
<value>Choose the default formatting method when capturing text</value>
3982+
</data>
3983+
<data name="TextExtractor_DefaultOutputMode_None.Content" xml:space="preserve">
3984+
<value>None</value>
3985+
</data>
3986+
<data name="TextExtractor_DefaultOutputMode_SingleLine.Content" xml:space="preserve">
3987+
<value>Single line</value>
3988+
</data>
3989+
<data name="TextExtractor_DefaultOutputMode_Table.Content" xml:space="preserve">
3990+
<value>Table</value>
3991+
</data>
39773992
<data name="Alternate_OOBE_AlwaysOnTop_Description.Text" xml:space="preserve">
39783993
<value>Pin a window so that:</value>
39793994
</data>

src/settings-ui/Settings.UI/ViewModels/PowerOcrViewModel.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,22 @@ public HotkeySettings ActivationShortcut
178178
}
179179
}
180180

181+
public int DefaultOutputMode
182+
{
183+
get => _powerOcrSettings.Properties.DefaultOutputMode;
184+
set
185+
{
186+
if (_powerOcrSettings.Properties.DefaultOutputMode != value)
187+
{
188+
_powerOcrSettings.Properties.DefaultOutputMode = value;
189+
OnPropertyChanged(nameof(DefaultOutputMode));
190+
191+
_settingsUtils.SaveSettings(_powerOcrSettings.ToJsonString(), PowerOcrSettings.ModuleName);
192+
NotifySettingsChanged();
193+
}
194+
}
195+
}
196+
181197
internal void UpdateLanguages()
182198
{
183199
int preferredLanguageIndex = -1;

0 commit comments

Comments
 (0)