Skip to content

Commit

Permalink
Merge pull request #503 from TheJoeFin/search-history-from-qsl
Browse files Browse the repository at this point in the history
Search history from qsl
  • Loading branch information
TheJoeFin authored Dec 19, 2024
2 parents 1012e3c + e05bdaa commit 0a2b7c4
Show file tree
Hide file tree
Showing 12 changed files with 426 additions and 88 deletions.
3 changes: 3 additions & 0 deletions Text-Grab/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@
<setting name="GrabFrameScrollBehavior" serializeAs="String">
<value>Resize</value>
</setting>
<setting name="LookupSearchHistory" serializeAs="String">
<value>True</value>
</setting>
</Text_Grab.Properties.Settings>
</userSettings>
</configuration>
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>
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;
}
}
}
14 changes: 13 additions & 1 deletion Text-Grab/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Text-Grab/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,8 @@
<Setting Name="GrabFrameScrollBehavior" Type="System.String" Scope="User">
<Value Profile="(Default)">Resize</Value>
</Setting>
<Setting Name="LookupSearchHistory" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
30 changes: 24 additions & 6 deletions Text-Grab/Services/HistoryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class HistoryService

private static readonly int maxHistoryTextOnly = 100;
private static readonly int maxHistoryWithImages = 10;
private List<HistoryInfo> HistoryTextOnly = new();
private List<HistoryInfo> HistoryWithImage = new();
private DispatcherTimer saveTimer = new();
private List<HistoryInfo> HistoryTextOnly = [];
private List<HistoryInfo> HistoryWithImage = [];
private readonly DispatcherTimer saveTimer = new();
private readonly Settings DefaultSettings = AppUtilities.TextGrabSettings;
#endregion Fields

Expand Down Expand Up @@ -119,7 +119,7 @@ public async Task LoadHistories()
public async Task PopulateMenuItemWithRecentGrabs(MenuItem recentGrabsMenuItem)
{
List<HistoryInfo> grabsHistory = GetRecentGrabs();
grabsHistory = grabsHistory.OrderByDescending(x => x.CaptureDateTime).ToList();
grabsHistory = [.. grabsHistory.OrderByDescending(x => x.CaptureDateTime)];

recentGrabsMenuItem.Items.Clear();

Expand Down Expand Up @@ -244,6 +244,23 @@ public void WriteHistory()
WriteHistoryFiles(HistoryWithImage, nameof(HistoryWithImage), maxHistoryWithImages);
}
}

public void RemoveTextHistoryItem(HistoryInfo historyItem)
{
HistoryTextOnly.Remove(historyItem);

saveTimer.Stop();
saveTimer.Start();
}

public void RemoveImageHistoryItem(HistoryInfo historyItem)
{
HistoryWithImage.Remove(historyItem);

saveTimer.Stop();
saveTimer.Start();
}

#endregion Public Methods

#region Private Methods
Expand All @@ -252,14 +269,14 @@ private static async Task<List<HistoryInfo>> LoadHistory(string fileName)
{
string rawText = await FileUtilities.GetTextFileAsync($"{fileName}.json", FileStorageKind.WithHistory);

if (string.IsNullOrWhiteSpace(rawText)) return new List<HistoryInfo>();
if (string.IsNullOrWhiteSpace(rawText)) return [];

List<HistoryInfo>? tempHistory = JsonSerializer.Deserialize<List<HistoryInfo>>(rawText);

if (tempHistory is List<HistoryInfo> jsonList && jsonList.Count > 0)
return tempHistory;

return new List<HistoryInfo>();
return [];
}

private static void WriteHistoryFiles(List<HistoryInfo> history, string fileName, int maxNumberToSave)
Expand Down Expand Up @@ -310,5 +327,6 @@ private void SaveTimer_Tick(object? sender, EventArgs e)
WriteHistory();
CachedBitmap = null;
}

