Skip to content

Commit 2c8a74f

Browse files
authored
Merge pull request #504 from TheJoeFin/dev
v4.7
2 parents d5840e9 + 79e4212 commit 2c8a74f

26 files changed

+866
-220
lines changed

Tests/Tests.csproj

+2-2
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.11.1" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
1313
<PackageReference Include="xunit" Version="2.9.2" />
14-
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.42">
14+
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
<PrivateAssets>all</PrivateAssets>
1717
</PackageReference>

Text-Grab-Package/Package.appxmanifest

+1-1
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.6.0.0" />
14+
Version="4.7.0.0" />
1515

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

Text-Grab-Package/Text-Grab-Package.wapproj

+5
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,10 @@
161161
<SkipGetTargetFrameworkProperties>True</SkipGetTargetFrameworkProperties>
162162
</ProjectReference>
163163
</ItemGroup>
164+
<ItemGroup>
165+
<PackageReference Include="System.Net.Http" Version="4.3.4" />
166+
<PackageReference Include="System.Private.Uri" Version="4.3.2" />
167+
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
168+
</ItemGroup>
164169
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
165170
</Project>

Text-Grab/App.config

+9
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@
145145
<setting name="GrabFrameScrollBehavior" serializeAs="String">
146146
<value>Resize</value>
147147
</setting>
148+
<setting name="LookupSearchHistory" serializeAs="String">
149+
<value>True</value>
150+
</setting>
151+
<setting name="DefaultWebSearch" serializeAs="String">
152+
<value />
153+
</setting>
154+
<setting name="WebSearchItemsJson" serializeAs="String">
155+
<value />
156+
</setting>
148157
</Text_Grab.Properties.Settings>
149158
</userSettings>
150159
</configuration>

Text-Grab/Controls/BottomBarSettings.xaml

+4-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
Margin="0,0,8,0"
7575
d:Symbol="Diamond24"
7676
FontSize="24"
77-
Symbol="{Binding Path=SymbolIcon, Mode=TwoWay}" />
77+
Symbol="{Binding Path=SymbolIcon,
78+
Mode=TwoWay}" />
7879
</Viewbox>
7980
</DataTemplate>
8081
</GridViewColumn.CellTemplate>
@@ -173,7 +174,8 @@
173174
Margin="0,0,8,0"
174175
d:Symbol="Diamond24"
175176
FontSize="24"
176-
Symbol="{Binding Path=SymbolIcon, Mode=TwoWay}" />
177+
Symbol="{Binding Path=SymbolIcon,
178+
Mode=TwoWay}" />
177179
</Viewbox>
178180
</DataTemplate>
179181
</GridViewColumn.CellTemplate>

Text-Grab/Controls/CollapsibleButton.xaml

+8-3
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,28 @@
2424
<ui:SymbolIcon
2525
Margin="12,2"
2626
d:Symbol="Diamond24"
27-
Symbol="{Binding Path=ButtonSymbol, Mode=TwoWay, ElementName=CollapsibleButtonUserControl}" />
27+
Symbol="{Binding Path=ButtonSymbol,
28+
Mode=TwoWay,
29+
ElementName=CollapsibleButtonUserControl}" />
2830

2931
<TextBlock
3032
x:Name="ButtonTextBlock"
3133
Grid.Column="1"
3234
Margin="0,0,12,0"
3335
VerticalAlignment="Center"
3436
d:Text="Design Text"
35-
Text="{Binding ElementName=CollapsibleButtonUserControl, Path=ButtonText, Mode=TwoWay}" />
37+
Text="{Binding ElementName=CollapsibleButtonUserControl,
38+
Path=ButtonText,
39+
Mode=TwoWay}" />
3640
</Grid>
3741
<Button.ContextMenu>
3842
<ContextMenu>
3943
<MenuItem
4044
Name="ChangeButtonLayout"
4145
Click="ChangeButtonLayout_Click"
4246
Header="Change Style"
43-
IsEnabled="{Binding ElementName=CollapsibleButtonUserControl, Path=CanChangeStyle}" />
47+
IsEnabled="{Binding ElementName=CollapsibleButtonUserControl,
48+
Path=CanChangeStyle}" />
4449
</ContextMenu>
4550
</Button.ContextMenu>
4651
</Button>

Text-Grab/Models/ButtonInfo.cs

