fasdfsa commited on
Commit
7e97feb
·
1 Parent(s): 32726bd

调整窗口显示,增加快捷键

Browse files
src/WpfEditor/App.xaml.cs CHANGED
@@ -15,6 +15,7 @@ namespace WpfEditor
15
  var win = Echodict.EchodictWindow.Instance; // 第一次实例化,后面启动就快了
16
 
17
  var window = new TreeMenuPage();
 
18
  window.Show();
19
  }
20
  }
 
15
  var win = Echodict.EchodictWindow.Instance; // 第一次实例化,后面启动就快了
16
 
17
  var window = new TreeMenuPage();
18
+ window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
19
  window.Show();
20
  }
21
  }
src/WpfEditor/EchoDictWindow.xaml.cs CHANGED
@@ -43,6 +43,7 @@ namespace Echodict
43
  private bool _isReady = false;
44
  private string? _startupWord;
45
  private bool _forceClose = false;
 
46
 
47
 
48
  public EchodictWindow()
@@ -52,6 +53,14 @@ namespace Echodict
52
  // Default hidden and minimized
53
  this.Visibility = Visibility.Hidden;
54
  this.WindowState = WindowState.Minimized;
 
 
 
 
 
 
 
 
55
 
56
  Application.Current.Exit += (s, e) =>
57
  {
 
43
  private bool _isReady = false;
44
  private string? _startupWord;
45
  private bool _forceClose = false;
46
+ public WindowState LastWindowState { get; private set; } = WindowState.Normal;
47
 
48
 
49
  public EchodictWindow()
 
53
  // Default hidden and minimized
54
  this.Visibility = Visibility.Hidden;
55
  this.WindowState = WindowState.Minimized;
56
+
57
+ this.StateChanged += (s, e) =>
58
+ {
59
+ if (this.WindowState != WindowState.Minimized)
60
+ {
61
+ LastWindowState = this.WindowState;
62
+ }
63
+ };
64
 
65
  Application.Current.Exit += (s, e) =>
66
  {
src/WpfEditor/TextEditorControl.cs CHANGED
@@ -390,9 +390,13 @@ namespace WpfEditor
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
  }
 
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
  var win = Echodict.EchodictWindow.Instance;
398
+ // Without an Owner, CenterOwner behaves like Manual. Use CenterScreen instead.
399
+ win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
400
  win.ShowWord(text);
401
  }
402
  }
src/WpfEditor/TreeMenuPage.xaml.cs CHANGED
@@ -46,6 +46,24 @@ namespace WpfEditor
46
 
47
  });
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  Loaded += TreeMenuPage_Loaded;
50
  Closing += TreeMenuPage_Closing;
51
  StateChanged += TreeMenuPage_StateChanged;
@@ -81,7 +99,27 @@ namespace WpfEditor
81
  ScreenGrabber.OnCaptured = async (bitmap, type) => await ScreenshotCallbackAsync(bitmap, type, null);
82
  ScreenGrabber.Capture(true);
83
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  contextMenu.Items.Add(ocrMenuItem);
 
 
85
  contextMenu.Items.Add(exitMenuItem);
86
  _notifyIcon.ContextMenuStrip = contextMenu;
87
 
 
46
 
47
  });
48
 
49
+ GlobalHotKey.RegisterHotKey("Alt + D", () => {
50
+ var win = Echodict.EchodictWindow.Instance;
51
+ if (win.WindowState == WindowState.Minimized)
52
+ {
53
+ win.WindowState = win.LastWindowState;
54
+ }
55
+ win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
56
+ win.Show();
57
+ win.Activate();
58
+ win.Topmost = true;
59
+ });
60
+
61
+ GlobalHotKey.RegisterHotKey("Alt + E", () => {
62
+ Show();
63
+ WindowState = WindowState.Normal;
64
+ Activate();
65
+ });
66
+
67
  Loaded += TreeMenuPage_Loaded;
68
  Closing += TreeMenuPage_Closing;
69
  StateChanged += TreeMenuPage_StateChanged;
 
99
  ScreenGrabber.OnCaptured = async (bitmap, type) => await ScreenshotCallbackAsync(bitmap, type, null);
100
  ScreenGrabber.Capture(true);
101
  };
102
+ var EchoEditorMenuItem = new ToolStripMenuItem("Alt+E EchoEditor");
103
+ EchoEditorMenuItem.Click += (s, e) => {
104
+ Show();
105
+ WindowState = WindowState.Normal;
106
+ Activate();
107
+ };
108
+ var EchoDictMenuItem = new ToolStripMenuItem("Alt+D EchoDict");
109
+ EchoDictMenuItem.Click += (s, e) => {
110
+ var win = Echodict.EchodictWindow.Instance;
111
+ if (win.WindowState == WindowState.Minimized)
112
+ {
113
+ win.WindowState = win.LastWindowState;
114
+ }
115
+ win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
116
+ win.Show();
117
+ win.Activate();
118
+ win.Topmost = true;
119
+ };
120
  contextMenu.Items.Add(ocrMenuItem);
121
+ contextMenu.Items.Add(EchoDictMenuItem);
122
+ contextMenu.Items.Add(EchoEditorMenuItem);
123
  contextMenu.Items.Add(exitMenuItem);
124
  _notifyIcon.ContextMenuStrip = contextMenu;
125