Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.

Commit 35576b2

Browse files
committed
improve pined, add MaxDataCount in settings
1 parent 66699f6 commit 35576b2

File tree

10 files changed

+101
-57
lines changed

10 files changed

+101
-57
lines changed

build/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class BuildContext : FrostingContext
3434
public Lazy<SolutionParserResult> DefaultSln { get; set; }
3535
public const string DeployFramework = "net7.0-windows";
3636
public string PublishDir = ".dist";
37-
public string PublishVersion = "0.2.2";
37+
public string PublishVersion = "0.2.3";
3838

3939
public BuildContext(ICakeContext context)
4040
: base(context)
@@ -105,7 +105,7 @@ public override void Run(BuildContext context)
105105
});
106106
context.CreateDirectory(dstDir);
107107
var files = context
108-
.GetFiles(@$"{srcDir}/**/(*(c|C)lipboard*.(png|json|dll)|*.png|plugin.json|*simulator.dll)");
108+
.GetFiles(@$"{srcDir}/**/(*(c|C)lipboard*.(png|json|dll)|*.png|plugin.json|(*simulator|Xceed.Wpf.Toolkit.NET5).dll)");
109109
foreach (var f in files)
110110
context.Information($"Adding: {f}");
111111
context.ZipCompress(

src/ClipboardR.Core/Settings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class Settings
77
public string ConfigFile = null!;
88

99
public bool CacheImages { get; set; } = false;
10+
public uint MaxDataCount { get; set; } = 10000;
1011

1112
public void Save()
1213
{

src/ClipboardR.Core/Struct.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public struct ClipboardData : IEquatable<ClipboardData>
1717
public int InitScore;
1818
public DateTime Time;
1919
public bool Pined;
20+
public DateTime CreateTime;
2021

2122
public bool Equals(ClipboardData b)
2223
{

src/ClipboardR.Panels/ClipboardR.Panels.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
</ItemGroup>
2626

2727
<ItemGroup>
28+
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.5.0" />
2829
<PackageReference Include="Flow.Launcher.Plugin" Version="4.0.2" />
2930
</ItemGroup>
3031

src/ClipboardR.Panels/SettingsPanel.xaml

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,70 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
67
xmlns:local="clr-namespace:ClipboardR.Panels"
78
mc:Ignorable="d"
89
d:DesignHeight="120" d:DesignWidth="400"
910
DataContext="{Binding RelativeSource={RelativeSource Self}}"
1011
>
11-
<Grid Height="100" Margin="0,10,0,10" Width="NaN">
12+
<Grid
13+
Height="100" Width="NaN"
14+
Margin="0,10,0,10"
15+
HorizontalAlignment="Center"
16+
VerticalAlignment="Center">
1217
<Grid.RowDefinitions>
13-
<RowDefinition Height="43*" />
14-
<RowDefinition Height="43*" />
18+
<RowDefinition Height="30*" />
19+
<RowDefinition Height="70*" />
1520
</Grid.RowDefinitions>
16-
<CheckBox Grid.Row="0" Content="Cache Images" IsChecked="{Binding settings.CacheImages}"
17-
HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="16" />
18-
<Label Grid.Row="1" Content="Restart FlowLauncher to apply" HorizontalAlignment="Center" Margin="0,4,0,0"
19-
VerticalAlignment="Center" FontSize="18" />
20-
21+
<Grid.ColumnDefinitions>
22+
<ColumnDefinition Width="Auto"/>
23+
<ColumnDefinition Width="Auto"/>
24+
<ColumnDefinition Width="Auto"/>
25+
</Grid.ColumnDefinitions>
26+
<CheckBox
27+
x:Name="CkBoxCacheImages"
28+
Grid.Row="0" Grid.Column="0"
29+
Content="Cache Images"
30+
IsChecked="{Binding settings.CacheImages}"
31+
Checked="CkBoxCacheImages_OnChecked"
32+
Unchecked="CkBoxCacheImages_OnChecked"
33+
HorizontalAlignment="Center"
34+
VerticalAlignment="Center"
35+
FontSize="14"/>
36+
<Label
37+
Grid.Row="0" Grid.Column="1"
38+
Content="Max Record Count: "
39+
FontSize="14"
40+
HorizontalAlignment="Right"
41+
VerticalAlignment="Center"/>
42+
<xctk:UIntegerUpDown
43+
x:Name="UpDownMaxRecCount"
44+
Grid.Row="0" Grid.Column="2"
45+
Width="80"
46+
HorizontalAlignment="Left"
47+
VerticalAlignment="Center"
48+
FontSize="14"
49+
Value="{Binding settings.MaxDataCount}"
50+
ValueChanged="UpDownMaxRecCount_OnValueChanged"
51+
/>
52+
<Button
53+
x:Name="BtnRestartFlow"
54+
Grid.Row="1" Grid.Column="0"
55+
Width="70" Height="30"
56+
Padding="3, 3, 3, 3"
57+
HorizontalAlignment="Right"
58+
Content="Restart"
59+
Click="BtnRestartFlow_OnClick"
60+
FontSize="18"/>
61+
<Label
62+
Grid.Row="1" Grid.Column="1"
63+
Grid.ColumnSpan="2"
64+
Content="Flow.Launcher to apply"
65+
HorizontalAlignment="Left"
66+
VerticalAlignment="Center"
67+
HorizontalContentAlignment="Center"
68+
VerticalContentAlignment="Center"
69+
Margin="5, 5, 5, 5"
70+
FontSize="18" />
2171
</Grid>
2272
</UserControl>
Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,38 @@
11
using System;
2+
using System.Windows;
23
using System.Windows.Controls;
34
using System.Windows.Input;
45
using Flow.Launcher.Plugin;
56
using ClipboardR.Core;
7+
using Xceed.Wpf.Toolkit;
68

79
namespace ClipboardR.Panels;
810

911
public partial class SettingsPanel : UserControl
1012
{
1113
public Settings settings { get; set; }
12-
// public ICommand OnCkboxCacheImagesChanged { get; set; }
1314
private PluginInitContext _context { get; set; }
1415
public SettingsPanel(Settings settings, PluginInitContext ctx)
1516
{
1617
this.settings = settings;
1718
_context = ctx;
1819
InitializeComponent();
19-
// TODO: Won't work
20-
// OnCkboxCacheImagesChanged = new RelayCommand((p) =>
21-
// {
22-
// var isChecked = (bool)p;
23-
// if (settings.CacheImages == isChecked) return;
24-
// settings.CacheImages = isChecked;
25-
// _context.API.ShowMsg($"{isChecked}");
26-
// });
2720
}
2821

29-
// public class RelayCommand : ICommand
30-
// {
31-
// public event EventHandler? CanExecuteChanged;
32-
// private Action<object> _action;
33-
//
34-
// public RelayCommand(Action<object> action)
35-
// {
36-
// _action = action;
37-
// }
38-
// public bool CanExecute(object? o)
39-
// {
40-
// return true;
41-
// }
42-
//
43-
// public void Execute(object? parameter)
44-
// {
45-
// if (parameter is null) return;
46-
// var p = (bool)parameter;
47-
// _action?.Invoke(p);
48-
// }
49-
// }
22+
private void CkBoxCacheImages_OnChecked(object sender, RoutedEventArgs e)
23+
{
24+
if (sender is CheckBox c)
25+
settings.CacheImages = c.IsChecked ?? false;
26+
}
27+
28+
private void UpDownMaxRecCount_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
29+
{
30+
if (sender is UIntegerUpDown { Value: { } } u)
31+
settings.MaxDataCount = u.Value.Value;
32+
}
33+
34+
private void BtnRestartFlow_OnClick(object sender, RoutedEventArgs e)
35+
{
36+
_context.API.RestartApp();
37+
}
5038
}

src/ClipboardR/ClipboardR.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<Content Include="plugin.json">
3232
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3333
</Content>
34-
<Content Include="Images/clipboard.png">
34+
<Content Include="Images/*.png">
3535
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3636
</Content>
3737
</ItemGroup>
2.31 KB
Loading

src/ClipboardR/Main.cs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ public class ClipboardR : IPlugin, IDisposable, ISettingProvider, ISavable
2121
private DirectoryInfo ClipDir { get; set; } = null!;
2222
private DirectoryInfo ClipCacheDir { get; set; } = null!;
2323
private string _defaultIconPath = null!;
24-
private const int MaxDataCount = 1000;
24+
private string _defaultPinIconPath = null!;
25+
private uint _maxDataCount = 10000;
2526
private const string PinUnicode = "📌";
2627
private Settings _settings = null!;
2728
private string _settingsPath = null!;
2829
private int CurrentScore { get; set; } = 0;
2930

30-
// private readonly InputSimulator inputSimulator = new InputSimulator();
3131
private PluginInitContext? _context;
3232
private LinkedList<ClipboardData> _dataList = new();
3333

@@ -43,6 +43,7 @@ public void Init(PluginInitContext ctx)
4343
: new DirectoryInfo(imageCacheDirectoryPath);
4444

4545
_defaultIconPath = Path.Join(ClipDir.FullName, "Images/clipboard.png");
46+
_defaultPinIconPath = Path.Join(ClipDir.FullName, "Images/clipboard_pined.png");
4647

4748
_settingsPath = Path.Join(ClipDir.FullName, "settings.json");
4849
if (File.Exists(_settingsPath))
@@ -55,6 +56,8 @@ public void Init(PluginInitContext ctx)
5556

5657
_settings.ConfigFile = _settingsPath;
5758
_settings.Save();
59+
60+
_maxDataCount = _settings.MaxDataCount;
5861
}
5962

6063
public List<Result> Query(Query query)
@@ -72,16 +75,17 @@ public List<Result> Query(Query query)
7275

7376
private Result ClipDataToResult(ClipboardData o)
7477
{
75-
var disSubTitle = o.Pined ? $"{PinUnicode}: {o.SenderApp}" : o.SenderApp!;
78+
var dispSubTitle = $"{o.CreateTime:yyyy-MM-dd-hh-mm-ss}: {o.SenderApp}";
79+
dispSubTitle = o.Pined ? $"{PinUnicode}{dispSubTitle}" : dispSubTitle;
7680
return new Result
7781
{
7882
Title = o.DisplayTitle,
79-
SubTitle = disSubTitle,
83+
SubTitle = dispSubTitle,
8084
Icon = () => o.Icon,
8185
CopyText = o.Text,
8286
Score = o.Score,
8387
TitleToolTip = o.Text,
84-
SubTitleToolTip = disSubTitle,
88+
SubTitleToolTip = dispSubTitle,
8589
PreviewPanel = new Lazy<UserControl>(() => new PreviewPanel(
8690
o,
8791
_context!,
@@ -120,6 +124,7 @@ private void _OnClipboardChange(object? sender, SharpClipboard.ClipboardChangedE
120124
InitScore = CurrentScore + 1,
121125
Time = DateTime.Now,
122126
Pined = false,
127+
CreateTime = DateTime.Now,
123128
};
124129
switch (e.ContentType)
125130
{
@@ -130,7 +135,6 @@ private void _OnClipboardChange(object? sender, SharpClipboard.ClipboardChangedE
130135
clipboardData.Text = $"Image:{clipboardData.Time:yy-MM-dd-HH:mm:ss}";
131136
if (_settings.CacheImages) Utils.SaveImageCache(clipboardData, ClipCacheDir);
132137
clipboardData.Icon = _clipboard.ClipboardImage.ToBitmapImage();
133-
134138
break;
135139
case SharpClipboard.ContentTypes.Files:
136140
var t = _clipboard.ClipboardFiles.ToArray();
@@ -150,7 +154,7 @@ private void _OnClipboardChange(object? sender, SharpClipboard.ClipboardChangedE
150154
if (_dataList.Any(node => node.Equals(clipboardData)))
151155
return;
152156
_dataList.AddFirst(clipboardData);
153-
if (_dataList.Count > MaxDataCount)
157+
if (_dataList.Count > _maxDataCount)
154158
_dataList.RemoveLast();
155159
CurrentScore++;
156160
}
@@ -174,18 +178,17 @@ public void RemoveFromDatalist(ClipboardData clipboardData)
174178
_context!.API.ChangeQuery(_context.CurrentPluginMetadata.ActionKeyword, true);
175179
}
176180

177-
public void PinOneRecord(ClipboardData clipboardData)
181+
public void PinOneRecord(ClipboardData c)
178182
{
179-
_dataList.Remove(clipboardData);
180-
_dataList.AddLast(clipboardData);
183+
_dataList.Remove(c);
184+
if (c.Type is SharpClipboard.ContentTypes.Text or SharpClipboard.ContentTypes.Files)
185+
c.Icon = c.Pined
186+
? new BitmapImage(new Uri(_defaultPinIconPath, UriKind.RelativeOrAbsolute))
187+
: new BitmapImage(new Uri(_defaultIconPath, UriKind.RelativeOrAbsolute));
188+
_dataList.AddLast(c);
181189
_context!.API.ChangeQuery(_context.CurrentPluginMetadata.ActionKeyword, true);
182190
}
183191

184-
// private Task<bool> HideMainWindow()
185-
// {
186-
//
187-
// }
188-
189192
public void Save()
190193
{
191194
_settings?.Save();

src/ClipboardR/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Name": "ClipboardR",
55
"Description": "A clipboard plugin for Flow.Launcher, support pictures!",
66
"Author": "Rainyl",
7-
"Version": "0.2.2",
7+
"Version": "0.2.3",
88
"Language": "csharp",
99
"Website": "https://github.com/rainyl/Flow.Launcher.Plugin.ClipboardR",
1010
"IcoPath": "Images/clipboard.png",

0 commit comments

Comments
 (0)