Skip to content

Commit bed6db1

Browse files
authored
Merge pull request #472 from TheJoeFin/dev
v4.5
2 parents 6f95355 + 1f24918 commit bed6db1

28 files changed

+943
-361
lines changed

Tests/ScreenLayoutTests.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Windows;
1+
using Dapplo.Windows.User32;
2+
using System.Windows;
23
using Text_Grab;
34

45
namespace Tests;
@@ -92,7 +93,7 @@ public void SmallRectanglesContained()
9293
double smallLeft2 = display2.CenterPoint().X - (sideLength / 2);
9394
double smallTop2 = display2.CenterPoint().Y - (sideLength / 2);
9495
Rect smallRect2 = new(smallLeft2, smallTop2, sideLength, sideLength);
95-
96+
9697
Assert.True(display2.Contains(smallRect2));
9798
Assert.False(display1.Contains(smallRect2));
9899
Assert.False(display3.Contains(smallRect2));
@@ -121,7 +122,7 @@ public void SmallRectanglesContained456()
121122
double smallLeft5 = display5.CenterPoint().X - (sideLength / 2);
122123
double smallTop5 = display5.CenterPoint().Y - (sideLength / 2);
123124
Rect smallRect5 = new(smallLeft5, smallTop5, sideLength, sideLength);
124-
125+
125126
Assert.True(display5.Contains(smallRect5));
126127
Assert.False(display4.Contains(smallRect5));
127128
Assert.False(display6.Contains(smallRect5));
@@ -134,4 +135,26 @@ public void SmallRectanglesContained456()
134135
Assert.False(display4.Contains(smallRect6));
135136
Assert.False(display5.Contains(smallRect6));
136137
}
138+
139+
140+
[Fact]
141+
public void CompareDapploToWinForms()
142+
{
143+
DisplayInfo[] dapploDisplays = Dapplo.Windows.User32.DisplayInfo.AllDisplayInfos;
144+
145+
System.Windows.Forms.Screen[] winFormsDisplays = System.Windows.Forms.Screen.AllScreens;
146+
147+
Assert.Equal(dapploDisplays.Length, winFormsDisplays.Length);
148+
149+
for (int i = 0; i < dapploDisplays.Length; i++)
150+
{
151+
Rect dapploRect = dapploDisplays[i].Bounds;
152+
Rect winFormsRect = winFormsDisplays[i].Bounds.AsRect();
153+
154+
Point dapploCenterPoint = dapploRect.CenterPoint();
155+
Point winFormsCenterPoint = winFormsRect.CenterPoint();
156+
157+
Assert.Equal(dapploCenterPoint, winFormsCenterPoint);
158+
}
159+
}
137160
}

Tests/Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0-preview-24080-01" />
13-
<PackageReference Include="xunit" Version="2.7.1" />
14-
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.8">
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
13+
<PackageReference Include="xunit" Version="2.8.1" />
14+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
<PrivateAssets>all</PrivateAssets>
1717
</PackageReference>

Text-Grab-Package/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Identity
1212
Name="40087JoeFinApps.TextGrab"
1313
Publisher="CN=153F3B0F-BA3D-4964-8098-71AC78A1DF6A"
14-
Version="4.4.2.0" />
14+
Version="4.5.0.0" />
1515

1616
<Properties>
1717
<DisplayName>Text Grab</DisplayName>

Text-Grab/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@
139139
<setting name="EtwUseMargins" serializeAs="String">
140140
<value>False</value>
141141
</setting>
142+
<setting name="CloseFrameOnGrab" serializeAs="String">
143+
<value>False</value>
144+
</setting>
145+
<setting name="GrabFrameScrollBehavior" serializeAs="String">
146+
<value>Resize</value>
147+
</setting>
142148
</Text_Grab.Properties.Settings>
143149
</userSettings>
144150
</configuration>

Text-Grab/App.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
using System.IO;
88
using System.Threading.Tasks;
99
using System.Windows;
10-
using System.Windows.Forms;
1110
using System.Windows.Media;
1211
using System.Windows.Threading;
12+
using Text_Grab.Controls;
1313
using Text_Grab.Models;
1414
using Text_Grab.Properties;
1515
using Text_Grab.Services;
@@ -35,7 +35,7 @@ public partial class App : System.Windows.Application
3535

3636
public List<int> HotKeyIds { get; set; } = new();
3737
public int NumberOfRunningInstances { get; set; } = 0;
38-
public NotifyIcon? TextGrabIcon { get; set; }
38+
public NotifyIconWindow? TextGrabIcon { get; set; }
3939
#endregion Properties
4040

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

