app: pick the recordings folder and cut paths to the row

The folder was a text field, and the path was always cut to its last
two folders, so a wide window dropped folders it had room for and a
narrow one showed only the tail.

The row now shows the path the settings hold, cut in the middle at
whatever width the labels and the button leave it, with Select folder
opening the system's folder dialog through rune's native-file-dialog
feature. Form keeps no copy of the path any more; the draft is the one
place it lives.

The quick tab's recordings folder and the daemon tab's log file get the
same cut, and short_path goes.
This commit is contained in:
vhaudiquet committed 2026-11-23 23:53:21 +01:00
1 parent dbdec05752
commit 1bb2874753
5 files changed
+109 -30

No files matched your search

+63 -27
View File
@@ -15,7 +15,6 @@ pub struct Form {
pub dirty: bool,
pub saving: bool,
pub open_select: Option<&'static str>,
pub path: TextEdit,
pub naming: TextEdit,
pub poll_interval: TextEdit,
pub bitrate: TextEdit,
@@ -28,7 +27,6 @@ impl Form {
pub fn empty() -> Self {
let draft = Settings::default();
Self {
path: TextEdit::new(&draft.output.path),
naming: TextEdit::new(&draft.output.naming_pattern),
poll_interval: TextEdit::new(draft.daemon.poll_interval_ms.to_string()),
bitrate: TextEdit::new(draft.audio.bitrate.to_string()),
@@ -49,7 +47,6 @@ impl Form {
return;
}
self.draft = settings.clone();
self.path.replace_text(&settings.output.path);
self.naming.replace_text(&settings.output.naming_pattern);
self.poll_interval
.replace_text(settings.daemon.poll_interval_ms.to_string());
@@ -63,7 +60,6 @@ impl Form {
/// Pull the text fields into the draft and hand it to `updateSettings`.
pub fn settings(&mut self) -> Settings {
let mut out = self.draft.clone();
out.output.path = self.path.text.trim().to_string();
out.output.naming_pattern = self.naming.text.trim().to_string();
out.daemon.poll_interval_ms = self
.poll_interval
@@ -134,6 +130,57 @@ fn text_row(
ui::setting_row_with(p, key, label, hint, ui::text_field(p, key, label, edit, to))
}
/// The folder recordings land in, as the settings hold it, and the button that replaces it with
/// one the system's dialog picks. The path is read back, not typed: a folder is a thing you find.
fn path_row(p: Paint, app: &App, key: &'static str, label: &'static str, hint: &'static str) -> El {
// The whole path, not the last folders. It gets what the labels and the button leave, and a
// middle "…" when that is not enough, so the window's width picks the cut and no character
// count does. The margin holds it off the labels once the row is tight.
let shown = text(&app.form.draft.output.path)
.key("path")
.font(body(12.0))
.color(p.muted())
.ml(space::S2)
.truncate_middle();
let pick = ui::button_tx(
p,
"pick-folder",
"Select folder",
false,
move |app: &mut App, tx: &mut rune::Tx| {
let options = rune::FileDialogOptions {
title: hint.to_string(),
directory: Some(app.output_dir()),
..Default::default()
};
tx.open_folder(options, |app: &mut App, result, _| match result {
Ok(Some(path)) => {
app.form.draft.output.path = path.display().to_string();
app.form.dirty = true;
}
Ok(None) => {}
Err(e) => app.notify_error(format!("No folder dialog: {e}")),
});
},
);
ui::setting_row_with(
p,
key,
label,
hint,
// Growing the control and letting itself be small give the text a bounded width to elide
// inside; content-sized, the row would run off the card.
row()
.gap(space::S2)
.center_y()
.grow(1.0)
.min_w(0.0)
.justify_end()
.child(shown)
.child(pick),
)
}
#[allow(clippy::too_many_arguments)] // the columns of a settings row
fn select_row(
p: Paint,
@@ -395,26 +442,17 @@ fn quick(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>, content:
p,
"recordings-folder",
"Recordings folder",
text(short_path(&app.form.draft.output.path))
// Cut in the middle against the row's width, so a narrow window elides.
text(&app.form.draft.output.path)
.key("path")
.font(body(12.0))
.color(p.muted()),
.color(p.muted())
.ml(space::S2)
.truncate_middle(),
)],
))
}
/// A path as it fits on a row: the last two segments, with the rest elided.
fn short_path(path: &str) -> String {
let sep = std::path::MAIN_SEPARATOR;
let normalized = path.replace(sep, "/");
let parts: Vec<&str> = normalized.split('/').filter(|p| !p.is_empty()).collect();
match parts.len() {
0 => path.to_string(),
1 | 2 => parts.join(&sep.to_string()),
n => format!("…{sep}{}{sep}{}", parts[n - 2], parts[n - 1]),
}
}
fn recording(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>, content: El) -> El {
let v = &app.form.draft.video;
let o = &app.form.draft.output;
@@ -473,13 +511,12 @@ fn recording(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>, cont
},
)),
vec![
text_row(
path_row(
p,
app,
"output-path",
"Folder",
"Where finished recordings are written",
&app.form.path,
|app| &mut app.form.path,
),
text_row(
p,
@@ -913,7 +950,10 @@ fn advanced(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>, conte
text(value)
.key("value")
.font(type_::MONO_CAPTION)
.color(p.muted()),
.color(p.muted())
.ml(space::S2)
// A long value, the log path most of all, is cut to the row's width.
.truncate_middle(),
)
};
let recording = if app.status.is_recording { "yes" } else { "no" };
@@ -951,11 +991,7 @@ fn advanced(app: &App, p: Paint, kit: &rune_kit::Kit, layer: &mut Vec<El>, conte
.map(|id| id.to_string())
.unwrap_or_else(|| "none".into()),
),
status_row(
"daemon-log",
"Log file",
short_path(&crate::daemon::log_path()),
),
status_row("daemon-log", "Log file", crate::daemon::log_path()),
],
))
.child(ui::card(
+13 -1
View File
@@ -412,6 +412,18 @@ pub fn button(
label: &str,
primary: bool,
on_press: impl Fn(&mut App) + Send + Sync + 'static,
) -> El {
button_tx(p, key, label, primary, move |app, _| on_press(app))
}
/// [`button`] whose press gets the frame's [`Tx`], for a control that asks the window for
/// something: a native folder dialog, an open URL, a clipboard read.
pub fn button_tx(
p: Paint,
key: &str,
label: &str,
primary: bool,
on_press: impl Fn(&mut App, &mut rune::Tx) + Send + Sync + 'static,
) -> El {
el().key(key)
.role("button")
@@ -424,7 +436,7 @@ pub fn button(
.fill(if primary { p.accent } else { p.t.control_off })
.hover(p.t.hover)
.press(p.t.press)
.on_press(on_press)
.on_press_tx(on_press)
.child(
text(label)
.key("label")