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

Commit 1bb96ec

Browse files
committed
new: save image manually
1 parent c510664 commit 1bb96ec

File tree

10 files changed

+76
-34
lines changed

10 files changed

+76
-34
lines changed

Flow.Launcher.Plugin.ClipboardR.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClipboardR.Core.Test", "src
1313
EndProject
1414
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Build", "build\Build.csproj", "{8AE1016A-11A6-4A6C-B5F4-97149923841C}"
1515
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClipboardR.Panels.Test", "src\ClipboardR.Panels.Test\ClipboardR.Panels.Test.csproj", "{B5DC21C9-618A-48D1-969F-E8D5BF7FBFD6}"
17+
EndProject
1618
Global
1719
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1820
Debug|Any CPU = Debug|Any CPU
@@ -39,6 +41,10 @@ Global
3941
{8AE1016A-11A6-4A6C-B5F4-97149923841C}.Debug|Any CPU.Build.0 = Debug|Any CPU
4042
{8AE1016A-11A6-4A6C-B5F4-97149923841C}.Release|Any CPU.ActiveCfg = Release|Any CPU
4143
{8AE1016A-11A6-4A6C-B5F4-97149923841C}.Release|Any CPU.Build.0 = Release|Any CPU
44+
{B5DC21C9-618A-48D1-969F-E8D5BF7FBFD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45+
{B5DC21C9-618A-48D1-969F-E8D5BF7FBFD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
46+
{B5DC21C9-618A-48D1-969F-E8D5BF7FBFD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
47+
{B5DC21C9-618A-48D1-969F-E8D5BF7FBFD6}.Release|Any CPU.Build.0 = Release|Any CPU
4248
EndGlobalSection
4349
GlobalSection(SolutionProperties) = preSolution
4450
HideSolutionNode = FALSE

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ Original Repo: [Wox.Plugin.ClipboardManager](https://github.com/Wox-launcher/Wox
1414

1515
Ported to Flow.Launcher: [Flow.Launcher.Plugin.ClipboardHistory](https://github.com/liberize/Flow.Launcher.Plugin.ClipboardHistory)
1616

17+
## Features
18+
19+
- Preview panel, support images
20+
- Copy & delete record
21+
- Cache images supported
22+
- Manually save images
23+
1724
## Installation
1825

1926
### Using release
@@ -40,8 +47,9 @@ If you want to save images in your clipboard, open the `CacheImages` option in s
4047

4148
## Todo List
4249

43-
- [ ] Save images maually
44-
- [ ] Cached images format defination
50+
- [x] Save images manually
51+
- [ ] Cached images format definition
52+
- [ ] Image OCR
4553

4654
## License
4755

build/Build.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<OutputType>Exe</OutputType>
44
<TargetFramework>net7.0-windows</TargetFramework>
55
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
6+
<Nullable>enable</Nullable>
67
</PropertyGroup>
78
<ItemGroup>
89
<PackageReference Include="Cake.Compression" Version="0.3.0" />

build/Program.cs

Lines changed: 1 addition & 1 deletion
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.0";
37+
public string PublishVersion = "0.2.1";
3838

3939
public BuildContext(ICakeContext context)
4040
: base(context)

src/ClipboardR.Core/Utils.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Drawing;
2+
3+
namespace ClipboardR.Core;
4+
5+
public static class Utils
6+
{
7+
private static Random _random = new();
8+
9+
public static string RandomString(int length)
10+
{
11+
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-";
12+
return new string(Enumerable.Repeat(chars, length)
13+
.Select(s => s[_random.Next(s.Length)]).ToArray());
14+
}
15+
16+
public static string? SaveImageCache(ClipboardData clipboardData, DirectoryInfo clipCacheDir)
17+
{
18+
if (clipboardData.Data is not Image img) return null;
19+
var name = RandomString(10);
20+
var path = Path.Join(clipCacheDir.FullName, $"{name}.png");
21+
22+
img.Save(path);
23+
return path;
24+
}
25+
}
3.9 KB
Loading

src/ClipboardR.Panels/PreviewPanel.xaml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
xmlns:local="clr-namespace:ClipboardR.Panels"
77
mc:Ignorable="d">
88
<UserControl.Resources>
9-
<Image x:Key="Copy" Source="pack://application:,,,/ClipboardR.Panels;Component/Images/copy.png" Height="30" Width="30" />
10-
<Image x:Key="Pin" Source="pack://application:,,,/ClipboardR.Panels;Component/Images/pin.png" Height="30" Width="30" />
11-
<Image x:Key="Pined" Source="pack://application:,,,/ClipboardR.Panels;Component/Images/pined.png" Height="30" Width="30" />
12-
<Image x:Key="Delete" Source="pack://application:,,,/ClipboardR.Panels;Component/Images/delete.png" Height="30" Width="30" />
9+
<Image x:Key="CopyIcon" Source="pack://application:,,,/ClipboardR.Panels;Component/Images/copy.png" Height="30" Width="30" />
10+
<Image x:Key="PinIcon" Source="pack://application:,,,/ClipboardR.Panels;Component/Images/pin.png" Height="30" Width="30" />
11+
<Image x:Key="PinedIcon" Source="pack://application:,,,/ClipboardR.Panels;Component/Images/pined.png" Height="30" Width="30" />
12+
<Image x:Key="DeleteIcon" Source="pack://application:,,,/ClipboardR.Panels;Component/Images/delete.png" Height="30" Width="30" />
13+
<Image x:Key="SaveIcon" Source="pack://application:,,,/ClipboardR.Panels;Component/Images/save.png"></Image>
1314
</UserControl.Resources>
1415
<Grid
1516
MinWidth="300" MinHeight="100"
@@ -26,7 +27,17 @@
2627
x:Name="PreImage" Margin="3,3,3,3"
2728
HorizontalAlignment="Center" VerticalAlignment="Center"
2829
Visibility="Hidden"
29-
MaxWidth="320" MaxHeight="400" />
30+
MaxWidth="320" MaxHeight="400" >
31+
<Image.ContextMenu>
32+
<ContextMenu>
33+
<MenuItem Header="Save" Click="ImSaveAs_Click">
34+
<MenuItem.Icon>
35+
<DynamicResource ResourceKey="SaveIcon"></DynamicResource>
36+
</MenuItem.Icon>
37+
</MenuItem>
38+
</ContextMenu>
39+
</Image.ContextMenu>
40+
</Image>
3041
<TextBox Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Grid.RowSpan="1" IsUndoEnabled="False"
3142
x:Name="TxtBoxPre" HorizontalAlignment="Center"
3243
Panel.ZIndex="1" FontSize="14" TextAlignment="Left" Padding="5,5,5,5"
@@ -49,21 +60,21 @@
4960
HorizontalAlignment="Center" VerticalAlignment="Bottom"
5061
Width="33" Height="33" Padding="0, 0, 0, 0"
5162
Margin="5,5,5,5" Click="BtnCopy_Click" >
52-
<DynamicResource ResourceKey="Copy"/>
63+
<DynamicResource ResourceKey="CopyIcon"/>
5364
</Button>
5465
<Button Grid.Row="0" Grid.Column="1"
5566
x:Name="BtnPin" ToolTip="Pin on top"
5667
HorizontalAlignment="Center" VerticalAlignment="Bottom"
5768
Width="33" Height="33" Padding="0, 0, 0, 0"
5869
Margin="5,5,5,5" Click="BtnPin_Click" >
59-
<DynamicResource ResourceKey="Pined"/>
70+
<DynamicResource ResourceKey="PinIcon"/>
6071
</Button>
6172
<Button Grid.Row="0" Grid.Column="2"
6273
x:Name="BtnDelete" ToolTip="Delete this record"
6374
HorizontalAlignment="Center" VerticalAlignment="Bottom"
6475
Width="33" Height="33" Padding="0, 0, 0, 0"
6576
Margin="5,5,5,5" Click="BtnDelete_Click" >
66-
<DynamicResource ResourceKey="Delete"/>
77+
<DynamicResource ResourceKey="DeleteIcon"/>
6778
</Button>
6879
</Grid>
6980

src/ClipboardR.Panels/PreviewPanel.xaml.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,20 @@ public partial class PreviewPanel : UserControl
1616
{
1717
private ClipboardData _clipboardData;
1818
private PluginInitContext _context;
19+
private DirectoryInfo CacheDir { get; set; }
1920
private Action<ClipboardData> DeleteOneRecord { get; set; }
2021
private Action<ClipboardData> CopyRecord { get; set; }
2122
private Action<ClipboardData> PinRecord { get; set; }
2223
private int OldScore { get; set; }
2324

24-
public PreviewPanel(ClipboardData clipboardData, PluginInitContext context, Action<ClipboardData> delAction,
25+
public PreviewPanel(ClipboardData clipboardData, PluginInitContext context,
26+
DirectoryInfo cacheDir,
27+
Action<ClipboardData> delAction,
2528
Action<ClipboardData> copyAction, Action<ClipboardData> pinAction)
2629
{
2730
_clipboardData = clipboardData;
2831
_context = context;
32+
CacheDir = cacheDir;
2933
DeleteOneRecord = delAction;
3034
CopyRecord = copyAction;
3135
PinRecord = pinAction;
@@ -86,7 +90,7 @@ private void BtnDelete_Click(object sender, System.Windows.RoutedEventArgs e)
8690

8791
private void SetBtnIcon()
8892
{
89-
BtnPin.Content = FindResource(_clipboardData.Pined ? "Pined" : "Pin");
93+
BtnPin.Content = FindResource(_clipboardData.Pined ? "PinedIcon" : "PinIcon");
9094
}
9195

9296
private void TxtBoxPre_GotFocus(object sender, System.Windows.RoutedEventArgs e)
@@ -105,4 +109,9 @@ private void BtnPin_Click(object sender, RoutedEventArgs e)
105109
_clipboardData.Score = _clipboardData.Pined ? int.MaxValue : _clipboardData.InitScore;
106110
PinRecord?.Invoke(_clipboardData);
107111
}
112+
113+
private void ImSaveAs_Click(object sender, RoutedEventArgs e)
114+
{
115+
Utils.SaveImageCache(_clipboardData, CacheDir);
116+
}
108117
}

src/ClipboardR/Main.cs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using System.Windows.Media.Imaging;
1010
using WindowsInput;
1111
using WK.Libraries.SharpClipboardNS;
12-
using Image = System.Drawing.Image;
1312
using ClipboardR.Core;
1413
using ClipboardR.Panels;
1514

@@ -23,7 +22,6 @@ public class ClipboardR : IPlugin, IDisposable, ISettingProvider, ISavable
2322
private string _defaultIconPath = null!;
2423
private const int MaxDataCount = 1000;
2524
private const string PinUnicode = "📌";
26-
private static Random _random = new();
2725
private Settings _settings = null!;
2826
private string _settingsPath = null!;
2927
private int CurrentScore { get; set; } = 0;
@@ -86,6 +84,7 @@ private Result ClipDataToResult(ClipboardData o)
8684
PreviewPanel = new Lazy<UserControl>(() => new PreviewPanel(
8785
o,
8886
_context!,
87+
ClipCacheDir,
8988
delAction: RemoveFromDatalist,
9089
copyAction: CopyToClipboard,
9190
pinAction: PinOneRecord
@@ -126,7 +125,7 @@ private void _OnClipboardChange(object? sender, SharpClipboard.ClipboardChangedE
126125
break;
127126
case SharpClipboard.ContentTypes.Image:
128127
clipboardData.Text = $"Image:{clipboardData.Time:yy-MM-dd-HH:mm:ss}";
129-
if (_settings.CacheImages) SaveImageCache(clipboardData);
128+
if (_settings.CacheImages) Utils.SaveImageCache(clipboardData, ClipCacheDir);
130129
clipboardData.Icon = _clipboard.ClipboardImage.ToBitmapImage();
131130

132131
break;
@@ -153,25 +152,8 @@ private void _OnClipboardChange(object? sender, SharpClipboard.ClipboardChangedE
153152
CurrentScore++;
154153
}
155154

156-
private string? SaveImageCache(ClipboardData clipboardData)
157-
{
158-
if (clipboardData.Data is not Image img) return null;
159-
var name = RandomString(10);
160-
var path = Path.Join(ClipCacheDir.FullName, $"{name}.png");
161-
162-
img.Save(path);
163-
return path;
164-
}
165-
166155
public Control CreateSettingPanel() => new SettingsPanel(_settings, _context!);
167156

168-
private string RandomString(int length)
169-
{
170-
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-";
171-
return new string(Enumerable.Repeat(chars, length)
172-
.Select(s => s[_random.Next(s.Length)]).ToArray());
173-
}
174-
175157
public void Dispose()
176158
{
177159
}

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.0",
7+
"Version": "0.2.1",
88
"Language": "csharp",
99
"Website": "https://github.com/rainyl/Flow.Launcher.Plugin.ClipboardR",
1010
"IcoPath": "Images/clipboard.png",

0 commit comments

Comments
 (0)