fasdfsa commited on
Commit
798be0d
·
1 Parent(s): 8cd514d

增加 OCR 结果窗口

Browse files
src/WpfEditor/EchoDictWindow.xaml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ <Window x:Class="WpfEditor.EchoDictWindow"
2
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4
+ Title="Echodict" Height="200" Width="400">
5
+ <Grid>
6
+ <TextBlock x:Name="textBlock" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="16" />
7
+ </Grid>
8
+ </Window>
src/WpfEditor/EchoDictWindow.xaml.cs ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using System.Windows;
2
+
3
+ namespace WpfEditor
4
+ {
5
+ public partial class EchoDictWindow : Window
6
+ {
7
+ public EchoDictWindow(string text)
8
+ {
9
+ InitializeComponent();
10
+ textBlock.Text = text;
11
+ }
12
+ }
13
+ }
src/WpfEditor/OCRResultWindow.xaml ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <Window x:Class="WpfEditor.OCRResultWindow"
2
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6
+ xmlns:local="clr-namespace:WpfEditor"
7
+ mc:Ignorable="d"
8
+ Title="OCR识别结果" Height="450" Width="800">
9
+ <Grid>
10
+ <RichTextBox x:Name="richTextBox" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
11
+ <RichTextBox.ContextMenu>
12
+ <ContextMenu>
13
+ <MenuItem Header="剪切" Click="CutMenuItem_Click" />
14
+ <MenuItem Header="复制" Click="CopyMenuItem_Click" />
15
+ <MenuItem Header="粘贴" Click="PasteMenuItem_Click" />
16
+ <MenuItem Header="jisho" Click="JishoMenuItem_Click" />
17
+ <MenuItem Header="naver" Click="NaverMenuItem_Click" />
18
+ <MenuItem Header="naverja" Click="NaverjaMenuItem_Click" />
19
+ <MenuItem Header="echodict" Click="EchodictMenuItem_Click" />
20
+ </ContextMenu>
21
+ </RichTextBox.ContextMenu>
22
+ </RichTextBox>
23
+ </Grid>
24
+ </Window>
src/WpfEditor/OCRResultWindow.xaml.cs ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using System;
2
+ using System.Collections.Generic;
3
+ using System.Linq;
4
+ using System.Text;
5
+ using System.Threading.Tasks;
6
+ using System.Windows;
7
+ using System.Windows.Controls;
8
+ using System.Windows.Data;
9
+ using System.Windows.Documents;
10
+ using System.Windows.Forms;
11
+ using System.Windows.Input;
12
+ using System.Windows.Media;
13
+ using System.Windows.Media.Imaging;
14
+ using System.Windows.Shapes;
15
+
16
+ namespace WpfEditor
17
+ {
18
+ /// <summary>
19
+ /// OCRResultWindow.xaml 的交互逻辑
20
+ /// </summary>
21
+ public partial class OCRResultWindow : Window
22
+ {
23
+ private string selectText = "";
24
+
25
+ public OCRResultWindow(string text="")
26
+ {
27
+ InitializeComponent();
28
+ if (text.Length > 0)
29
+ {
30
+ richTextBox.AppendText(text);
31
+ }
32
+ richTextBox.PreviewMouseRightButtonUp += RichTextBox_PreviewMouseRightButtonUp;
33
+ }
34
+
35
+
36
+ private void RichTextBox_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e)
37
+ {
38
+ var selected = richTextBox.Selection.Text;
39
+ if (selectText != selected)
40
+ {
41
+ selectText = selected;
42
+ }
43
+ }
44
+
45
+ private void CutMenuItem_Click(object sender, RoutedEventArgs e)
46
+ {
47
+ richTextBox.Cut();
48
+ }
49
+
50
+ private void CopyMenuItem_Click(object sender, RoutedEventArgs e)
51
+ {
52
+ richTextBox.Copy();
53
+ }
54
+
55
+ private void PasteMenuItem_Click(object sender, RoutedEventArgs e)
56
+ {
57
+ richTextBox.Paste();
58
+ }
59
+
60
+ private void JishoMenuItem_Click(object sender, RoutedEventArgs e)
61
+ {
62
+ var content = System.Web.HttpUtility.UrlEncode(this.selectText);
63
+
64
+ String url = $"https://jisho.org/search/{content}";
65
+ //BrowserHelper.OpenBrowserUrl(url, BrowserType.Google);
66
+ }
67
+
68
+ private void NaverMenuItem_Click(object sender, RoutedEventArgs e)
69
+ {
70
+ var content = System.Web.HttpUtility.UrlEncode(this.selectText);
71
+
72
+ String url = $"https://ko.dict.naver.com/#/search?query={content}";
73
+ //BrowserHelper.OpenBrowserUrl(url, BrowserType.Google);
74
+ }
75
+
76
+ private void NaverjaMenuItem_Click(object sender, RoutedEventArgs e)
77
+ {
78
+ var content = System.Web.HttpUtility.UrlEncode(this.selectText);
79
+
80
+ String url = $"https://ja.dict.naver.com/#/search?query={content}";
81
+ //BrowserHelper.OpenBrowserUrl(url, BrowserType.Google);
82
+ }
83
+
84
+ private void EchodictMenuItem_Click(object sender, RoutedEventArgs e)
85
+ {
86
+ var win = new EchoDictWindow(selectText);
87
+ win.Show();
88
+ }
89
+
90
+ }
91
+ }
src/WpfEditor/TreeMenuPage.xaml.cs CHANGED
@@ -41,6 +41,9 @@ namespace WpfEditor
41
  //ShowBalloonTip("图像不存在");
42
  return;
43
  }
 
 
 
44
  }
45
 
46
  private void MenuButton_Click(object sender, RoutedEventArgs e)
 
41
  //ShowBalloonTip("图像不存在");
42
  return;
43
  }
44
+
45
+ var win = new OCRResultWindow("just a test.");
46
+ win.Show();
47
  }
48
 
49
  private void MenuButton_Click(object sender, RoutedEventArgs e)