Skip to content

Commit

Permalink
Merge pull request #504 from TheJoeFin/dev
Browse files Browse the repository at this point in the history
v4.7
  • Loading branch information
TheJoeFin authored Dec 21, 2024
2 parents d5840e9 + 79e4212 commit 2c8a74f
Show file tree
Hide file tree
Showing 26 changed files with 866 additions and 220 deletions.
4 changes: 2 additions & 2 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.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0-pre.42">
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<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.6.0.0" />
Version="4.7.0.0" />

<Properties>
<DisplayName>Text Grab</DisplayName>
Expand Down
5 changes: 5 additions & 0 deletions Text-Grab-Package/Text-Grab-Package.wapproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,10 @@
<SkipGetTargetFrameworkProperties>True</SkipGetTargetFrameworkProperties>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Private.Uri" Version="4.3.2" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
</ItemGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
</Project>
9 changes: 9 additions & 0 deletions Text-Grab/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@
<setting name="GrabFrameScrollBehavior" serializeAs="String">
<value>Resize</value>
</setting>
<setting name="LookupSearchHistory" serializeAs="String">
<value>True</value>
</setting>
<setting name="DefaultWebSearch" serializeAs="String">
<value />
</setting>
<setting name="WebSearchItemsJson" serializeAs="String">
<value />
</setting>
</Text_Grab.Properties.Settings>
</userSettings>
</configuration>
6 changes: 4 additions & 2 deletions Text-Grab/Controls/BottomBarSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
Margin="0,0,8,0"
d:Symbol="Diamond24"
FontSize="24"
Symbol="{Binding Path=SymbolIcon, Mode=TwoWay}" />
Symbol="{Binding Path=SymbolIcon,
Mode=TwoWay}" />
</Viewbox>
</DataTemplate>
</GridViewColumn.CellTemplate>
Expand Down Expand Up @@ -173,7 +174,8 @@
Margin="0,0,8,0"
d:Symbol="Diamond24"
FontSize="24"
Symbol="{Binding Path=SymbolIcon, Mode=TwoWay}" />
Symbol="{Binding Path=SymbolIcon,
Mode=TwoWay}" />
</Viewbox>
</DataTemplate>
</GridViewColumn.CellTemplate>
Expand Down
11 changes: 8 additions & 3 deletions Text-Grab/Controls/CollapsibleButton.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,28 @@
<ui:SymbolIcon
Margin="12,2"
d:Symbol="Diamond24"
Symbol="{Binding Path=ButtonSymbol, Mode=TwoWay, ElementName=CollapsibleButtonUserControl}" />
Symbol="{Binding Path=ButtonSymbol,
Mode=TwoWay,
ElementName=CollapsibleButtonUserControl}" />

