diff --git a/.all-contributorsrc b/.all-contributorsrc new file mode 100644 index 0000000..af94712 --- /dev/null +++ b/.all-contributorsrc @@ -0,0 +1,39 @@ +{ + "projectName": "ja-learner", + "projectOwner": "ks233", + "files": [ + "README.md" + ], + "commitType": "docs", + "commitConvention": "angular", + "contributorsPerLine": 7, + "contributors": [ + { + "login": "ks233", + "name": "ks233", + "avatar_url": "https://avatars.githubusercontent.com/u/38981529?v=4", + "profile": "https://ks233.github.io/", + "contributions": [ + "code" + ] + }, + { + "login": "shaka0919", + "name": "Harvey Wang", + "avatar_url": "https://avatars.githubusercontent.com/u/17539962?v=4", + "profile": "https://github.com/shaka0919", + "contributions": [ + "code" + ] + }, + { + "login": "ly-nld", + "name": "跨性别", + "avatar_url": "https://avatars.githubusercontent.com/u/38471793?v=4", + "profile": "http://lgbt.sh", + "contributions": [ + "infra" + ] + } + ] +} diff --git a/GUI/MainForm.cs b/GUI/MainForm.cs index 2d40f4e..5e4592e 100644 --- a/GUI/MainForm.cs +++ b/GUI/MainForm.cs @@ -1,13 +1,6 @@ using Microsoft.Web.WebView2.Core; using System.Diagnostics; -using System.Runtime.InteropServices; -using MeCab; -using System.Text; -using System.Reflection.Metadata; -using OpenAI_API.Chat; using Microsoft.VisualBasic; -using System.Windows.Forms.Design; -using System.Net.Http; namespace ja_learner { @@ -16,9 +9,30 @@ public partial class MainForm : Form DictForm dictForm; TextAnalyzer textAnalyzer = new TextAnalyzer(); - GptCaller gptCaller; private string sentence = ""; - + private bool immersiveMode = false; + public bool ImmersiveMode + { + get { return immersiveMode; } + set + { + if (value) + { + webView.Parent = this; + tabControl.Hide(); + panel1.Hide(); + FormBorderStyle = FormBorderStyle.None; + } + else + { + webView.Parent = tabControl.TabPages[0]; + tabControl.Show(); + panel1.Show(); + FormBorderStyle = FormBorderStyle.Sizable; + } + immersiveMode = value; + } + } public string Sentence { get { return sentence; } @@ -82,6 +96,20 @@ private void CoreWebView2_NewWindowRequested(object sender, CoreWebView2NewWindo private void CoreWebView2_WebMessageReceived(object sender, CoreWebView2WebMessageReceivedEventArgs e) { string message = e.TryGetWebMessageAsString(); + // 来自webview的特殊按键事件处理 + if (message == "DBLCLICK") + { + ImmersiveMode = !ImmersiveMode; + return; + } + else if (message == "MOUSEDOWN") + { + // if (ImmersiveMode) + { + Drag(); + } + return; + } dictForm.SearchText(message); dictForm.ShowAndFocus(); Focus(); @@ -111,16 +139,16 @@ private void MainForm_SizeChanged(object sender, EventArgs e) { if (timerWindowAttach.Enabled) { - heightAfter = this.Height; + heightAfter = Height; if (dictForm.Visible) { - dictForm.Width = this.Right - WindowAttacher.TargetWindowRect.Right; + dictForm.Width = Right - WindowAttacher.TargetWindowRect.Right; } } } - private System.Drawing.Point locationBefore; // 记录普通模式下窗口的位置 + private Point locationBefore; // 记录普通模式下窗口的位置 private Size sizeBefore; // 记录普通模式下窗口的大小 private int heightAfter = 200; // 附着模式时,窗体通常会比较矮 @@ -131,17 +159,17 @@ private void checkBoxWindowAttach_CheckedChanged(object sender, EventArgs e) if (checkBoxWindowAttach.Checked) { // 记录普通状态的窗口位置,切换到吸附状态下的窗口位置 - sizeBefore = this.Size; - locationBefore = this.Location; - this.Height = heightAfter; + sizeBefore = Size; + locationBefore = Location; + Height = heightAfter; timerWindowAttach.Enabled = true; } else { timerWindowAttach.Enabled = false; - heightAfter = this.Height; - this.Size = sizeBefore; - this.Location = locationBefore; + heightAfter = Height; + Size = sizeBefore; + Location = locationBefore; } } @@ -151,7 +179,7 @@ private void timerWindowAttach_Tick(object sender, EventArgs e) { WindowAttacher.AttachWindows(this, dictForm); } - catch (Exception ex) + catch { WindowAttach = false; } @@ -176,6 +204,10 @@ public bool WindowAttach private void checkBoxClipboardMode_CheckedChanged(object sender, EventArgs e) { ClipBoardMode = checkBoxClipboardMode.Checked; + if (ClipBoardMode) + { + Sentence = Clipboard.GetText(TextDataFormat.UnicodeText).Trim().Replace(" ", ""); + } } private void timerGetClipboard_Tick(object sender, EventArgs e) { @@ -201,7 +233,7 @@ public bool ClipBoardMode private void btnInputText_Click(object sender, EventArgs e) { - Sentence = Microsoft.VisualBasic.Interaction.InputBox("手动输入", "输入句子", "", 0, 0); + Sentence = Interaction.InputBox("手动输入", "输入句子", "", 0, 0); } private void timerSelectWindow_Tick(object sender, EventArgs e) @@ -250,7 +282,7 @@ private void textBoxHwnd_TextChanged(object sender, EventArgs e) string windowTitle = WindowAttacher.GetWindowTitle(hwnd); checkBoxWindowAttach.Text = $"与【{windowTitle}】对齐"; // 判断窗口句柄是不是自己的 - if (hwnd == this.Handle || hwnd == dictForm.Handle) + if (hwnd == Handle || hwnd == dictForm.Handle) { checkBoxWindowAttach.Enabled = false; return; @@ -340,7 +372,51 @@ private void comboBoxExtraPrompts_Click(object sender, EventArgs e) async private void checkBoxTranslateKatakana_CheckedChanged(object sender, EventArgs e) { - await webView.ExecuteScriptAsync($"setTranslateKatakana({checkBoxTranslateKatakana.Checked.ToString().ToLower()})"); + string param = checkBoxTranslateKatakana.Checked ? "true" : "false"; + await webView.ExecuteScriptAsync($"setTranslateKatakana({param})"); + } + + // https://stackoverflow.com/questions/31199437/borderless-and-resizable-form-c + // 从↑抄来的代码,无边框模式下可调整窗口大小 + const int WM_NCHITTEST = 0x0084; + const int HTCLIENT = 1; + const int HTCAPTION = 2; + protected override void WndProc(ref Message m) + { + base.WndProc(ref m); + switch (m.Msg) + { + case WM_NCHITTEST: + if (m.Result == (IntPtr)HTCLIENT) + { + m.Result = (IntPtr)HTCAPTION; + } + break; + } + } + protected override CreateParams CreateParams + { + get + { + CreateParams cp = base.CreateParams; + cp.Style |= 0x40000; + return cp; + } + } + + // 窗口拖拽 + public const int WM_NCLBUTTONDOWN = 0xA1; + public const int HT_CAPTION = 0x2; + + [System.Runtime.InteropServices.DllImport("user32.dll")] + public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); + [System.Runtime.InteropServices.DllImport("user32.dll")] + public static extern bool ReleaseCapture(); + + private void Drag() + { + ReleaseCapture(); + SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0); } } } \ No newline at end of file diff --git a/README.md b/README.md index b7914f1..64b9c0a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -
ks233 💻 |
+ Harvey Wang 💻 |
+ 跨性别 🚇 |
+