Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

Help menu: a dialog keeps the address when no browser opens; shorter hints

liangforstudyd73196f3f720
diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv
index 6baf943b2..72a4e7c96 100644
--- a/crates/ui-egui/src/i18n/es.tsv
+++ b/crates/ui-egui/src/i18n/es.tsv
@@ -3587,7 +3587,8 @@
Show the presets folder Mostrar la carpeta de ajustes preestablecidos
Delete this preset Eliminar este ajuste preestablecido
Opens in your web browser: {url} Se abre en el navegador web: {url}
- Saves this session's log and shows it in your file manager (no web page). Guarda el registro de esta sesión y lo muestra en el explorador de archivos (no abre ninguna página web).
- Shows a report on this computer in a FilmCraft window (no web page). Muestra un informe sobre este equipo en una ventana de FilmCraft (no abre ninguna página web).
- Shows the version, community links and credits in a FilmCraft window (no web page). Muestra la versión, los enlaces de la comunidad y los créditos en una ventana de FilmCraft (no abre ninguna página web).
- Couldn't open your web browser ({error}). The address is copied to the clipboard: {url} No se pudo abrir el navegador web ({error}). La dirección se ha copiado al portapapeles: {url}
+ Saves this session's log and shows it in your file manager. Guarda el registro de esta sesión y lo muestra en el explorador de archivos.
+ Shows a report on this computer. Muestra un informe sobre este equipo.
+ Shows the version, community links and credits in a FilmCraft window. Muestra la versión, los enlaces de la comunidad y los créditos en una ventana de FilmCraft.
+ Couldn't open your web browser No se pudo abrir el navegador web
+ Open this address in your browser yourself: Abre esta dirección tú mismo en el navegador:
diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv
index e641321b1..cfb00816b 100644
--- a/crates/ui-egui/src/i18n/ja.tsv
+++ b/crates/ui-egui/src/i18n/ja.tsv
@@ -3589,7 +3589,8 @@
Show the presets folder プリセットフォルダーを表示
Delete this preset このプリセットを削除
Opens in your web browser: {url} ウェブブラウザーで開きます:{url}
- Saves this session's log and shows it in your file manager (no web page). このセッションのログを保存し、ファイルマネージャーで表示します(ウェブページは開きません)。
- Shows a report on this computer in a FilmCraft window (no web page). このコンピューターのレポートを FilmCraft のウィンドウに表示します(ウェブページは開きません)。
- Shows the version, community links and credits in a FilmCraft window (no web page). バージョン、コミュニティへのリンク、クレジットを FilmCraft のウィンドウに表示します(ウェブページは開きません)。
- Couldn't open your web browser ({error}). The address is copied to the clipboard: {url} ウェブブラウザーを開けませんでした({error})。アドレスをクリップボードにコピーしました:{url}
+ Saves this session's log and shows it in your file manager. このセッションのログを保存し、ファイルマネージャーで表示します。
+ Shows a report on this computer. このコンピューターのレポートを表示します。
+ Shows the version, community links and credits in a FilmCraft window. バージョン、コミュニティへのリンク、クレジットを FilmCraft のウィンドウに表示します。
+ Couldn't open your web browser ウェブブラウザーを開けませんでした
+ Open this address in your browser yourself: このアドレスをご自身でブラウザーで開いてください:
diff --git a/crates/ui-egui/src/i18n/zh-cn.tsv b/crates/ui-egui/src/i18n/zh-cn.tsv
index 423f2c07d..15c07adc9 100644
--- a/crates/ui-egui/src/i18n/zh-cn.tsv
+++ b/crates/ui-egui/src/i18n/zh-cn.tsv
@@ -3565,7 +3565,8 @@
Show the presets folder 显示预设文件夹
Delete this preset 删除此预设
Opens in your web browser: {url} 在网页浏览器中打开:{url}
- Saves this session's log and shows it in your file manager (no web page). 保存本次会话的日志并在文件管理器中显示(不打开网页)。
- Shows a report on this computer in a FilmCraft window (no web page). 在 FilmCraft 窗口中显示本机的报告(不打开网页)。
- Shows the version, community links and credits in a FilmCraft window (no web page). 在 FilmCraft 窗口中显示版本、社区链接和致谢(不打开网页)。
- Couldn't open your web browser ({error}). The address is copied to the clipboard: {url} 无法打开网页浏览器({error})。地址已复制到剪贴板:{url}
+ Saves this session's log and shows it in your file manager. 保存本次会话的日志并在文件管理器中显示。
+ Shows a report on this computer. 显示本机的报告。
+ Shows the version, community links and credits in a FilmCraft window. 在 FilmCraft 窗口中显示版本、社区链接和致谢。
+ Couldn't open your web browser 无法打开网页浏览器
+ Open this address in your browser yourself: 请自行在浏览器中打开此地址:
diff --git a/crates/ui-egui/src/links.rs b/crates/ui-egui/src/links.rs
index 5c4d257ca..37df98da1 100644
--- a/crates/ui-egui/src/links.rs
+++ b/crates/ui-egui/src/links.rs
@@ -26,6 +26,13 @@ pub const ALL: [(&str, &str, &str); 5] = [
("help.reportIssue", "Report an Issue…", ISSUES),
];
+/// A link the web browser couldn't open (`ui.failedLink`): the address and the reason.
+#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
+pub struct FailedLink {
+ pub url: String,
+ pub error: String,
+}
+
/// The URL a `help.*` link command opens.
pub fn url_for(command: &str) -> Option<&'static str> {
ALL.iter().find(|(id, _, _)| *id == command).map(|(_, _, u)| *u)
@@ -40,9 +47,9 @@ pub fn menu_hint(command: &str) -> Option<String> {
}
Some(
match command {
- "help.revealLogFiles" => tl!("Saves this session's log and shows it in your file manager (no web page)."),
- "help.systemCompatibilityReport" => tl!("Shows a report on this computer in a FilmCraft window (no web page)."),
- "app.about" => tl!("Shows the version, community links and credits in a FilmCraft window (no web page)."),
+ "help.revealLogFiles" => tl!("Saves this session's log and shows it in your file manager."),
+ "help.systemCompatibilityReport" => tl!("Shows a report on this computer."),
+ "app.about" => tl!("Shows the version, community links and credits in a FilmCraft window."),
_ => return None,
}
.to_string(),
@@ -53,22 +60,66 @@ pub fn menu_hint(command: &str) -> Option<String> {
/// [`HostHooks::open_url`](crate::HostHooks::open_url) opens it; without the hook, or when it
/// fails, it goes through `ctx.open_url`, which only does something on the web: the native egui
/// backend is built without its `links` feature, so there it would only log (#642). When the
-/// host can't open a browser, the address goes to the clipboard and the status bar says so, so
-/// the click is never silently lost.
+/// host can't open a browser, a dialog shows the address until it is closed ([`show_failed`]),
+/// so the click is never silently lost: the clipboard can fail too, and egui only logs that.
pub fn open(app: &mut crate::FilmcraftApp, ctx: &egui::Context, url: &str) {
if let Some(f) = app.hooks.open_url.as_mut() {
match f(url) {
Ok(()) => return,
Err(error) => {
log::warn!("can't open {url} in the browser: {error}");
- ctx.copy_text(url.to_string());
- app.ui.status = tlf!("Couldn't open your web browser ({error}). The address is copied to the clipboard: {url}", error, url);
+ app.ui.failed_link = Some(FailedLink { url: url.to_string(), error });
}
}
}
ctx.open_url(egui::OpenUrl::new_tab(url));
}
+/// The dialog for a link the browser couldn't open: the reason, and the address in a read-only
+/// field you can select from, with Copy. It stays until Close or Escape, so the address is still
+/// there after switching to another window. Automation ids: `failedLink.url`, `failedLink.copy`,
+/// `failedLink.close`.
+pub fn show_failed(app: &mut crate::FilmcraftApp, ctx: &egui::Context) {
+ let Some(link) = app.ui.failed_link.clone() else { return };
+ let mut close = false;
+ let mut elems: Vec<(&str, egui::Rect, String)> = Vec::new();
+ egui::Window::new(tl!("Couldn't open your web browser"))
+ .id(egui::Id::new("failed-link"))
+ .collapsible(false)
+ .resizable(false)
+ .pivot(egui::Align2::CENTER_CENTER)
+ .default_pos(ctx.content_rect().center())
+ .show(ctx, |ui| {
+ ui.set_max_width(460.0);
+ if !link.error.is_empty() {
+ ui.label(egui::RichText::new(&link.error).small());
+ }
+ ui.label(tl!("Open this address in your browser yourself:"));
+ ui.horizontal(|ui| {
+ let mut text = link.url.as_str();
+ let r = ui.add(egui::TextEdit::singleline(&mut text).desired_width(340.0));
+ elems.push(("failedLink.url", r.rect, link.url.clone()));
+ let c = ui.button(tl!("Copy"));
+ elems.push(("failedLink.copy", c.rect, "Copy".into()));
+ if c.clicked() {
+ ui.ctx().copy_text(link.url.clone());
+ }
+ });
+ ui.add_space(6.0);
+ ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
+ let r = ui.button(tl!("Close"));
+ elems.push(("failedLink.close", r.rect, "Close".into()));
+ close |= r.clicked();
+ });
+ });
+ for (id, r, label) in elems {
+ app.auto.add(id, r, &label);
+ }
+ if close || ctx.input(|i| i.key_pressed(egui::Key::Escape) && !i.pointer.any_down()) {
+ app.ui.failed_link = None;
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -111,16 +162,58 @@ mod tests {
let fallback: Vec<String> =
ctx.output(|o| o.commands.iter().filter_map(|c| if let egui::OutputCommand::OpenUrl(u) = c { Some(u.url.clone()) } else { None }).collect());
assert_eq!(fallback, [ISSUES]);
- // ... and keeps the address at hand: copied, and named in the status bar with the reason
- let copied: Vec<String> =
- ctx.output(|o| o.commands.iter().filter_map(|c| if let egui::OutputCommand::CopyText(t) = c { Some(t.clone()) } else { None }).collect());
- assert_eq!(copied, [ISSUES]);
- assert!(app.ui.status.contains(ISSUES) && app.ui.status.contains("no browser"), "{}", app.ui.status);
+ // ... and keeps the address on screen with the reason until the dialog is closed
+ assert_eq!(app.ui.failed_link, Some(FailedLink { url: ISSUES.into(), error: "no browser".into() }));
+ }
+
+ /// The failed-link dialog shows the address until it is closed, and Copy copies it.
+ #[test]
+ fn failed_link_dialog_keeps_the_address_until_closed() {
+ let mut app = crate::FilmcraftApp::new(filmcraft_engine::Session::default());
+ app.hooks.open_url = Some(Box::new(|_: &str| Err("no browser".into())));
+ let ctx = egui::Context::default();
+ let time = std::cell::Cell::new(0.0);
+ let frame = |app: &mut crate::FilmcraftApp, events: Vec<egui::Event>| {
+ app.auto.begin_frame();
+ time.set(time.get() + 0.05);
+ let mut out = ctx.run_ui(egui::RawInput { time: Some(time.get()), events, ..Default::default() }, |ui| show_failed(app, ui.ctx()));
+ out.textures_delta.clear();
+ out
+ };
+ open(&mut app, &egui::Context::default(), GITHUB);
+ for _ in 0..3 {
+ frame(&mut app, Vec::new());
+ }
+ assert!(app.auto.elements.iter().find(|e| e.id == "failedLink.url").is_some_and(|e| e.label == GITHUB), "address shown");
+ let at = |app: &crate::FilmcraftApp, id: &str| {
+ app.auto.elements.iter().find(|e| e.id == id).map(|e| egui::pos2(e.rect[0] + e.rect[2] / 2.0, e.rect[1] + e.rect[3] / 2.0)).unwrap()
+ };
+ // press and release on separate frames; returns what was copied
+ let click = |app: &mut crate::FilmcraftApp, p: egui::Pos2| {
+ let b = |pressed| egui::Event::PointerButton { pos: p, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() };
+ let mut copied: Vec<String> = Vec::new();
+ for events in [vec![egui::Event::PointerMoved(p)], vec![b(true)], vec![b(false)], Vec::new()] {
+ let out = frame(app, events);
+ copied
+ .extend(out.platform_output.commands.iter().filter_map(|c| if let egui::OutputCommand::CopyText(t) = c { Some(t.clone()) } else { None }));
+ }
+ copied
+ };
+ let copy = at(&app, "failedLink.copy");
+ assert_eq!(click(&mut app, copy), [GITHUB]);
+ // other frames (another window in front) don't close it; Close does
+ for _ in 0..3 {
+ frame(&mut app, Vec::new());
+ }
+ assert!(app.ui.failed_link.is_some());
+ let close = at(&app, "failedLink.close");
+ click(&mut app, close);
+ assert_eq!(app.ui.failed_link, None);
}
#[test]
fn help_menu_items_say_where_they_go() {
- // links name their address; the other Help items say they stay inside FilmCraft
+ // links name their address; the other Help items say what they do instead
for (id, _, url) in ALL {
let hint = menu_hint(id).unwrap();
assert!(hint.contains(url) && hint.contains("web browser"), "{id}: {hint}");
@@ -134,7 +227,8 @@ mod tests {
assert!(help_items.len() >= ALL.len() + 3, "{help_items:?}");
for id in &help_items {
let hint = menu_hint(id).unwrap_or_else(|| panic!("{id} has no hover hint"));
- assert!(hint.contains("web browser") || hint.contains("no web page"), "{id}: {hint}");
+ let link = url_for(id).is_some() || id == "help.filmcraftHelp";
+ assert_eq!(hint.contains("web browser"), link, "{id}: {hint}");
}
assert_eq!(menu_hint("edit.undo"), None);
}
diff --git a/crates/ui-egui/src/panels/dialogs.rs b/crates/ui-egui/src/panels/dialogs.rs
index fa4f94076..f8dd2eafd 100644
--- a/crates/ui-egui/src/panels/dialogs.rs
+++ b/crates/ui-egui/src/panels/dialogs.rs
@@ -18,6 +18,7 @@ pub fn show(app: &mut FilmcraftApp, ctx: &egui::Context) {
crate::panels::workspaces::dialogs(app, ctx);
crate::panels::voiceover::show(app, ctx);
crate::panels::remix::show(app, ctx);
+ crate::links::show_failed(app, ctx);
crate::panels::interchange_export::show(app, ctx);
crate::panels::frame_export::show(app, ctx);
crate::panels::project_dialogs::show(app, ctx);
diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs
index c6b7d40ce..f24e5fa30 100644
--- a/crates/ui-egui/src/state.rs
+++ b/crates/ui-egui/src/state.rs
@@ -468,6 +468,10 @@ pub struct UiState {
pub show_scopes: bool,
/// Transient status line shown in the footer.
pub status: String,
+ /// A link the web browser couldn't open, shown with its address until closed
+ /// ([`crate::links::show_failed`]).
+ #[serde(default)]
+ pub failed_link: Option<crate::links::FailedLink>,
/// The colour parameter an armed eyedropper will fill with the next pixel clicked in the Program
/// monitor (Esc or a click elsewhere disarms it). Never saved.
#[serde(skip)]
@@ -974,6 +978,7 @@ impl Default for UiState {
dark: true,
show_scopes: false,
status: String::new(),
+ failed_link: None,
eyedropper: None,
keyframe_selection: Vec::new(),
essential_sound_tab: "Edit".into(),