Skip to content

Commit

Permalink
Merge pull request #472 from TheJoeFin/dev
Browse files Browse the repository at this point in the history
v4.5
  • Loading branch information
TheJoeFin authored Jun 14, 2024
2 parents 6f95355 + 1f24918 commit bed6db1
Show file tree
Hide file tree
Showing 28 changed files with 943 additions and 361 deletions.
29 changes: 26 additions & 3 deletions Tests/ScreenLayoutTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using Dapplo.Windows.User32;
using System.Windows;
using Text_Grab;

namespace Tests;
Expand Down Expand Up @@ -92,7 +93,7 @@ public void SmallRectanglesContained()
double smallLeft2 = display2.CenterPoint().X - (sideLength / 2);
double smallTop2 = display2.CenterPoint().Y - (sideLength / 2);
Rect smallRect2 = new(smallLeft2, smallTop2, sideLength, sideLength);

Assert.True(display2.Contains(smallRect2));
Assert.False(display1.Contains(smallRect2));
Assert.False(display3.Contains(smallRect2));
Expand Down Expand Up @@ -121,7 +122,7 @@ public void SmallRectanglesContained456()
double smallLeft5 = display5.CenterPoint().X - (sideLength / 2);
double smallTop5 = display5.CenterPoint().Y - (sideLength / 2);
Rect smallRect5 = new(smallLeft5, smallTop5, sideLength, sideLength);

Assert.True(display5.Contains(smallRect5));
Assert.False(display4.Contains(smallRect5));
Assert.False(display6.Contains(smallRect5));
Expand All @@ -134,4 +135,26 @@ public void SmallRectanglesContained456()
Assert.False(display4.Contains(smallRect6));
Assert.False(display5.Contains(smallRect6));
}


[Fact]
public void CompareDapploToWinForms()
{
DisplayInfo[] dapploDisplays = Dapplo.Windows.User32.DisplayInfo.AllDisplayInfos;

System.Windows.Forms.Screen[] winFormsDisplays = System.Windows.Forms.Screen.AllScreens;

Assert.Equal(dapploDisplays.Length, winFormsDisplays.Length);

for (int i = 0; i < dapploDisplays.Length; i++)
{
Rect dapploRect = dapploDisplays[i].Bounds;
Rect winFormsRect = winFormsDisplays[i].Bounds.AsRect();

Point dapploCenterPoint = dapploRect.CenterPoint();
Point winFormsCenterPoint = winFormsRect.CenterPoint();

Assert.Equal(dapploCenterPoint, winFormsCenterPoint);
}
}
}
6 changes: 3 additions & 3 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0-preview-24080-01" />
<PackageReference Include="xunit" Version="2.7.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.8">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion Text-Grab-Package/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Identity
Name="40087JoeFinApps.TextGrab"
Publisher="CN=153F3B0F-BA3D-4964-8098-71AC78A1DF6A"
Version="4.4.2.0" />
Version="4.5.0.0" />

<Properties>
<DisplayName>Text Grab</DisplayName>
Expand Down
6 changes: 6 additions & 0 deletions Text-Grab/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@
<setting name="EtwUseMargins" serializeAs="String">
<value>False</value>
</setting>
<setting name="CloseFrameOnGrab" serializeAs="String">
<value>False</value>
</setting>
<setting name="GrabFrameScrollBehavior" serializeAs="String">
<value>Resize</value>
</setting>
</Text_Grab.Properties.Settings>
</userSettings>
</configuration>
6 changes: 3 additions & 3 deletions Text-Grab/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
using System.IO;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Media;
using System.Windows.Threading;
using Text_Grab.Controls;
using Text_Grab.Models;
using Text_Grab.Properties;
using Text_Grab.Services;
Expand All @@ -35,7 +35,7 @@ public partial class App : System.Windows.Application

public List<int> HotKeyIds { get; set; } = new();
public int NumberOfRunningInstances { get; set; } = 0;
public NotifyIcon? TextGrabIcon { get; set; }
public NotifyIconWindow? TextGrabIcon { get; set; }
#endregion Properties

#region Methods
Expand Down Expand Up @@ -228,7 +228,7 @@ private static async Task<bool> TryToOpenFile(string possiblePath, bool isQuiet)

private void appExit(object sender, ExitEventArgs e)
{
TextGrabIcon?.Dispose();
TextGrabIcon?.Close();
Singleton<HistoryService>.Instance.WriteHistory();
}

