fasdfsa commited on
Commit
4cd6e5c
·
1 Parent(s): 58fd7d2

echodict 窗体使用单件实例,并在 App 类里实例化

Browse files
data/img/3cf1b1a493ac306bbce7c3ce798cbf1b.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9d1821b4b70f27af109bcb1af502829c2181f46bd4b610b7d70863099928cdc0
3
+ size 51832
data/json/3cf1b1a493ac306bbce7c3ce798cbf1b.json ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "height": 550,
3
+ "prism_wordsInfo": [
4
+ {
5
+ "charInfo": [
6
+ {
7
+ "guid": "9354714b-0950-41e4-bf47-8b568df10ebf",
8
+ "h": 189,
9
+ "isDeleted": 0,
10
+ "w": 39,
11
+ "word": "す",
12
+ "x": 205,
13
+ "y": 92
14
+ },
15
+ {
16
+ "guid": "dfaf26cc-c659-478e-a5c4-32d2451dcb32",
17
+ "h": 189,
18
+ "isDeleted": 0,
19
+ "w": 39,
20
+ "word": "い",
21
+ "x": 205,
22
+ "y": 92
23
+ },
24
+ {
25
+ "guid": "449282e1-b3d1-4d49-988b-9f912763e1c0",
26
+ "h": 189,
27
+ "isDeleted": 0,
28
+ "w": 39,
29
+ "word": "ま",
30
+ "x": 205,
31
+ "y": 92
32
+ },
33
+ {
34
+ "guid": "076cdd8e-c3bc-4ab3-b0bb-80410c0fa1cb",
35
+ "h": 189,
36
+ "isDeleted": 0,
37
+ "w": 39,
38
+ "word": "せ",
39
+ "x": 205,
40
+ "y": 92
41
+ },
42
+ {
43
+ "guid": "02c34205-a440-4967-9284-1f342afdb1a4",
44
+ "h": 189,
45
+ "isDeleted": 0,
46
+ "w": 39,
47
+ "word": "ー",
48
+ "x": 205,
49
+ "y": 92
50
+ }
51
+ ],
52
+ "height": 189,
53
+ "pos": [
54
+ {
55
+ "x": 205,
56
+ "y": 92
57
+ },
58
+ {
59
+ "x": 244,
60
+ "y": 92
61
+ },
62
+ {
63
+ "x": 244,
64
+ "y": 281
65
+ },
66
+ {
67
+ "x": 205,
68
+ "y": 281
69
+ }
70
+ ],
71
+ "width": 39,
72
+ "word": "すいませー",
73
+ "x": 205,
74
+ "y": 92
75
+ },
76
+ {
77
+ "charInfo": [
78
+ {
79
+ "guid": "d479e8f4-6288-41f2-8c53-f2d509568119",
80
+ "h": 81,
81
+ "isDeleted": 0,
82
+ "w": 48,
83
+ "word": "誰",
84
+ "x": 116,
85
+ "y": 253
86
+ },
87
+ {
88
+ "guid": "c6b64e8d-cfd5-4927-b5de-9be0ddbe623f",
89
+ "h": 81,
90
+ "isDeleted": 0,
91
+ "w": 48,
92
+ "word": "か",
93
+ "x": 116,
94
+ "y": 253
95
+ },
96
+ {
97
+ "guid": "bc03839e-f759-4a29-b655-2e8ae9a7e1bc",
98
+ "h": 174,
99
+ "isDeleted": 0,
100
+ "w": 38,
101
+ "word": "ま",
102
+ "x": 74,
103
+ "y": 288
104
+ },
105
+ {
106
+ "guid": "dfa73cbb-2ef5-48d0-a9a6-4ec7be04a2d4",
107
+ "h": 174,
108
+ "isDeleted": 0,
109
+ "w": 38,
110
+ "word": "せ",
111
+ "x": 74,
112
+ "y": 288
113
+ },
114
+ {
115
+ "guid": "5cc1d0da-312b-45de-b485-847d5d9f879d",
116
+ "h": 174,
117
+ "isDeleted": 0,
118
+ "w": 38,
119
+ "word": "ん",
120
+ "x": 74,
121
+ "y": 288
122
+ },
123
+ {
124
+ "guid": "5c60f285-685c-429f-8928-86650a2c1de6",
125
+ "h": 174,
126
+ "isDeleted": 0,
127
+ "w": 38,
128
+ "word": "か",
129
+ "x": 74,
130
+ "y": 288
131
+ },
132
+ {
133
+ "guid": "090e91bd-9ee2-45fa-8671-f889d2eb57c8",
134
+ "h": 174,
135
+ "isDeleted": 0,
136
+ "w": 38,
137
+ "word": "ー",
138
+ "x": 74,
139
+ "y": 288
140
+ }
141
+ ],
142
+ "height": 209,
143
+ "pos": [
144
+ {
145
+ "x": 74,
146
+ "y": 253
147
+ },
148
+ {
149
+ "x": 164,
150
+ "y": 253
151
+ },
152
+ {
153
+ "x": 164,
154
+ "y": 462
155
+ },
156
+ {
157
+ "x": 74,
158
+ "y": 462
159
+ }
160
+ ],
161
+ "width": 90,
162
+ "word": "誰かませんかー",
163
+ "x": 74,
164
+ "y": 253
165
+ }
166
+ ],
167
+ "width": 353
168
+ }
src/WpfEditor/App.xaml.cs CHANGED
@@ -12,6 +12,8 @@ namespace WpfEditor
12
 
