forked from CopyPlusPlus/CopyPlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Manual.xaml.cs
127 lines (104 loc) · 4.01 KB
/
Manual.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
namespace CopyPlusPlus
{
/// <summary>
/// Interaction logic for Manual.xaml
/// </summary>
public partial class Manual
{
//Get MainWindow
private readonly MainWindow _mainWindow =
Application.Current.Windows.Cast<Window>().FirstOrDefault(window => window is MainWindow) as MainWindow;
// 如果正在处理中,再次点击按钮,直接返回
private bool _lineStatus;
private bool _spaceStatus;
private bool _widthStatus;
public Manual()
{
InitializeComponent();
}
private void MergeLineBtn_Click(object sender, RoutedEventArgs e)
{
if (_lineStatus) return;
_lineStatus = true;
if (!Clipboard.ContainsText()) return;
var text = Clipboard.GetText();
if (text.Length > 1)
for (var counter = 0; counter < text.Length; ++counter)
// 合并换行
if (counter >= 0 && text[counter] == '\r')
{
if (counter > 0)
{
// 如果检测到句号结尾,则不去掉换行
if (text[counter - 1] == '。' && _mainWindow.RemainChinese) continue;
if (text[counter - 1] == '.' && _mainWindow.RemainEnglish) continue;
}
// 去除换行
try
{
text = text.Remove(counter, 2);
}
catch
{
text = text.Remove(counter, 1);
}
--counter;
// 判断 非负数越界 或 句末
if (counter >= 0 && counter != text.Length - 1)
// 判断 非中文 结尾, 则加一个空格
if (!Regex.IsMatch(text[counter].ToString(), "[\n ,。?!《》\u4e00-\u9fa5]"))
text = text.Insert(counter + 1, " ");
}
Clipboard.SetDataObject(text);
_lineStatus = false;
}
private void MergeSpacesBtn_Click(object sender, RoutedEventArgs e)
{
if (_spaceStatus) return;
_spaceStatus = true;
if (!Clipboard.ContainsText()) return;
var text = Clipboard.GetText();
for (var counter = 0; counter < text.Length - 1; counter++)
if (counter >= 0 && text[counter] == ' ')
{
text = text.Remove(counter, 1);
--counter;
}
Clipboard.SetDataObject(text);
_spaceStatus = false;
}
private void WidthBtn_Click(object sender, RoutedEventArgs e)
{
if (_widthStatus) return;
_widthStatus = true;
if (Clipboard.ContainsText())
Clipboard.SetDataObject(Clipboard.GetText().Normalize(NormalizationForm.FormKC));
_widthStatus = false;
}
private void PinSwitch(object sender, RoutedEventArgs e)
{
Topmost = !Topmost;
var converter = new BrushConverter();
Pin.Background = Pin.Background.ToString() == "#FFFFFEFF"
? (Brush)converter.ConvertFromString("#00F6F2F2")
: (Brush)converter.ConvertFromString("#FFFFFEFF");
}
private void Manual_OnClosed(object sender, EventArgs e)
{
_mainWindow.Show();
_mainWindow.GlobalSwitch = true;
}
private void OnMergeRight(object sender, MouseButtonEventArgs e)
{
var remain = new RemainOriginal();
remain.Show();
}
}
}