Expand Down
103 changes: 103 additions & 0 deletions Text-Grab/Controls/NotifyIconWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<Window
x:Class="Text_Grab.Controls.NotifyIconWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WpfUiIcon="http://schemas.lepo.co/wpfui/2022/xaml/tray"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Text_Grab.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:wpfui="http://schemas.lepo.co/wpfui/2022/xaml"
Title="NotifyIconWindow"
Width="0"
Height="0"
Activated="Window_Activated"
Background="Transparent"
IsHitTestVisible="False"
Left="-50"
Opacity="0"
ShowInTaskbar="True"
ToolTip="Text Grab"
Top="-50"
WindowStyle="ToolWindow"
mc:Ignorable="d">
<Grid>
<WpfUiIcon:NotifyIcon
x:Name="NotifyIcon"
Icon="/Images/TealSelect40.png"
IsVisibleChanged="NotifyIcon_IsVisibleChanged"
LeftClick="NotifyIcon_LeftClick"
ToolTip="Text Grab">
<WpfUiIcon:NotifyIcon.Menu>
<ContextMenu>
<MenuItem
x:Name="SettingsMenuItem"
Click="SettingsMenuItem_Click"
Header="Settings">
<MenuItem.Icon>
<wpfui:SymbolIcon Symbol="Settings24" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem
x:Name="LastGrabMenuItem"
Click="LastGrabMenuItem_Click"
Header="Edit Last Grab">
<MenuItem.Icon>
<wpfui:SymbolIcon Symbol="ImageEdit24" />
</MenuItem.Icon>
</MenuItem>
<MenuItem
x:Name="LookupMenuItem"
Click="LookupMenuItem_Click"
Header="Quick Simple Lookup">
<MenuItem.Icon>
<wpfui:SymbolIcon Symbol="TextBulletListSquareSearch20" />
</MenuItem.Icon>
</MenuItem>
<MenuItem
x:Name="PreviousRegionMenuItem"
Click="PreviousRegionMenuItem_Click"
Header="Grab Previous Region">
<MenuItem.Icon>
<wpfui:SymbolIcon Symbol="History24" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem
x:Name="FullscreenGrabMenuItem"
Click="FullscreenGrabMenuItem_Click"
Header="Fullscreen Grab">
<MenuItem.Icon>
<wpfui:SymbolIcon Symbol="SlideAdd24" />
</MenuItem.Icon>
</MenuItem>
<MenuItem
x:Name="GrabFrameMenuItem"
Click="GrabFrameMenuItem_Click"
Header="Grab Frame">
<MenuItem.Icon>
<wpfui:SymbolIcon Symbol="PanelBottom20" />
</MenuItem.Icon>
</MenuItem>
<MenuItem
x:Name="EditWindowMenuItem"
Click="EditWindowMenuItem_Click"
Header="Edit Text Window">
<MenuItem.Icon>
<wpfui:SymbolIcon Symbol="WindowEdit20" />
</MenuItem.Icon>
</MenuItem>
<Separator />
<MenuItem
x:Name="CloseMenuItem"
Click="Exit_Click"
Header="Close Text Grab">
<MenuItem.Icon>
<wpfui:SymbolIcon Symbol="Dismiss24" />
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</WpfUiIcon:NotifyIcon.Menu>
</WpfUiIcon:NotifyIcon>
</Grid>
</Window>
75 changes: 75 additions & 0 deletions Text-Grab/Controls/NotifyIconWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System.Windows;
using Text_Grab.Services;
using Text_Grab.Utilities;
using Text_Grab.Views;
using Wpf.Ui.Tray.Controls;

namespace Text_Grab.Controls;
/// <summary>
/// Interaction logic for NotifyIconWindow.xaml
/// </summary>
public partial class NotifyIconWindow : Window
{
public NotifyIconWindow()
{
InitializeComponent();
}

private void Exit_Click(object sender, RoutedEventArgs e)
{
App.Current.Shutdown();
}

private void NotifyIcon_LeftClick(NotifyIcon sender, RoutedEventArgs e)
{
e.Handled = true;
App.DefaultLaunch();
}

private void Window_Activated(object sender, System.EventArgs e)
{
Hide();
NotifyIcon.Visibility = Visibility.Visible;
}

private void EditWindowMenuItem_Click(object sender, RoutedEventArgs e)
{
EditTextWindow etw = new(); etw.Show();
}

private void GrabFrameMenuItem_Click(object sender, RoutedEventArgs e)
{
GrabFrame gf = new(); gf.Show();
}

private void FullscreenGrabMenuItem_Click(object sender, RoutedEventArgs e)
{
WindowUtilities.LaunchFullScreenGrab();
}

private async void PreviousRegionMenuItem_Click(object sender, RoutedEventArgs e)
{
await OcrUtilities.GetTextFromPreviousFullscreenRegion();
}

private void LookupMenuItem_Click(object sender, RoutedEventArgs e)
{
QuickSimpleLookup qsl = new(); qsl.Show();
}

private void LastGrabMenuItem_Click(object sender, RoutedEventArgs e)
{
Singleton<HistoryService>.Instance.GetLastHistoryAsGrabFrame();
}

private void SettingsMenuItem_Click(object sender, RoutedEventArgs e)
{
SettingsWindow sw = new(); sw.Show();
}

private void NotifyIcon_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (!NotifyIcon.IsVisible)
NotifyIcon.Visibility = Visibility.Visible;
}
}
5 changes: 5 additions & 0 deletions Text-Grab/Controls/WordBorder.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
HorizontalAlignment="Left"
Click="TryToAlphaMenuItem_Click"
Header="Try To Make _Letters" />
<MenuItem
x:Name="MakeSingleLineMenuItem"
HorizontalAlignment="Left"
Click="MakeSingleLineMenuItem_Click"
Header="Make Text _Single Line" />
<Separator />
<MenuItem
x:Name="MergeWordBordersMenuItem"
Expand Down
9 changes: 9 additions & 0 deletions Text-Grab/Controls/WordBorder.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,14 @@ private void TryToNumberMenuItem_Click(object sender, RoutedEventArgs e)
OwnerGrabFrame?.UndoableWordChange(this, oldWord, true);
}

private void MakeSingleLineMenuItem_Click(object sender, RoutedEventArgs e)
{
string oldWord = Word;
Word = Word.MakeStringSingleLine();

OwnerGrabFrame?.UndoableWordChange(this, oldWord, true);
}

private void WordBorder_MouseEnter(object sender, RoutedEventArgs e)
{
if (OwnerGrabFrame?.isCtrlDown is true)
Expand All @@ -351,6 +359,7 @@ private void WordBorder_MouseLeave(object sender, RoutedEventArgs e)
{
MoveResizeBorder.Visibility = Visibility.Collapsed;
}

private void WordBorderControl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (EditWordTextBox.Visibility == Visibility.Collapsed)
Expand Down
Loading

0 comments on commit bed6db1

Please sign in to comment.