13
  //new MainWindow().Show();
14
 
 
 
15
  var window = new TreeMenuPage();
16
  window.Show();
17
  }
 
12
 
13
  //new MainWindow().Show();
14
 
15
+ var win = Echodict.EchodictWindow.Instance; // 第一次实例化,后面启动就快了
16
+
17
  var window = new TreeMenuPage();
18
  window.Show();
19
  }
src/WpfEditor/EchoDictWindow.xaml.cs CHANGED
@@ -23,17 +23,42 @@ namespace Echodict
23
  /// </summary>
24
  public partial class EchodictWindow : Window
25
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  private List<Dictionary> _dicts = new List<Dictionary>();
27
  private List<string> _sourcePaths = new List<string>();
28
  private List<DictGroup> _groups = new List<DictGroup>();
29
  private string _currentSelectionId = "ALL";
30
  private bool _isReady = false;
31
  private string? _startupWord;
 
32
 
33
 
34
  public EchodictWindow()
35
  {
36
  InitializeComponent();
 
 
 
 
 
 
 
 
 
 
 
37
  LoadConfig();
38
 
39
  // Initial scan if we have paths but no dicts loaded yet
@@ -59,33 +84,34 @@ namespace Echodict
59
  _isReady = true;
60
  }
61
 
62
- public EchodictWindow(string? startupWord = null)
63
  {
64
- InitializeComponent();
65
- _startupWord = startupWord;
66
- LoadConfig();
67
-
68
- // Initial scan if we have paths but no dicts loaded yet
69
- if (_sourcePaths.Count > 0)
70
- {
71
- Loaded += (s, e) => ScanAndLoadDictionaries();
72
- }
73
- else
74
  {
75
- // Initialize empty selector
76
- RefreshDictSelector();
77
  }
 
 
 
 
78
 
79
- Browser.RequestHandler = new DictRequestHandler(_dicts, (query) =>
80
- {
81
- Dispatcher.Invoke(() =>
82
- {
83
- SideSearchBox.Text = query;
84
- Search(query, true);
85
- });
86
- });
87
-
88
- _isReady = true;
 
 
 
 
 
 
89
  }
90
 
91
 
 
23
  /// </summary>
24
  public partial class EchodictWindow : Window