#endregion Private Methods
}
24 changes: 16 additions & 8 deletions Text-Grab/Styles/ButtonStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@
x:Name="PART_Popup"
AllowsTransparency="true"
Focusable="false"
IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
IsOpen="{Binding IsSubmenuOpen,
RelativeSource={RelativeSource TemplatedParent}}"
Placement="Bottom"
PlacementTarget="{Binding ElementName=templateRoot}"
PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}">
Expand All @@ -237,9 +238,12 @@
VerticalAlignment="Top">
<Rectangle
x:Name="OpaqueRect"
Width="{Binding ActualWidth, ElementName=SubMenuBorder}"
Height="{Binding ActualHeight, ElementName=SubMenuBorder}"
Fill="{Binding Background, ElementName=SubMenuBorder}" />
Width="{Binding ActualWidth,
ElementName=SubMenuBorder}"
Height="{Binding ActualHeight,
ElementName=SubMenuBorder}"
Fill="{Binding Background,
ElementName=SubMenuBorder}" />
</Canvas>
<Rectangle
Width="1"
Expand Down Expand Up @@ -450,7 +454,8 @@
AllowsTransparency="true"
Focusable="false"
HorizontalOffset="-2"
IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}"
IsOpen="{Binding IsSubmenuOpen,
RelativeSource={RelativeSource TemplatedParent}}"
Placement="Right"
PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}"
VerticalOffset="-3">
Expand All @@ -469,9 +474,12 @@
VerticalAlignment="Top">
<Rectangle
x:Name="OpaqueRect"
Width="{Binding ActualWidth, ElementName=SubMenuBorder}"
Height="{Binding ActualHeight, ElementName=SubMenuBorder}"
Fill="{Binding Background, ElementName=SubMenuBorder}" />
Width="{Binding ActualWidth,
ElementName=SubMenuBorder}"
Height="{Binding ActualHeight,
ElementName=SubMenuBorder}"
Fill="{Binding Background,
ElementName=SubMenuBorder}" />
</Canvas>
<Rectangle
Width="1"
Expand Down
12 changes: 9 additions & 3 deletions Text-Grab/Styles/DataGridStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,18 @@
<DataGridDetailsPresenter
Grid.Row="1"
Grid.Column="1"
SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding AreRowDetailsFrozen, ConverterParameter={x:Static SelectiveScrollingOrientation.Vertical}, Converter={x:Static DataGrid.RowDetailsScrollingConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
SelectiveScrollingGrid.SelectiveScrollingOrientation="{Binding AreRowDetailsFrozen,
ConverterParameter={x:Static SelectiveScrollingOrientation.Vertical},
Converter={x:Static DataGrid.RowDetailsScrollingConverter},
RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
Visibility="{TemplateBinding DetailsVisibility}" />
<DataGridRowHeader
Grid.RowSpan="2"
SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical"
Visibility="{Binding HeadersVisibility, ConverterParameter={x:Static DataGridHeadersVisibility.Row}, Converter={x:Static DataGrid.HeadersVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />
Visibility="{Binding HeadersVisibility,
ConverterParameter={x:Static DataGridHeadersVisibility.Row},
Converter={x:Static DataGrid.HeadersVisibilityConverter},
RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}" />
</SelectiveScrollingGrid>
</Border>
</ControlTemplate>
Expand Down Expand Up @@ -155,4 +161,4 @@
</Setter>
</Style>

</ResourceDictionary>
</ResourceDictionary>
5 changes: 3 additions & 2 deletions Text-Grab/Styles/TextBoxStyles.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@
x:Name="Arrow"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}">
Data="{Binding Content,
RelativeSource={RelativeSource TemplatedParent}}">
<Path.Fill>
<SolidColorBrush x:Name="ArrowFill" Color="{DynamicResource ControlMediumColor}" />
</Path.Fill>
Expand Down Expand Up @@ -359,4 +360,4 @@
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
</ResourceDictionary>
2 changes: 1 addition & 1 deletion Text-Grab/Views/FullscreenGrab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public partial class FullscreenGrab : Window
private double xShiftDelta;
private double yShiftDelta;
private HistoryInfo? historyInfo;
private bool usingTesseract;
private readonly bool usingTesseract;
private static readonly Settings DefaultSettings = AppUtilities.TextGrabSettings;

#endregion Fields
Expand Down
Loading

0 comments on commit 0a2b7c4

Please sign in to comment.