+2-26
Original file line numberDiff line numberDiff line change
@@ -200,33 +200,9 @@ public ButtonInfo(string buttonText, string symbolText, string background, strin
200200
new()
201201
{
202202
OrderNumber = 1.7,
203-
ButtonText = "Google...",
203+
ButtonText = "Web Search",
204204
SymbolText = "",
205-
Command = "GoogleSearchCmd",
206-
SymbolIcon = SymbolRegular.GlobeSearch24
207-
},
208-
new()
209-
{
210-
OrderNumber = 1.8,
211-
ButtonText = "Bing...",
212-
SymbolText = "",
213-
Command = "BingSearchCmd",
214-
SymbolIcon = SymbolRegular.GlobeSearch24
215-
},
216-
new()
217-
{
218-
OrderNumber = 1.9,
219-
ButtonText = "Duck Duck Go...",
220-
SymbolText = "",
221-
Command = "DuckDuckGoSearchCmd",
222-
SymbolIcon = SymbolRegular.GlobeSearch24
223-
},
224-
new()
225-
{
226-
OrderNumber = 1.91,
227-
ButtonText = "Search GitHub...",
228-
SymbolText = "",
229-
Command = "GitHubSearchCmd",
205+
Command = "DefaultWebSearchCmd",
230206
SymbolIcon = SymbolRegular.GlobeSearch24
231207
},
232208
new()

Text-Grab/Models/LookupItem.cs

+55-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
1-
using System;
1+
using Humanizer;
2+
using System;
23

34
namespace Text_Grab.Models;
45

6+
public enum LookupItemKind
7+
{
8+
Simple = 0,
9+
EditWindow = 1,
10+
GrabFrame = 2,
11+
Link = 3,
12+
}
13+
514
public class LookupItem : IEquatable<LookupItem>
615
{
7-
public string shortValue { get; set; } = string.Empty;
8-
public string longValue { get; set; } = string.Empty;
16+
public string ShortValue { get; set; } = string.Empty;
17+
public string LongValue { get; set; } = string.Empty;
18+
19+
public Wpf.Ui.Controls.SymbolRegular UiSymbol
20+
{
21+
get
22+
{
23+
return Kind switch
24+
{
25+
LookupItemKind.Simple => Wpf.Ui.Controls.SymbolRegular.Copy20,
26+
LookupItemKind.EditWindow => Wpf.Ui.Controls.SymbolRegular.Window24,
27+
LookupItemKind.GrabFrame => Wpf.Ui.Controls.SymbolRegular.PanelBottom20,
28+
LookupItemKind.Link => Wpf.Ui.Controls.SymbolRegular.Link24,
29+
_ => Wpf.Ui.Controls.SymbolRegular.Copy20,
30+
};
31+
}
32+
}
33+
34+
public LookupItemKind Kind { get; set; } = LookupItemKind.Simple;
935

1036
public LookupItem()
1137
{
@@ -14,13 +40,34 @@ public LookupItem()
1440

1541
public LookupItem(string sv, string lv)
1642
{
17-
shortValue = sv;
18-
longValue = lv;
43+
ShortValue = sv;
44+
LongValue = lv;
1945
}
2046

21-
public override string ToString() => $"{shortValue} {longValue}";
47+
public LookupItem(HistoryInfo historyInfo)
48+
{
49+
ShortValue = historyInfo.CaptureDateTime.Humanize() + Environment.NewLine + historyInfo.CaptureDateTime.ToString("F");
50+
LongValue = historyInfo.TextContent.Length > 100 ? historyInfo.TextContent[..100].Trim() + "…" : historyInfo.TextContent.Trim();
51+
52+
HistoryItem = historyInfo;
53+
54+
if (string.IsNullOrEmpty(historyInfo.ImagePath))
55+
Kind = LookupItemKind.EditWindow;
56+
else
57+
Kind = LookupItemKind.GrabFrame;
58+
}
59+
60+
public HistoryInfo? HistoryItem { get; set; }
61+
62+
public override string ToString()
63+
{
64+
if (HistoryItem is not null)
65+
return $"{HistoryItem.CaptureDateTime:F} {HistoryItem.TextContent}";
66+
67+
return $"{ShortValue} {LongValue}";
68+
}
2269

23-
public string ToCSVString() => $"{shortValue},{longValue}";
70+
public string ToCSVString() => $"{ShortValue},{LongValue}";
2471

2572
public bool Equals(LookupItem? other)
2673
{
@@ -32,4 +79,4 @@ public bool Equals(LookupItem? other)
3279

3380
return false;
3481
}
35-
}
82+
}

Text-Grab/Models/WebSearchUrlModel.cs

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Text.Json;
4+
using Text_Grab.Utilities;
5+
6+
namespace Text_Grab.Models;
7+
8+
public record WebSearchUrlModel
9+
{
10+
public string Name { get; set; } = string.Empty;
11+
public string Url { get; set; } = string.Empty;
12+
13+
private WebSearchUrlModel? defaultSearcher;
14+
15+
public WebSearchUrlModel DefaultSearcher
16+
{
17+
get
18+
{
19+
defaultSearcher ??= GetDefaultSearcher();
20+
return defaultSearcher;
21+
}
22+
set
23+
{
24+
defaultSearcher = value;
25+
SaveDefaultSearcher(defaultSearcher);
26+
}
27+
}
28+
29+
public override string ToString() => Name;
30+
31+
private List<WebSearchUrlModel> webSearchers = [];
32+
33+
public List<WebSearchUrlModel> WebSearchers
34+
{
35+
get
36+
{
37+
if (webSearchers.Count == 0)
38+
webSearchers = GetWebSearchUrls();
39+
40+
return webSearchers;
41+
}
42+
set
43+
{
44+
webSearchers = value;
45+
SaveWebSearchUrls(webSearchers);
46+
}
47+
}
48+
49+
private WebSearchUrlModel GetDefaultSearcher()
50+
{
51+
string searcherName = AppUtilities.TextGrabSettings.DefaultWebSearch;
52+
if (string.IsNullOrWhiteSpace(searcherName))
53+
return WebSearchers[0];
54+
55+
WebSearchUrlModel? searcher = WebSearchers
56+
.FirstOrDefault(searcher => searcher.Name == searcherName);
57+
58+
return searcher ?? WebSearchers[0];
59+
}
60+
61+
private void SaveDefaultSearcher(WebSearchUrlModel webSearchUrl)
62+
{
63+
AppUtilities.TextGrabSettings.DefaultWebSearch = webSearchUrl.Name;
64+
AppUtilities.TextGrabSettings.Save();
65+
}
66+
67+
private static List<WebSearchUrlModel> GetDefaultWebSearchUrls()
68+
{
69+
return
70+
[
71+
new() { Name = "Google", Url = "https://www.google.com/search?q=" },
72+
new() { Name = "Bing", Url = "https://www.bing.com/search?q=" },
73+
new() { Name = "DuckDuckGo", Url = "https://duckduckgo.com/?q=" },
74+
new() { Name = "Brave", Url = "https://search.brave.com/search?q=" },
75+
new() { Name = "GitHub Code", Url = "https://github.com/search?type=code&q=" },
76+
new() { Name = "GitHub Repos", Url = "https://github.com/search?type=repositories&q=" },
77+
];
78+
}
79+
80+
public static List<WebSearchUrlModel> GetWebSearchUrls()
81+
{
82+
string json = AppUtilities.TextGrabSettings.WebSearchItemsJson;
83+
if (string.IsNullOrWhiteSpace(json))
84+
return GetDefaultWebSearchUrls();
85+
List<WebSearchUrlModel>? webSearchUrls = JsonSerializer.Deserialize<List<WebSearchUrlModel>>(json);
86+
if (webSearchUrls is null || webSearchUrls.Count == 0)
87+
return GetDefaultWebSearchUrls();
88+
89+
return webSearchUrls;
90+
}
91+
92+
public static void SaveWebSearchUrls(List<WebSearchUrlModel> webSearchUrls)
93+
{
94+
string json = JsonSerializer.Serialize(webSearchUrls);
95+
AppUtilities.TextGrabSettings.WebSearchItemsJson = json;
96+
AppUtilities.TextGrabSettings.Save();
97+
}
98+
}

Text-Grab/Pages/GeneralSettings.xaml

+20-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
77
xmlns:local="clr-namespace:Text_Grab.Pages"
88
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9+
xmlns:models="clr-namespace:Text_Grab.Models"
910
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
1011
Title="GeneralSettings"
1112
d:DesignHeight="1450"
@@ -27,7 +28,7 @@
2728
x:Name="VersionTextblock"
2829
VerticalAlignment="Center"
2930
Style="{StaticResource TextBodyNormal}"
30-
Text="Version 4.6.0" />
31+
Text="Version 4.7.0" />
3132

3233
<ui:HyperlinkButton
3334
x:Name="OpenExeFolderButton"
@@ -212,6 +213,24 @@
212213
Disabling may speed up results
213214
</TextBlock>
214215

216+
<TextBlock
217+
Margin="0,16,0,4"
218+
FontSize="16"
219+
Style="{StaticResource TextHeader}"
220+
Text="Web Search Options" />
221+
<ComboBox
222+
x:Name="WebSearchersComboBox"
223+
Width="300"
224+
HorizontalAlignment="Left"
225+
IsTextSearchCaseSensitive="False"
226+
SelectionChanged="WebSearchersComboBox_SelectionChanged">
227+
<ComboBox.ItemTemplate>
228+
<DataTemplate>
229+
<TextBlock Text="{Binding}" />
230+
</DataTemplate>
231+
</ComboBox.ItemTemplate>
232+
</ComboBox>
233+
215234
<TextBlock
216235
Margin="0,16,0,4"
217236
FontSize="16"

0 commit comments

Comments
 (0)