<TextBlock
x:Name="ButtonTextBlock"
Grid.Column="1"
Margin="0,0,12,0"
VerticalAlignment="Center"
d:Text="Design Text"
Text="{Binding ElementName=CollapsibleButtonUserControl, Path=ButtonText, Mode=TwoWay}" />
Text="{Binding ElementName=CollapsibleButtonUserControl,
Path=ButtonText,
Mode=TwoWay}" />
</Grid>
<Button.ContextMenu>
<ContextMenu>
<MenuItem
Name="ChangeButtonLayout"
Click="ChangeButtonLayout_Click"
Header="Change Style"
IsEnabled="{Binding ElementName=CollapsibleButtonUserControl, Path=CanChangeStyle}" />
IsEnabled="{Binding ElementName=CollapsibleButtonUserControl,
Path=CanChangeStyle}" />
</ContextMenu>
</Button.ContextMenu>
</Button>
28 changes: 2 additions & 26 deletions Text-Grab/Models/ButtonInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,33 +200,9 @@ public ButtonInfo(string buttonText, string symbolText, string background, strin
new()
{
OrderNumber = 1.7,
ButtonText = "Google...",
ButtonText = "Web Search",
SymbolText = "",
Command = "GoogleSearchCmd",
SymbolIcon = SymbolRegular.GlobeSearch24
},
new()
{
OrderNumber = 1.8,
ButtonText = "Bing...",
SymbolText = "",
Command = "BingSearchCmd",
SymbolIcon = SymbolRegular.GlobeSearch24
},
new()
{
OrderNumber = 1.9,
ButtonText = "Duck Duck Go...",
SymbolText = "",
Command = "DuckDuckGoSearchCmd",
SymbolIcon = SymbolRegular.GlobeSearch24
},
new()
{
OrderNumber = 1.91,
ButtonText = "Search GitHub...",
SymbolText = "",
Command = "GitHubSearchCmd",
Command = "DefaultWebSearchCmd",
SymbolIcon = SymbolRegular.GlobeSearch24
},
new()
Expand Down
63 changes: 55 additions & 8 deletions Text-Grab/Models/LookupItem.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
using System;
using Humanizer;
using System;

namespace Text_Grab.Models;

public enum LookupItemKind
{
Simple = 0,
EditWindow = 1,
GrabFrame = 2,
Link = 3,
}

public class LookupItem : IEquatable<LookupItem>
{
public string shortValue { get; set; } = string.Empty;
public string longValue { get; set; } = string.Empty;
public string ShortValue { get; set; } = string.Empty;
public string LongValue { get; set; } = string.Empty;

public Wpf.Ui.Controls.SymbolRegular UiSymbol
{
get
{
return Kind switch
{
LookupItemKind.Simple => Wpf.Ui.Controls.SymbolRegular.Copy20,
LookupItemKind.EditWindow => Wpf.Ui.Controls.SymbolRegular.Window24,
LookupItemKind.GrabFrame => Wpf.Ui.Controls.SymbolRegular.PanelBottom20,
LookupItemKind.Link => Wpf.Ui.Controls.SymbolRegular.Link24,
_ => Wpf.Ui.Controls.SymbolRegular.Copy20,
};
}
}

public LookupItemKind Kind { get; set; } = LookupItemKind.Simple;

public LookupItem()
{
Expand All @@ -14,13 +40,34 @@ public LookupItem()

public LookupItem(string sv, string lv)
{
shortValue = sv;
longValue = lv;
ShortValue = sv;
LongValue = lv;
}

public override string ToString() => $"{shortValue} {longValue}";
public LookupItem(HistoryInfo historyInfo)
{
ShortValue = historyInfo.CaptureDateTime.Humanize() + Environment.NewLine + historyInfo.CaptureDateTime.ToString("F");
LongValue = historyInfo.TextContent.Length > 100 ? historyInfo.TextContent[..100].Trim() + "…" : historyInfo.TextContent.Trim();

HistoryItem = historyInfo;

if (string.IsNullOrEmpty(historyInfo.ImagePath))
Kind = LookupItemKind.EditWindow;
else
Kind = LookupItemKind.GrabFrame;
}

public HistoryInfo? HistoryItem { get; set; }

public override string ToString()
{
if (HistoryItem is not null)
return $"{HistoryItem.CaptureDateTime:F} {HistoryItem.TextContent}";

return $"{ShortValue} {LongValue}";
}

public string ToCSVString() => $"{shortValue},{longValue}";
public string ToCSVString() => $"{ShortValue},{LongValue}";

public bool Equals(LookupItem? other)
{
Expand All @@ -32,4 +79,4 @@ public bool Equals(LookupItem? other)

return false;
}
}
}
98 changes: 98 additions & 0 deletions Text-Grab/Models/WebSearchUrlModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Text_Grab.Utilities;

namespace Text_Grab.Models;

public record WebSearchUrlModel
{
public string Name { get; set; } = string.Empty;
public string Url { get; set; } = string.Empty;

private WebSearchUrlModel? defaultSearcher;

public WebSearchUrlModel DefaultSearcher
{
get
{
defaultSearcher ??= GetDefaultSearcher();
return defaultSearcher;
}
set
{
defaultSearcher = value;
SaveDefaultSearcher(defaultSearcher);
}
}

public override string ToString() => Name;

private List<WebSearchUrlModel> webSearchers = [];

public List<WebSearchUrlModel> WebSearchers
{
get
{
if (webSearchers.Count == 0)
webSearchers = GetWebSearchUrls();

return webSearchers;
}
set
{
webSearchers = value;
SaveWebSearchUrls(webSearchers);
}
}

private WebSearchUrlModel GetDefaultSearcher()
{
string searcherName = AppUtilities.TextGrabSettings.DefaultWebSearch;
if (string.IsNullOrWhiteSpace(searcherName))
return WebSearchers[0];

WebSearchUrlModel? searcher = WebSearchers
.FirstOrDefault(searcher => searcher.Name == searcherName);

return searcher ?? WebSearchers[0];
}

private void SaveDefaultSearcher(WebSearchUrlModel webSearchUrl)
{
AppUtilities.TextGrabSettings.DefaultWebSearch = webSearchUrl.Name;
AppUtilities.TextGrabSettings.Save();
}

private static List<WebSearchUrlModel> GetDefaultWebSearchUrls()
{
return
[
new() { Name = "Google", Url = "https://www.google.com/search?q=" },
new() { Name = "Bing", Url = "https://www.bing.com/search?q=" },
new() { Name = "DuckDuckGo", Url = "https://duckduckgo.com/?q=" },
new() { Name = "Brave", Url = "https://search.brave.com/search?q=" },
new() { Name = "GitHub Code", Url = "https://github.com/search?type=code&q=" },
new() { Name = "GitHub Repos", Url = "https://github.com/search?type=repositories&q=" },
];
}

public static List<WebSearchUrlModel> GetWebSearchUrls()
{
string json = AppUtilities.TextGrabSettings.WebSearchItemsJson;
if (string.IsNullOrWhiteSpace(json))
return GetDefaultWebSearchUrls();
List<WebSearchUrlModel>? webSearchUrls = JsonSerializer.Deserialize<List<WebSearchUrlModel>>(json);
if (webSearchUrls is null || webSearchUrls.Count == 0)
return GetDefaultWebSearchUrls();

return webSearchUrls;
}

public static void SaveWebSearchUrls(List<WebSearchUrlModel> webSearchUrls)
{
string json = JsonSerializer.Serialize(webSearchUrls);
AppUtilities.TextGrabSettings.WebSearchItemsJson = json;
AppUtilities.TextGrabSettings.Save();
}
}
21 changes: 20 additions & 1 deletion Text-Grab/Pages/GeneralSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Text_Grab.Pages"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:models="clr-namespace:Text_Grab.Models"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Title="GeneralSettings"
d:DesignHeight="1450"
Expand All @@ -27,7 +28,7 @@
x:Name="VersionTextblock"
VerticalAlignment="Center"
Style="{StaticResource TextBodyNormal}"
Text="Version 4.6.0" />
Text="Version 4.7.0" />

<ui:HyperlinkButton
x:Name="OpenExeFolderButton"
Expand Down Expand Up @@ -212,6 +213,24 @@
Disabling may speed up results
</TextBlock>

<TextBlock
Margin="0,16,0,4"
FontSize="16"
Style="{StaticResource TextHeader}"
Text="Web Search Options" />
<ComboBox
x:Name="WebSearchersComboBox"
Width="300"
HorizontalAlignment="Left"
IsTextSearchCaseSensitive="False"
SelectionChanged="WebSearchersComboBox_SelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>

<TextBlock
Margin="0,16,0,4"
FontSize="16"
Expand Down
Loading

0 comments on commit 2c8a74f

Please sign in to comment.