Skip to content

Commit

Permalink
Catch settings getting applied when settings pages load
Browse files Browse the repository at this point in the history
Save Tesseract path when setting it
Fixes #448
Fixes #450
  • Loading branch information
TheJoeFin committed Apr 14, 2024
1 parent 08366bc commit 95be674
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 8 deletions.
4 changes: 1 addition & 3 deletions Text-Grab/Pages/GeneralSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Title="GeneralSettings"
d:DesignHeight="450"
d:DesignHeight="1450"
d:DesignWidth="800"
Loaded="Page_Loaded"
mc:Ignorable="d">
Expand Down Expand Up @@ -203,7 +203,6 @@
<ui:ToggleSwitch
Name="ReadBarcodesBarcode"
Checked="ReadBarcodesBarcode_Checked"
IsChecked="True"
Unchecked="ReadBarcodesBarcode_Unchecked">
<TextBlock Style="{StaticResource TextBodyNormal}">
Try to read barcodes
Expand Down Expand Up @@ -299,7 +298,6 @@
<ui:ToggleSwitch
Name="HistorySwitch"
Checked="HistorySwitch_Checked"
IsChecked="True"
Unchecked="HistorySwitch_Unchecked">
<TextBlock Style="{StaticResource TextBodyNormal}">
Keep recent history of Grabs and Edit Text Windows
Expand Down
78 changes: 76 additions & 2 deletions Text-Grab/Pages/GeneralSettings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Windows.Controls;
using System.Windows.Media;
using Text_Grab.Properties;
using Text_Grab.Services;
using Text_Grab.Utilities;
using Windows.ApplicationModel;
using Wpf.Ui.Controls;
Expand All @@ -23,6 +22,7 @@ public partial class GeneralSettings : Page
private readonly Brush BadBrush = new SolidColorBrush(Colors.Red);
private readonly Brush GoodBrush = new SolidColorBrush(Colors.Transparent);
private double InsertDelaySeconds = 1.5;
private bool settingsSet = false;

#endregion Fields

Expand Down Expand Up @@ -127,11 +127,13 @@ private async void Page_Loaded(object sender, RoutedEventArgs e)
TryInsertCheckbox.IsChecked = DefaultSettings.TryInsert;
InsertDelaySeconds = DefaultSettings.InsertDelay;
SecondsTextBox.Text = InsertDelaySeconds.ToString("##.#", System.Globalization.CultureInfo.InvariantCulture);

settingsSet = true;
}

private void ValidateTextIsNumber(object sender, TextChangedEventArgs e)
{
if (!IsLoaded)
if (!settingsSet)
return;

if (sender is System.Windows.Controls.TextBox numberInputBox)
Expand All @@ -155,26 +157,41 @@ private void ValidateTextIsNumber(object sender, TextChangedEventArgs e)

private void FullScreenRDBTN_Checked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.DefaultLaunch = TextGrabMode.Fullscreen.ToString();
}

private void GrabFrameRDBTN_Checked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.DefaultLaunch = TextGrabMode.GrabFrame.ToString();
}

private void EditTextRDBTN_Checked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.DefaultLaunch = TextGrabMode.EditText.ToString();
}

private void QuickLookupRDBTN_Checked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.DefaultLaunch = TextGrabMode.QuickLookup.ToString();
}

private void RunInBackgroundChkBx_Checked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

if (sender is not ToggleSwitch runInBackgroundSwitch)
return;

Expand All @@ -184,101 +201,158 @@ private void RunInBackgroundChkBx_Checked(object sender, RoutedEventArgs e)

private void SystemThemeRdBtn_Checked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.AppTheme = AppTheme.System.ToString();
App.SetTheme();
}

private void LightThemeRdBtn_Checked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.AppTheme = AppTheme.Light.ToString();
App.SetTheme();
}

private void DarkThemeRdBtn_Checked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.AppTheme = AppTheme.Dark.ToString();
App.SetTheme();
}

private void ReadBarcodesBarcode_Checked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.TryToReadBarcodes = true;
}

private void ReadBarcodesBarcode_Unchecked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.TryToReadBarcodes = false;
}

private void HistorySwitch_Checked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.UseHistory = true;
}

private void HistorySwitch_Unchecked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.UseHistory = false;
}

private void ErrorCorrectBox_Checked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.CorrectErrors = true;
}

private void ErrorCorrectBox_Unchecked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.CorrectErrors = false;
}

private void CorrectToLatin_Checked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.CorrectToLatin = true;
}

private void CorrectToLatin_Unchecked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.CorrectToLatin = false;
}

