知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.
Swift androidlinuxlive-captionsmacosmeeting-notesmenubar-appsimultaneous-interpretationspeech-recognitionsubtitlesswiftswiftuitranslationwindows
feat(windows): fix a misheard word in the transcript or the meeting record, answer new names in the notes window, and keep a word list in Settings
wqugurub3e48051dd93
diff --git a/site/changelog.json b/site/changelog.jsonindex 03aaefa..5bc5f04 100644--- a/site/changelog.json+++ b/site/changelog.json@@ -93,6 +93,30 @@],"title": "开会时听错的人名和术语,字幕和纪要里当场就改对(需要 AI 服务)。","text": "每句话说完,AI 服务在翻译这句时顺带找出听错的词:读音相近的错字(质压 → 质押)直接改,词表里记过的听错写法不问就改,没见过的名字先等你确认。记录里仍留着原来听到的话。Windows 上字幕的翻译和原文由 Ming 一次给出,所以开着这个功能时每句会多发一次文字请求。"+ },+ {+ "kind": "new",+ "platforms": [+ "windows"+ ],+ "title": "改过的词带虚线,指着那句话能看到原来听成什么并改回;没见过的名字在纪要窗口问一次“这样改对吗?”。",+ "text": "纪要窗口顶上的卡片只要点“对 / 不对”,不会抢走会议软件的焦点;点 × 就等会后再看,共享屏幕让对方看到时不弹。会后打开会议记录,上方列出还等你确认的词,一个个点“对 / 不对 / 改成…”。每次改动都有“撤销”。"+ },+ {+ "kind": "new",+ "platforms": [+ "windows"+ ],+ "title": "会议记录里可以自己改听错的词:右键或指着一句选“改这句…”,整场同样听错的地方一起改,并记进词表。",+ "text": "也可以只改这一处;只改一处的不记进词表。"+ },+ {+ "kind": "new",+ "platforms": [+ "windows"+ ],+ "title": "设置里多了“词表”:常用的人名、产品名一次贴进来,会中就照这些写法改。",+ "text": "一行一个,常被听错的写法写在 = 后面(Morpho = 莫拉、莫法),贴进来时先显示会新增几个、补充几个、跳过几个。写法和听错的形式都能就地改,删掉的词可以撤销;同一个听错的形式已经记在别的词下时,会问归哪个词。词表和 Mac 版格式相同,只存在这台电脑上。"}]},diff --git a/windows/README.md b/windows/README.mdindex 867723c..8e3fb0a 100644--- a/windows/README.md+++ b/windows/README.md@@ -4,6 +4,7 @@ Cicada 的 Windows 版:把电脑播放的声音变成双语字幕和实时纪- 抓声音:WASAPI 进程回环,排除知了自己(Windows 10 2004 起)。- 识别:Ming(`Ming-3.0-audio-flash`)分段识别,一次请求同时返回语言、原文和译文;需要 Ling key。用不了 Ling 的可以在 设置 › AI 服务 换成 OpenRouter、ZenMux 或兼容 OpenAI 的地址:听交给它能输入音频的模型(同样的提示词,字幕晚 1–2 秒),纪要和翻译用它的文字模型,同传声音用它的声音模型,没有时用 Windows 的声音。+- 改正听错的词:和 Mac 版同样的规则和提示词(读音相近才直接改,拼音用 `src/Cicada.Core/Data/pinyin.tsv`,由 Apple 的 ICU/CLDR 汉字转拼音一次生成;新名字先问;词表 `vocabulary.json` 和 Mac 同格式)。Ming 一次给出原文和译文,没有单独的文字翻译请求可搭,所以开着时每句话会多发一次文字请求。没有声音也能试:`cicadactl silentlisten zh-CN`,再 `heard <一句话>`。- 纪要、记录格式、提示词、多语言文案都和 Mac 版一致;文案的英日韩翻译直接用 `Resources/*.lproj/Localizable.strings`,Windows 独有的在 `src/Cicada/Strings/`。- 新版本:启动时和每 4 小时查一次 GitHub Releases(`UpdateChecker`),只认带 Windows 安装包的发布;有新版本时托盘图标出现红点、每个版本发一次通知(正在听时等会议结束),托盘面板和设置 › 关于也会提示。点“安装”由知了自己下载这台电脑对应架构的 `Cicada-<版本>-Windows-x64.exe` / `-ARM64.exe`(1.1.0 只认 `Cicada-Setup.exe` 这两个旧名字,发布时一并附上)、对照 `checksums.txt` 校验后安装并重新打开,不经过浏览器,所以 SmartScreen 不拦。开发版只在设了 `CICADA_UPDATE_FEED` 或用 `updatefeed` 调试命令时才查。diff --git a/windows/src/Cicada/App.cs b/windows/src/Cicada/App.csindex 27ee5b8..5206de6 100644--- a/windows/src/Cicada/App.cs+++ b/windows/src/Cicada/App.cs@@ -889,6 +889,9 @@ sealed class Controller}public void SettingsPage(string id) => settingsWindow?.Show(id);+ /// Debug: 改这句… on a record's line; 词表 › 粘贴导入 with `text` pasted in.+ public void DebugEditLine(string id, string line) { ShowRecords(id); mainWindow?.DebugEdit(id, line); }+ public void DebugPaste(string text) { ShowSettings(); SettingsPage("words"); settingsWindow?.DebugImport(text); }// MARK: AI 服务@@ -1384,6 +1387,8 @@ static class DebugServerreturn new JsonObject { ["changed"] = app.Fixes.Edit(p[0], id, opts[0], everywhere: !opts.Contains("one"), remember: !opts.Contains("keep0")) };}case "fixundo": app.Fixes.Undo(); break;+ case "fixeditor": { var (id, lineId) = FixTarget(app, arg); app.DebugEditLine(id, lineId); break; } // fixeditor <line> [@id]+ case "vocabpaste": app.DebugPaste(arg); break; // vocabpaste <line|line…>: 粘贴导入, filled in, not importedcase "state": break;default: return new JsonObject { ["error"] = $"unknown command {parts[0]}" };}diff --git a/windows/src/Cicada/FixViews.cs b/windows/src/Cicada/FixViews.csnew file mode 100644index 0000000..69d60a3--- /dev/null+++ b/windows/src/Cicada/FixViews.cs@@ -0,0 +1,256 @@+using System.Windows;+using System.Windows.Controls;+using System.Windows.Documents;+using System.Windows.Input;+using System.Windows.Media;+using static Cicada.Strings;++namespace Cicada.App;++/// 改正听错的词's pieces, shared by the notes window and the meeting record (the Mac's FixViews.swift+/// and NotesViews.swift › FixedWords, FixConfirmCard, joinFixed): the line with its fixed words+/// underlined, what each was heard as with 改回, the 这样改对吗? card, the banner over a finished+/// meeting, and the toast with 撤销.+static class FixViews+{+ static readonly SolidColorBrush ChipFill = Frozen(0xF2, 0xF3, 0xF5);+ static SolidColorBrush Frozen(byte r, byte g, byte b) { var x = new SolidColorBrush(Color.FromRgb(r, g, b)); x.Freeze(); return x; }++ static readonly TextDecorationCollection Dotted = MakeDotted();+ static TextDecorationCollection MakeDotted()+ {+ var pen = new Pen(Palette.Tertiary, 1.2) { DashStyle = new DashStyle([1, 2], 0), DashCap = PenLineCap.Round };+ pen.Freeze();+ var c = new TextDecorationCollection { new TextDecoration(TextDecorationLocation.Underline, pen, 2, TextDecorationUnit.FontRecommended, TextDecorationUnit.Pixel) };+ c.Freeze();+ return c;+ }++ /// The line as shown, each fixed word with a dotted underline; words waiting for the user+ /// (这样改对吗?) on a pale wash, as heard.+ public static TextBlock LineText(TranscriptLine l, double size, Brush color)+ {+ var t = Ui.Text("", size, color);+ var (text, marks) = Correction.Apply(l.Fixes ?? [], l.Src);+ var style = new byte[text.Length];+ foreach (var (start, length) in marks) for (int i = start; i < start + length && i < style.Length; i++) style[i] = 1;+ foreach (var f in l.Fixes ?? [])+ if (f.Ask == true && f.From.Length > 0 && text.IndexOf(f.From, StringComparison.Ordinal) is var at and >= 0)+ for (int i = at; i < at + f.From.Length; i++) if (style[i] == 0) style[i] = 2;+ int from = 0;+ for (int i = 1; i <= text.Length; i++)+ {+ if (i < text.Length && style[i] == style[from]) continue;+ var run = new Run(text[from..i]);+ if (style[from] == 1) run.TextDecorations = Dotted;+ else if (style[from] == 2) run.Background = Palette.AccentPale;+ t.Inlines.Add(run);+ from = i;+ }+ return t;+ }++ /// Under a paragraph: each fixed word, what it was heard as, and 改回. `edit`: 改这句… after them+ /// (the meeting record).+ public static FrameworkElement FixedWords(TranscriptLine l, Action<LineFix> revert, Action? edit = null)+ {+ var wrap = new WrapPanel { Margin = new Thickness(0, 4, 0, 0) };+ foreach (var f in (l.Fixes ?? []).Where(f => f.Applied))+ {+ var c = Correction.Core(f.From, f.To);+ var words = new TextBlock { FontFamily = Palette.Font, FontSize = 11, Foreground = Palette.Ink, VerticalAlignment = VerticalAlignment.Center };+ words.Inlines.Add(new Run(L("听成")) { Foreground = Palette.Tertiary });+ words.Inlines.Add(new Run(" " + c.From));+ words.Inlines.Add(new Run(" → ") { Foreground = Palette.Tertiary });+ words.Inlines.Add(new Run(c.To));+ var back = Ui.LinkText(L("改回"), () => revert(f), 11);+ back.FontWeight = FontWeights.SemiBold;+ back.Margin = new Thickness(6, 0, 0, 0);+ wrap.Children.Add(new Border+ {+ Background = ChipFill, CornerRadius = new CornerRadius(6), Padding = new Thickness(8, 3, 8, 3), Margin = new Thickness(0, 0, 6, 4),+ Child = Ui.Row(0, words, back),+ });+ }+ if (edit is not null)+ {+ var link = Ui.LinkText(L("改这句…"), edit, 11);+ link.FontWeight = FontWeights.SemiBold;+ link.VerticalAlignment = VerticalAlignment.Center;+ link.Margin = new Thickness(2, 0, 0, 4);+ wrap.Children.Add(link);+ }+ return wrap;+ }++ /// 这样改对吗?: a name sound couldn't check, asked about once. Clicks only: the notes window+ /// never takes focus. 对 fixes every line waiting on it and adds it to the word list; × puts it+ /// off until after the meeting (稍后再看).+ public static FrameworkElement ConfirmCard(TranscriptLine line, LineFix fix, int count, Action<bool> answer, Action? later)+ {+ var c = Correction.Core(fix.From, fix.To);+ var head = new DockPanel();+ if (count > 1)+ {+ var n = Ui.Text($"1 / {count}", 12, Palette.Tertiary, wrap: false);+ DockPanel.SetDock(n, Dock.Right);+ head.Children.Add(n);+ }+ var title = Ui.Text(L("这样改对吗?"), 13, Palette.Ink, FontWeights.Bold, wrap: false);+ var hint = Ui.Text(L("确认后整场一起改,以后也这样改"), 12, Palette.Tertiary, wrap: false);+ hint.Margin = new Thickness(8, 0, 4, 0);+ head.Children.Add(Ui.Row(0, title, hint));++ var words = new TextBlock { FontFamily = Palette.Font, FontSize = 14, Foreground = Palette.Ink, TextTrimming = TextTrimming.CharacterEllipsis };+ words.Inlines.Add(new Run(c.From));+ words.Inlines.Add(new Run(" → ") { Foreground = Palette.Tertiary });+ words.Inlines.Add(new Run(c.To) { FontWeight = FontWeights.Bold });+ var where = Ui.Text($"{Languages.Clock(line.T)} · {line.Src}", 11, Palette.Tertiary, wrap: false);+ var buttons = Ui.Row(8, Small(Ui.Button(L("对"), () => answer(true), Ui.Kind.Primary, height: 28)), Small(Ui.Button(L("不对"), () => answer(false), height: 28)));+ if (later is not null)+ {+ var x = Ui.IconButton(Icons.Close, L("稍后再看"), later, Palette.Tertiary, 28, 11);+ buttons.Children.Add(x);+ x.Margin = new Thickness(2, 0, 0, 0);+ }+ var body = new DockPanel { Margin = new Thickness(0, 8, 0, 0) };+ DockPanel.SetDock(buttons, Dock.Right);+ buttons.Margin = new Thickness(8, 0, 0, 0);+ body.Children.Add(buttons);+ body.Children.Add(Ui.Stack(2, words, where));+ return new Border+ {+ Background = Palette.Surface, BorderBrush = Palette.Stroke, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(10),+ Padding = new Thickness(12, 10, 12, 10), Child = new StackPanel { Children = { head, body } },+ };+ }++ static Button Small(Button b) { b.MinWidth = 0; b.Padding = new Thickness(14, 0, 14, 0); return b; }++ /// Above a finished meeting's transcript: how many words were fixed, and the ones waiting for+ /// the user, one at a time (对 / 不对 / 改成…). Nothing once there was nothing to fix.+ public static FrameworkElement? Banner(Session s, LiveFixes fixes, Action<string> show, Action<TranscriptLine, string> edit)+ {+ var waiting = fixes.Pending(s.Id);+ var fixedCount = s.Lines.Sum(l => (l.Fixes ?? []).Count(f => f.Applied));+ if (waiting.Count == 0)+ return fixedCount > 0 ? Ui.Text(LF("改了 %lld 处听错的词", fixedCount), 12, Palette.Tertiary) : null;+ var (line, fix) = waiting[0];+ var c = Correction.Core(fix.From, fix.To);+ var title = Ui.Text(LF("改了 %lld 处听错的词,%lld 处等你确认", fixedCount, waiting.Count), 13, Palette.Ink, FontWeights.SemiBold);+ var what = new TextBlock { FontFamily = Palette.Font, FontSize = 12, Foreground = Palette.Secondary };+ what.Inlines.Add(new Run($"{c.From} → {c.To}?"));+ what.Inlines.Add(new Run($" · {Languages.Clock(line.T)}") { Foreground = Palette.Tertiary });+ var text = Ui.Stack(2, title, what);+ text.Cursor = Cursors.Hand;+ text.Background = Brushes.Transparent;+ text.MouseLeftButtonUp += (_, _) => show(line.Id);+ var buttons = Ui.Row(8,+ Small(Ui.Button(L("对"), () => fixes.Answer(fix, true, s.Id), Ui.Kind.Primary, height: 30)),+ Small(Ui.Button(L("不对"), () => fixes.Answer(fix, false, s.Id), Ui.Kind.Subtle, height: 30)),+ Small(Ui.Button(L("改成…"), () => edit(line, Correction.Apply((line.Fixes ?? []).Where(f => f.Applied).ToList(), line.Src).Text), Ui.Kind.Subtle, height: 30)));+ var dock = new DockPanel();+ DockPanel.SetDock(buttons, Dock.Right);+ buttons.Margin = new Thickness(10, 0, 0, 0);+ dock.Children.Add(buttons);+ dock.Children.Add(text);+ return new Border+ {+ Background = AccentWash, BorderBrush = Palette.AccentPale, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(12),+ Padding = new Thickness(14, 10, 14, 10), Child = dock,+ };+ }++ static readonly SolidColorBrush AccentWash = Frozen(0xFE, 0xF6, 0xF3);++ /// The last fix decision said back for a few seconds, with 撤销 (null when there is none).+ public static FrameworkElement? Toast(LiveFixes fixes)+ {+ if (fixes.Toast is not { } t) return null;+ var row = Ui.Row(14, Ui.Text(t.Text, 13, Brushes.White, wrap: false));+ if (fixes.CanUndo)+ {+ var undo = Ui.Text(L("撤销"), 13, new SolidColorBrush(Color.FromRgb(0xFF, 0xB5, 0x9C)), FontWeights.SemiBold, wrap: false);+ undo.Cursor = Cursors.Hand;+ undo.Margin = new Thickness(14, 0, 0, 0);+ undo.MouseLeftButtonDown += (_, e) => { e.Handled = true; fixes.Undo(); };+ System.Windows.Automation.AutomationProperties.SetName(undo, L("撤销"));+ row.Children.Add(undo);+ }+ return new Border+ {+ Background = Palette.Night, CornerRadius = new CornerRadius(10), Padding = new Thickness(14, 9, 14, 9), Child = row,+ HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Bottom,+ Effect = new System.Windows.Media.Effects.DropShadowEffect { BlurRadius = 16, ShadowDepth = 4, Opacity = 0.25 },+ };+ }++ /// 改这句… in the meeting record: the line as shown, to rewrite. What changed becomes the+ /// user's own fix, on every line heard the same way or only this one; Enter applies, Esc+ /// cancels.+ public sealed class Editor : StackPanel+ {+ readonly TranscriptLine line;+ readonly string session;+ readonly LiveFixes fixes;+ readonly Action done;+ readonly TextBox box;+ readonly ContentControl options = new();+ bool everywhere = true, keep = true;++ public Editor(TranscriptLine line, string session, LiveFixes fixes, string start, Action done)+ {+ this.line = line; this.session = session; this.fixes = fixes; this.done = done;+ box = new TextBox { Text = start, FontSize = 15, TextWrapping = TextWrapping.Wrap, AcceptsReturn = false };+ System.Windows.Automation.AutomationProperties.SetName(box, L("改这句"));+ box.TextChanged += (_, _) => Options();+ box.KeyDown += (_, e) =>+ {+ if (e.Key == Key.Enter) { e.Handled = true; Apply(); }+ else if (e.Key == Key.Escape) { e.Handled = true; done(); }+ };+ Children.Add(Ui.Field(box));+ options.Margin = new Thickness(0, 8, 0, 0);+ Children.Add(options);+ var hint = Ui.Text(L("回车 改成 · esc 取消"), 11, Palette.Tertiary, wrap: false);+ hint.VerticalAlignment = VerticalAlignment.Center;+ var buttons = Ui.Row(8, Small(Ui.Button(L("取消"), done, height: 30)), Small(Ui.Button(L("改成"), Apply, Ui.Kind.Primary, height: 30)));+ var bar = Ui.Spread(hint, buttons);+ bar.Margin = new Thickness(0, 8, 0, 0);+ Children.Add(bar);+ Options();+ Loaded += (_, _) => { box.Focus(); box.CaretIndex = box.Text.Length; };+ }++ void Options()+ {+ if (fixes.SameHeard(line.Id, session, box.Text) is not { } same) { options.Content = null; return; }+ var stack = new StackPanel();+ var heard = new TextBlock { FontFamily = Palette.Font, FontSize = 12, Foreground = Palette.Ink };+ heard.Inlines.Add(new Run(L("听成") + " ") { Foreground = Palette.Tertiary });+ heard.Inlines.Add(new Run(same.Heard));+ stack.Children.Add(heard);+ if (same.Count > 1)+ {+ var all = new RadioButton { Content = LF("整场听成 %@ 的 %lld 处都改", same.Heard, same.Count), IsChecked = everywhere, FontSize = 12, Margin = new Thickness(0, 6, 0, 0), GroupName = "scope" + line.Id };+ var one = new RadioButton { Content = L("只改这一处"), IsChecked = !everywhere, FontSize = 12, Margin = new Thickness(0, 4, 0, 0), GroupName = "scope" + line.Id };+ all.Checked += (_, _) => { everywhere = true; Options(); };+ one.Checked += (_, _) => { everywhere = false; Options(); };+ stack.Children.Add(all); stack.Children.Add(one);+ }+ var remember = new CheckBox { Content = L("记进词表,以后自动改"), IsChecked = keep, FontSize = 12, Margin = new Thickness(0, 6, 0, 0), IsEnabled = same.Count <= 1 || everywhere };+ remember.Checked += (_, _) => keep = true;+ remember.Unchecked += (_, _) => keep = false;+ stack.Children.Add(remember);+ options.Content = stack;+ }++ void Apply()+ {+ if (fixes.SameHeard(line.Id, session, box.Text) is not { } same) { done(); return; }+ var all = same.Count > 1 ? everywhere : true;+ fixes.Edit(line.Id, session, box.Text, all, keep && all);+ done();+ }+ }+}diff --git a/windows/src/Cicada/MainWindow.cs b/windows/src/Cicada/MainWindow.csindex 9655ffe..55e782c 100644--- a/windows/src/Cicada/MainWindow.cs+++ b/windows/src/Cicada/MainWindow.cs@@ -44,6 +44,8 @@ sealed class MainWindow : Windowstring? selected;string tab = "notes";double? jumpTo;+ /// A line to show, marked for a moment (the fix banner's 听成 … → …?).+ string? jumpLine;string? shownKey;bool refreshQueued;readonly ContentControl pill = new() { VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(0, 8, 0, 0) };@@ -167,7 +169,7 @@ sealed class MainWindow : Windowif (selected is null || shown.All(s => s.Id != selected)) selected = shown[0].Id;foreach (var child in list.Children.OfType<Button>()) Paint(child);// Store changes come in a burst while a meeting runs; redraw the open page only if it changed.- if (PageKey() == shownKey) return;+ if (PageKey() == shownKey) { ShowToast(); return; }ShowDetail();}@@ -388,7 +390,7 @@ sealed class MainWindow : Window/// What the open page shows; a store change that leaves it the same doesn't redraw it.string? PageKey() => selected is not null && app.Store.Get(selected) is { } cur- ? $"{selected}|{tab}|{SessionStore.DisplayTitle(cur)}|{cur.Lines.Count}|{cur.Notes?.Covered}|{cur.Notes?.Final}|{app.Listen.Listening}|{app.Notes.GeneratingId == selected}|{cur.HasAudio}|{Recording.Playable(cur)}|{app.Settings.RecordAudio}"+ ? $"{selected}|{tab}|{SessionStore.DisplayTitle(cur)}|{cur.Lines.Count}|{cur.Notes?.Covered}|{cur.Notes?.Final}|{app.Listen.Listening}|{app.Notes.GeneratingId == selected}|{cur.HasAudio}|{Recording.Playable(cur)}|{app.Settings.RecordAudio}|{FixKey(cur)}|{cur.Lines.Sum(l => l.Dst?.Length ?? 0)}": null;void ShowDetail()@@ -471,7 +473,23 @@ sealed class MainWindow : Windowpinned.Visibility = below < 0 ? Visibility.Visible : Visibility.Collapsed;};if (pendingJump is { } jump) { pendingJump = null; jump(scroll); }- detail.Content = new Grid { Children = { scroll, pinned } };+ // The last fix decision with 撤销, along the bottom of the page.+ toastHost.Margin = new Thickness(0, 0, 0, 18);+ toastHost.VerticalAlignment = VerticalAlignment.Bottom; toastHost.HorizontalAlignment = HorizontalAlignment.Center;+ if (toastHost.Parent is Grid old) old.Children.Remove(toastHost);+ detail.Content = new Grid { Children = { scroll, pinned, toastHost } };+ ShowToast();+ }++ readonly ContentControl toastHost = new();+ string? toastKey;++ void ShowToast()+ {+ var key = app.Fixes.Toast is { } t ? $"{t.Id}|{app.Fixes.CanUndo}" : null;+ if (key == toastKey && toastHost.Content is not null == (key is not null)) return;+ toastKey = key;+ toastHost.Content = FixViews.Toast(app.Fixes);}/// 生成纪要 or 复制纪要, 导出… and ···, beside the tabs (and again in the pinned bar).@@ -603,17 +621,54 @@ sealed class MainWindow : Windowreturn article;}+ // 改这句…: the line being rewritten and what the editor opens with.+ string? editingLine;+ string editingStart = "";++ void EditLine(TranscriptLine l, string start)+ {+ editingLine = l.Id; editingStart = start; tab = "transcript"; jumpLine = l.Id;+ ShowDetail();+ }++ void EditDone() { editingLine = null; ShowDetail(); }++ /// Debug: 改这句… on line `line` of record `id`, as from its menu.+ public void DebugEdit(string id, string line)+ {+ selected = id;+ if (app.Store.Get(id)?.Lines.FirstOrDefault(l => l.Id == line) is { } l) EditLine(l, l.Shown);+ }++ /// A fix count and state per record, so a decision redraws the page.+ static string FixKey(Session s) => string.Join(",", s.Lines.Where(l => l.Fixes is not null).Select(l => string.Join("", l.Fixes!.Select(f => $"{f.From}>{f.To}{(f.Ask == true ? "?" : "")}{(f.Off == true ? "x" : "")}{(f.User == true ? "u" : "")};"))));+FrameworkElement Transcript(Session s){var body = new StackPanel();FrameworkElement? target = null;rows.Clear(); lit = -1;Action<double>? play = player is not null ? PlayFrom : null;- // The line nearest the topic's time (older notes may hold a time no line has).- var nearest = jumpTo is { } t0 && s.Lines.Count > 0 ? s.Lines.MinBy(l => Math.Abs(l.T - t0)) : null;+ // 改正听错的词: over a finished meeting, the fixes waiting for the user and how many were made.+ var live = app.Listen.Listening && app.Listen.SessionId == s.Id;+ if (!live && FixViews.Banner(s, app.Fixes, id => { jumpLine = id; ShowDetail(); }, EditLine) is { } banner)+ {+ banner.Margin = new Thickness(0, 0, 0, 14);+ body.Children.Add(banner);+ }+ // The line nearest the topic's time (older notes may hold a time no line has), or the one asked for.+ var nearest = jumpLine is { } jl ? s.Lines.FirstOrDefault(l => l.Id == jl)+ : jumpTo is { } t0 && s.Lines.Count > 0 ? s.Lines.MinBy(l => Math.Abs(l.T - t0)) : null;foreach (var (l, who, ink, place) in NotesWindow.Speakers(s.Lines, app.Settings.SpeakerVoices)){- var line = NotesWindow.TranscriptRow(l, who, ink, place, play);+ var editor = editingLine == l.Id ? new FixViews.Editor(l, s.Id, app.Fixes, editingStart, EditDone) : null;+ var line = NotesWindow.TranscriptRow(l, who, ink, place, play, revert: f => app.Fixes.Revert(f, l.Id, s.Id),+ edit: () => EditLine(l, l.Shown), editor: editor);+ var menu = new ContextMenu { FontFamily = Palette.Font };+ var item = new MenuItem { Header = L("改这句…") };+ item.Click += (_, _) => EditLine(l, l.Shown);+ menu.Items.Add(item);+ line.ContextMenu = menu;if (ReferenceEquals(l, nearest)) target = line;if (play is not null && line is Panel row0 && FindTime(row0) is { } time) rows.Add((l.T, row0, time));body.Children.Add(line);@@ -637,7 +692,7 @@ sealed class MainWindow : Windowfade.Tick += (_, _) => { row.Background = Brushes.Transparent; fade.Stop(); };fade.Start();}- jumpTo = null;+ jumpTo = null; jumpLine = null;if (player is not null) Dispatcher.BeginInvoke(UpdatePlayer, DispatcherPriority.Loaded);return body;}diff --git a/windows/src/Cicada/NotesWindow.cs b/windows/src/Cicada/NotesWindow.csindex d09c399..4fcd327 100644--- a/windows/src/Cicada/NotesWindow.cs+++ b/windows/src/Cicada/NotesWindow.cs@@ -170,6 +170,7 @@ sealed class NotesWindow : Window{builtFor = mode; headerKey = tabsKey = barsKey = null;header = new ContentControl(); bars = new ContentControl(); ending = new ContentControl(); endingKey = null; live = new ContentControl(); tabs = new ContentControl(); footer = new ContentControl();+ ask = new ContentControl(); toast = new ContentControl(); askKey = toastKey = null;scroll = new ScrollViewer { VerticalScrollBarVisibility = ScrollBarVisibility.Auto, Padding = new Thickness(20, 16, 16, 12) };Content = Subtitles ? SubtitleFrame() : PanelFrame();}@@ -181,6 +182,11 @@ sealed class NotesWindow : Windowif (ek != endingKey) { endingKey = ek; ending.Content = EndingStrip(); }var bk = $"{app.Listen.Problem}|{app.Listen.ProblemStatus}|{(app.Listen.Listening && app.Notes.Status is NotesEngine.State.Failed or NotesEngine.State.RateLimited or NotesEngine.State.Unreachable or NotesEngine.State.Updating ? app.Notes.Status : null)}|{app.Ling.Health.Failure?.Why}|{app.Settings.AiProvider}|{app.CanSwitchToLing}|{app.Translator.GoogleOff && app.Translator.SentencesUntranslated}|{app.Settings.ShowInCapture}|{hiddenFromCapture}";if (bk != barsKey) { barsKey = bk; bars.Content = Bars(); }+ var asking = app.Listen.SessionId is { } aid && !app.Settings.ShowInCapture ? app.Fixes.Asking(aid) : null;+ var ak = asking is { } a0 ? $"{a0.Line.Id}|{a0.Fix}|{a0.Of}" : null;+ if (ak != askKey) { askKey = ak; ask.Content = AskCard(asking); }+ var tk = app.Fixes.Toast is { } t0 ? $"{t0.Id}|{app.Fixes.CanUndo}" : null;+ if (tk != toastKey) { toastKey = tk; toast.Content = FixViews.Toast(app.Fixes); }live.Content = LiveCard();var count = app.Listen.SessionId is { } sid ? app.Store.Get(sid)?.Lines.Count ?? 0 : 0;if ($"{tab}|{count}" != tabsKey) { tabsKey = $"{tab}|{count}"; tabs.Content = TabRow(); }@@ -204,6 +210,9 @@ sealed class NotesWindow : WindowTop(header);Top(ending);Top(bars);+ // 这样改对吗? above both tabs: the window opens on 纪要, where a card in the transcript+ // would never be seen.+ Top(ask);tabs.Margin = new Thickness(12, 0, 12, 0);Top(tabs);DockPanel.SetDock(footer, Dock.Bottom);@@ -211,6 +220,11 @@ sealed class NotesWindow : Windowlive.Margin = new Thickness(12, 8, 12, 0);DockPanel.SetDock(live, Dock.Bottom);dock.Children.Add(live);+ // The last fix decision with 撤销, just above the sentence being said.+ toast.HorizontalAlignment = HorizontalAlignment.Center;+ toast.Margin = new Thickness(12, 8, 12, 0);+ DockPanel.SetDock(toast, Dock.Bottom);+ dock.Children.Add(toast);dock.Children.Add(scroll);return Ui.Floating(dock, Palette.Surface);}@@ -566,7 +580,10 @@ sealed class NotesWindow : Windowvar body = new StackPanel();// Stored as they arrive (the notes count them); shown in time order, so a sentence I said// sits between the other side's, which come back from Ming a little later.- foreach (var (l, who, ink, place) in Speakers(lines, app.Settings.SpeakerVoices)) body.Children.Add(TranscriptRow(l, who, ink, place));+ var sid = app.Listen.SessionId;+ var latest = lines.Count > 0 ? lines[^1].Id : null;+ foreach (var (l, who, ink, place) in Speakers(lines, app.Settings.SpeakerVoices))+ body.Children.Add(TranscriptRow(l, who, ink, place, revert: sid is null ? null : f => app.Fixes.Revert(f, l.Id, sid), open: l.Id == latest && app.Listen.Listening));return body;}@@ -598,9 +615,14 @@ sealed class NotesWindow : Window/// One line of the transcript as on the Mac: who (in their colour) and when, the original in/// grey, the translation in ink. With `play` (a record with its recording) the time is a link/// that plays from there; it is tagged "time" so the player can light it.- internal static FrameworkElement TranscriptRow(TranscriptLine l, string? who = null, Brush? ink = null, bool place = false, Action<double>? play = null)- {- var text = new StackPanel { Margin = new Thickness(0, who is null && !place ? 0 : 6, 0, 12) };+ /// 改正听错的词: the fixed words are underlined; pointing at the line (or `open`, the line being+ /// said: hover in a window that never takes focus isn't to be counted on) shows what each was+ /// heard as with 改回 (`revert`), and 改这句… (`edit`, the meeting record). `editor` takes the+ /// original's place while the line is being rewritten.+ internal static FrameworkElement TranscriptRow(TranscriptLine l, string? who = null, Brush? ink = null, bool place = false, Action<double>? play = null,+ Action<LineFix>? revert = null, bool open = false, Action? edit = null, FrameworkElement? editor = null)+ {+ var text = new StackPanel { Margin = new Thickness(0, who is null && !place ? 0 : 6, 0, 12), Background = Brushes.Transparent };var time = Ui.Text(Languages.Clock(l.T), 12, play is null ? Palette.Tertiary : Palette.TimeLink, wrap: false);if (play is not null){@@ -618,8 +640,25 @@ sealed class NotesWindow : Windowfor (int i = 1; i < head.Children.Count; i++) ((FrameworkElement)head.Children[i]).Margin = new Thickness(i == 1 && place && who is not null ? 6 : 8, 0, 0, 0);text.Children.Add(head);var translated = !string.IsNullOrEmpty(l.Dst) && l.Dst != l.Src && l.Dst != l.Shown;- text.Children.Add(Gap(Ui.Text(l.Shown, translated ? 13 : 15, translated ? Palette.Secondary : Palette.Ink), 3, top: true));+ if (editor is not null)+ {+ text.Children.Add(Gap(editor, 3, top: true));+ return text;+ }+ text.Children.Add(Gap(FixViews.LineText(l, translated ? 13 : 15, translated ? Palette.Secondary : Palette.Ink), 3, top: true));if (translated) text.Children.Add(Gap(Ui.Text(l.Dst!, 15, Palette.Ink), 2, top: true));+ var hasFixes = revert is not null && (l.Fixes ?? []).Any(f => f.Applied);+ if (hasFixes || edit is not null)+ {+ var words = FixViews.FixedWords(l, revert ?? (_ => { }), edit);+ words.Visibility = open && hasFixes ? Visibility.Visible : Visibility.Collapsed;+ text.Children.Add(words);+ if (!open)+ {+ text.MouseEnter += (_, _) => words.Visibility = Visibility.Visible;+ text.MouseLeave += (_, _) => words.Visibility = Visibility.Collapsed;+ }+ }return text;}@@ -650,6 +689,20 @@ sealed class NotesWindow : Window};}+ // 改正听错的词: the card and the toast, rebuilt only when what they show changes.+ ContentControl ask = new(), toast = new();+ string? askKey, toastKey;++ /// 这样改对吗? for the first name waiting. Not while the window is shown to the other side+ /// (共享屏幕时让对方看到): names wait for after the meeting then.+ FrameworkElement? AskCard((TranscriptLine Line, LineFix Fix, int Position, int Of)? asking)+ {+ if (asking is not { } a || app.Listen.SessionId is not { } id) return null;+ var card = FixViews.ConfirmCard(a.Line, a.Fix, a.Of, yes => app.Fixes.Answer(a.Fix, yes, id), () => app.Fixes.Later(a.Fix, id));+ card.Margin = new Thickness(12, 0, 12, 8);+ return card;+ }+/// Who can see this window, and when the notes change next.FrameworkElement Footer(){diff --git a/windows/src/Cicada/SettingsWindow.cs b/windows/src/Cicada/SettingsWindow.csindex 65da47d..3d31f65 100644--- a/windows/src/Cicada/SettingsWindow.cs+++ b/windows/src/Cicada/SettingsWindow.cs@@ -9,7 +9,7 @@ namespace Cicada.App;/// 设置, as the Mac's settings window with no title bar: the categories as plain words on the left,/// the chosen one on a white pill, and its page on the right under a big title, the settings in/// white cards on the grey ground with each control at the right.-sealed class SettingsWindow : Window+sealed partial class SettingsWindow : Window{readonly Controller app;readonly ScrollViewer scroll = new() { VerticalScrollBarVisibility = ScrollBarVisibility.Auto, Padding = new Thickness(40, 44, 40, 40) };@@ -61,6 +61,7 @@ sealed class SettingsWindow : WindowCard(Icons.Globe, L("翻译成"), null, Ui.Choice(Ui.TargetOptions(), app.Settings.Target, app.SetTarget)),Card(null, L("纪要语言"), null, Ui.Choice([("system", L("和字幕一样")), .. Languages.Targets.Select(t => (t.Code, t.Name))], app.Settings.NotesLanguage, v => { app.Settings.NotesLanguage = v; Save(); })),Card(null, L("界面语言"), L("重新打开知了后生效"), Ui.Choice([("system", L("跟随系统")), ("zh-Hans", "简体中文"), ("en", "English"), ("ja", "日本語"), ("ko", "한국어")], app.Settings.UiLanguage, v => { app.Settings.UiLanguage = v; Save(); }))));+ if (current == "words") Section(page, "words", L("词表"), WordCards());var size = new Slider { Minimum = 18, Maximum = 32, Value = app.Settings.SubtitleSize, Width = 200, IsSnapToTickEnabled = true, TickFrequency = 1, VerticalAlignment = VerticalAlignment.Center };System.Windows.Automation.AutomationProperties.SetName(size, L("字幕文字大小"));size.ValueChanged += (_, e) => { app.Settings.SubtitleSize = (int)e.NewValue; Save(); };@@ -146,7 +147,7 @@ sealed class SettingsWindow : Windownav.Children.Clear();(string id, string icon, string label)[] items =[- ("ai", Icons.Key, L("AI 服务")), ("lang", Icons.Globe, L("语言")), ("listen", Icons.Wave, L("听的时候")),+ ("ai", Icons.Key, L("AI 服务")), ("lang", Icons.Globe, L("语言")), ("words", Icons.List, L("词表")), ("listen", Icons.Wave, L("听的时候")),("speak", Icons.Mic, L("同声传译")), ("end", Icons.Stop, L("结束会议")), ("privacy", Icons.Shield, L("隐私与启动")), ("about", Icons.Info, L("关于")),];foreach (var (id, icon, label) in items)@@ -361,6 +362,12 @@ sealed class SettingsWindow : Window: notesOn ? Row(L("实时纪要"), uses, "ok", L("会中每 45 秒更新")): Row(L("实时纪要"), off, "off", reason == AICheck.Reason.NoJSON ? L("这个服务不支持 JSON") : reason == AICheck.Reason.NoModel ? L("换一个模型后可用") : later);yield return textOn ? Row(L("翻译"), uses, "ok", L("整句用它;不行时换 Google")) : Row(L("翻译"), "Google", "off", ling.HasKey ? L("先用 Google 翻译") : L("没有 key 时照常可用"));+ // 改正听错的词 (the Mac hides this row where the service hears, as here: Windows has no other+ // way to hear, so it is shown, and says what it costs: Ming's translation leaves no text+ // request to ride on, so each finished line is one more).+ var fixOn = textOn && app.Settings.FixMisheard;+ yield return Row(L("改正听错的词"), fixOn ? uses : textOn ? L("已关") : off, fixOn ? "ok" : "off",+ fixOn ? L("每句话说完多发一次文字请求") : textOn ? L("在“词表”里打开") : later);// Windows speaks when the service can't, as the Mac does with its own voice.var speaks = ling.Speaks && !down;yield return speaks ? Row(L("同传声音"), uses, "ok", ling.LastVoice is { } last ? (last.Ok ? L("上次同传时正常") : L("上次同传没出声,用了 Windows 的声音")) : c.IsLing ? L("Ming 的声音") : c.VoiceModel!)diff --git a/windows/src/Cicada/Strings/en.lproj/Windows.strings b/windows/src/Cicada/Strings/en.lproj/Windows.stringsindex 0fcdc9d..b8cd754 100644--- a/windows/src/Cicada/Strings/en.lproj/Windows.strings+++ b/windows/src/Cicada/Strings/en.lproj/Windows.strings@@ -321,3 +321,7 @@/* 打开麦克风: the Mac's words name the Mac. */"关着 · 只听电脑声音" = "Off · PC audio only";"电脑声音照常在记" = "The PC's audio is still being recorded";++/* 改正听错的词: Ming translates with the audio, so fixing is a request of its own; the list is on this PC. */+"每句话说完多发一次文字请求" = "One more text request per finished sentence";+"最多 %lld 个,满了优先用最近的。只存在这台电脑上" = "Up to %lld, recent ones first. Stored only on this PC";diff --git a/windows/src/Cicada/Strings/ja.lproj/Windows.strings b/windows/src/Cicada/Strings/ja.lproj/Windows.stringsindex 80801a7..9c3310f 100644--- a/windows/src/Cicada/Strings/ja.lproj/Windows.strings+++ b/windows/src/Cicada/Strings/ja.lproj/Windows.strings@@ -321,3 +321,7 @@/* 打开麦克风: the Mac's words name the Mac. */"关着 · 只听电脑声音" = "オフ · PC の音だけ";"电脑声音照常在记" = "PC の音声はそのまま記録中";++/* 改正听错的词: Ming translates with the audio, so fixing is a request of its own; the list is on this PC. */+"每句话说完多发一次文字请求" = "文ごとにテキストのリクエストが 1 回増えます";+"最多 %lld 个,满了优先用最近的。只存在这台电脑上" = "最大 %lld 個、最近使ったものを優先。この PC にだけ保存";diff --git a/windows/src/Cicada/Strings/ko.lproj/Windows.strings b/windows/src/Cicada/Strings/ko.lproj/Windows.stringsindex 4c1e221..cbdbee3 100644--- a/windows/src/Cicada/Strings/ko.lproj/Windows.strings+++ b/windows/src/Cicada/Strings/ko.lproj/Windows.strings@@ -321,3 +321,7 @@/* 打开麦克风: the Mac's words name the Mac. */"关着 · 只听电脑声音" = "꺼짐 · PC 소리만";"电脑声音照常在记" = "PC 소리는 계속 기록 중";++/* 改正听错的词: Ming translates with the audio, so fixing is a request of its own; the list is on this PC. */+"每句话说完多发一次文字请求" = "문장마다 텍스트 요청이 한 번 더 갑니다";+"最多 %lld 个,满了优先用最近的。只存在这台电脑上" = "최대 %lld개, 최근 것을 우선. 이 PC에만 저장";diff --git a/windows/src/Cicada/WordListSettings.cs b/windows/src/Cicada/WordListSettings.csnew file mode 100644index 0000000..d7a0c48--- /dev/null+++ b/windows/src/Cicada/WordListSettings.cs@@ -0,0 +1,311 @@+using System.Windows;+using System.Windows.Controls;+using System.Windows.Documents;+using System.Windows.Input;+using System.Windows.Media;+using static Cicada.Strings;++namespace Cicada.App;++/// 设置 › 词表 (the Mac's WordListSettings.swift): the switches for 改正听错的词, and the word list+/// itself: each word, what it has been heard as, where it came from and how often it fixed a line.+/// Everything is edited in place; changes count from the next sentence on.+sealed partial class SettingsWindow+{+ string wordQuery = "";+ /// A deleted word, shown in its place with 撤销 for a few seconds.+ (Vocabulary.Term Term, int Index)? deleted;+ DateTime deletedAt;+ /// The word whose spelling is being changed, and what was typed as a heard form per word.+ string? renaming;+ readonly Dictionary<string, string> newHeard = [];+ /// A heard form typed under a word that another word already has: whose it should be.+ (string Word, string Heard, string Owner)? conflict;++ FrameworkElement[] WordCards()+ {+ var s = app.Settings;+ var usable = app.Ling.Usable;+ FrameworkElement fixControl = usable+ ? Ui.Switch(s.FixMisheard, v => { s.FixMisheard = v; Save(); Render(); }, L("会中改正听错的词"))+ : Ui.LinkText(L("去设置"), () => { current = "ai"; Render(); });+ var ask = Ui.Switch(s.AskNames, v => { s.AskNames = v; Save(); }, L("没见过的名字和专称先问我"));+ ask.IsEnabled = s.FixMisheard && usable;+ var switches = Group(+ Card(null, L("会中改正听错的词"), usable ? LF("走 %@,只发文字", app.Ling.ServiceName) : L("接上 AI 服务后才会改"), fixControl),+ Card(null, L("没见过的名字和专称先问我"), L("关掉就只改词表里的词和同音错字"), ask));++ var terms = app.Vocabulary.Terms;+ var head = new DockPanel { Margin = new Thickness(6, 8, 0, 0) };+ var import = Ui.Button(L("粘贴导入…"), ImportWords, Ui.Kind.Primary, height: 32);+ import.MinWidth = 0;+ DockPanel.SetDock(import, Dock.Right);+ head.Children.Add(import);+ if (terms.Count > 12)+ {+ var search = new TextBox { Text = wordQuery, Width = 160 };+ System.Windows.Automation.AutomationProperties.SetName(search, L("搜索词表"));+ search.TextChanged += (_, _) => { wordQuery = search.Text; Dispatcher.BeginInvoke(() => { Render(); FocusSearch(); }); };+ var field = Ui.Field(search);+ field.Margin = new Thickness(0, 0, 10, 0);+ DockPanel.SetDock(field, Dock.Right);+ head.Children.Add(field);+ }+ var title = Ui.Text(L("词"), 13, Palette.Secondary, FontWeights.SemiBold, wrap: false);+ if (terms.Count > 0) title.Inlines.Add(new Run($" {terms.Count}") { Foreground = Palette.Tertiary, FontWeight = FontWeights.Normal });+ title.VerticalAlignment = VerticalAlignment.Center;+ head.Children.Add(title);++ FrameworkElement list;+ if (terms.Count == 0 && deleted is null)+ {+ var empty = Ui.Text(L("还没有词。把常用的人名、产品名贴进来,会中就照这些写法改"), 12, Palette.Tertiary);+ empty.Margin = new Thickness(6, 0, 0, 0);+ list = empty;+ }+ else+ {+ var rows = new List<FrameworkElement>();+ if (deleted is { } d)+ {+ var text = new TextBlock { FontFamily = Palette.Font, FontSize = 13, Foreground = Palette.Secondary, VerticalAlignment = VerticalAlignment.Center };+ text.Inlines.Add(new Run(L("已删除") + " "));+ text.Inlines.Add(new Run(d.Term.Word) { FontWeight = FontWeights.Bold });+ var undo = Ui.LinkText(L("撤销"), () => { app.Vocabulary.Insert(d.Term, d.Index); deleted = null; Render(); }, 12);+ undo.VerticalAlignment = VerticalAlignment.Center;+ var row = Ui.Spread(text, undo);+ row.MinHeight = 40;+ rows.Add(row);+ }+ var q = Vocabulary.Key(wordQuery);+ // Most recently useful first, then the rest newest first.+ var shown = Enumerable.Reverse(terms).OrderByDescending(t => t.Used ?? DateTimeOffset.MinValue)+ .Where(t => q.Length == 0 || Vocabulary.Key(t.Word).Contains(q) || t.Heard.Any(h => Vocabulary.Key(h).Contains(q)));+ foreach (var t in shown) rows.Add(WordRow(t, terms));+ list = Group([.. rows]);+ }+ var foot = Ui.Text(LF("最多 %lld 个,满了优先用最近的。只存在这台电脑上", Vocabulary.Limit), 11, Palette.Tertiary);+ foot.Margin = new Thickness(6, 0, 0, 0);+ return [switches, head, list, foot];+ }++ void FocusSearch()+ {+ // The page is drawn again on each key: give the search box its focus back.+ var box = FindChild<TextBox>(scroll, b => System.Windows.Automation.AutomationProperties.GetName(b) == L("搜索词表"));+ if (box is not null) { box.Focus(); box.CaretIndex = box.Text.Length; }+ }++ static T? FindChild<T>(DependencyObject root, Func<T, bool> match) where T : DependencyObject+ {+ for (int i = 0; i < VisualTreeHelper.GetChildrenCount(root); i++)+ {+ var c = VisualTreeHelper.GetChild(root, i);+ if (c is T t && match(t)) return t;+ if (FindChild(c, match) is { } found) return found;+ }+ return null;+ }++ /// One word: its spelling (a click changes it), what it was heard as (× takes one off, a field+ /// adds one), where it came from, how often it fixed a line, and delete.+ FrameworkElement WordRow(Vocabulary.Term t, List<Vocabulary.Term> all)+ {+ FrameworkElement word;+ if (renaming == t.Word)+ {+ var box = new TextBox { Text = t.Word, Width = 140, FontWeight = FontWeights.SemiBold };+ void Done() { if (renaming != t.Word) return; renaming = null; app.Vocabulary.Rename(t.Word, box.Text); Render(); }+ box.KeyDown += (_, e) =>+ {+ if (e.Key == Key.Enter) { e.Handled = true; Done(); }+ else if (e.Key == Key.Escape) { e.Handled = true; renaming = null; Render(); }+ };+ box.LostKeyboardFocus += (_, _) => Done();+ box.Loaded += (_, _) => { box.Focus(); box.SelectAll(); };+ word = Ui.Field(box);+ }+ else+ {+ var w = Ui.Text(t.Word, 13, Palette.Ink, FontWeights.SemiBold, wrap: false);+ w.Width = 140; w.Cursor = Cursors.Hand; w.ToolTip = L("点一下改写法");+ w.MouseLeftButtonUp += (_, _) => { renaming = t.Word; Render(); };+ word = w;+ }+ word.VerticalAlignment = VerticalAlignment.Center;++ var heard = new WrapPanel { VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(12, 0, 0, 0) };+ foreach (var h in t.Heard) heard.Children.Add(HeardChip(h, () => { app.Vocabulary.Forget(h, t.Word); Render(); }));+ var add = new TextBox { Text = newHeard.GetValueOrDefault(t.Word, ""), Width = 120, FontSize = 11, MinHeight = 0, Padding = new Thickness(4, 1, 4, 1) };+ System.Windows.Automation.AutomationProperties.SetName(add, L("加一个容易听错的词"));+ var hint = Ui.Text(L("加一个容易听错的词"), 11, Palette.Tertiary, wrap: false);+ hint.IsHitTestVisible = false; hint.Margin = new Thickness(7, 0, 0, 0); hint.VerticalAlignment = VerticalAlignment.Center;+ hint.Visibility = add.Text.Length == 0 ? Visibility.Visible : Visibility.Collapsed;+ add.TextChanged += (_, _) => { newHeard[t.Word] = add.Text; hint.Visibility = add.Text.Length == 0 ? Visibility.Visible : Visibility.Collapsed; };+ add.KeyDown += (_, e) => { if (e.Key == Key.Enter) { e.Handled = true; AddHeard(t, add.Text); } };+ var addBox = new Border+ {+ BorderBrush = Palette.FieldLine, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(5), Margin = new Thickness(0, 2, 4, 2),+ Child = new Grid { Children = { add, hint } },+ // Only while pointed at (or typed in): hidden, it would still take room and wrap the forms.+ Visibility = add.Text.Length > 0 ? Visibility.Visible : Visibility.Collapsed,+ };+ add.BorderThickness = new Thickness(0); add.Background = Brushes.Transparent;+ heard.Children.Add(addBox);++ var source = Ui.Text(t.Source == "live" ? L("会中确认") : L("你加的"), 11, t.Source == "live" ? Palette.AccentText : Palette.Tertiary, wrap: false);+ source.MinWidth = 64; source.VerticalAlignment = VerticalAlignment.Center;+ var count = Ui.Text(t.Fixes > 0 ? LF("改过 %lld 次", t.Fixes) : L("还没用上"), 11, Palette.Tertiary, wrap: false);+ count.MinWidth = 64; count.VerticalAlignment = VerticalAlignment.Center;+ var trash = Ui.IconButton(Icons.Trash, L("从词表里删掉"), () => Remove(t, all), Palette.Tertiary, 28, 13);+ trash.Opacity = 0.35;+ var right = Ui.Row(8, source, count, trash);+ var dock = new DockPanel { MinHeight = 40, Margin = new Thickness(0, 4, 0, 4), Background = Brushes.Transparent };+ DockPanel.SetDock(word, Dock.Left); DockPanel.SetDock(right, Dock.Right);+ dock.Children.Add(word); dock.Children.Add(right); dock.Children.Add(heard);+ dock.MouseEnter += (_, _) => { addBox.Visibility = Visibility.Visible; trash.Opacity = 1; };+ dock.MouseLeave += (_, _) => { if (add.Text.Length == 0 && !add.IsKeyboardFocused) addBox.Visibility = Visibility.Collapsed; trash.Opacity = 0.35; };++ if (conflict is { } c && c.Word == t.Word)+ {+ var say = Ui.Text(LF("“%@”已经记在 %@ 下", c.Heard, c.Owner), 12, Palette.Ink);+ say.VerticalAlignment = VerticalAlignment.Center;+ var move = Ui.Button(LF("改给 %@", t.Word), () =>+ {+ app.Vocabulary.Forget(c.Heard, c.Owner);+ app.Vocabulary.Confirm(c.Heard, t.Word, t.Source);+ conflict = null; Render();+ }, Ui.Kind.Primary, height: 28);+ var both = Ui.Button(L("两个都留"), () => { app.Vocabulary.Confirm(c.Heard, t.Word, t.Source); conflict = null; Render(); }, height: 28);+ move.MinWidth = both.MinWidth = 0;+ var bar = Ui.Spread(say, Ui.Row(8, both, move));+ bar.Margin = new Thickness(0, 0, 0, 10);+ return new StackPanel { Children = { dock, bar } };+ }+ return dock;+ }++ static FrameworkElement HeardChip(string text, Action remove)+ {+ var x = Ui.IconButton(Icons.Close, L("删掉这个听错的词"), remove, Palette.Tertiary, 14, 8);+ x.Visibility = Visibility.Collapsed;+ x.Margin = new Thickness(3, 0, 0, 0);+ var chip = new Border+ {+ Background = Palette.Subtle, CornerRadius = new CornerRadius(5), Padding = new Thickness(6, 2, 6, 2), Margin = new Thickness(0, 2, 4, 2),+ Child = Ui.Row(0, Ui.Text(text, 11, Palette.Secondary, wrap: false), x),+ };+ chip.MouseEnter += (_, _) => x.Visibility = Visibility.Visible;+ chip.MouseLeave += (_, _) => x.Visibility = Visibility.Collapsed;+ return chip;+ }++ void AddHeard(Vocabulary.Term t, string typed)+ {+ var h = typed.Trim();+ newHeard.Remove(t.Word);+ if (h.Length == 0 || Correction.Length(h) > 40) { Render(); return; }+ if (app.Vocabulary.Owners(h, t.Word).FirstOrDefault() is { } owner) conflict = (t.Word, h, owner);+ else app.Vocabulary.Confirm(h, t.Word, t.Source);+ Render();+ }++ void Remove(Vocabulary.Term t, List<Vocabulary.Term> all)+ {+ var index = Math.Max(0, all.FindIndex(x => x.Word == t.Word));+ app.Vocabulary.Remove(t.Word);+ deleted = (t, index);+ var at = deletedAt = DateTime.UtcNow;+ var timer = new System.Windows.Threading.DispatcherTimer { Interval = TimeSpan.FromSeconds(8) };+ timer.Tick += (_, _) => { timer.Stop(); if (deletedAt == at) { deleted = null; Render(); } };+ timer.Start();+ Render();+ }++ /// 粘贴导入: many words at once, each line one word, heard forms after "=". The counts follow+ /// what is pasted, and the button says how many go in.+ void ImportWords()+ {+ var dialog = new Window+ {+ Owner = this, WindowStyle = WindowStyle.None, AllowsTransparency = true, Background = Brushes.Transparent, ResizeMode = ResizeMode.NoResize,+ ShowInTaskbar = false, SizeToContent = SizeToContent.Height, Width = 456 + 32, WindowStartupLocation = WindowStartupLocation.CenterOwner,+ FontFamily = Palette.Font, Title = L("粘贴导入"),+ };+ var box = new TextBox { AcceptsReturn = true, TextWrapping = TextWrapping.Wrap, Height = 180, FontSize = 13, VerticalScrollBarVisibility = ScrollBarVisibility.Auto };+ System.Windows.Automation.AutomationProperties.SetName(box, L("粘贴导入"));+ var placeholder = Ui.Text("Uniswap V3\nMorpho = 莫拉、莫法\n巡检", 13, Palette.Tertiary);+ placeholder.IsHitTestVisible = false; placeholder.Margin = new Thickness(12, 8, 0, 0);+ var counts = Ui.Text("", 12, Palette.Secondary);+ var skipped = Ui.Text("", 11, Palette.AccentText);+ Vocabulary.ImportResult? result = null;+ Button? go = null, close = null;+ void Update()+ {+ placeholder.Visibility = box.Text.Length == 0 ? Visibility.Visible : Visibility.Collapsed;+ if (result is { } r)+ {+ counts.Text = LF("新增 %lld · 补充听成 %lld · 跳过 %lld", r.Added, r.Updated, r.Skipped.Count);+ counts.Foreground = Palette.Ink; counts.FontWeight = FontWeights.SemiBold;+ skipped.Text = r.Skipped.Count > 0 ? LF("第 %@ 行没加进去:超过 40 个字", string.Join("、", r.Skipped)) : "";+ return;+ }+ var p = app.Vocabulary.Preview(box.Text);+ counts.Text = box.Text.Trim().Length == 0 ? "" : LF("新增 %lld · 补充听成 %lld · 跳过 %lld", p.Added, p.Updated, p.Skipped.Count);+ if (go is not null)+ {+ ((StackPanel)go.Content).Children.OfType<TextBlock>().First().Text = LF("导入 %lld 个", p.Added + p.Updated);+ go.IsEnabled = p.Added + p.Updated > 0;+ }+ }+ box.TextChanged += (_, _) => Update();+ go = Ui.Button(LF("导入 %lld 个", 0), () =>+ {+ result = app.Vocabulary.Import(box.Text);+ box.Text = ""; box.IsEnabled = false;+ go!.Visibility = Visibility.Collapsed;+ ((StackPanel)close!.Content).Children.OfType<TextBlock>().First().Text = L("完成");+ Update();+ Render();+ }, Ui.Kind.Primary);+ close = Ui.Button(L("取消"), dialog.Close);+ close.IsCancel = true;+ var buttons = new Grid();+ buttons.ColumnDefinitions.Add(new ColumnDefinition());+ buttons.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(8) });+ buttons.ColumnDefinitions.Add(new ColumnDefinition());+ Grid.SetColumn(go, 2);+ buttons.Children.Add(close); buttons.Children.Add(go);+ Update();+ var field = new Border { BorderBrush = Palette.FieldLine, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(8), Padding = new Thickness(4), Child = new Grid { Children = { box, placeholder } } };+ box.BorderThickness = new Thickness(0);+ var body = Ui.Stack(12, Ui.Text(L("粘贴导入"), 20, Palette.Ink, FontWeights.Bold), Ui.Text(L("一行一个。常被听错的词,写在 = 后面"), 12, Palette.Secondary), field, Ui.Stack(4, counts, skipped));+ dialog.Content = new Border+ {+ Margin = new Thickness(16), Background = Palette.Surface, BorderBrush = Palette.Line, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(16),+ Effect = new System.Windows.Media.Effects.DropShadowEffect { BlurRadius = 32, ShadowDepth = 8, Opacity = 0.25 },+ Child = new StackPanel+ {+ Children =+ {+ new Border { Padding = new Thickness(24, 24, 24, 16), Child = body },+ new Border { Padding = new Thickness(24, 0, 24, 24), Child = buttons },+ },+ },+ };+ dialog.Loaded += (_, _) => box.Focus();+ importing = dialog;+ dialog.ShowDialog();+ importing = null;+ }++ /// The paste dialog while it is open (the debug pipe types into it).+ Window? importing;++ /// Debug: paste `text` into an open 粘贴导入, or open it first.+ public void DebugImport(string text)+ {+ if (importing is null) { Dispatcher.BeginInvoke(ImportWords); Dispatcher.BeginInvoke(() => DebugImport(text), System.Windows.Threading.DispatcherPriority.ApplicationIdle); return; }+ if (FindChild<TextBox>(importing, _ => true) is { } box) box.Text = text.Replace('|', '\n');+ }+}