diff --git a/apps/notecraft-cli/src/main.rs b/apps/notecraft-cli/src/main.rs index 97af1846..f479b7ed 100644 --- a/apps/notecraft-cli/src/main.rs +++ b/apps/notecraft-cli/src/main.rs @@ -202,6 +202,17 @@ fn describe(o: &Output) -> String { Output::Path(p) => display_path(p), Output::Text(t) => t.clone(), Output::Count(n) => n.to_string(), + Output::Spoken(found) => { + let mut lines: Vec = found + .clips + .iter() + .map(|c| format!("{} {} at {}\n {}", c.title, c.recording, notecraft_store::spoken::clock(c.start_ms), c.text)) + .collect(); + for u in &found.unindexed { + lines.push(format!("not searchable (no timed transcript): {} {}", u.title, u.recording)); + } + lines.join("\n") + } Output::Page(p) => format!("{} page \"{}\" ({} characters)\n{}", p.format.id(), p.title, p.body.chars().count(), p.body), Output::Versions(versions) => versions.iter().map(|v| format!("{} {} {} bytes", v.id, v.created, v.bytes)).collect::>().join("\n"), Output::Recycled(items) => { diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rs index c88b8504..25fe7759 100644 --- a/crates/engine/src/commands.rs +++ b/crates/engine/src/commands.rs @@ -57,6 +57,8 @@ pub enum Output { Tagged(Vec), Report(Report), Count(usize), + /// Spoken words found in approved transcripts, and the recordings with none (issue #550). + Spoken(notecraft_store::spoken::Found), } pub struct CommandSpec { @@ -778,6 +780,26 @@ fn search_query(s: &mut Session, p: &Params) -> Result { Ok(Output::Hits(hits)) } +/// Spoken words in approved transcripts (issue #550): the timed lines that hold the query, with +/// the recording and the time each was said, and the recordings in the scope with no timed +/// transcript to search. Refused while the audio search setting is off. +fn search_spoken(s: &mut Session, p: &Params) -> Result { + use notecraft_store::spoken; + if s.settings.get(spoken::SETTING).as_deref().map(str::trim) != Some("true") { + return Err(EngineError::BadParam(format!("searching spoken words is off; set {} to true to turn it on", spoken::SETTING))); + } + let limit = match p.get("limit") { + Some(l) => l.trim().parse::().map_err(|_| EngineError::BadParam("limit must be a number".into()))?.min(500), + None => 40, + }; + let query = req(p, "q")?; + let found = match p.get("scope").map(|scope| scope.trim()).filter(|scope| !scope.is_empty()) { + Some(scope) => spoken::search([s.resolve(scope)?], query, limit), + None => spoken::search(tree::child_dirs(s.root()).into_iter().chain(s.opened_elsewhere().iter().cloned()), query, limit), + }; + Ok(Output::Spoken(found)) +} + /// The tagged notes in a scope: what Find Tags lists in its Tags Summary (issue #166). fn tags_find(s: &mut Session, p: &Params) -> Result { let limit = match p.get("limit") { @@ -1378,6 +1400,13 @@ text (optional): the alt text; empty removes it", changes_tree: false, run: search_query, }, + CommandSpec { + id: "search.spoken", + label: "Search spoken words in recordings", + params: "q (required): words said in a recording\nlimit (optional): at most this many lines (default 40, at most 500)\nscope (optional): page or folder to search, relative to the notebooks folder; every open notebook when left out\nThe words searched are the timed lines of transcripts approved with Insert > Transcribe. Off until the setting audio_search is true", + changes_tree: false, + run: search_spoken, + }, CommandSpec { id: "tags.find", label: "Find tagged notes", @@ -2528,4 +2557,31 @@ mod tests { } assert_eq!(std::fs::read_to_string(&outside).expect("outside"), "keep"); } + + /// Issue #550: spoken words are searched only once the setting is on, and a recording with no + /// timed transcript is reported. + #[test] + fn spoken_words_are_searched_once_audio_search_is_on() { + let t = TempDir::new("engine-spoken"); + let settings = Settings::at(t.path().join("settings").join("s.toml")); + let mut s = Session::new(&t.path().join("notebooks"), settings.clone()).expect("session"); + let book = path_of(s.run("notebook.create", &p(&[("name", "Book")])).expect("notebook")); + let section = + path_of(s.run("node.create", &p(&[("parent", &book.to_string_lossy()), ("kind", "section"), ("title", "Talks")])).expect("section")); + let page = + path_of(s.run("node.create", &p(&[("parent", §ion.to_string_lossy()), ("kind", "page"), ("title", "Kickoff")])).expect("page")); + std::fs::create_dir_all(page.join("assets")).expect("assets"); + std::fs::write(page.join("assets").join("Talk.wav"), b"RIFF").expect("audio"); + std::fs::write(page.join("assets").join("Other.mp3"), b"ID3").expect("audio"); + let body = "

Talk.wav

[00:02:03.400 - 00:02:07.000] Ship the importer next

"; + s.run("page.save", &p(&[("path", &page.to_string_lossy()), ("body", body)])).expect("save"); + assert!(s.run("search.spoken", &p(&[("q", "importer")])).is_err(), "off until it is turned on"); + settings.set(notecraft_store::spoken::SETTING, "true").expect("setting"); + let Output::Spoken(found) = s.run("search.spoken", &p(&[("q", "importer")])).expect("search") else { panic!("spoken") }; + assert_eq!(found.clips.len(), 1); + assert_eq!((found.clips[0].recording.as_str(), found.clips[0].start_ms), ("assets/Talk.wav", 123_400)); + assert_eq!(found.unindexed.iter().map(|u| u.recording.as_str()).collect::>(), ["assets/Other.mp3"]); + let json = crate::output_json(&Output::Spoken(found)); + assert_eq!(json["clips"][0]["start"], "00:02:03"); + } } diff --git a/crates/engine/src/json.rs b/crates/engine/src/json.rs index 34cf9fea..1567c58c 100644 --- a/crates/engine/src/json.rs +++ b/crates/engine/src/json.rs @@ -65,6 +65,19 @@ pub fn output_json(o: &Output) -> Value { }) .collect(), ), + Output::Spoken(found) => json!({ + "clips": found.clips.iter().map(|c| json!({ + "path": display_path(&c.page), + "title": c.title, + "recording": c.recording, + "start": notecraft_store::spoken::clock(c.start_ms), + "startMs": c.start_ms, + "endMs": c.end_ms, + "text": c.text, + "block": c.block, + })).collect::>(), + "unindexed": found.unindexed.iter().map(|u| json!({"path": display_path(&u.page), "title": u.title, "recording": u.recording})).collect::>(), + }), Output::Report(r) => { json!({"nodes": r.nodes, "problems": r.problems.iter().map(|p| json!({"path": display_path(&p.path), "message": p.message})).collect::>()}) } diff --git a/crates/store/src/lib.rs b/crates/store/src/lib.rs index f55ce1b1..4c6f61bd 100644 --- a/crates/store/src/lib.rs +++ b/crates/store/src/lib.rs @@ -28,6 +28,7 @@ pub mod recent; pub mod recycle; pub mod search; pub mod settings; +pub mod spoken; pub mod tags; pub mod testing; pub mod tree; diff --git a/crates/store/src/spoken.rs b/crates/store/src/spoken.rs new file mode 100644 index 00000000..2d30823f --- /dev/null +++ b/crates/store/src/spoken.rs @@ -0,0 +1,251 @@ +//! Spoken words in recordings, for search (issue #550). +//! +//! NoteCraft hears nothing by itself: the words it can search are the ones a person approved +//! from a recording. Insert > Transcribe puts a link to the recording on the page and, under it, +//! each line of the approved transcript with its time in the recording: +//! `[00:01:05.200 - 00:01:09.800] the words`. Those lines are the index. A line belongs to the +//! last recording linked above it on the page. +//! +//! A recording or video beside a page with no timed line under any link to it cannot be +//! searched, and is reported as such, so the person knows which clips still need a transcript. + +use crate::page::load_page; +use crate::tree::{child_dirs, page_file, read_node}; +use notecraft_formats::{Block, boxes, render}; +use std::path::{Path, PathBuf}; + +/// The setting that turns searching spoken words on. Off unless it is `true`, as OneNote's +/// Audio Search is off until it is turned on. +pub const SETTING: &str = "audio_search"; + +/// The kinds of file taken for a recording or a video. +pub const MEDIA_EXTENSIONS: &[&str] = &["wav", "mp3", "m4a", "aac", "ogg", "oga", "opus", "flac", "wma", "webm", "mp4", "m4v", "mov", "mkv", "avi"]; + +/// Whether a link or file name names a recording or a video. +pub fn is_media(name: &str) -> bool { + let name = name.split(['#', '?']).next().unwrap_or(name); + Path::new(name).extension().and_then(|e| e.to_str()).is_some_and(|e| MEDIA_EXTENSIONS.iter().any(|m| m.eq_ignore_ascii_case(e))) +} + +/// One timed line of an approved transcript. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Clip { + /// The page the line is on. + pub page: PathBuf, + pub title: String, + /// The recording, as the page links to it (`assets/Meeting.wav`). + pub recording: String, + pub start_ms: u64, + pub end_ms: u64, + /// The words, without their time. + pub text: String, + /// The line's block on the page, to put the caret on. + pub block: usize, +} + +/// A recording beside a page, or linked from it, with no timed transcript to search. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Unindexed { + pub page: PathBuf, + pub title: String, + pub recording: String, +} + +/// What a search of spoken words found, and the recordings it could not look in. +#[derive(Clone, Debug, Default, PartialEq, Eq)] +pub struct Found { + pub clips: Vec, + pub unindexed: Vec, +} + +/// `hh:mm:ss.mmm` in milliseconds. +fn millis(stamp: &str) -> Option { + let (clock, ms) = stamp.trim().split_once('.')?; + let mut parts = clock.split(':'); + let (h, m, s) = (parts.next()?.parse::().ok()?, parts.next()?.parse::().ok()?, parts.next()?.parse::().ok()?); + if parts.next().is_some() || m > 59 || s > 59 || ms.len() != 3 { + return None; + } + Some(((h * 60 + m) * 60 + s) * 1000 + ms.parse::().ok()?) +} + +/// A transcript line's time and words: `[start - end] words`. +pub fn timed_line(text: &str) -> Option<(u64, u64, &str)> { + let rest = text.trim_start().strip_prefix('[')?; + let (range, words) = rest.split_once(']')?; + let (start, end) = range.split_once(" - ")?; + let (start, end) = (millis(start)?, millis(end)?); + let words = words.trim(); + (end >= start && !words.is_empty()).then_some((start, end, words)) +} + +/// `hh:mm:ss`, for showing where in a recording a line is. +pub fn clock(ms: u64) -> String { + let s = ms / 1000; + format!("{:02}:{:02}:{:02}", s / 3600, s / 60 % 60, s % 60) +} + +/// The recording a block links to, if it links to one. +fn linked_recording(block: &Block) -> Option { + let Block::Paragraph(spans, _) = block else { return None }; + spans.iter().filter_map(|span| span.link.as_deref()).find(|link| is_media(link) && !link.contains("://")).map(str::to_string) +} + +/// The timed transcript lines of one page, and its recordings that have none. +pub fn page_clips(dir: &Path) -> (Vec, Vec) { + let Ok(page) = load_page(dir) else { return (Vec::new(), Vec::new()) }; + let title = read_node(dir).map(|n| n.title).unwrap_or_default(); + let blocks = boxes::read(page.format, &page.body).0; + let mut clips = Vec::new(); + let mut linked: Vec = Vec::new(); + let mut current: Option = None; + for (index, block) in blocks.iter().enumerate() { + if let Some(recording) = linked_recording(block) { + if !linked.contains(&recording) { + linked.push(recording.clone()); + } + current = Some(recording); + continue; + } + let Some(recording) = ¤t else { continue }; + let text = render::blocks_to_text(std::slice::from_ref(block)); + if let Some((start_ms, end_ms, words)) = timed_line(&text) { + clips.push(Clip { + page: dir.to_path_buf(), + title: title.clone(), + recording: recording.clone(), + start_ms, + end_ms, + text: words.to_string(), + block: index, + }); + } + } + // Every recording the page links to or keeps beside it, once, by its link. + let mut recordings = linked; + let mut files: Vec = + crate::assets::list(dir).into_iter().map(|(name, _)| format!("assets/{name}")).filter(|name| is_media(name)).collect(); + files.sort(); + for file in files { + if !recordings.contains(&file) { + recordings.push(file); + } + } + let unindexed = recordings + .into_iter() + .filter(|recording| !clips.iter().any(|clip| &clip.recording == recording)) + .map(|recording| Unindexed { page: dir.to_path_buf(), title: title.clone(), recording }) + .collect(); + (clips, unindexed) +} + +fn collect_pages(dir: &Path, out: &mut Vec) { + if page_file(dir).is_some() { + out.push(dir.to_path_buf()); + } + for child in child_dirs(dir) { + collect_pages(&child, out); + } +} + +/// The timed transcript lines under `roots` (pages, or folders of them) that hold every word of +/// `query`, in page order, at most `limit`, and every recording there with no timed transcript. +/// A word of the query matches a word of the line that starts with it, ignoring case. +pub fn search(roots: impl IntoIterator, query: &str, limit: usize) -> Found { + let wanted = notecraft_search::tokenize(query); + let mut found = Found::default(); + let mut pages = Vec::new(); + for root in roots { + collect_pages(&root, &mut pages); + } + for page in pages { + let (clips, unindexed) = page_clips(&page); + found.unindexed.extend(unindexed); + if wanted.is_empty() { + continue; + } + for clip in clips { + if found.clips.len() >= limit { + break; + } + let words = notecraft_search::tokenize(&clip.text); + if wanted.iter().all(|want| words.iter().any(|word| word.starts_with(want.as_str()))) { + found.clips.push(clip); + } + } + } + found +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::testing::TempDir; + use crate::{NodeKind, PageFormat, Settings, ops, page}; + + fn transcript_page(t: &TempDir, format: PageFormat) -> (PathBuf, PathBuf) { + let settings = Settings::at(t.path().join("settings.toml")); + let book = ops::create_notebook(t.path(), "Book", Some(format), &settings).expect("notebook"); + let section = ops::create_node(&book, "Meetings", NodeKind::Section, Some(format), &settings).expect("section"); + let page = ops::create_node(§ion, "Standup", NodeKind::Page, Some(format), &settings).expect("page"); + std::fs::create_dir_all(page.join("assets")).expect("assets"); + std::fs::write(page.join("assets/Meeting.wav"), b"RIFF").expect("audio"); + std::fs::write(page.join("assets/Silent.mp4"), b"video").expect("video"); + let lines = [ + "Before the recording: budget talk elsewhere.", + "[00:00:01.520 - 00:00:05.321] The budget for the quarter", + "[00:01:05.000 - 00:01:09.800] Ship the folder format first", + "Unstamped words", + ]; + let body = match format { + PageFormat::Html => { + let mut b = format!("

{}

Meeting.wav

", lines[0]); + for line in &lines[1..] { + b.push_str(&format!("

{line}

")); + } + b + } + PageFormat::Cmgfm => { + let mut b = format!("{}\n\n[Meeting.wav](assets/Meeting.wav)\n\n", lines[0]); + for line in &lines[1..] { + b.push_str(&format!("{}\n\n", line.replace('[', "\\[").replace(']', "\\]"))); + } + b + } + }; + page::save_body(&page, &body).expect("save"); + (book, page) + } + + #[test] + fn timed_lines_under_a_recording_are_found_with_their_time() { + for format in PageFormat::ALL { + let t = TempDir::new("spoken-search"); + let (book, page) = transcript_page(&t, format); + let found = search([book.clone()], "BUDGET quart", 10); + assert_eq!(found.clips.len(), 1, "{format:?}: only the timed line, not the words above the link: {found:?}"); + let clip = &found.clips[0]; + assert_eq!((clip.recording.as_str(), clip.start_ms, clip.end_ms), ("assets/Meeting.wav", 1520, 5321), "{format:?}"); + assert_eq!(clip.text, "The budget for the quarter"); + assert_eq!(clip.title, "Standup"); + let (clips, _) = page_clips(&page); + assert_eq!(clips.iter().map(|c| c.block).collect::>(), [clip.block, clip.block + 1], "{format:?}"); + assert_eq!(search([book.clone()], "folder", 10).clips[0].start_ms, 65_000); + assert!(search([book.clone()], "unstamped", 10).clips.is_empty(), "a line with no time is not a clip"); + // The video has no transcript: it is reported, not searched. + assert_eq!(found.unindexed.iter().map(|u| u.recording.as_str()).collect::>(), ["assets/Silent.mp4"], "{format:?}"); + } + } + + #[test] + fn transcript_times_are_read_strictly() { + assert_eq!(timed_line("[00:00:01.520 - 00:00:05.321] Words"), Some((1520, 5321, "Words"))); + assert_eq!(timed_line("[01:02:03.004 - 01:02:04.000] x "), Some((3_723_004, 3_724_000, "x"))); + assert_eq!(timed_line("[00:00:05.000 - 00:00:01.000] backwards"), None); + assert_eq!(timed_line("[00:61:00.000 - 00:62:00.000] bad minutes"), None); + assert_eq!(timed_line("[00:00:01.520 - 00:00:05.321]"), None); + assert_eq!(timed_line("No time here"), None); + assert_eq!(clock(65_400), "00:01:05"); + assert!(is_media("assets/clip.MP4") && is_media("a.wav#t=5") && !is_media("photo.png")); + } +} diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 6adac8c7..d1123ee3 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -89,6 +89,8 @@ fn fetch_page_files(dir: &Path, wait: Duration) -> Option, + /// The groups of commands the person made for the ribbon (issue #568). + custom_groups: Vec, + /// Customize the Ribbon while it is open: the groups as they are being changed. + customizing: Option, + /// Spoken words found in approved transcripts for the same query, while audio search is on + /// (issue #550), and the recordings in the scope that have no timed transcript. + spoken: notecraft_store::spoken::Found, /// Where each search result is, as its notebook and section titles (issue #370). hit_trails: Vec, /// The result chosen with the arrow keys, if any (issue #370). @@ -2251,6 +2260,7 @@ impl NoteCraftApp { let session_auto_shapes = session.settings.get("auto_shapes").is_some_and(|v| v.trim() == "true"); let session_eraser = session.settings.get(ERASER_KEY).and_then(|v| crate::inkpad::Eraser::parse(&v)).unwrap_or_default(); let session_scratch_out = session.settings.get(SCRATCH_OUT_KEY).is_some_and(|v| v.trim() == "true"); + let session_settings_groups = session.settings.get(crate::ribbon_custom::KEY).unwrap_or_default(); let session_page_prefs = page_prefs_in(&session.settings); let session_auto_switch = session.settings.get("switch_by_device").is_none_or(|v| v.trim() != "false"); let session_update_check_off = session.settings.get("update_check_off_at_start").is_some_and(|v| v.trim() == "true"); @@ -2339,6 +2349,9 @@ impl NoteCraftApp { search: String::new(), searched: String::new(), hits: Vec::new(), + spoken: Default::default(), + custom_groups: crate::ribbon_custom::load(&session_settings_groups), + customizing: None, hit_trails: Vec::new(), search_pick: None, search_scope: SearchScope::default(), @@ -7038,6 +7051,10 @@ impl NoteCraftApp { backstage::Act::CheckForUpdates => crate::update::start(ui.ctx().clone(), self.update.clone()), backstage::Act::OpenReleases => ui.ctx().open_url(egui::OpenUrl::new_tab(backstage::LATEST_RELEASE)), backstage::Act::ResetPreferences => self.dialog = Some(Dialog::ResetPreferences), + backstage::Act::CustomizeRibbon => { + self.backstage = None; + self.open_customize_ribbon(); + } #[cfg(feature = "voice")] backstage::Act::DictationSetup => { self.backstage = None; @@ -7724,6 +7741,7 @@ impl NoteCraftApp { pageedit::FontValue::Unavailable => Some("11".to_owned()), }; let view = ribbon::View { + custom_groups: &self.custom_groups, layout: self.ribbon_layout, split_panes: self.split_panes, always_on_top: self.always_on_top, @@ -12082,6 +12100,7 @@ impl NoteCraftApp { self.search.clear(); self.searched.clear(); self.hits.clear(); + self.spoken = Default::default(); self.hit_trails.clear(); self.search_pick = None; self.search_scope = SearchScope::All; @@ -12116,6 +12135,16 @@ impl NoteCraftApp { Ok(Output::Hits(hits)) => hits, _ => Vec::new(), }; + // Spoken words, only while audio search is on (issue #550): the same words, scope and + // number asked of the recordings' approved transcripts. + self.spoken = if self.audio_search_on() { + match self.session.run("search.spoken", &query) { + Ok(Output::Spoken(found)) => found, + _ => Default::default(), + } + } else { + Default::default() + }; self.hit_trails = self.hits.iter().map(|hit| search_trail(self.session.tree(), &hit.path)).collect(); self.sort_hits(); self.search_pick = None; @@ -12158,6 +12187,51 @@ impl NoteCraftApp { (self.hits, self.hit_trails) = rows.into_iter().unzip(); } + /// Whether search looks in the words said in recordings (issue #550). Off until it is turned + /// on, as OneNote's Audio Search is. + pub fn audio_search_on(&self) -> bool { + self.session.settings.get(notecraft_store::spoken::SETTING).as_deref().map(str::trim) == Some("true") + } + + /// Turns searching spoken words on or off, and searches again. + pub fn set_audio_search(&mut self, on: bool) { + let _ = self.session.settings.set(notecraft_store::spoken::SETTING, if on { "true" } else { "false" }); + if !self.search.trim().is_empty() { + self.refresh_search(); + } + } + + /// A spoken-words result chosen (issue #550): its page opens with the caret on the line said, + /// and the window says which recording it is in and when. + pub fn open_spoken_result(&mut self, ctx: &Context, clip: ¬ecraft_store::spoken::Clip) { + self.dismiss_search(); + self.open_path(&path_str(&clip.page)); + if self.editor.as_ref().is_some_and(|ed| ed.dir == clip.page) { + self.go_to_block(ctx, clip.block); + } + let recording = clip.recording.rsplit('/').next().unwrap_or(&clip.recording); + self.say(crate::i18n::format_message_id( + "ui.spoken_result_opened", + &[("recording", recording), ("time", ¬ecraft_store::spoken::clock(clip.start_ms))], + )); + } + + /// What the last search found in recordings (issue #550), for `ui.inspect`: each line's page + /// title, recording, time and block, and the recordings it could not search. + fn spoken_search_state(&self) -> Value { + json!({ + "on": self.audio_search_on(), + "clips": self.spoken.clips.iter().map(|c| json!({ + "title": c.title, + "recording": c.recording, + "start": notecraft_store::spoken::clock(c.start_ms), + "block": c.block, + "text": c.text, + })).collect::>(), + "unindexed": self.spoken.unindexed.iter().map(|u| u.recording.clone()).collect::>(), + }) + } + fn open_search_result(&mut self, ctx: &Context, path: &Path) { let hit = self.hits.iter().find(|hit| hit.path == path).cloned(); let words = self.searched.trim().to_string(); @@ -12651,6 +12725,9 @@ impl NoteCraftApp { return; } let mut chosen: Option = None; + let mut chosen_clip: Option = None; + let audio_on = self.audio_search_on(); + let mut audio = audio_on; let mut scope = self.search_scope; let mut sort = self.search_sort; let mut pin = false; @@ -12700,6 +12777,14 @@ impl NoteCraftApp { scope = choice; } } + // Issue #550: the words said in recordings, once turned on. + if ui + .add(egui::Button::selectable(audio, crate::tl_id!("ui.search_spoken_words"))) + .on_hover_text(crate::tl_id!("ui.search_spoken_words_tip")) + .clicked() + { + audio = !audio; + } }); if !empty && !self.hits.is_empty() { ui.horizontal_wrapped(|ui| { @@ -12725,6 +12810,45 @@ impl NoteCraftApp { ui.weak(crate::tl_id!("ui.search_prompt")); return; } + // Issue #550: the lines said in recordings, each with its time, above the pages. + if audio_on { + let spoken = &self.spoken; + if !spoken.clips.is_empty() { + ui.weak(crate::tl_id!("ui.spoken_words_heading")); + for clip in spoken.clips.iter().take(8) { + let recording = clip.recording.rsplit('/').next().unwrap_or(&clip.recording); + let line = format!("\u{25B6} {} {} \u{2014} {}", notecraft_store::spoken::clock(clip.start_ms), clip.text, clip.title); + if ui + .add(egui::Button::new(egui::RichText::new(line).color(tokens.text)).frame(false).truncate()) + .on_hover_text(crate::i18n::format_message_id( + "ui.spoken_result_tip", + &[("recording", recording), ("time", ¬ecraft_store::spoken::clock(clip.start_ms))], + )) + .clicked() + { + chosen_clip = Some(clip.clone()); + } + } + } + if !spoken.unindexed.is_empty() { + let names: Vec = spoken + .unindexed + .iter() + .map(|u| format!("{} \u{2014} {}", u.recording.rsplit('/').next().unwrap_or(&u.recording), u.title)) + .collect(); + ui.label( + egui::RichText::new(crate::i18n::format_count_message_id( + "ui.recordings_not_searchable_n", + spoken.unindexed.len() as u64, + &[], + )) + .small() + .color(tokens.muted), + ) + .on_hover_text(names.join("\n")); // i18n-exempt: line break between recording names + } + ui.add_space(2.0); + } if self.hits.is_empty() { ui.weak(crate::tl_id!("ui.no_pages_match")); return; @@ -12760,6 +12884,14 @@ impl NoteCraftApp { self.pin_search(); return; } + if let Some(clip) = chosen_clip { + self.open_spoken_result(ctx, &clip); + return; + } + if audio != audio_on { + self.set_audio_search(audio); + return; + } if scope != self.search_scope { self.search_scope = scope; self.refresh_search(); @@ -17508,6 +17640,8 @@ impl NoteCraftApp { "pinnedSearch": self.pinned_search.as_ref().map(|p| json!({"query": p.query, "scope": p.scope, "hits": p.hits.len(), "chosen": p.chosen})), "proofing": self.proofing_state(), "linkedNotes": self.linked_notes_state(), + "customGroups": self.custom_groups_state(), + "spokenSearch": self.spoken_search_state(), "sectionLocks": self.section_locks_state(), "accessibility": json!({ "open": self.accessibility_open, @@ -17994,6 +18128,7 @@ impl NoteCraftApp { self.direction_keys(ctx); self.hierarchy_keys(ctx); self.restore_last_page(); + self.customize_ribbon_window(ctx); self.section_locks_tick(ctx); self.attach_dropped(ctx); if matches!(self.backstage, Some("Export" | "Share")) diff --git a/crates/ui-egui/src/app/customize_ribbon.rs b/crates/ui-egui/src/app/customize_ribbon.rs new file mode 100644 index 00000000..93b45336 --- /dev/null +++ b/crates/ui-egui/src/app/customize_ribbon.rs @@ -0,0 +1,197 @@ +//! File > Options > Customize the Ribbon (issue #568): the person's own groups of commands, to +//! add, name, put on a tab, order, hide and fill, and a reset to the ribbon as it comes. +//! +//! Every control is an ordinary button, box or list, reached with Tab and worked with Enter or +//! Space, so the window is used from the keyboard as the rest are. The groups are only kept when +//! Save is pressed; Cancel leaves the ribbon as it was. + +use super::{NoteCraftApp, modal_backdrop, modal_button, modal_frame, modal_title, stay_above}; +use crate::ribbon_custom::{self, Command, Group, MOST_COMMANDS, MOST_GROUPS, TABS}; +use egui::Context; + +/// The groups as Customize the Ribbon is changing them. +pub(super) struct Editing { + groups: Vec, + /// The group whose commands are shown below the list. + chosen: usize, +} + +impl NoteCraftApp { + /// Opens Customize the Ribbon with the groups as they are. + pub(super) fn open_customize_ribbon(&mut self) { + self.customizing = Some(Editing { groups: self.custom_groups.clone(), chosen: 0 }); + } + + /// Keeps `groups` as the ribbon's own groups, and in the settings. + pub fn set_custom_groups(&mut self, groups: Vec) { + match self.session.settings.set(ribbon_custom::KEY, &ribbon_custom::save(&groups)) { + Ok(()) => { + self.custom_groups = ribbon_custom::load(&ribbon_custom::save(&groups)); + self.say(crate::tl_id!("ui.ribbon_groups_saved")); + } + Err(e) => self.complain(&e.to_string()), + } + } + + /// The ribbon as it comes: none of the person's groups. + pub fn reset_custom_groups(&mut self) { + self.set_custom_groups(Vec::new()); + } + + /// The person's groups, by name, tab and commands, for `ui.inspect`. + pub(super) fn custom_groups_state(&self) -> serde_json::Value { + serde_json::Value::Array( + self.custom_groups + .iter() + .map(|g| serde_json::json!({"name": g.name, "tab": g.tab, "shown": g.shown, "commands": g.commands.iter().map(|c| c.id()).collect::>()})) + .collect(), + ) + } + + pub(super) fn customize_ribbon_window(&mut self, ctx: &Context) { + let Some(mut editing) = self.customizing.take() else { return }; + let tokens = self.tokens; + let (mut keep, mut save, mut reset) = (true, false, false); + let backdrop = modal_backdrop(ctx, "customize-ribbon-backdrop"); + egui::Window::new(crate::tl_id!("ui.customize_the_ribbon")) + .title_bar(false) + .collapsible(false) + .resizable(false) + .order(egui::Order::Foreground) + .fixed_size(egui::vec2(560.0, 0.0)) + .anchor(egui::Align2::CENTER_CENTER, egui::vec2(0.0, 0.0)) + .frame(modal_frame(&tokens)) + .show(ctx, |ui| { + stay_above(ui, backdrop); + modal_title(ui, &tokens, crate::tl_id!("ui.customize_the_ribbon")); + ui.label(egui::RichText::new(crate::tl_id!("ui.customize_the_ribbon_about")).size(11.5).color(tokens.muted)); + ui.add_space(6.0); + let groups = &mut editing.groups; + let mut remove: Option = None; + let mut shift: Option<(usize, isize)> = None; + egui::ScrollArea::vertical().id_salt("custom-groups").max_height(180.0).show(ui, |ui| { + if groups.is_empty() { + ui.weak(crate::tl_id!("ui.no_custom_groups_yet")); + } + for (i, group) in groups.iter_mut().enumerate() { + ui.horizontal(|ui| { + if ui.radio(editing.chosen == i, "").on_hover_text(crate::tl_id!("ui.custom_group_commands_below")).clicked() { + editing.chosen = i; + } + let name = ui.add( + egui::TextEdit::singleline(&mut group.name).desired_width(150.0).hint_text(crate::tl_id!("ui.custom_group_name")), + ); + if name.gained_focus() { + editing.chosen = i; + } + egui::ComboBox::from_id_salt(("custom-group-tab", i)).width(90.0).selected_text(crate::tl!(group.tab)).show_ui( + ui, + |ui| { + for tab in TABS { + if ui.selectable_label(group.tab == tab, crate::tl!(tab)).clicked() { + group.tab = tab; + } + } + }, + ); + ui.checkbox(&mut group.shown, crate::tl_id!("ui.custom_group_shown")); + // i18n-exempt: arrow and cross glyphs, named by their hover text + if ui.small_button("\u{25B2}").on_hover_text(crate::tl_id!("ui.move_up")).clicked() { + shift = Some((i, -1)); + } + // i18n-exempt: arrow and cross glyphs, named by their hover text + if ui.small_button("\u{25BC}").on_hover_text(crate::tl_id!("ui.move_down")).clicked() { + shift = Some((i, 1)); + } + // i18n-exempt: arrow and cross glyphs, named by their hover text + if ui.small_button("\u{2715}").on_hover_text(crate::tl_id!("ui.remove_custom_group")).clicked() { + remove = Some(i); + } + }); + } + }); + if let Some((i, by)) = shift { + ribbon_custom::shift(groups, i, by); + editing.chosen = i.checked_add_signed(by).filter(|to| *to < groups.len()).unwrap_or(i); + } + if let Some(i) = remove { + groups.remove(i); + editing.chosen = editing.chosen.min(groups.len().saturating_sub(1)); + } + if groups.len() < MOST_GROUPS && ui.button(crate::tl_id!("ui.new_custom_group")).clicked() { + groups.push(Group::new(crate::tl_id!("ui.new_group_name"))); + editing.chosen = groups.len() - 1; + } + ui.separator(); + if let Some(group) = groups.get_mut(editing.chosen) { + ui.label(egui::RichText::new(crate::i18n::format_message_id("ui.commands_in_group", &[("name", &group.name)])).strong()); + let mut drop: Option = None; + let mut nudge: Option<(usize, isize)> = None; + for (i, command) in group.commands.iter().enumerate() { + ui.horizontal(|ui| { + ui.label(command.label()); + // i18n-exempt: arrow and cross glyphs, named by their hover text + if ui.small_button("\u{25B2}").on_hover_text(crate::tl_id!("ui.move_up")).clicked() { + nudge = Some((i, -1)); + } + // i18n-exempt: arrow and cross glyphs, named by their hover text + if ui.small_button("\u{25BC}").on_hover_text(crate::tl_id!("ui.move_down")).clicked() { + nudge = Some((i, 1)); + } + // i18n-exempt: arrow and cross glyphs, named by their hover text + if ui.small_button("\u{2715}").on_hover_text(crate::tl_id!("ui.remove_command")).clicked() { + drop = Some(i); + } + }); + } + if let Some((i, by)) = nudge { + ribbon_custom::shift(&mut group.commands, i, by); + } + if let Some(i) = drop { + group.commands.remove(i); + } + if group.commands.len() < MOST_COMMANDS { + let offered: Vec = Command::ALL.into_iter().filter(|c| !group.commands.contains(c)).collect(); + let mut added = None; + egui::ComboBox::from_id_salt("custom-group-add").width(220.0).selected_text(crate::tl_id!("ui.add_a_command")).show_ui( + ui, + |ui| { + for command in offered { + if ui.selectable_label(false, command.label()).clicked() { + added = Some(command); + } + } + }, + ); + if let Some(command) = added { + group.commands.push(command); + } + } + } + ui.add_space(8.0); + ui.horizontal(|ui| { + if ui.button(crate::tl_id!("ui.reset_ribbon_groups")).on_hover_text(crate::tl_id!("ui.reset_ribbon_groups_tip")).clicked() { + reset = true; + } + ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { + if modal_button(ui, &tokens, crate::tl_id!("ui.save_custom_groups"), true).clicked() { + save = true; + } + if modal_button(ui, &tokens, crate::tl_id!("ui.cancel"), false).clicked() || ui.input(|i| i.key_pressed(egui::Key::Escape)) { + keep = false; + } + }); + }); + }); + if reset { + self.reset_custom_groups(); + keep = false; + } else if save { + self.set_custom_groups(editing.groups.clone()); + keep = false; + } + if keep { + self.customizing = Some(editing); + } + } +} diff --git a/crates/ui-egui/src/backstage.rs b/crates/ui-egui/src/backstage.rs index 66cb1069..359915f6 100644 --- a/crates/ui-egui/src/backstage.rs +++ b/crates/ui-egui/src/backstage.rs @@ -92,6 +92,8 @@ pub enum Act { SetAutoSwitch(bool), /// Erase ink with a scratch-out gesture, on or off (issue #569). SetScratchOut(bool), + /// Open Customize the Ribbon: the person's own groups of commands (issue #568). + CustomizeRibbon, /// The page layout preferences, as they are now. SetPagePrefs(PagePrefs), /// Options > Quick Notes (issue #567): new Quick Notes go into this section, or with `None` @@ -943,6 +945,12 @@ fn options_page( } ui.label(egui::RichText::new(crate::tl_id!("ui.scratch_out_tip")).size(11.5).color(t.muted)); ui.add_space(12.0); + // Issue #568: groups of the commands the person uses most, on the tabs they choose. + if open_action(ui, crate::tl_id!("ui.customize_the_ribbon_ellipsis"), 230.0, 34.0, t, false).clicked() { + acts.push(Act::CustomizeRibbon); + } + ui.label(egui::RichText::new(crate::tl_id!("ui.customize_the_ribbon_hint")).size(11.5).color(t.muted)); + ui.add_space(12.0); page_prefs_options(ui, page_prefs, t, acts); section_heading(ui, 1); let current = crate::i18n::format_message_id("ui.notebooks_folder_current", &[("folder", notebooks_folder)]); diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 25021d17..a574c3fa 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -80,6 +80,7 @@ pub mod quickaccess; pub mod reader; pub mod replay; pub mod ribbon; +pub mod ribbon_custom; pub mod ribbon_icons; pub mod saver; pub mod sectiontabs; diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index 78840551..333da7bd 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -720,6 +720,8 @@ fn first_grid_line(min: f32, anchor: f32, step: f32) -> f32 { #[derive(Clone, Copy, Debug, Default)] pub struct View<'a> { pub layout: Layout, + /// The groups of commands the person made, on the tabs they chose (issue #568). + pub custom_groups: &'a [crate::ribbon_custom::Group], /// True when the side panel is two columns. pub split_panes: bool, /// True when the window is kept above the others. @@ -896,6 +898,17 @@ fn classic_tab(ui: &mut Ui, chosen: &str, source: bool, view: &View<'_>, format: SOURCE_TAB => source_tab(ui, format, t, acts), _ => home_tab(ui, view, t, acts), } + // The person's own groups for this tab, after its own, as Office puts a custom group + // (issue #568). Each button does what the ribbon's own button for it does. + for custom in view.custom_groups.iter().filter(|g| g.shown && g.tab == chosen && !g.commands.is_empty()) { + group(ui, &custom.name, t, |ui| { + for command in &custom.commands { + if big(ui, command.icon(), command.label(), command.label(), t).clicked() { + acts.push(command.act()); + } + } + }); + } } fn command_strip(ui: &mut Ui, key: egui::Id, t: &Tokens, add: impl FnOnce(&mut Ui)) { @@ -989,6 +1002,19 @@ fn simplified_tab(ui: &mut Ui, chosen: &str, source: bool, view: &View<'_>, form acts.push(act); } } + // The person's own groups for this tab (issue #568): one button each, opening its commands. + for custom in view.custom_groups.iter().filter(|g| g.shown && g.tab == chosen && !g.commands.is_empty()) { + let icon = custom.commands.first().map_or(Icon::Plus, |c| c.icon()); + let button = strip_button(ui, SplitIcon::Icon(icon), &custom.name, &custom.name, true, t); + command_popup(&button, acts, |ui, acts| { + for command in &custom.commands { + if ui.button(command.label()).clicked() { + acts.push(command.act()); + ui.close(); + } + } + }); + } let label = crate::tl_id!("ui.ribbon_more_commands"); let more = strip_button(ui, SplitIcon::Icon(Icon::Bars), label, label, true, t); command_popup(&more, acts, |ui, acts| { diff --git a/crates/ui-egui/src/ribbon_custom.rs b/crates/ui-egui/src/ribbon_custom.rs new file mode 100644 index 00000000..d178cea7 --- /dev/null +++ b/crates/ui-egui/src/ribbon_custom.rs @@ -0,0 +1,350 @@ +//! Groups of commands the person makes for the ribbon (issue #568), as Office's Customize the +//! Ribbon adds groups of its own to a tab. +//! +//! A group has a name, the tab it goes on, whether it is shown, and its commands, picked from the +//! commands below: ones the ribbon already has, each doing exactly what its own button does. The +//! groups are kept in the setting `ribbon_custom_groups`. With none (the default) the ribbon is +//! as it always was; Reset takes them all away again. + +use crate::icons::Icon; +use crate::ribbon::Act; + +/// The setting the groups are kept in. +pub const KEY: &str = "ribbon_custom_groups"; +/// The tabs a group can go on, by the names the ribbon gives them. +pub const TABS: [&str; 6] = ["Home", "Insert", "Draw", "History", "Review", "View"]; +/// At most this many groups, and this many commands in one. +pub const MOST_GROUPS: usize = 12; +pub const MOST_COMMANDS: usize = 16; + +/// A command a group can hold. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Command { + Paste, + PasteTextOnly, + ClearFormatting, + FindTags, + MeetingDetails, + InsertTable, + AddFile, + AddPicture, + AddPrintout, + Symbols, + InsertSpace, + Spelling, + Thesaurus, + CheckAccessibility, + PageVersions, + RecentEdits, + NextUnread, + FindByAuthor, + RecycleBin, + QuickNote, + NewWindow, + DockToDesktop, + AlwaysOnTop, + FullPage, + ImmersiveReader, + PageTemplates, + SendPage, +} + +impl Command { + pub const ALL: [Command; 27] = [ + Command::Paste, + Command::PasteTextOnly, + Command::ClearFormatting, + Command::FindTags, + Command::MeetingDetails, + Command::InsertTable, + Command::AddFile, + Command::AddPicture, + Command::AddPrintout, + Command::Symbols, + Command::InsertSpace, + Command::Spelling, + Command::Thesaurus, + Command::CheckAccessibility, + Command::PageVersions, + Command::RecentEdits, + Command::NextUnread, + Command::FindByAuthor, + Command::RecycleBin, + Command::QuickNote, + Command::NewWindow, + Command::DockToDesktop, + Command::AlwaysOnTop, + Command::FullPage, + Command::ImmersiveReader, + Command::PageTemplates, + Command::SendPage, + ]; + + /// The name the setting keeps it by. + pub fn id(self) -> &'static str { + match self { + Command::Paste => "paste", + Command::PasteTextOnly => "paste_text_only", + Command::ClearFormatting => "clear_formatting", + Command::FindTags => "find_tags", + Command::MeetingDetails => "meeting_details", + Command::InsertTable => "insert_table", + Command::AddFile => "add_file", + Command::AddPicture => "add_picture", + Command::AddPrintout => "add_printout", + Command::Symbols => "symbols", + Command::InsertSpace => "insert_space", + Command::Spelling => "spelling", + Command::Thesaurus => "thesaurus", + Command::CheckAccessibility => "check_accessibility", + Command::PageVersions => "page_versions", + Command::RecentEdits => "recent_edits", + Command::NextUnread => "next_unread", + Command::FindByAuthor => "find_by_author", + Command::RecycleBin => "recycle_bin", + Command::QuickNote => "quick_note", + Command::NewWindow => "new_window", + Command::DockToDesktop => "dock_to_desktop", + Command::AlwaysOnTop => "always_on_top", + Command::FullPage => "full_page", + Command::ImmersiveReader => "immersive_reader", + Command::PageTemplates => "page_templates", + Command::SendPage => "send_page", + } + } + + pub fn parse(id: &str) -> Option { + Command::ALL.into_iter().find(|c| c.id() == id.trim()) + } + + /// Its name on the button and in Customize the Ribbon. + pub fn label(self) -> &'static str { + match self { + Command::Paste => crate::tl_id!("ribbon_custom.paste"), + Command::PasteTextOnly => crate::tl_id!("ribbon_custom.paste_text_only"), + Command::ClearFormatting => crate::tl_id!("ribbon_custom.clear_formatting"), + Command::FindTags => crate::tl_id!("ribbon_custom.find_tags"), + Command::MeetingDetails => crate::tl_id!("ribbon_custom.meeting_details"), + Command::InsertTable => crate::tl_id!("ribbon_custom.insert_table"), + Command::AddFile => crate::tl_id!("ribbon_custom.add_file"), + Command::AddPicture => crate::tl_id!("ribbon_custom.add_picture"), + Command::AddPrintout => crate::tl_id!("ribbon_custom.add_printout"), + Command::Symbols => crate::tl_id!("ribbon_custom.symbols"), + Command::InsertSpace => crate::tl_id!("ribbon_custom.insert_space"), + Command::Spelling => crate::tl_id!("ribbon_custom.spelling"), + Command::Thesaurus => crate::tl_id!("ribbon_custom.thesaurus"), + Command::CheckAccessibility => crate::tl_id!("ribbon_custom.check_accessibility"), + Command::PageVersions => crate::tl_id!("ribbon_custom.page_versions"), + Command::RecentEdits => crate::tl_id!("ribbon_custom.recent_edits"), + Command::NextUnread => crate::tl_id!("ribbon_custom.next_unread"), + Command::FindByAuthor => crate::tl_id!("ribbon_custom.find_by_author"), + Command::RecycleBin => crate::tl_id!("ribbon_custom.recycle_bin"), + Command::QuickNote => crate::tl_id!("ribbon_custom.quick_note"), + Command::NewWindow => crate::tl_id!("ribbon_custom.new_window"), + Command::DockToDesktop => crate::tl_id!("ribbon_custom.dock_to_desktop"), + Command::AlwaysOnTop => crate::tl_id!("ribbon_custom.always_on_top"), + Command::FullPage => crate::tl_id!("ribbon_custom.full_page"), + Command::ImmersiveReader => crate::tl_id!("ribbon_custom.immersive_reader"), + Command::PageTemplates => crate::tl_id!("ribbon_custom.page_templates"), + Command::SendPage => crate::tl_id!("ribbon_custom.send_page"), + } + } + + pub fn icon(self) -> Icon { + match self { + Command::Paste | Command::PasteTextOnly => Icon::Clip, + Command::ClearFormatting => Icon::Eraser, + Command::FindTags => Icon::Todo, + Command::MeetingDetails => Icon::Calendar, + Command::InsertTable => Icon::Table, + Command::AddFile => Icon::Attach, + Command::AddPicture => Icon::Picture, + Command::AddPrintout => Icon::Print, + Command::Symbols => Icon::Symbol, + Command::InsertSpace => Icon::InsertSpace, + Command::Spelling => Icon::Spelling, + Command::Thesaurus => Icon::Thesaurus, + Command::CheckAccessibility => Icon::Help, + Command::PageVersions => Icon::PageStack, + Command::RecentEdits => Icon::Clock, + Command::NextUnread => Icon::Page, + Command::FindByAuthor => Icon::Search, + Command::RecycleBin => Icon::Eraser, + Command::QuickNote => Icon::Page, + Command::NewWindow => Icon::Plus, + Command::DockToDesktop => Icon::PageWidth, + Command::AlwaysOnTop => Icon::MoveUp, + Command::FullPage => Icon::FullPage, + Command::ImmersiveReader => Icon::Bars, + Command::PageTemplates => Icon::PageStack, + Command::SendPage => Icon::Link, + } + } + + /// What the button does: the same act as the ribbon's own button for it. + pub fn act(self) -> Act { + match self { + Command::Paste => Act::Paste, + Command::PasteTextOnly => Act::PastePlain, + Command::ClearFormatting => Act::ClearFormatting, + Command::FindTags => Act::FindTags, + Command::MeetingDetails => Act::MeetingDetails, + Command::InsertTable => Act::InsertTableDialog, + Command::AddFile => Act::AddFile, + Command::AddPicture => Act::AddPicture, + Command::AddPrintout => Act::AddPrintout, + Command::Symbols => Act::Symbols, + Command::InsertSpace => Act::InsertSpaceTool, + Command::Spelling => Act::Spelling, + Command::Thesaurus => Act::Thesaurus, + Command::CheckAccessibility => Act::CheckAccessibility, + Command::PageVersions => Act::PageVersions, + Command::RecentEdits => Act::RecentEdits, + Command::NextUnread => Act::NextUnread, + Command::FindByAuthor => Act::FindByAuthor, + Command::RecycleBin => Act::RecycleBin, + Command::QuickNote => Act::QuickNote, + Command::NewWindow => Act::NewWindow, + Command::DockToDesktop => Act::ToggleDock, + Command::AlwaysOnTop => Act::ToggleAlwaysOnTop, + Command::FullPage => Act::ToggleFullPage, + Command::ImmersiveReader => Act::ImmersiveReader, + Command::PageTemplates => Act::PageTemplates, + Command::SendPage => Act::SendPage, + } + } +} + +/// One group the person made. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Group { + pub name: String, + /// One of `TABS`. + pub tab: &'static str, + pub shown: bool, + pub commands: Vec, +} + +impl Group { + pub fn new(name: &str) -> Group { + Group { name: name.to_string(), tab: TABS[0], shown: true, commands: Vec::new() } + } +} + +/// A group's name in the setting: the characters that part the groups and their fields, and +/// `#` (which the settings reader takes for a comment), written as `%XX`. +fn encode(name: &str) -> String { + let mut out = String::new(); + for c in name.chars() { + if matches!(c, '%' | '|' | ';' | ',' | '#' | '"' | '\n' | '\r') { + for b in c.to_string().bytes() { + out.push_str(&format!("%{b:02X}")); + } + } else { + out.push(c); + } + } + out +} + +fn decode(text: &str) -> String { + let bytes = text.as_bytes(); + let mut out = Vec::with_capacity(bytes.len()); + let mut i = 0; + while i < bytes.len() { + if bytes[i] == b'%' + && let Some(b) = text.get(i + 1..i + 3).and_then(|h| u8::from_str_radix(h, 16).ok()) + { + out.push(b); + i += 3; + continue; + } + out.push(bytes[i]); + i += 1; + } + String::from_utf8_lossy(&out).into_owned() +} + +/// The groups the setting holds: `name|tab|shown|command,command` for each, parted by `;`. +/// A group whose tab or commands are not known keeps what is; a name left empty is dropped. +pub fn load(text: &str) -> Vec { + text.split(';') + .filter_map(|part| { + let mut fields = part.split('|'); + let name = decode(fields.next()?.trim()); + if name.trim().is_empty() { + return None; + } + let tab = fields.next().and_then(|t| TABS.into_iter().find(|tab| *tab == t.trim())).unwrap_or(TABS[0]); + let shown = fields.next().is_none_or(|s| s.trim() != "hidden"); + let mut commands: Vec = Vec::new(); + for command in fields.next().unwrap_or_default().split(',').filter_map(Command::parse) { + if !commands.contains(&command) && commands.len() < MOST_COMMANDS { + commands.push(command); + } + } + Some(Group { name: name.trim().to_string(), tab, shown, commands }) + }) + .take(MOST_GROUPS) + .collect() +} + +/// The setting's text for `groups`. +pub fn save(groups: &[Group]) -> String { + groups + .iter() + .filter(|g| !g.name.trim().is_empty()) + .map(|g| { + format!( + "{}|{}|{}|{}", + encode(g.name.trim()), + g.tab, + if g.shown { "shown" } else { "hidden" }, + g.commands.iter().map(|c| c.id()).collect::>().join(",") + ) + }) + .collect::>() + .join(";") +} + +/// Moves the item at `from` one place up (`-1`) or down (`1`), if there is room. +pub fn shift(list: &mut [T], from: usize, by: isize) { + if let Some(to) = from.checked_add_signed(by).filter(|to| *to < list.len()) + && from < list.len() + { + list.swap(from, to); + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn groups_keep_their_names_tabs_order_and_commands() { + let groups = vec![ + Group { name: "My tools; #1 | best, 100%".into(), tab: "Review", shown: true, commands: vec![Command::Spelling, Command::FullPage] }, + Group { name: "Hidden one".into(), tab: "Home", shown: false, commands: vec![Command::Paste] }, + ]; + let text = save(&groups); + assert!(!text.contains('#'), "the settings reader takes # for a comment: {text}"); + assert_eq!(load(&text), groups); + assert_eq!(load(""), Vec::::new()); + // What is not known is left out, not guessed at. + let odd = load("Mine|Nowhere|shown|spelling,unknown,spelling;|Home|shown|paste"); + assert_eq!(odd, vec![Group { name: "Mine".into(), tab: "Home", shown: true, commands: vec![Command::Spelling] }]); + } + + #[test] + fn every_command_has_its_own_id() { + for c in Command::ALL { + assert_eq!(Command::parse(c.id()), Some(c)); + } + let mut list = vec![1, 2, 3]; + shift(&mut list, 0, -1); + shift(&mut list, 2, 1); + assert_eq!(list, [1, 2, 3], "nothing moves past an end"); + shift(&mut list, 0, 1); + assert_eq!(list, [2, 1, 3]); + } +} diff --git a/crates/ui-egui/tests/ui.rs b/crates/ui-egui/tests/ui.rs index 60760af0..0c3d780d 100644 --- a/crates/ui-egui/tests/ui.rs +++ b/crates/ui-egui/tests/ui.rs @@ -21572,3 +21572,103 @@ fn a_password_protected_section_locks_unlocks_and_is_locked_again_on_close() { assert!(!page.exists(), "html={html}"); } } + +/// Issue #568: the person's own ribbon groups show on the tab they chose, after its own groups, +/// and each button does what the ribbon's own button for that command does. A hidden group does +/// not show; Reset takes the ribbon back to how it comes; File > Options opens the editor. +#[test] +fn custom_ribbon_groups_show_on_their_tab_and_work_like_the_ribbon() { + use notecraft_ui_egui::ribbon_custom::{Command, Group}; + for theme in [LIGHT, DARK] { + let (_t, app, s) = sample_app("ui-custom-ribbon-groups"); + let mut h = harness(app, theme); + h.state_mut().open_path(&s.md_page.to_string_lossy()); + settle(&mut h); + h.get_by_label("Review").click(); + settle(&mut h); + let own = h.query_all_by_label("Spelling").count(); + assert_eq!(h.query_all_by_label("My checks").count(), 0); + + let mine = Group { name: "My checks".into(), tab: "Review", shown: true, commands: vec![Command::Spelling] }; + let hidden = Group { name: "Put away".into(), tab: "Review", shown: false, commands: vec![Command::Thesaurus] }; + h.state_mut().set_custom_groups(vec![mine, hidden]); + settle(&mut h); + assert_eq!(h.query_all_by_label("My checks").count(), 1, "the group's name shows on the Review tab"); + assert_eq!(h.query_all_by_label("Spelling").count(), own + 1, "its Spelling button sits beside the ribbon's own"); + assert_eq!(h.query_all_by_label("Put away").count(), 0, "a hidden group does not show"); + assert_eq!(look_at(&mut h)["customGroups"].as_array().map(Vec::len), Some(2), "both groups are kept"); + + h.query_all_by_label("Spelling").last().expect("the group's button").click(); + settle(&mut h); + assert!(!look_at(&mut h)["proofing"]["spelling"].is_null(), "the group's Spelling checks spelling, as the ribbon's own does"); + + h.get_by_label("Home").click(); + settle(&mut h); + assert_eq!(h.query_all_by_label("My checks").count(), 0, "the group is only on the tab it was put on"); + + h.state_mut().reset_custom_groups(); + settle(&mut h); + assert_eq!(look_at(&mut h)["customGroups"], json!([]), "Reset leaves none of the person's groups"); + + h.state_mut().open_backstage_page("Options"); + settle(&mut h); + h.get_by_label("Customize the Ribbon…").click(); + settle(&mut h); + assert!(h.query_all_by_label("Customize the Ribbon").count() > 0, "Options opens Customize the Ribbon"); + assert_eq!(h.query_all_by_label("No groups of your own yet.").count(), 1); + h.get_by_label("New Group").click(); + settle(&mut h); + h.get_by_label("Save").click(); + settle(&mut h); + assert_eq!(look_at(&mut h)["customGroups"][0]["name"], "New Group", "Save keeps the new group"); + review(&mut h, &format!("custom_ribbon_groups_{}", theme.mode.is_dark())); + } +} + +/// Issue #550: with audio search on, the words said in a recording are found from its approved +/// transcript, and the result opens the page at the line said at that time. A recording with no +/// timed transcript is reported. With audio search off (as it comes), nothing is searched. +#[test] +fn spoken_words_are_found_in_approved_transcripts_when_audio_search_is_on() { + for html in [false, true] { + let (_t, app, s) = sample_app("ui-spoken-search"); + let page = if html { &s.html_page } else { &s.md_page }; + std::fs::create_dir_all(page.join("assets")).expect("assets"); + std::fs::write(page.join("assets/Meeting.wav"), b"RIFF").expect("audio"); + std::fs::write(page.join("assets/Silent.mp4"), b"video").expect("video"); + let body = if html { + "

Notes

Meeting.wav

[00:00:01.520 - 00:00:05.321] The zebra budget for the quarter

[00:01:05.000 - 00:01:09.800] Ship it

".to_string() + } else { + "Notes\n\n[Meeting.wav](assets/Meeting.wav)\n\n\\[00:00:01.520 - 00:00:05.321\\] The zebra budget for the quarter\n\n\\[00:01:05.000 - 00:01:09.800\\] Ship it\n".to_string() + }; + notecraft_store::page::save_body(page, &body).expect("fixture"); + let mut h = harness(app, if html { DARK } else { LIGHT }); + h.state_mut().open_path(&page.to_string_lossy()); + settle(&mut h); + + search_for(&mut h, "zebra"); + let state = look_at(&mut h)["spokenSearch"].clone(); + assert_eq!(state["on"], false, "audio search is off until turned on"); + assert_eq!(state["clips"], json!([]), "with it off, no recording is searched"); + assert_eq!(h.query_all_by_label("Said in recordings").count(), 0); + + h.state_mut().set_audio_search(true); + settle(&mut h); + let state = look_at(&mut h)["spokenSearch"].clone(); + assert_eq!(state["clips"].as_array().map(Vec::len), Some(1), "html={html}: {state}"); + assert_eq!(state["clips"][0]["start"], "00:00:01"); + assert_eq!(state["clips"][0]["recording"], "assets/Meeting.wav"); + assert_eq!(state["unindexed"], json!(["assets/Silent.mp4"]), "the video with no transcript is reported"); + assert_eq!(h.query_all_by_label("Said in recordings").count(), 1); + assert_eq!(h.query_all_by_label_contains("1 recording has no timed transcript").count(), 1); + review(&mut h, &format!("spoken_search_{html}")); + + let block = state["clips"][0]["block"].as_u64().expect("block"); + h.query_all_by_label_contains("The zebra budget").next().expect("the result").click(); + settle(&mut h); + let seen = look_at(&mut h); + assert_eq!(seen["page"]["caret"]["block"].as_u64(), Some(block), "html={html}: the result opens the page at the timed line"); + assert!(h.state().body().unwrap_or_default().contains("zebra"), "the transcript's page is open"); + assert!(h.state().audio_search_on(), "the preference is kept"); + } +} diff --git a/docs/commands.md b/docs/commands.md index fa0fa3b8..bd06e848 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -490,6 +490,17 @@ Parameters: - limit (optional): at most this many hits (default 40, at most 500) - scope (optional): page or folder to search, relative to the notebooks folder; every open notebook when left out +## `search.spoken` + +Search spoken words in recordings. + +Parameters: + +- q (required): words said in a recording +- limit (optional): at most this many lines (default 40, at most 500) +- scope (optional): page or folder to search, relative to the notebooks folder; every open notebook when left out +- The words searched are the timed lines of transcripts approved with Insert > Transcribe. Off until the setting audio_search is true + ## `tags.find` Find tagged notes. diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 62e6062e..e879146e 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -52,7 +52,7 @@ returns `{}`); later requests on the same connection may leave it out. Replies: | `auth` | none | `{}` | | `engine.commands` | none | every command: `id`, `label`, `params`, `changesTree` | | `engine.execute` | `command`, `params` (object) | the command's output; same as `notecraft-cli run` | -| `ui.inspect` | none | visible tree rows, open page, canvas `viewOffset` in screen points and `horizontalBar` and `horizontalThumb` (the page's sideways scroll bar and its thumb as `[left, top, right, bottom]` in screen points, or null when the page fits the view) (the caret: its block, text, `at` and `anchor` in characters; `containers`: the boxes the blocks are arranged in; `across`: a selection dragged across more than one block, as the block and byte at each end, or null; `selectedContainer`: the index of the box that is selected, or null; `edgesShown`: the boxes whose edges are showing, by index; `nav` (`back` and `forward` counts and the `current` page), `quickAccess` (which of Back, Forward, Undo and Redo are shown, `below`, `hidden`); `windowFrame` (`own` when the band across the top is the title bar, `system` when the system draws it); and `history`: how many steps of undo the page is keeping, where in them it is, and whether undo and redo have anywhere to go), theme, `pagePrefs` (File > Options: `centrePage`, `fitDateBox`, `outlineNewBoxes`), window size, `pageDiagrams` (the same counts for the Mermaid diagrams of the page as it is drawn, `found`, `drawn`, `drawing`, `failed`), `panes` (whether the side panel is split into organisers and pages, and whether the organisers column is showing), `tagsSummary` (while Home > Find Tags is open: its `scope`, `page`, `section`, `notebook` or `all`, whether it shows only `unchecked` To Do items, and the `lines` it lists, each with its `tag`, `text`, `done` (for a To Do), `page` and `section`; null while it is closed), `paper` (the rule lines behind the pages, by id), `proofing` (Review's spelling and thesaurus: the `language` checked in, the one `chosen` (empty for Automatic), `status` (`native`, `dictionary`, `no-dictionary`, `not-checked` or `not-loaded`), `spelling` while its pane is open (the `words` spelt wrong, each with its `word`, `block`, `cell`, `start` and `end` in characters, the `current` one, and `otherScript`, how many words in another script were passed over), and `thesaurus` while it is open (the `query`, the `place` of the word on the page, its `meanings` each with `part` and `words`, and `missing` when there is no thesaurus for the language)), `linkedNotes` (Review > Linked Notes: whether its pane is `open`, the source it is `running` with (`kind`, `target`, `title`) or null, and the page's linked `paragraphs`, each with its `block`, `source` and `kind`), `sectionLocks` (the password-protected `sections` in the open notebooks, each with its `title` and whether it is `locked`, how many this window holds unlocked, `unlockedHere`, and the password being `asking` for, with its `ask` (`Protect`, `Change`, `Remove` or `LockLeftOpen`) and `problem`, or null) and `pen` (see below) | +| `ui.inspect` | none | visible tree rows, open page, canvas `viewOffset` in screen points and `horizontalBar` and `horizontalThumb` (the page's sideways scroll bar and its thumb as `[left, top, right, bottom]` in screen points, or null when the page fits the view) (the caret: its block, text, `at` and `anchor` in characters; `containers`: the boxes the blocks are arranged in; `across`: a selection dragged across more than one block, as the block and byte at each end, or null; `selectedContainer`: the index of the box that is selected, or null; `edgesShown`: the boxes whose edges are showing, by index; `nav` (`back` and `forward` counts and the `current` page), `quickAccess` (which of Back, Forward, Undo and Redo are shown, `below`, `hidden`); `windowFrame` (`own` when the band across the top is the title bar, `system` when the system draws it); and `history`: how many steps of undo the page is keeping, where in them it is, and whether undo and redo have anywhere to go), theme, `pagePrefs` (File > Options: `centrePage`, `fitDateBox`, `outlineNewBoxes`), window size, `pageDiagrams` (the same counts for the Mermaid diagrams of the page as it is drawn, `found`, `drawn`, `drawing`, `failed`), `panes` (whether the side panel is split into organisers and pages, and whether the organisers column is showing), `tagsSummary` (while Home > Find Tags is open: its `scope`, `page`, `section`, `notebook` or `all`, whether it shows only `unchecked` To Do items, and the `lines` it lists, each with its `tag`, `text`, `done` (for a To Do), `page` and `section`; null while it is closed), `paper` (the rule lines behind the pages, by id), `proofing` (Review's spelling and thesaurus: the `language` checked in, the one `chosen` (empty for Automatic), `status` (`native`, `dictionary`, `no-dictionary`, `not-checked` or `not-loaded`), `spelling` while its pane is open (the `words` spelt wrong, each with its `word`, `block`, `cell`, `start` and `end` in characters, the `current` one, and `otherScript`, how many words in another script were passed over), and `thesaurus` while it is open (the `query`, the `place` of the word on the page, its `meanings` each with `part` and `words`, and `missing` when there is no thesaurus for the language)), `linkedNotes` (Review > Linked Notes: whether its pane is `open`, the source it is `running` with (`kind`, `target`, `title`) or null, and the page's linked `paragraphs`, each with its `block`, `source` and `kind`), `sectionLocks` (the password-protected `sections` in the open notebooks, each with its `title` and whether it is `locked`, how many this window holds unlocked, `unlockedHere`, and the password being `asking` for, with its `ask` (`Protect`, `Change`, `Remove` or `LockLeftOpen`) and `problem`, or null), `customGroups` (the person's own ribbon groups, each with its `name`, `tab`, whether it is `shown` and its `commands` by id), `spokenSearch` (whether audio search is `on`, the `clips` found for the query, each with its `title`, `recording`, `start`, `block` and `text`, and the `unindexed` recordings with no timed transcript) and `pen` (see below) | | `ui.window.reload` | none | `{reloaded: bool}`; explicitly discard local changes and reload the page | | `ui.window.keep-copy` | none | `{path: string}`; keep local text and ink as a new sibling page | | `ui.open` | `path` (relative to the notebooks folder) | the same as `ui.inspect`, or an error | diff --git a/docs/feature-parity.md b/docs/feature-parity.md index 9d0a5542..e69d3042 100644 --- a/docs/feature-parity.md +++ b/docs/feature-parity.md @@ -30,7 +30,7 @@ side by side. Status words: | Retrieval | Full-text search | Done | Across all notebooks, title and body. | | Retrieval | Links between pages | Partial | Clicking a link opens the named page, section, external file, or web URL. Copy link to page generates `notecraft:/book/section/page` links; the page's menu has Copy Link to Paragraph, which adds `?p=` and keeps finding the paragraph after it moves (issue #530). Links are followed by path; links by ID, links inside table cells, and links inside mixed bidi lines are not built. | | Retrieval | Versions, recycle bin | Partial | History tab provides Page Versions (stores and restores snapshots of a page's file together with its ink and attachments, issue #553; versions taken before that are marked "words only") and Notebook Recycle Bin (restores or permanently removes deleted pages, sections, and section groups). Deleting entire notebooks is not supported in the bin. | -| Retrieval | OCR, audio search | Partial | Printed text in pictures and printout pages is read on this computer with the `ocrs` models (setting `ocr_models`), found by search, and copied with the picture menu's Copy Text from Picture, for one picture or one or every printout page, shown for review first. Handwriting recognition and audio search are not built. Raw stroke data (`nc:dabs`) in ink files is preserved for future handwriting recognition. | +| Retrieval | OCR, audio search | Partial | Printed text in pictures and printout pages is read on this computer with the `ocrs` models (setting `ocr_models`), found by search, and copied with the picture menu's Copy Text from Picture, for one picture or one or every printout page, shown for review first. Audio search (search box > Spoken words, setting `audio_search`, off until turned on) finds words in transcripts approved with Insert > Transcribe and opens the page at the line said at that time; recordings with no timed transcript are reported (`search.spoken`). Handwriting recognition is not built. Raw stroke data (`nc:dabs`) in ink files is preserved for future handwriting recognition. | | Sync | Cloud sync and backup | Done by design | Plain files in a synced folder (OneDrive, Dropbox, Nextcloud, Syncthing). File changes debounce and defer during active ink strokes. Real-time conflict merging is not built. | | Sync | Local backups | Partial | File > Info > Backups (issue #552): automatic or Back Up Now copies of each open notebook into a chosen folder, with an interval and a number kept. Open Backups shows a backup's sections and pages and restores a page, section or group as a copy, or the whole backup as a new notebook. Not in the browser build. | | Sync | Section passwords | Partial | A section's menu has Password Protect This Section, Lock Section, Change Password and Remove Password; Review > Password and Lock All do the same for the open section and every unlocked one (issue #523). A locked section is one file sealed with XChaCha20-Poly1305 under an Argon2id key: its pages, pictures, ink and versions are not on disk, in search, in backups or in the recycle bin while it is locked. Unlocked sections lock again after 10 minutes with no input (setting `section_lock_idle_minutes`, 0 for never) and when the window closes; one left unlocked when the program stopped is offered to be locked at the next start. Not built: the web build's notebooks, wiping the plain files' old disk blocks, and importing OneNote's protected sections. | @@ -42,6 +42,6 @@ side by side. Status words: | Output | Add-ins, AI | Later | | | Look | Themes | Done | 14 themes, contrast checked. `themes.md`. | | Look | Ruled and grid page backgrounds | Done | Format Background on Draw or View provides none, lines, or squares with selectable rule line colours and page tint colours, stored per page in metadata (`notecraft:paper`, `notecraft:page-color`) and contrast-checked across themes. | -| Look | Office-style ribbon | Partial | Home, Insert, Draw, History and View tabs with Office-style groups, Styles and Tags galleries, contextual Table and Source tabs, section tabs layout, and File screen. Immersive Reader and Dock to Desktop are available. The Review tab has Spelling, Thesaurus, Language, Check Accessibility, Linked Notes, and Password and Lock All for protected sections. A general Help tab remains unbuilt. | +| Look | Office-style ribbon | Partial | Home, Insert, Draw, History and View tabs with Office-style groups, Styles and Tags galleries, contextual Table and Source tabs, section tabs layout, and File screen. Immersive Reader and Dock to Desktop are available. The Review tab has Spelling, Thesaurus, Language, Check Accessibility, Linked Notes, and Password and Lock All for protected sections. File > Options > Customize the Ribbon adds, orders, hides and resets the person's own groups of commands on the tabs they choose. A general Help tab remains unbuilt. | | Files | See what a page is made of | Done | The code view lists every file of a page and shows what is in each. The other app keeps a section in one binary file that a text editor cannot read. `how-to/look-inside-a-page.md`. | | Look | Platforms | Partial | Desktop builds (Windows MSI/zip, Linux deb/rpm/AppImage/tar.gz, macOS DMG/zip) and browser WASM demo are actively built and verified in CI. Android arm64 APK builds with a phone layout, but lacks native file pickers, system clipboard, and on-device signoff. | diff --git a/docs/gaps.md b/docs/gaps.md index 1c39e3c9..fff7740e 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -529,6 +529,17 @@ narrower than 600 points, on Android, a narrow desktop window or the browser bui disk-recovery tool may still find them. A note window of its own (Dock to Desktop) is a separate program and is not told when another window locks the section its page is in. A section is sealed in memory whole, so a very large section needs as much free memory to lock. +- **Customize the Ribbon** (issue #568) lets the person add, name, order, hide and fill groups of + their own on any of the Home, Insert, Draw, History, Review and View tabs, from File > Options. + A group holds a chosen set of 27 commands (the ones that work the same wherever they are + pressed); commands that need a choice of their own, such as a font or a colour, and the ribbon's + own groups cannot be moved or hidden yet. A group goes after the tab's own groups. +- **Spoken-word search** (issue #550) searches the timed lines of transcripts approved with + Insert > Transcribe, once the search box's Spoken words is turned on (setting `audio_search`). + NoteCraft has no player that can start a recording part way through, so a result opens the + page at the line said at that time, with the recording's link above it. A recording with no + timed transcript is counted and named but not searched; nothing transcribes it on its own. The + pinned search pane does not list spoken results yet. - **Containers are a first pass.** A page can hold several boxes, each with its own place, width and blocks; a box is moved by the bar along its top and resized by its right edge, and the arrangement is kept in the page's own file. Clicking open paper starts a new box diff --git a/i18n/ar-XB.tsv b/i18n/ar-XB.tsv index cda0f1c5..de767a3b 100644 --- a/i18n/ar-XB.tsv +++ b/i18n/ar-XB.tsv @@ -2028,3 +2028,54 @@ @id ui.lock_all_sections_tip [[RLI]]$$$Lock every password-protected section that is unlocked.@@@[[PDI]] @id ui.sections_locked_n [[RLI]]$$$Locked {n} section.|Locked {n} sections.@@@[[PDI]] @id ui.review_section_group [[RLI]]$$$Section@@@[[PDI]] +@id ui.search_spoken_words [[RLI]]$$$Spoken words@@@[[PDI]] +@id ui.search_spoken_words_tip [[RLI]]$$$Also search the words said in recordings and videos, from the transcripts approved with Insert > Transcribe. Off until turned on.@@@[[PDI]] +@id ui.spoken_words_heading [[RLI]]$$$Said in recordings@@@[[PDI]] +@id ui.spoken_result_tip [[RLI]]$$$Open the page at the line said at {time} in {recording}@@@[[PDI]] +@id ui.spoken_result_opened [[RLI]]$$$Said at {time} in {recording}. The recording's link is above the transcript.@@@[[PDI]] +@id ui.recordings_not_searchable_n [[RLI]]$$${n} recording has no timed transcript, so its words are not searched.|{n} recordings have no timed transcript, so their words are not searched.@@@[[PDI]] +@id ui.customize_the_ribbon_ellipsis [[RLI]]$$$Customize the Ribbon…@@@[[PDI]] +@id ui.customize_the_ribbon_hint [[RLI]]$$$Make groups of the commands you use most, and put them on the tabs you choose.@@@[[PDI]] +@id ui.customize_the_ribbon [[RLI]]$$$Customize the Ribbon@@@[[PDI]] +@id ui.customize_the_ribbon_about [[RLI]]$$$Your groups come after a tab's own. Each button does what the ribbon's own button for it does. Nothing changes until you save.@@@[[PDI]] +@id ui.ribbon_groups_saved [[RLI]]$$$The ribbon's groups are saved.@@@[[PDI]] +@id ui.no_custom_groups_yet [[RLI]]$$$No groups of your own yet.@@@[[PDI]] +@id ui.custom_group_commands_below [[RLI]]$$$Show this group's commands below@@@[[PDI]] +@id ui.custom_group_name [[RLI]]$$$Group name@@@[[PDI]] +@id ui.custom_group_shown [[RLI]]$$$Shown@@@[[PDI]] +@id ui.remove_custom_group [[RLI]]$$$Remove this group@@@[[PDI]] +@id ui.new_custom_group [[RLI]]$$$New Group@@@[[PDI]] +@id ui.new_group_name [[RLI]]$$$New Group@@@[[PDI]] +@id ui.commands_in_group [[RLI]]$$$Commands in {name}@@@[[PDI]] +@id ui.remove_command [[RLI]]$$$Remove this command@@@[[PDI]] +@id ui.add_a_command [[RLI]]$$$Add a command…@@@[[PDI]] +@id ui.reset_ribbon_groups [[RLI]]$$$Reset@@@[[PDI]] +@id ui.reset_ribbon_groups_tip [[RLI]]$$$Remove all your groups: the ribbon as it comes.@@@[[PDI]] +@id ribbon_custom.paste [[RLI]]$$$Paste@@@[[PDI]] +@id ribbon_custom.paste_text_only [[RLI]]$$$Keep Text Only@@@[[PDI]] +@id ribbon_custom.clear_formatting [[RLI]]$$$Clear Formatting@@@[[PDI]] +@id ribbon_custom.find_tags [[RLI]]$$$Find Tags@@@[[PDI]] +@id ribbon_custom.meeting_details [[RLI]]$$$Meeting Details@@@[[PDI]] +@id ribbon_custom.insert_table [[RLI]]$$$Insert Table@@@[[PDI]] +@id ribbon_custom.add_file [[RLI]]$$$File@@@[[PDI]] +@id ribbon_custom.add_picture [[RLI]]$$$Picture@@@[[PDI]] +@id ribbon_custom.add_printout [[RLI]]$$$Printout@@@[[PDI]] +@id ribbon_custom.symbols [[RLI]]$$$Symbol@@@[[PDI]] +@id ribbon_custom.insert_space [[RLI]]$$$Insert Space@@@[[PDI]] +@id ribbon_custom.spelling [[RLI]]$$$Spelling@@@[[PDI]] +@id ribbon_custom.thesaurus [[RLI]]$$$Thesaurus@@@[[PDI]] +@id ribbon_custom.check_accessibility [[RLI]]$$$Check Accessibility@@@[[PDI]] +@id ribbon_custom.page_versions [[RLI]]$$$Page Versions@@@[[PDI]] +@id ribbon_custom.recent_edits [[RLI]]$$$Recent Edits@@@[[PDI]] +@id ribbon_custom.next_unread [[RLI]]$$$Next Unread@@@[[PDI]] +@id ribbon_custom.find_by_author [[RLI]]$$$Find by Author@@@[[PDI]] +@id ribbon_custom.recycle_bin [[RLI]]$$$Recycle Bin@@@[[PDI]] +@id ribbon_custom.quick_note [[RLI]]$$$Quick Note@@@[[PDI]] +@id ribbon_custom.new_window [[RLI]]$$$New Window@@@[[PDI]] +@id ribbon_custom.dock_to_desktop [[RLI]]$$$Dock to Desktop@@@[[PDI]] +@id ribbon_custom.always_on_top [[RLI]]$$$Always on Top@@@[[PDI]] +@id ribbon_custom.full_page [[RLI]]$$$Full Page View@@@[[PDI]] +@id ribbon_custom.immersive_reader [[RLI]]$$$Immersive Reader@@@[[PDI]] +@id ribbon_custom.page_templates [[RLI]]$$$Page Templates@@@[[PDI]] +@id ribbon_custom.send_page [[RLI]]$$$Send Page@@@[[PDI]] +@id ui.save_custom_groups [[RLI]]$$$Save@@@[[PDI]] diff --git a/i18n/en-XA.tsv b/i18n/en-XA.tsv index 3fbc5ff4..6ce8fcbe 100644 --- a/i18n/en-XA.tsv +++ b/i18n/en-XA.tsv @@ -2028,3 +2028,54 @@ @id ui.lock_all_sections_tip $$$Lock every password-protected section that is unlocked.@@@ @id ui.sections_locked_n $$$Locked {n} section.|Locked {n} sections.@@@ @id ui.review_section_group $$$Section@@@ +@id ui.search_spoken_words $$$Spoken words@@@ +@id ui.search_spoken_words_tip $$$Also search the words said in recordings and videos, from the transcripts approved with Insert > Transcribe. Off until turned on.@@@ +@id ui.spoken_words_heading $$$Said in recordings@@@ +@id ui.spoken_result_tip $$$Open the page at the line said at {time} in {recording}@@@ +@id ui.spoken_result_opened $$$Said at {time} in {recording}. The recording's link is above the transcript.@@@ +@id ui.recordings_not_searchable_n $$${n} recording has no timed transcript, so its words are not searched.|{n} recordings have no timed transcript, so their words are not searched.@@@ +@id ui.customize_the_ribbon_ellipsis $$$Customize the Ribbon…@@@ +@id ui.customize_the_ribbon_hint $$$Make groups of the commands you use most, and put them on the tabs you choose.@@@ +@id ui.customize_the_ribbon $$$Customize the Ribbon@@@ +@id ui.customize_the_ribbon_about $$$Your groups come after a tab's own. Each button does what the ribbon's own button for it does. Nothing changes until you save.@@@ +@id ui.ribbon_groups_saved $$$The ribbon's groups are saved.@@@ +@id ui.no_custom_groups_yet $$$No groups of your own yet.@@@ +@id ui.custom_group_commands_below $$$Show this group's commands below@@@ +@id ui.custom_group_name $$$Group name@@@ +@id ui.custom_group_shown $$$Shown@@@ +@id ui.remove_custom_group $$$Remove this group@@@ +@id ui.new_custom_group $$$New Group@@@ +@id ui.new_group_name $$$New Group@@@ +@id ui.commands_in_group $$$Commands in {name}@@@ +@id ui.remove_command $$$Remove this command@@@ +@id ui.add_a_command $$$Add a command…@@@ +@id ui.reset_ribbon_groups $$$Reset@@@ +@id ui.reset_ribbon_groups_tip $$$Remove all your groups: the ribbon as it comes.@@@ +@id ribbon_custom.paste $$$Paste@@@ +@id ribbon_custom.paste_text_only $$$Keep Text Only@@@ +@id ribbon_custom.clear_formatting $$$Clear Formatting@@@ +@id ribbon_custom.find_tags $$$Find Tags@@@ +@id ribbon_custom.meeting_details $$$Meeting Details@@@ +@id ribbon_custom.insert_table $$$Insert Table@@@ +@id ribbon_custom.add_file $$$File@@@ +@id ribbon_custom.add_picture $$$Picture@@@ +@id ribbon_custom.add_printout $$$Printout@@@ +@id ribbon_custom.symbols $$$Symbol@@@ +@id ribbon_custom.insert_space $$$Insert Space@@@ +@id ribbon_custom.spelling $$$Spelling@@@ +@id ribbon_custom.thesaurus $$$Thesaurus@@@ +@id ribbon_custom.check_accessibility $$$Check Accessibility@@@ +@id ribbon_custom.page_versions $$$Page Versions@@@ +@id ribbon_custom.recent_edits $$$Recent Edits@@@ +@id ribbon_custom.next_unread $$$Next Unread@@@ +@id ribbon_custom.find_by_author $$$Find by Author@@@ +@id ribbon_custom.recycle_bin $$$Recycle Bin@@@ +@id ribbon_custom.quick_note $$$Quick Note@@@ +@id ribbon_custom.new_window $$$New Window@@@ +@id ribbon_custom.dock_to_desktop $$$Dock to Desktop@@@ +@id ribbon_custom.always_on_top $$$Always on Top@@@ +@id ribbon_custom.full_page $$$Full Page View@@@ +@id ribbon_custom.immersive_reader $$$Immersive Reader@@@ +@id ribbon_custom.page_templates $$$Page Templates@@@ +@id ribbon_custom.send_page $$$Send Page@@@ +@id ui.save_custom_groups $$$Save@@@ diff --git a/i18n/en.tsv b/i18n/en.tsv index 8359944a..83683a1c 100644 --- a/i18n/en.tsv +++ b/i18n/en.tsv @@ -2028,3 +2028,54 @@ @id ui.lock_all_sections_tip Lock every password-protected section that is unlocked. @id ui.sections_locked_n Locked {n} section.|Locked {n} sections. @id ui.review_section_group Section +@id ui.search_spoken_words Spoken words +@id ui.search_spoken_words_tip Also search the words said in recordings and videos, from the transcripts approved with Insert > Transcribe. Off until turned on. +@id ui.spoken_words_heading Said in recordings +@id ui.spoken_result_tip Open the page at the line said at {time} in {recording} +@id ui.spoken_result_opened Said at {time} in {recording}. The recording's link is above the transcript. +@id ui.recordings_not_searchable_n {n} recording has no timed transcript, so its words are not searched.|{n} recordings have no timed transcript, so their words are not searched. +@id ui.customize_the_ribbon_ellipsis Customize the Ribbon… +@id ui.customize_the_ribbon_hint Make groups of the commands you use most, and put them on the tabs you choose. +@id ui.customize_the_ribbon Customize the Ribbon +@id ui.customize_the_ribbon_about Your groups come after a tab's own. Each button does what the ribbon's own button for it does. Nothing changes until you save. +@id ui.ribbon_groups_saved The ribbon's groups are saved. +@id ui.no_custom_groups_yet No groups of your own yet. +@id ui.custom_group_commands_below Show this group's commands below +@id ui.custom_group_name Group name +@id ui.custom_group_shown Shown +@id ui.remove_custom_group Remove this group +@id ui.new_custom_group New Group +@id ui.new_group_name New Group +@id ui.commands_in_group Commands in {name} +@id ui.remove_command Remove this command +@id ui.add_a_command Add a command… +@id ui.reset_ribbon_groups Reset +@id ui.reset_ribbon_groups_tip Remove all your groups: the ribbon as it comes. +@id ribbon_custom.paste Paste +@id ribbon_custom.paste_text_only Keep Text Only +@id ribbon_custom.clear_formatting Clear Formatting +@id ribbon_custom.find_tags Find Tags +@id ribbon_custom.meeting_details Meeting Details +@id ribbon_custom.insert_table Insert Table +@id ribbon_custom.add_file File +@id ribbon_custom.add_picture Picture +@id ribbon_custom.add_printout Printout +@id ribbon_custom.symbols Symbol +@id ribbon_custom.insert_space Insert Space +@id ribbon_custom.spelling Spelling +@id ribbon_custom.thesaurus Thesaurus +@id ribbon_custom.check_accessibility Check Accessibility +@id ribbon_custom.page_versions Page Versions +@id ribbon_custom.recent_edits Recent Edits +@id ribbon_custom.next_unread Next Unread +@id ribbon_custom.find_by_author Find by Author +@id ribbon_custom.recycle_bin Recycle Bin +@id ribbon_custom.quick_note Quick Note +@id ribbon_custom.new_window New Window +@id ribbon_custom.dock_to_desktop Dock to Desktop +@id ribbon_custom.always_on_top Always on Top +@id ribbon_custom.full_page Full Page View +@id ribbon_custom.immersive_reader Immersive Reader +@id ribbon_custom.page_templates Page Templates +@id ribbon_custom.send_page Send Page +@id ui.save_custom_groups Save diff --git a/tools/ocr-lab/src/app.rs b/tools/ocr-lab/src/app.rs index 66776f68..fafefa56 100644 --- a/tools/ocr-lab/src/app.rs +++ b/tools/ocr-lab/src/app.rs @@ -667,6 +667,7 @@ impl Lab { can_ink_redo: false, ink_held: false, accessibility_open: false, + custom_groups: &[], linked_notes_open: false, spelling_open: false, thesaurus_open: false,