private void NeverUseClipboardChkBx_Checked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.NeverAutoUseClipboard = true;
}

private void NeverUseClipboardChkBx_Unchecked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.NeverAutoUseClipboard = false;
}

private async void StartupOnLoginCheckBox_Checked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.StartupOnLogin = true;
await ImplementAppOptions.ImplementStartupOption(true);
}

private async void StartupOnLoginCheckBox_Unchecked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.StartupOnLogin = false;
await ImplementAppOptions.ImplementStartupOption(false);
}

private void TryInsertCheckbox_Checked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.TryInsert = true;
}

private void TryInsertCheckbox_Unchecked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.TryInsert = false;
}

private void ShowToastCheckBox_Checked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.ShowToast = true;
}

private void ShowToastCheckBox_Unchecked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.ShowToast = false;
}
}
21 changes: 21 additions & 0 deletions Text-Grab/Pages/KeysSettings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Text_Grab.Pages;
public partial class KeysSettings : Page
{
private readonly Settings DefaultSettings = AppUtilities.TextGrabSettings;
private bool settingsSet = false;

public KeysSettings()
{
Expand All @@ -23,6 +24,9 @@ public KeysSettings()

private void ShortcutControl_Recording(object sender, EventArgs e)
{
if (!settingsSet)
return;

foreach (UIElement child in ShortcutsStackPanel.Children)
if (child is ShortcutControl shortcutControl
&& sender is ShortcutControl senderShortcut
Expand All @@ -32,6 +36,9 @@ private void ShortcutControl_Recording(object sender, EventArgs e)

private void ShortcutControl_KeySetChanged(object sender, EventArgs e)
{
if (!settingsSet)
return;

if (HotKeysAllDifferent())
{
List<ShortcutKeySet> shortcutKeys = [];
Expand Down Expand Up @@ -133,17 +140,25 @@ private void Page_Loaded(object sender, RoutedEventArgs e)
break;
}
}

settingsSet = true;
}

private void RunInBackgroundChkBx_Checked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.RunInTheBackground = true;
ImplementAppOptions.ImplementBackgroundOption(DefaultSettings.RunInTheBackground);
DefaultSettings.Save();
}

private void RunInBackgroundChkBx_Unchecked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.RunInTheBackground = false;
ImplementAppOptions.ImplementBackgroundOption(DefaultSettings.RunInTheBackground);
GlobalHotkeysCheckbox.IsChecked = false;
Expand All @@ -152,11 +167,17 @@ private void RunInBackgroundChkBx_Unchecked(object sender, RoutedEventArgs e)

private void GlobalHotkeysCheckbox_Checked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.GlobalHotkeysEnabled = true;
}

private void GlobalHotkeysCheckbox_Unchecked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

DefaultSettings.GlobalHotkeysEnabled = false;
}
}
1 change: 1 addition & 0 deletions Text-Grab/Pages/LanguageSettings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public partial class LanguageSettings : Page
private bool usingTesseract;
private readonly Settings DefaultSettings = AppUtilities.TextGrabSettings;


public LanguageSettings()
{
InitializeComponent();
Expand Down
12 changes: 12 additions & 0 deletions Text-Grab/Pages/TesseractSettings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace Text_Grab.Pages;
public partial class TesseractSettings : Page
{
private readonly Settings DefaultSettings = AppUtilities.TextGrabSettings;
private bool settingsSet = false;


public TesseractSettings()
{
Expand All @@ -24,13 +26,18 @@ public TesseractSettings()

private void TesseractPathTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (!settingsSet)
return;

if (sender is not System.Windows.Controls.TextBox pathTextbox || pathTextbox.Text is not string pathText)
return;

if (File.Exists(pathText))
UseTesseractCheckBox.IsEnabled = true;
else
UseTesseractCheckBox.IsEnabled = false;

DefaultSettings.TesseractPath = pathText;
}

private void OpenPathButton_Click(object sender, RoutedEventArgs args)
Expand Down Expand Up @@ -62,6 +69,9 @@ private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e

private void UseTesseractCheckBox_Checked(object sender, RoutedEventArgs e)
{
if (!settingsSet)
return;

if (sender is not ToggleSwitch useTesseractSwitch)
return;

Expand All @@ -80,5 +90,7 @@ private void Page_Loaded(object sender, RoutedEventArgs e)
UseTesseractCheckBox.IsChecked = false;
UseTesseractCheckBox.IsEnabled = false;
DefaultSettings.UseTesseract = false;

settingsSet = true;
}
}
Loading

0 comments on commit 95be674

Please sign in to comment.