mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
fix(ui): browse for scratch disk folders (#13588)
Co-authored-by: FredApps <[email protected]>
This commit is contained in:
1 parent
c844ba9016
commit
274d456acd
3 files changed
+48
-1
No files matched your search
@@ -126,3 +126,24 @@ fn image_processor_source_picker_hides_folder_fields_for_open_documents() {
|
||||
assert_eq!(field(&h, "source"), Some(json!("open")));
|
||||
assert_eq!(h.query_all_by_label("Browse…").count(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scratch_disk_browse_sets_only_the_selected_draft_and_cancel_keeps_it() {
|
||||
let (mut h, asked) = harness(vec![Some(FileDialogAnswer::FolderTo("/tmp/scratch".into())), None]);
|
||||
let id = crate::prefs_ui::open_preferences(h.state_mut(), "scratchDisks");
|
||||
h.run_steps(4);
|
||||
assert_eq!(h.query_all_by_label("Browse…").count(), 0, "system temp is not browsable");
|
||||
h.get_by_label("Add disk").click();
|
||||
h.run_steps(3);
|
||||
h.get_by_label("Browse…").click();
|
||||
h.run_steps(4);
|
||||
let values = &h.state().ui.dialogs.iter().find(|d| d.id == id).unwrap().fields["values"];
|
||||
assert_eq!(values["scratchDisks"]["disks"][0]["path"], "(system temp)");
|
||||
assert_eq!(values["scratchDisks"]["disks"][1]["path"], "/tmp/scratch");
|
||||
assert_eq!(h.state().session.prefs().scratch_disks.disks.len(), 1, "selection edits only the draft");
|
||||
h.get_by_label("Browse…").click();
|
||||
h.run_steps(4);
|
||||
let values = &h.state().ui.dialogs.iter().find(|d| d.id == id).unwrap().fields["values"];
|
||||
assert_eq!(values["scratchDisks"]["disks"][1]["path"], "/tmp/scratch");
|
||||
assert!(matches!(asked.borrow().as_slice(), [FileDialogRequest::Folder { .. }, FileDialogRequest::Folder { .. }]));
|
||||
}
|
||||
@@ -736,6 +736,26 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {
|
||||
outcome = dialog_body(app, ui, &d, &mut fields, id, interactive);
|
||||
}
|
||||
crate::field_tab::end(ui.ctx(), tab);
|
||||
if let Some(index) = fields.remove("__scratchBrowse").and_then(|v| v.as_u64()) {
|
||||
let dialog_id = d.id;
|
||||
let result = app.ask_folder(move |app, path| {
|
||||
let dialog = app.ui.dialog_mut(dialog_id).ok_or("the dialog was closed")?;
|
||||
let disk = dialog
|
||||
.fields
|
||||
.get_mut("values")
|
||||
.and_then(|v| v.pointer_mut(&format!("/scratchDisks/disks/{index}/path")))
|
||||
.ok_or("the scratch disk was removed")?;
|
||||
if disk.as_str().is_some_and(|s| s.trim() != "(system temp)") {
|
||||
*disk = json!(path);
|
||||
}
|
||||
Ok(Value::Null)
|
||||
});
|
||||
if let Err(error) = result
|
||||
&& error != crate::file_dialog::CANCELLED
|
||||
{
|
||||
app.ui.status = error;
|
||||
}
|
||||
}
|
||||
if let Some(Value::String(key)) = fields.remove(BROWSE_FIELD) {
|
||||
browse_field(app, d.id, &fields, &key);
|
||||
}
|
||||
|
||||
@@ -311,6 +311,9 @@ fn prefs_body(ui: &mut egui::Ui, f: &mut Map<String, Value>, system: Option<egui
|
||||
});
|
||||
});
|
||||
});
|
||||
if let Some(index) = ui.ctx().data_mut(|data| data.remove_temp::<usize>(egui::Id::unique("prefs-scratch-browse"))) {
|
||||
f.insert("__scratchBrowse".into(), json!(index));
|
||||
}
|
||||
f.insert("section".into(), json!(section));
|
||||
f.insert("__search".into(), json!(search));
|
||||
f.insert("values".into(), values);
|
||||
@@ -594,12 +597,15 @@ fn field_rows(ui: &mut egui::Ui, section: &str, obj: &mut Map<String, Value>, ke
|
||||
ui.label(RichText::new(tl!("Scratch disks")).color(t.text_dim));
|
||||
let mut items = items.clone();
|
||||
ui.vertical(|ui| {
|
||||
for d in &mut items {
|
||||
for (index, d) in items.iter_mut().enumerate() {
|
||||
ui.horizontal(|ui| {
|
||||
let mut on = d.get("enabled").and_then(Value::as_bool).unwrap_or(false);
|
||||
let mut path = d.get("path").and_then(Value::as_str).unwrap_or("").to_string();
|
||||
crate::widgets::checkbox(ui, &mut on, tl!("Enabled"));
|
||||
ui.add(egui::TextEdit::singleline(&mut path).desired_width(240.0)).accessible_name(tl!("Path"));
|
||||
if path.trim() != "(system temp)" && ui.small_button(tl!("Browse…")).clicked() {
|
||||
ui.ctx().data_mut(|data| data.insert_temp(egui::Id::unique("prefs-scratch-browse"), index));
|
||||
}
|
||||
*d = json!({"enabled": on, "path": path});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user