25
  {
26
+ private static EchodictWindow? _instance;
27
+ public static EchodictWindow Instance
28
+ {
29
+ get
30
+ {
31
+ if (_instance == null)
32
+ {
33
+ _instance = new EchodictWindow();
34
+ }
35
+ return _instance;
36
+ }
37
+ }
38
+
39
  private List<Dictionary> _dicts = new List<Dictionary>();
40
  private List<string> _sourcePaths = new List<string>();
41
  private List<DictGroup> _groups = new List<DictGroup>();
42
  private string _currentSelectionId = "ALL";
43
  private bool _isReady = false;
44
  private string? _startupWord;
45
+ private bool _forceClose = false;
46
 
47
 
48
  public EchodictWindow()
49
  {
50
  InitializeComponent();
51
+
52
+ // Default hidden and minimized
53
+ this.Visibility = Visibility.Hidden;
54
+ this.WindowState = WindowState.Minimized;
55
+
56
+ Application.Current.Exit += (s, e) =>
57
+ {
58
+ _forceClose = true;
59
+ this.Close();
60
+ };
61
+
62
  LoadConfig();
63
 
64
  // Initial scan if we have paths but no dicts loaded yet
 
84
  _isReady = true;
85
  }
86
 
87
+ protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
88
  {
89
+ if (_forceClose)
 
 
 
 
 
 
 
 
 
90
  {
91
+ base.OnClosing(e);
92
+ return;
93
  }
94
+
95
+ e.Cancel = true;
96
+ this.Hide();
97
+ }
98
 
99
+ public void ShowWord(string word)
100
+ {
101
+ if (!this.IsLoaded)
102
+ {
103
+ _startupWord = word;
104
+ }
105
+ else
106
+ {
107
+ SideSearchBox.Text = word;
108
+ Search(word, true);
109
+ }
110
+
111
+ this.Show();
112
+ this.WindowState = WindowState.Normal;
113
+ this.Activate();
114
+ this.Topmost = true;
115
  }
116
 
117
 
src/WpfEditor/EditDictionaries.xaml.cs CHANGED
@@ -171,7 +171,8 @@ namespace Echodict
171
  Height = 150,
172
  Title = caption,
173
  WindowStartupLocation = WindowStartupLocation.CenterScreen,
174
- ResizeMode = ResizeMode.NoResize
 
175
  };
176
  StackPanel sp = new StackPanel() { Margin = new Thickness(10) };
177
  Label lbl = new Label() { Content = text };
 
171
  Height = 150,
172
  Title = caption,
173
  WindowStartupLocation = WindowStartupLocation.CenterScreen,
174
+ ResizeMode = ResizeMode.NoResize,
175
+ Topmost = true
176
  };
177
  StackPanel sp = new StackPanel() { Margin = new Thickness(10) };
178
  Label lbl = new Label() { Content = text };
src/WpfEditor/TextEditorControl.cs CHANGED
@@ -320,7 +320,7 @@ namespace WpfEditor
320
  {
321
  Header = "查询"
322
  };
323
- QeryMenuItem.Click += OnQeryMenuItemClick;
324
  ContextMenu.Items.Add(QeryMenuItem);
325
 
326
  // 翻译菜单项
@@ -384,16 +384,16 @@ namespace WpfEditor
384
  }
385
 
386
  // "翻译"菜单项点击事件处理
387
- private async void OnQeryMenuItemClick(object sender, RoutedEventArgs e)
388
  {
389
  if (HasSelection())
390
  {
391
  string text = GetSelectedText();
392
 
393
- var win = new Echodict.EchodictWindow(text);
394
  win.Owner = Window.GetWindow(this);
395
  win.WindowStartupLocation = WindowStartupLocation.CenterOwner;
396
- win.Show();
397
  }
398
  }
399
 
 
320
  {
321
  Header = "查询"
322
  };
323
+ QeryMenuItem.Click += OnQueryMenuItemClick;
324
  ContextMenu.Items.Add(QeryMenuItem);
325
 
326
  // 翻译菜单项
 
384
  }
385
 
386
  // "翻译"菜单项点击事件处理
387
+ private async void OnQueryMenuItemClick(object sender, RoutedEventArgs e)
388
  {
389
  if (HasSelection())
390
  {
391
  string text = GetSelectedText();
392
 
393
+ var win = Echodict.EchodictWindow.Instance;
394
  win.Owner = Window.GetWindow(this);
395
  win.WindowStartupLocation = WindowStartupLocation.CenterOwner;
396
+ win.ShowWord(text);
397
  }
398
  }
399