229229
private void appExit(object sender, ExitEventArgs e)
230230
{
231-
TextGrabIcon?.Dispose();
231+
TextGrabIcon?.Close();
232232
Singleton<HistoryService>.Instance.WriteHistory();
233233
}
234234

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<Window
2+
x:Class="Text_Grab.Controls.NotifyIconWindow"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:WpfUiIcon="http://schemas.lepo.co/wpfui/2022/xaml/tray"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:local="clr-namespace:Text_Grab.Controls"
8+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
xmlns:wpfui="http://schemas.lepo.co/wpfui/2022/xaml"
10+
Title="NotifyIconWindow"
11+
Width="0"
12+
Height="0"
13+
Activated="Window_Activated"
14+
Background="Transparent"
15+
IsHitTestVisible="False"
16+
Left="-50"
17+
Opacity="0"
18+
ShowInTaskbar="True"
19+
ToolTip="Text Grab"
20+
Top="-50"
21+
WindowStyle="ToolWindow"
22+
mc:Ignorable="d">
23+
<Grid>
24+
<WpfUiIcon:NotifyIcon
25+
x:Name="NotifyIcon"
26+
Icon="/Images/TealSelect40.png"
27+
IsVisibleChanged="NotifyIcon_IsVisibleChanged"
28+
LeftClick="NotifyIcon_LeftClick"
29+
ToolTip="Text Grab">
30+
<WpfUiIcon:NotifyIcon.Menu>
31+
<ContextMenu>
32+
<MenuItem
33+
x:Name="SettingsMenuItem"
34+
Click="SettingsMenuItem_Click"
35+
Header="Settings">
36+
<MenuItem.Icon>
37+
<wpfui:SymbolIcon Symbol="Settings24" />
38+
</MenuItem.Icon>
39+
</MenuItem>
40+
<Separator />
41+
<MenuItem
42+
x:Name="LastGrabMenuItem"
43+
Click="LastGrabMenuItem_Click"
44+
Header="Edit Last Grab">
45+
<MenuItem.Icon>
46+
<wpfui:SymbolIcon Symbol="ImageEdit24" />
47+
</MenuItem.Icon>
48+
</MenuItem>
49+
<MenuItem
50+
x:Name="LookupMenuItem"
51+
Click="LookupMenuItem_Click"
52+
Header="Quick Simple Lookup">
53+
<MenuItem.Icon>
54+
<wpfui:SymbolIcon Symbol="TextBulletListSquareSearch20" />
55+
</MenuItem.Icon>
56+
</MenuItem>
57+
<MenuItem
58+
x:Name="PreviousRegionMenuItem"
59+
Click="PreviousRegionMenuItem_Click"
60+
Header="Grab Previous Region">
61+
<MenuItem.Icon>
62+
<wpfui:SymbolIcon Symbol="History24" />
63+
</MenuItem.Icon>
64+
</MenuItem>
65+
<Separator />
66+
<MenuItem
67+
x:Name="FullscreenGrabMenuItem"
68+
Click="FullscreenGrabMenuItem_Click"
69+
Header="Fullscreen Grab">
70+
<MenuItem.Icon>
71+
<wpfui:SymbolIcon Symbol="SlideAdd24" />
72+
</MenuItem.Icon>
73+
</MenuItem>
74+
<MenuItem
75+
x:Name="GrabFrameMenuItem"
76+
Click="GrabFrameMenuItem_Click"
77+
Header="Grab Frame">
78+
<MenuItem.Icon>
79+
<wpfui:SymbolIcon Symbol="PanelBottom20" />
80+
</MenuItem.Icon>
81+
</MenuItem>
82+
<MenuItem
83+
x:Name="EditWindowMenuItem"
84+
Click="EditWindowMenuItem_Click"
85+
Header="Edit Text Window">
86+
<MenuItem.Icon>
87+
<wpfui:SymbolIcon Symbol="WindowEdit20" />
88+
</MenuItem.Icon>
89+
</MenuItem>
90+
<Separator />
91+
<MenuItem
92+
x:Name="CloseMenuItem"
93+
Click="Exit_Click"
94+
Header="Close Text Grab">
95+
<MenuItem.Icon>
96+
<wpfui:SymbolIcon Symbol="Dismiss24" />
97+
</MenuItem.Icon>
98+
</MenuItem>
99+
</ContextMenu>
100+
</WpfUiIcon:NotifyIcon.Menu>
101+
</WpfUiIcon:NotifyIcon>
102+
</Grid>
103+
</Window>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System.Windows;
2+
using Text_Grab.Services;
3+
using Text_Grab.Utilities;
4+
using Text_Grab.Views;
5+
using Wpf.Ui.Tray.Controls;
6+
7+
namespace Text_Grab.Controls;
8+
/// <summary>
9+
/// Interaction logic for NotifyIconWindow.xaml
10+
/// </summary>
11+
public partial class NotifyIconWindow : Window
12+
{
13+
public NotifyIconWindow()
14+
{
15+
InitializeComponent();
16+
}
17+
18+
private void Exit_Click(object sender, RoutedEventArgs e)
19+
{
20+
App.Current.Shutdown();
21+
}
22+
23+
private void NotifyIcon_LeftClick(NotifyIcon sender, RoutedEventArgs e)
24+
{
25+
e.Handled = true;
26+
App.DefaultLaunch();
27+
}
28+
29+
private void Window_Activated(object sender, System.EventArgs e)
30+
{
31+
Hide();
32+
NotifyIcon.Visibility = Visibility.Visible;
33+
}
34+
35+
private void EditWindowMenuItem_Click(object sender, RoutedEventArgs e)
36+
{
37+
EditTextWindow etw = new(); etw.Show();
38+
}
39+
40+
private void GrabFrameMenuItem_Click(object sender, RoutedEventArgs e)
41+
{
42+
GrabFrame gf = new(); gf.Show();
43+
}
44+
45+
private void FullscreenGrabMenuItem_Click(object sender, RoutedEventArgs e)
46+
{
47+
WindowUtilities.LaunchFullScreenGrab();
48+
}
49+
50+
private async void PreviousRegionMenuItem_Click(object sender, RoutedEventArgs e)
51+
{
52+
await OcrUtilities.GetTextFromPreviousFullscreenRegion();
53+
}
54+
55+
private void LookupMenuItem_Click(object sender, RoutedEventArgs e)
56+
{
57+
QuickSimpleLookup qsl = new(); qsl.Show();
58+
}
59+
60+
private void LastGrabMenuItem_Click(object sender, RoutedEventArgs e)
61+
{
62+
Singleton<HistoryService>.Instance.GetLastHistoryAsGrabFrame();
63+
}
64+
65+
private void SettingsMenuItem_Click(object sender, RoutedEventArgs e)
66+
{
67+
SettingsWindow sw = new(); sw.Show();
68+
}
69+
70+
private void NotifyIcon_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
71+
{
72+
if (!NotifyIcon.IsVisible)
73+
NotifyIcon.Visibility = Visibility.Visible;
74+
}
75+
}

