Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit 9f5627d

Browse files
committed
UI update
1 parent ffffb33 commit 9f5627d

File tree

4 files changed

+62
-75
lines changed

4 files changed

+62
-75
lines changed

Diff for: CopyPlusPlus.csproj

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
<PropertyGroup>
44
<OutputType>WinExe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFramework>net5.0-windows</TargetFramework>
66
<UseWPF>true</UseWPF>
77
<ApplicationIcon>copy.ico</ApplicationIcon>
88
</PropertyGroup>
99

1010
<ItemGroup>
1111
<None Remove="image\AliPay.png" />
1212
<None Remove="image\GitHub.png" />
13-
<None Remove="image\wechat-gzh.jpg" />
1413
<None Remove="image\Wechat.png" />
1514
<None Remove="image\wechatgzh.jpg" />
1615
</ItemGroup>
@@ -31,7 +30,7 @@
3130
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3231
</Resource>
3332
<Resource Include="image\wechatgzh.jpg">
34-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
33+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3534
</Resource>
3635
</ItemGroup>
3736

Diff for: MainWindow.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<TextBlock x:Name="textBlock_contact" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" TextAlignment="Left" Margin="20,154,0,0" Width="188"><Run Text="遇到问题,或提建议,欢迎联系我" /></TextBlock>
4343
<TextBlock x:Name="textBlock_mail" HorizontalAlignment="Left" Margin="20,183,0,0" TextWrapping="Wrap" VerticalAlignment="Top" TextAlignment="Center"><Run Text="[email protected]" /></TextBlock>
4444
<TextBlock x:Name="textBlock_github" HorizontalAlignment="Left" Margin="20,0,0,167" TextWrapping="Wrap" VerticalAlignment="Bottom" TextAlignment="Center"><Run Text="项目已开源,欢迎Star" /></TextBlock>
45-
<Button Margin="145,0,236,165" Click="Github_Click" Cursor="Hand" VerticalAlignment="Bottom">
45+
<Button Margin="143,0,238,167" Click="Github_Click" Cursor="Hand" VerticalAlignment="Bottom">
4646
<Button.Template>
4747
<ControlTemplate>
4848
<Image Source="/image/GitHub.png" />

Diff for: MainWindow.xaml.cs

+59-71
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Security.Cryptography;
66
using System.Text;
77
using System.Text.Json;
8-
using System.Threading;
98
using System.Web;
109
using System.Windows;
1110
using System.Windows.Input;
@@ -23,114 +22,105 @@ public partial class MainWindow : Window
2322
#pragma warning disable CA2211 // Non-constant fields should not be visible
2423
public static bool changeStatus = false;
2524
#pragma warning restore CA2211 // Non-constant fields should not be visible
26-
bool switch1Check = true;
27-
bool switch2Check = false;
28-
bool switch3Check = false;
25+
private bool switch1Check = true;
26+
private bool switch2Check = false;
27+
private bool switch3Check = false;
28+
29+
public SharpClipboard clipboard;
2930

30-
public SharpClipboard clipboard = new SharpClipboard();
3131
public MainWindow()
3232
{
3333
InitializeComponent();
3434

35-
36-
// Attach your code to the ClipboardChanged event to listen to cuts/copies.
37-
clipboard.ClipboardChanged += ClipboardChanged;
38-
//disable issueing ClipboardChanged event when start
39-
clipboard.ObserveLastEntry = false;
40-
clipboard.ObservableFormats.Files = false;
41-
clipboard.ObservableFormats.Images = false;
35+
InitializeClipboardMonitor();
4236
}
4337

44-
public void InitializeClipboard()
38+
39+
//Initializes a new instance of SharpClipboard
40+
public void InitializeClipboardMonitor()
4541
{
4642
clipboard = new SharpClipboard();
43+
//Attach your code to the ClipboardChanged event to listen to cuts/copies
4744
clipboard.ClipboardChanged += ClipboardChanged;
4845
//disable issueing ClipboardChanged event when start
4946
clipboard.ObserveLastEntry = false;
47+
//disable monitoring files
5048
clipboard.ObservableFormats.Files = false;
49+
//disable monitoring images
5150
clipboard.ObservableFormats.Images = false;
5251
}
5352

