mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 03:17:43 +00:00
menu: summary::text_for writes the shortcut summary without a Ui, in the host's language
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
//! cheat sheet outside the dialog.
|
||||
|
||||
use std::fmt::Write as _;
|
||||
use std::sync::Arc;
|
||||
|
||||
use craft_host::Host;
|
||||
|
||||
use craft_keymap::{Binding, Keymap, Scope};
|
||||
use egui::Ui;
|
||||
@@ -109,6 +112,12 @@ pub fn text(km: &Keymap, ui: &Ui, title: &str) -> String {
|
||||
text_in(km, &Say::of(ui), title)
|
||||
}
|
||||
|
||||
/// [`text`] without a `Ui`, in the interface language of `host` (a command or a file export, which run outside a
|
||||
/// frame).
|
||||
pub fn text_for(km: &Keymap, host: &Arc<Host>, title: &str) -> String {
|
||||
text_in(km, &Say::of_host(host), title)
|
||||
}
|
||||
|
||||
pub(crate) fn text_in(km: &Keymap, text: &Say, title: &str) -> String {
|
||||
let mut s = one_line(title);
|
||||
s.push('\n');
|
||||
|
||||
@@ -262,6 +262,14 @@ impl Say {
|
||||
Say { words: view.words(), keys: view.words(), host: view.host().cloned(), rtl: view.direction().is_rtl(), folder: env.folder() }
|
||||
}
|
||||
|
||||
/// The words of `host`'s interface language, for code without a `Ui`: what [`Say::of`] reads in a scope under
|
||||
/// `host`, with the direction of the language.
|
||||
pub(crate) fn of_host(host: &Arc<Host>) -> Say {
|
||||
let words = host.words();
|
||||
let rtl = host.i18n().is_some_and(|i18n| i18n.rtl(host.lang()));
|
||||
Say { words: words.set(), keys: words.set(), host: Some(Arc::clone(host)), rtl, folder: Folder::new(host.language_code()) }
|
||||
}
|
||||
|
||||
/// The folder that folds search text in the dialog's language.
|
||||
pub(crate) fn folder(&self) -> Folder {
|
||||
self.folder
|
||||
|
||||
@@ -88,3 +88,25 @@ fn the_summary_lists_hold_bindings() {
|
||||
let (text, html) = summarize(&mut rig);
|
||||
assert!(!text.contains("Hold K") && !html.contains("Hold K"), "with holds off the summary has no hold: {text}");
|
||||
}
|
||||
|
||||
/// The summary written without a `Ui` (a command's file export) is the one Summarize… writes under the same host.
|
||||
#[trial]
|
||||
fn the_summary_without_a_ui_is_the_one_summarize_writes() {
|
||||
let host = Arc::new(Host::builder(AppInfo { id: "trial", name: "Trial", version: "0" }).build());
|
||||
let km = fixture::keymap(Platform::Mac);
|
||||
let mut rig = Rig::new(km.clone(), fixture::options(), None);
|
||||
rig.fixture.host(host.clone());
|
||||
rig.pass();
|
||||
rig.click("Summarize…");
|
||||
let text = rig
|
||||
.outcomes()
|
||||
.into_iter()
|
||||
.rev()
|
||||
.find_map(|o| match o {
|
||||
Outcome::Summary { text, .. } => Some(text),
|
||||
_ => None,
|
||||
})
|
||||
.expect("a summary");
|
||||
let (title, _) = text.split_once('\n').expect("a title line");
|
||||
assert_eq!(craft_menu::shortcuts::summary::text_for(&km, &host, title), text);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user