mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-10-19 09:22:12 +00:00
improved preview
This commit is contained in:
1 parent
b64c192c4f
commit
9033401094
11 files changed
+109
-4
No files matched your search
@@ -88,6 +88,16 @@ pub fn open_paths(
|
||||
})
|
||||
}
|
||||
|
||||
/// The files are open for good: the preview among them is not a preview anymore (the user did
|
||||
/// something to it that the engine does not see, like hiding it).
|
||||
#[tauri::command(async)]
|
||||
pub fn keep_files(state: State<AppState>, file_ids: Vec<Uuid>) {
|
||||
state.core(move |core| {
|
||||
core.workspace.keep(&file_ids);
|
||||
core.commit(None);
|
||||
})
|
||||
}
|
||||
|
||||
/// Writes the files among `ids` that are not the ones on the disk, asking where to put the ones
|
||||
/// that have no place: the file dialog for a single one, a folder for several of them. Says whether
|
||||
/// they were written, which is not the case if the user cancelled.
|
||||
|
||||
@@ -186,6 +186,7 @@ fn register_commands<R: tauri::Runtime>(builder: tauri::Builder<R>) -> tauri::Bu
|
||||
disk::workspace_state,
|
||||
disk::open_files,
|
||||
disk::open_paths,
|
||||
disk::keep_files,
|
||||
disk::open_folder,
|
||||
disk::close_folder,
|
||||
disk::close_files,
|
||||
|
||||
+4
-2
@@ -108,8 +108,10 @@ impl Core {
|
||||
self.workspace.keep(&[id]);
|
||||
}
|
||||
let (renamed, errors) = self.workspace.follow_names(&mut self.engine, &names);
|
||||
if kept || renamed {
|
||||
self.commit(None);
|
||||
// and it goes when something else is selected
|
||||
let dropped = self.workspace.drop_preview(&mut self.engine);
|
||||
if kept || renamed || dropped.is_some() {
|
||||
self.commit(dropped.as_ref());
|
||||
} else {
|
||||
self.persist();
|
||||
}
|
||||
|
||||
@@ -725,3 +725,43 @@ fn a_file_open_as_a_preview_is_replaced_until_it_is_kept_or_edited() {
|
||||
);
|
||||
std::fs::remove_dir_all(folder).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_preview_goes_when_something_else_is_selected_unless_it_was_kept() {
|
||||
let app = App::new();
|
||||
let folder = folder_with(&["a", "b", "c"]);
|
||||
let open = |name: &str, preview: bool| {
|
||||
app.call(
|
||||
"open_paths",
|
||||
json!({ "paths": [folder.join(format!("{name}.gpx"))], "preview": preview }),
|
||||
)["added"][0]
|
||||
.as_str()
|
||||
.map(str::to_string)
|
||||
};
|
||||
let order = |app: &App| app.call("file_order", json!({})).as_array().unwrap().len();
|
||||
let a = open("a", false).unwrap();
|
||||
|
||||
// looked at, then something else is selected: it goes
|
||||
let b = open("b", true).unwrap();
|
||||
assert_eq!(order(&app), 2);
|
||||
app.call("select", json!({ "fileIds": [a], "mode": "replace" }));
|
||||
assert_eq!(order(&app), 1);
|
||||
|
||||
// nothing selected: it stays
|
||||
open("b", true);
|
||||
app.call("select", json!({ "fileIds": [], "mode": "replace" }));
|
||||
assert_eq!(order(&app), 2);
|
||||
|
||||
// kept (hidden, its menu opened...): it stays when something else is selected
|
||||
let c = open("c", true).unwrap();
|
||||
assert_eq!(order(&app), 2, "c replaces b");
|
||||
app.call("keep_files", json!({ "fileIds": [c] }));
|
||||
assert_eq!(
|
||||
app.call("workspace_state", json!({}))["files"][&c]["preview"],
|
||||
false
|
||||
);
|
||||
app.call("select", json!({ "fileIds": [a], "mode": "replace" }));
|
||||
assert_eq!(order(&app), 2);
|
||||
let _ = b;
|
||||
std::fs::remove_dir_all(folder).unwrap();
|
||||
}
|
||||
@@ -450,6 +450,17 @@ impl Workspace {
|
||||
closed.merge(opened)
|
||||
}
|
||||
|
||||
/// Closes the preview when something else is selected (not nothing, nor something in it): it was
|
||||
/// only looked at. Says what changed in the engine, `None` if it stays.
|
||||
pub fn drop_preview(&mut self, engine: &mut Engine) -> Option<api::Outcome> {
|
||||
let id = self.preview?;
|
||||
let selected = engine.selection().file_ids();
|
||||
if selected.is_empty() || selected.contains(&FileId(id)) {
|
||||
return None;
|
||||
}
|
||||
Some(self.close_files(engine, &[id], false))
|
||||
}
|
||||
|
||||
/// The files are open for good: none of them is the preview anymore.
|
||||
pub fn keep(&mut self, ids: &[Uuid]) {
|
||||
if self.preview.is_some_and(|preview| ids.contains(&preview)) {
|
||||
|
||||
Reference in new issue
Block a user