Skip to content

Commit

Permalink
完成手动处理
Browse files Browse the repository at this point in the history
  • Loading branch information
wy-luke committed Jan 5, 2022
1 parent 2cbde21 commit 612932a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 23 deletions.
6 changes: 3 additions & 3 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@

<!--<TextBlock x:Name="TextAbstract1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="22,5,0,0" FontSize="13" Width="403"><Run Text="1. 划词触发" /></TextBlock>-->
<!--<TextBlock x:Name="TextAbstract2" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="22,30,0,0" FontSize="13" Width="403"><Run Text="2. 快捷键触发" /></TextBlock>-->
<mah:ToggleSwitch x:Name="SwitchSelectText" MinWidth="0" ContentDirection="LeftToRight" Content="划词 " FontWeight="Bold" ContentPadding="0,0,-10,0" FontFamily="Microsoft YaHei UI" Margin="34,0,0,0" IsOn="True" />
<mah:ToggleSwitch x:Name="SwitchShortcut" MinWidth="0" ContentDirection="LeftToRight" Content="Control+C+C " FontWeight="Bold" ContentPadding="0,0,-10,0" FontFamily="Microsoft YaHei UI" IsOn="True" HorizontalAlignment="Center" />
<Button Content="手动处理" HorizontalAlignment="Left" Margin="320,0,0,0" VerticalAlignment="Center" FontFamily="Microsoft YaHei UI" Click="ManualBtn_Click" Height="31" Width="82"/>
<mah:ToggleSwitch x:Name="SwitchSelectText" MinWidth="0" ContentDirection="LeftToRight" Content="划词 " FontWeight="Bold" ContentPadding="0,0,-10,0" FontFamily="Microsoft YaHei UI" Margin="35,0,0,0" IsOn="True" />
<mah:ToggleSwitch x:Name="SwitchShortcut" MinWidth="0" ContentDirection="LeftToRight" Content="Control+C+C " FontWeight="Bold" ContentPadding="0,0,-10,0" FontFamily="Microsoft YaHei UI" IsOn="True" Margin="156,0,0,0" />
<Button Content="手动处理" HorizontalAlignment="Left" Margin="338,0,0,0" VerticalAlignment="Center" FontFamily="Microsoft YaHei UI" Click="ManualBtn_Click" Height="20" Width="80"/>

<!--<TextBlock HorizontalAlignment="Left" VerticalAlignment="Top" Margin="16,46,0,0" FontSize="13" Width="187" Text="祝君创作顺利,走向人生巅峰!" />-->
</Grid>
Expand Down
15 changes: 7 additions & 8 deletions Manual.xaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<Window x:Class="CopyPlusPlus.Manual"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:CopyPlusPlus"
mc:Ignorable="d"
Title="Manual" Height="355" Width="565">
Title="手动处理" Height="355" Width="565">
<Grid>
<TextBox Margin="10,10,10,0" TextWrapping="Wrap" Text="将文本粘贴到这里" VerticalAlignment="Top" Height="263" FontFamily="Microsoft YaHei UI"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="45,294,0,0" VerticalAlignment="Top" Height="35" Width="100"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="213,294,0,0" VerticalAlignment="Top" Height="35" Width="100"/>

<TextBox x:Name="TextBox" Margin="10,10,10,38" TextWrapping="Wrap" Text="将文本粘贴到这里" FontFamily="Microsoft YaHei UI" GotFocus="TextBox_GotFocus" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" />
<Button Content="合并换行" Margin="20,0,0,7" VerticalAlignment="Bottom" Height="25" FontFamily="Microsoft YaHei UI" Click="MergeLineBtn_Click" HorizontalAlignment="Left" Width="58" />
<Button Content="合并空格" Margin="100,0,0,7" VerticalAlignment="Bottom" Height="25" FontFamily="Microsoft YaHei UI" Click="MergeSpacesBtn_Click" HorizontalAlignment="Left" Width="58" />
<Button Content="复制" Margin="180,0,0,7" VerticalAlignment="Bottom" Height="25" FontFamily="Microsoft YaHei UI" Click="CopyBtn_Click" HorizontalAlignment="Left" Width="58" />
</Grid>
</Window>
</Window>
69 changes: 57 additions & 12 deletions Manual.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CopyPlusPlus
{
Expand All @@ -23,5 +13,60 @@ public Manual()
{
InitializeComponent();
}

private void MergeLineBtn_Click(object sender, RoutedEventArgs e)
{
string text = TextBox.Text;
for (var counter = 0; counter < text.Length - 1; counter++)
{
// 合并换行
if (text[counter + 1] == '\r')
{
// 如果检测到句号结尾,则不去掉换行
if (text[counter] == '。') continue;

// 去除换行
try
{
text = text.Remove(counter + 1, 2);
}
catch
{
text = text.Remove(counter + 1, 1);
}

//判断 英文字母 或 英文逗号 结尾, 则加一个空格
if (Regex.IsMatch(text[counter].ToString(), "[a-zA-Z,]"))
text = text.Insert(counter + 1, " ");

// 判断 连词符- 结尾, 且前一个字符为英文单词, 则去除"-"
if (text[counter] == '-' &&
Regex.IsMatch(text[counter - 1].ToString(), "[a-zA-Z]"))
text = text.Remove(counter, 1);
}
}
TextBox.Text = text;
}

private void MergeSpacesBtn_Click(object sender, RoutedEventArgs e)
{
string text = TextBox.Text;
for (var counter = 0; counter < text.Length - 1; counter++)
{
if (text[counter] == ' ') text = text.Remove(counter, 1);
}
TextBox.Text = text;
}

private void CopyBtn_Click(object sender, RoutedEventArgs e)
{
Clipboard.SetText(TextBox.Text);
}

public void TextBox_GotFocus(object sender, RoutedEventArgs e)
{
TextBox.Text = string.Empty;
TextBox.GotFocus -= TextBox_GotFocus;
}
}
}
}

0 comments on commit 612932a

Please sign in to comment.