diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index c72a359a..e5b17420 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -9,7 +9,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Text-Grab-Package/Text-Grab-Package.wapproj b/Text-Grab-Package/Text-Grab-Package.wapproj index fa97345d..ccba0d23 100644 --- a/Text-Grab-Package/Text-Grab-Package.wapproj +++ b/Text-Grab-Package/Text-Grab-Package.wapproj @@ -161,5 +161,10 @@ True + + + + + \ No newline at end of file diff --git a/Text-Grab/Text-Grab.csproj b/Text-Grab/Text-Grab.csproj index 757c06f9..710271a8 100644 --- a/Text-Grab/Text-Grab.csproj +++ b/Text-Grab/Text-Grab.csproj @@ -72,7 +72,7 @@ - + diff --git a/Text-Grab/Utilities/CustomBottomBarUtilities.cs b/Text-Grab/Utilities/CustomBottomBarUtilities.cs index 90293561..a070db7b 100644 --- a/Text-Grab/Utilities/CustomBottomBarUtilities.cs +++ b/Text-Grab/Utilities/CustomBottomBarUtilities.cs @@ -71,6 +71,8 @@ public static List GetBottomBarButtons(EditTextWindow editTex List methods = GetMethods(editTextWindow); Dictionary routedCommands = EditTextWindow.GetRoutedCommands(); + int index = 1; + foreach (ButtonInfo buttonItem in GetCustomBottomBarItemsSetting()) { CollapsibleButton button = new() @@ -78,7 +80,7 @@ public static List GetBottomBarButtons(EditTextWindow editTex ButtonText = buttonItem.ButtonText, IsSymbol = buttonItem.IsSymbol, CustomButton = buttonItem, - ToolTip = buttonItem.ButtonText, + ToolTip = $"{buttonItem.ButtonText} (ctrl + {index})", ButtonSymbol = buttonItem.SymbolIcon }; @@ -97,6 +99,7 @@ public static List GetBottomBarButtons(EditTextWindow editTex button.Command = routedCommand; bottomBarButtons.Add(button); + index++; } return bottomBarButtons; diff --git a/Text-Grab/Utilities/StringMethods.cs b/Text-Grab/Utilities/StringMethods.cs index 11c162c5..d9a7b39e 100644 --- a/Text-Grab/Utilities/StringMethods.cs +++ b/Text-Grab/Utilities/StringMethods.cs @@ -122,6 +122,15 @@ public static (int, int) CursorWordBoundaries(this string input, int cursorPosit if (cursorPosition < 0) cursorPosition = 0; + try + { + char check = input[cursorPosition]; + } + catch (IndexOutOfRangeException) + { + return (cursorPosition, 0); + } + // Check if the cursor is at a space if (char.IsWhiteSpace(input[cursorPosition])) cursorPosition = FindNearestLetterIndex(input, cursorPosition); diff --git a/Text-Grab/Views/FullscreenGrab.xaml b/Text-Grab/Views/FullscreenGrab.xaml index 63fa6daa..0fc042fe 100644 --- a/Text-Grab/Views/FullscreenGrab.xaml +++ b/Text-Grab/Views/FullscreenGrab.xaml @@ -222,6 +222,72 @@ + + + + + + + + + + + + + + + + = flyoutMenu.Items.Count + || flyoutMenu.Items[numberPressed - 1] is not MenuItem selectedItem) + { + return; + } + + selectedItem.IsChecked = !selectedItem.IsChecked; + CheckIfAnyPostActionsSelcted(); + return; + } + + int numberOfLanguages = LanguagesComboBox.Items.Count; if (numberPressed <= numberOfLanguages && numberPressed - 1 >= 0 && numberPressed - 1 != LanguagesComboBox.SelectedIndex @@ -195,6 +211,25 @@ internal void KeyPressed(Key key, bool? isActive = null) } } + private void CheckIfAnyPostActionsSelcted() + { + if (NextStepDropDownButton.Flyout is not ContextMenu flyoutMenu || !flyoutMenu.HasItems) + return; + + foreach (object anyItem in flyoutMenu.Items) + { + if (anyItem is MenuItem item && item.IsChecked) + { + if (FindResource("DarkTeal") is SolidColorBrush tealButtonStyle) + NextStepDropDownButton.Background = tealButtonStyle; + return; + } + } + + if (FindResource("ControlFillColorDefaultBrush") is SolidColorBrush SymbolButtonStyle) + NextStepDropDownButton.Background = SymbolButtonStyle; + } + private static bool CheckIfCheckingOrUnchecking(object? sender) { bool isActive = false; @@ -637,26 +672,67 @@ private async void RegionClickCanvas_MouseUp(object sender, MouseButtonEventArgs }; } - if (!string.IsNullOrWhiteSpace(TextFromOCR)) + if (string.IsNullOrWhiteSpace(TextFromOCR)) { - if (SendToEditTextToggleButton.IsChecked is true && destinationTextBox is null) - { - EditTextWindow etw = WindowUtilities.OpenOrActivateWindow(); - destinationTextBox = etw.PassedTextControl; - } + BackgroundBrush.Opacity = .2; + TopButtonsStackPanel.Visibility = Visibility.Visible; + return; + } + + if (GuidFixMenuItem.IsChecked is true) + TextFromOCR = TextFromOCR.CorrectCommonGuidErrors(); - OutputUtilities.HandleTextFromOcr( - TextFromOCR, - isSingleLine, - isTable, - destinationTextBox); - WindowUtilities.CloseAllFullscreenGrabs(); + if (TrimEachLineMenuItem.IsChecked is true) + { + string workingString = TextFromOCR; + string[] stringSplit = workingString.Split(Environment.NewLine); + + string finalString = ""; + foreach (string line in stringSplit) + if (!string.IsNullOrWhiteSpace(line)) + finalString += line.Trim() + Environment.NewLine; + + TextFromOCR = finalString; } - else + + if (RemoveDuplicatesMenuItem.IsChecked is true) + TextFromOCR = TextFromOCR.RemoveDuplicateLines(); + + if (BingSearchPostCapture.IsChecked is true) { - BackgroundBrush.Opacity = .2; - TopButtonsStackPanel.Visibility = Visibility.Visible; + string searchStringUrlSafe = WebUtility.UrlEncode(TextFromOCR.MakeStringSingleLine()); + _ = await Windows.System.Launcher.LaunchUriAsync(new Uri(string.Format($"https://www.bing.com/search?q={searchStringUrlSafe}"))); + } + + if (GoogleSearchPostCapture.IsChecked is true) + { + string searchStringUrlSafe = WebUtility.UrlEncode(TextFromOCR.MakeStringSingleLine()); + _ = await Windows.System.Launcher.LaunchUriAsync(new Uri(string.Format($"https://www.google.com/search?q={searchStringUrlSafe}"))); } + + if (DuckSearchPostCapture.IsChecked is true) + { + string searchStringUrlSafe = WebUtility.UrlEncode(TextFromOCR.MakeStringSingleLine()); + _ = await Windows.System.Launcher.LaunchUriAsync(new Uri(string.Format($"https://duckduckgo.com/?va=d&t=he&q={searchStringUrlSafe}&ia=web"))); + } + + if (SendToEditTextToggleButton.IsChecked is true + && destinationTextBox is null + && BingSearchPostCapture.IsChecked is false) + { + EditTextWindow etw = WindowUtilities.OpenOrActivateWindow(); + destinationTextBox = etw.PassedTextControl; + } + + OutputUtilities.HandleTextFromOcr( + TextFromOCR, + isSingleLine, + isTable, + destinationTextBox); + WindowUtilities.CloseAllFullscreenGrabs(); + + if (InsertPostCapture.IsChecked is true && !DefaultSettings.TryInsert) + await WindowUtilities.TryInsertString(TextFromOCR); } private void SendToEditTextToggleButton_Click(object sender, RoutedEventArgs e) @@ -805,5 +881,10 @@ private void TableToggleButton_Click(object? sender = null, RoutedEventArgs? e = WindowUtilities.FullscreenKeyDown(Key.T, isActive); SelectSingleToggleButton(sender); } + + private void PostActionMenuItem_Click(object sender, RoutedEventArgs e) + { + CheckIfAnyPostActionsSelcted(); + } #endregion Methods }