Text-Grab/Controls/WordBorder.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@
8383
HorizontalAlignment="Left"
8484
Click="TryToAlphaMenuItem_Click"
8585
Header="Try To Make _Letters" />
86+
<MenuItem
87+
x:Name="MakeSingleLineMenuItem"
88+
HorizontalAlignment="Left"
89+
Click="MakeSingleLineMenuItem_Click"
90+
Header="Make Text _Single Line" />
8691
<Separator />
8792
<MenuItem
8893
x:Name="MergeWordBordersMenuItem"

Text-Grab/Controls/WordBorder.xaml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,14 @@ private void TryToNumberMenuItem_Click(object sender, RoutedEventArgs e)
339339
OwnerGrabFrame?.UndoableWordChange(this, oldWord, true);
340340
}
341341

342+
private void MakeSingleLineMenuItem_Click(object sender, RoutedEventArgs e)
343+
{
344+
string oldWord = Word;
345+
Word = Word.MakeStringSingleLine();
346+
347+
OwnerGrabFrame?.UndoableWordChange(this, oldWord, true);
348+
}
349+
342350
private void WordBorder_MouseEnter(object sender, RoutedEventArgs e)
343351
{
344352
if (OwnerGrabFrame?.isCtrlDown is true)
@@ -351,6 +359,7 @@ private void WordBorder_MouseLeave(object sender, RoutedEventArgs e)
351359
{
352360
MoveResizeBorder.Visibility = Visibility.Collapsed;
353361
}
362+
354363
private void WordBorderControl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
355364
{
356365
if (EditWordTextBox.Visibility == Visibility.Collapsed)

0 commit comments

Comments
 (0)