Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Text-Grab/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,12 @@ public static void SetTheme(object? sender = null, EventArgs? e = null)
#endif
}

Color teal = (Color)ColorConverter.ConvertFromString("#308E98");
Color teal = (Color)ColorConverter.ConvertFromString("#FF308E98");
ApplicationAccentColorManager.Apply(teal);
// ApplicationAccentColorManager.ApplySystemAccent();

// does not work:
//themeService.SetAccent(teal);
}

public static void WatchTheme()
Expand Down
23 changes: 9 additions & 14 deletions Text-Grab/Controls/FindAndReplaceWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,9 @@ private void SavePatternButton_Click(object sender, RoutedEventArgs e)
string sourceText = string.Empty;
if (textEditWindow is not null)
{
if (!string.IsNullOrWhiteSpace(textEditWindow.PassedTextControl.SelectedText))
sourceText = textEditWindow.PassedTextControl.SelectedText.MakeStringSingleLine().Truncate(30);
else
sourceText = textEditWindow.PassedTextControl.Text.MakeStringSingleLine().Truncate(30);
sourceText = !string.IsNullOrWhiteSpace(textEditWindow.PassedTextControl.SelectedText)
? textEditWindow.PassedTextControl.SelectedText.MakeStringSingleLine().Truncate(30)
: textEditWindow.PassedTextControl.Text.MakeStringSingleLine().Truncate(30);
}

// Open the RegexManager and start adding the pattern
Expand All @@ -603,16 +602,12 @@ private void UpdateSaveButtonVisibility()
// 1. Using regex mode
// 2. Find text is not empty
// 3. Pattern doesn't already exist in saved patterns
if (UsePaternCheckBox.IsChecked is true &&
!string.IsNullOrWhiteSpace(FindTextBox.Text) &&
!IsPatternAlreadySaved(FindTextBox.Text))
{
SavePatternButton.Visibility = Visibility.Visible;
}
else
{
SavePatternButton.Visibility = Visibility.Collapsed;
}
SavePatternButton.Visibility =
(UsePaternCheckBox.IsChecked is true &&
!string.IsNullOrWhiteSpace(FindTextBox.Text) &&
!IsPatternAlreadySaved(FindTextBox.Text))
? Visibility.Visible
: Visibility.Collapsed;
}

private bool IsPatternAlreadySaved(string pattern)
Expand Down
4 changes: 2 additions & 2 deletions Text-Grab/Models/GlobalLang.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public GlobalLang(string inputLang)
{
language = new(inputLang);
}
catch (System.ArgumentException)
catch (System.ArgumentException ex)
{

System.Diagnostics.Debug.WriteLine($"Failed to initialize language '{inputLang}': {ex.Message}");
}
AbbreviatedName = language.AbbreviatedName;
CultureDisplayName = language.DisplayName;
Expand Down
5 changes: 3 additions & 2 deletions Text-Grab/Pages/GeneralSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
Margin="12,0,0,0"
VerticalAlignment="Bottom"
Click="OpenExeFolderButton_Click"
Foreground="{StaticResource Teal}"
Visibility="Collapsed">
<TextBlock Text="Open EXE Containing Folder" />
</ui:HyperlinkButton>
Expand Down Expand Up @@ -66,10 +67,10 @@
HorizontalAlignment="Left"
Style="{StaticResource TextBodyNormal}"
Text="- Joe" />
<ui:HyperlinkButton NavigateUri="https://github.com/TheJoeFin/Text-Grab/issues">
<ui:HyperlinkButton Foreground="{StaticResource Teal}" NavigateUri="https://github.com/TheJoeFin/Text-Grab/issues">
🌐 https://github.com/TheJoeFin/Text-Grab/issues
</ui:HyperlinkButton>
<ui:HyperlinkButton NavigateUri="mailto:[email protected]">
<ui:HyperlinkButton Foreground="{StaticResource Teal}" NavigateUri="mailto:[email protected]">
📧 [email protected]
</ui:HyperlinkButton>
</StackPanel>
Expand Down
19 changes: 13 additions & 6 deletions Text-Grab/Services/CalculationService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NCalc;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -362,17 +363,23 @@ private async Task<string> EvaluateStandardExpressionAsync(string line)
// Register custom functions
RegisterCustomFunctions(expression);

object? result = await expression.EvaluateAsync();

if (result != null)
object? result = null;

try
{
string formattedResult = FormatResult(result);
return formattedResult;
result = await expression.EvaluateAsync();
}
else
catch (Exception)
{
return "null";
Debug.WriteLine($"Error evaluating expression: {line}");
}

if (result is null)
return "null";

string formattedResult = FormatResult(result);
return formattedResult;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Text-Grab/Services/HistoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void CacheLastBitmap(Bitmap bmp)
_cachedBitmapHandle = null;
}