5453
private void ClipboardChanged(Object sender, SharpClipboard.ClipboardChangedEventArgs e)
5554
{
56-
//if (e.SourceApplication.Title.Contains("CopyPlusPlus"))
57-
//{
58-
// return;
59-
//}
60-
if (true)
55+
// Is the content copied of text type?
56+
if (e.ContentType == SharpClipboard.ContentTypes.Text)
6157
{
62-
// Is the content copied of text type?
63-
if (e.ContentType == SharpClipboard.ContentTypes.Text)
64-
{
65-
// Get the cut/copied text.
66-
string text = e.Content.ToString();
58+
// Get the cut/copied text.
59+
string text = e.Content.ToString();
6760

68-
if (switch1Check == true || switch2Check == true)
61+
if (switch1Check == true || switch2Check == true)
62+
{
63+
for (int counter = 0; counter < text.Length - 1; counter++)
6964
{
70-
for (int counter = 0; counter < text.Length - 1; counter++)
65+
if (switch1Check == true)
7166
{
72-
if (switch1Check == true)
67+
if (text[counter + 1].ToString() == "\r")
7368
{
74-
if (text[counter + 1].ToString() == "\r")
69+
if (text[counter].ToString() == ".")
7570
{
76-
if (text[counter].ToString() == ".")
77-
{
78-
continue;
79-
}
80-
if (text[counter].ToString() == "。")
81-
{
82-
continue;
83-
}
84-
text = text.Remove(counter + 1, 2);
71+
continue;
8572
}
86-
}
87-
88-
if (switch2Check == true)
89-
{
90-
if (text[counter].ToString() == " ")
73+
if (text[counter].ToString() == "。")
9174
{
92-
text = text.Remove(counter, 1);
75+
continue;
9376
}
77+
text = text.Remove(counter + 1, 2);
9478
}
9579
}
96-
}
9780

98-
if (switch3Check == true)
99-
{
100-
if (changeStatus == false)
81+
if (switch2Check == true)
10182
{
102-
string appId = Properties.Settings.Default.AppID;
103-
string secretKey = Properties.Settings.Default.SecretKey;
104-
if (appId == "none" || secretKey == "none")
105-
{
106-
MessageBox.Show("请先设置翻译接口");
107-
108-
KeyInput keyinput = new KeyInput();
109-
keyinput.Show();
110-
changeStatus = true;
111-
}
112-
else
83+
if (text[counter].ToString() == " ")
11384
{
114-
text = BaiduTrans(appId, secretKey, text);
85+
text = text.Remove(counter, 1);
11586
}
11687
}
11788
}
118-
119-
clipboard.StopMonitoring();
120-
Clipboard.SetText(text);
121-
//Clipboard.Flush();
122-
InitializeClipboard();
123-
124-
12589
}
12690

127-
// If the cut/copied content is complex, use 'Other'.
128-
else if (e.ContentType == SharpClipboard.ContentTypes.Other)
91+
if (switch3Check == true)
12992
{
130-
//do nothing
93+
if (changeStatus == false)
94+
{
95+
string appId = Properties.Settings.Default.AppID;
96+
string secretKey = Properties.Settings.Default.SecretKey;
97+
if (appId == "none" || secretKey == "none")
98+
{
99+
MessageBox.Show("请先设置翻译接口");
131100

132-
// Do something with 'clipboard.ClipboardObject' or 'e.Content' here...
101+
KeyInput keyinput = new KeyInput();
102+
keyinput.Show();
103+
changeStatus = true;
104+
}
105+
else
106+
{
107+
text = BaiduTrans(appId, secretKey, text);
108+
}
109+
}
133110
}
111+
112+
clipboard.StopMonitoring();
113+
Clipboard.SetText(text);
114+
Clipboard.Flush();
115+
InitializeClipboardMonitor();
116+
}
117+
118+
// If the cut/copied content is complex, use 'Other'.
119+
else if (e.ContentType == SharpClipboard.ContentTypes.Other)
120+
{
121+
//do nothing
122+
123+
// Do something with 'clipboard.ClipboardObject' or 'e.Content' here...
134124
}
135125

136126
}
@@ -229,8 +219,6 @@ private void ShowInputWindowText(object sender, MouseButtonEventArgs e)
229219
changeStatus = true;
230220
}
231221

232-
233-
234222
private void SwitchUncheck(object sender, RoutedEventArgs e)
235223
{
236224
HorizontalToggleSwitch switchButton = sender as HorizontalToggleSwitch;

Diff for: image/wechatgzh.jpg

267 Bytes
Loading

0 commit comments

Comments
 (0)