CachedBitmap = null;
CachedBitmap?.Dispose();
CachedBitmap = bmp;
_cachedBitmapHandle = bmp.GetHbitmap();
}
Expand Down
18 changes: 16 additions & 2 deletions Text-Grab/Views/EditTextWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@
Background="Transparent"
BorderThickness="0"
Click="CalcToggleButton_Click"
ToolTip="Toggle Calculation Pane (Ctrl+P)">
ToolTip="Toggle Calculation Pane (Ctrl+P)&#x0a;Note: Text wrapping is disabled when calc pane is visible for better vertical alignment">
<ui:SymbolIcon FontSize="16" Symbol="Calculator24" />
</Button>
</Grid>
Expand Down Expand Up @@ -727,7 +727,21 @@
<Run Text="sqrt(x * y)" />
</TextBlock>
<TextBlock
Margin="0,8,0,0"
Margin="0,8,0,4"
FontSize="11"
FontWeight="SemiBold"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Text="Note:"
TextWrapping="Wrap" />
<TextBlock
Margin="0,0,0,8"
FontSize="11"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
TextWrapping="Wrap">
<Run Text="Text wrapping is automatically disabled when the calculation pane is visible to ensure calculation results align vertically with their corresponding input lines." />
</TextBlock>
<TextBlock
Margin="0,0,0,0"
FontSize="11"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
TextWrapping="Wrap">
Expand Down
19 changes: 19 additions & 0 deletions Text-Grab/Views/EditTextWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public partial class EditTextWindow : Wpf.Ui.Controls.FluentWindow
// Remember last non-collapsed width for the calc column
private GridLength _lastCalcColumnWidth = new(1, GridUnitType.Star);

// Remember text wrapping state before showing calc pane
private TextWrapping? _previousTextWrapping = null;

// Store extracted pattern and precision for mouse wheel adjustment
private ExtractedPattern? currentExtractedPattern = null;
private int currentPrecisionLevel = ExtractedPattern.DefaultPrecisionLevel;
Expand Down Expand Up @@ -3623,6 +3626,15 @@ private void SetCalcPaneVisibility()
// Restore previous width if it was collapsed
if (CalcColumn.Width.Value == 0)
CalcColumn.Width = _lastCalcColumnWidth;

// Disable text wrapping when calc pane is visible to maintain vertical alignment
// Store the previous wrapping state to restore later
if (PassedTextControl.TextWrapping != TextWrapping.NoWrap)
{
_previousTextWrapping = PassedTextControl.TextWrapping;
PassedTextControl.TextWrapping = TextWrapping.NoWrap;
}

_debounceTimer?.Start();
}
else
Expand All @@ -3635,6 +3647,13 @@ private void SetCalcPaneVisibility()
if (CalcColumn.Width.Value > 0)
_lastCalcColumnWidth = CalcColumn.Width;
CalcColumn.Width = new GridLength(0);

// Restore previous text wrapping setting when calc pane is hidden
if (_previousTextWrapping.HasValue)
{
PassedTextControl.TextWrapping = _previousTextWrapping.Value;
_previousTextWrapping = null;
}
}
}

Expand Down
23 changes: 11 additions & 12 deletions Text-Grab/Views/FullscreenGrab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -909,14 +909,6 @@ private void DisposeBitmapSource(System.Windows.Controls.Image image)

image.Source = null;
image.UpdateLayout();

// Force garbage collection for large bitmaps (> 1 megapixel)
if (oldSource.PixelWidth * oldSource.PixelHeight <= 1_000_000)
return;

GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
}

private void Window_Unloaded(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -1084,7 +1076,8 @@ private void EdgePanTimer_Tick(object? sender, EventArgs e)
else if (relativeY > windowRect.Height - edgeThresholdY)
panY = -EdgePanSpeed * (1.0 - ((windowRect.Height - relativeY) / edgeThresholdY));

if (panX != 0 || panY != 0)
const double Epsilon = 1e-6;
if (Math.Abs(panX) > Epsilon || Math.Abs(panY) > Epsilon)
PanBackgroundImage(panX, panY, transformGroup);
}

Expand Down Expand Up @@ -1206,9 +1199,15 @@ private void RegionClickCanvas_PreviewMouseWheel(object sender, MouseWheelEventA
}
}

double scale = 1;
if (e.Delta > 0)
scale = 1.1;
// Only create a new transform when zooming in (e.Delta > 0)
// Skip when zooming out at base scale since there's nothing to zoom out from
if (e.Delta <= 0)
{
e.Handled = true;
return;
}

double scale = 1.1;

TransformGroup newGroup = new();
ScaleTransform newScaleTransform = new()
Expand Down