mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-11-01 12:17:18 +00:00
* wasm first steps * parsing start * parsing continued * progress * progress * progress * progress * progress * progress * progress * progress * fixes * reorganize * change type * fix * progress * refactoring * progress * progress * progress * keep style info * progress * progress * remove (copy) in name * progress * merge methods into 1 * splice * progress * progress * progress * cleaning * progress * progress * progress * visibility * progress * progress * progress * progress * progress * fixes * progress * fix markers * fix * progress * progress * progress * progress * progress * progress * small fix * use engine info * fix popups * small fix * progress * progress * progress * clean tool * handle self closing elements * reduce data exchanges across boundary * copy on wasm side to avoid any data corruption * speed fix * routing * refactoring * reverse * reverse * crop * split * merge * progress * time tool * fix bounds for waypoints * reduce * fix reactivity * handle corrupt time data * export * progress * remove gpx js package * remove todo * update readme * cleaning * progress * fix link fields * remove unused fields * refactoring and tests * import and export of routes, ref #192 * per-chunk categories storage * cross-tab sync * outdated state * refactoring * reorder methods * refactoring * fix * improve flow * renaming * progress * progress * fix * progress * per file history * keep original flag * use history variant * fix * progress * file explorer * progress * fix * sticky folders * improved sticky folders * fix sortable * fix sortable * fix * fix tab size * no file delete on desktop * fix routing on other file * fix sorting * remember language * open links in browser * commit missing changes * avoid selecting on resize * clarify filename * explorer actions * fix folder styling * drop anywhere in folder * cleaning * fixes * remove focus-ring * full screen * small fix * consistent highlight color * improved preview * performance improvements * sparser data transfers * sparser data transfers * show popup once data is loaded * fix routing control size * fix * sparse desktop build * remove custom ign styles * use new endpoint for openhikingmap * strip native menu * reorder context menu items * route full support * route - track conversion * create route file action * route export, filter out anchors at high zoom level * clarify name handling * move hide & center to view * routes continued * update docs * fix power format, closes #378 * lint fixes * fix display of additional data with gaps, closes #361 * fix linting issues * fix import modules * fix multidrag * change base to resolve * fix type errors * fix layer typings * fix last type error * each keys * improve typings * deploy to cloudflare --------- Co-authored-by: vcoppe <vcoppe@hexaly.com>
108 lines
3.8 KiB
Rust
108 lines
3.8 KiB
Rust
//! Creating, loading, deleting, moving, copying and pasting files and their elements.
|
|
|
|
use gpx_engine::api;
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
use crate::convert::*;
|
|
use crate::ids::*;
|
|
use crate::session::*;
|
|
use crate::ts::*;
|
|
|
|
// File commands
|
|
|
|
/// Creates a file and selects it. With `route`, it starts with a route. With `lng` and `lat`, it
|
|
/// starts with a segment that holds that trackpoint (at `ele`, 0 by default): the one of its route
|
|
/// with `route`, of a track otherwise.
|
|
#[wasm_bindgen]
|
|
pub fn new_file(
|
|
name: &str,
|
|
lng: Option<f64>,
|
|
lat: Option<f64>,
|
|
ele: Option<f64>,
|
|
route: bool,
|
|
) -> Outcome {
|
|
run(|e| api::new_file(e, name, lng, lat, ele, route))
|
|
}
|
|
|
|
/// Loads files as a single command (one undo step). The files are in `data`, one after the
|
|
/// other, `lengths` being the number of bytes of each one. `names`: the name of each file when
|
|
/// its data has none (the name on disk, without extension). The files that cannot be read are
|
|
/// skipped, the first one that was read is selected.
|
|
#[wasm_bindgen]
|
|
pub fn load_files(data: &[u8], lengths: &[u32], names: Vec<String>) -> Outcome {
|
|
let lengths: Vec<usize> = lengths.iter().map(|length| *length as usize).collect();
|
|
run(|e| api::load_files(e, data, &lengths, &names))
|
|
}
|
|
|
|
#[wasm_bindgen]
|
|
pub fn duplicate() -> Outcome {
|
|
run(api::duplicate)
|
|
}
|
|
|
|
/// Deletes the selected elements. With `whole_files`, the files holding the selected elements are
|
|
/// deleted instead, even if only a track or a waypoint is selected.
|
|
#[wasm_bindgen]
|
|
pub fn delete(whole_files: bool) -> Outcome {
|
|
run(|e| api::delete(e, whole_files))
|
|
}
|
|
|
|
#[wasm_bindgen]
|
|
pub fn delete_all() -> Outcome {
|
|
run(api::delete_all)
|
|
}
|
|
|
|
/// Moves the files to `index` among the other files, in the given order (not undoable).
|
|
/// `file_ids_bytes`: concatenated 16-byte UUIDs.
|
|
#[wasm_bindgen]
|
|
pub fn reorder(file_ids_bytes: &[u8], index: usize) -> Outcome {
|
|
match uuid_list(file_ids_bytes) {
|
|
Some(ids) => run(|e| api::reorder(e, &ids, index)),
|
|
None => fail("the file ids are not a list of UUIDs"),
|
|
}
|
|
}
|
|
|
|
// Clipboard
|
|
|
|
/// Puts the selected elements in the clipboard. Nothing happens when nothing is selected.
|
|
#[wasm_bindgen]
|
|
pub fn copy() -> Outcome {
|
|
run(api::copy)
|
|
}
|
|
|
|
/// Like `copy`, but the elements are moved when they are pasted.
|
|
#[wasm_bindgen]
|
|
pub fn cut() -> Outcome {
|
|
run(api::cut)
|
|
}
|
|
|
|
/// Pastes the clipboard according to the selection (see `can_paste`). What is pasted is always
|
|
/// the elements as they were when they were copied or cut, even if they were changed or deleted
|
|
/// since. It can be pasted several times: what was copied is copied again, what was cut is moved
|
|
/// the first time (and the clipboard is not cut after that), then it is copied.
|
|
#[wasm_bindgen]
|
|
pub fn paste() -> Outcome {
|
|
run(api::paste)
|
|
}
|
|
|
|
/// Whether the clipboard can be pasted with the current selection.
|
|
#[wasm_bindgen]
|
|
pub fn can_paste() -> bool {
|
|
with_engine(api::can_paste).unwrap_or(false)
|
|
}
|
|
|
|
/// Moves elements (given as a `Selection`) to a place of the file tree, keeping their ids, like
|
|
/// dragging and dropping them does. The moved elements are selected.
|
|
///
|
|
/// Files can only go among the files; tracks among the files (each becomes a file) or the tracks
|
|
/// of a file; segments among the files (each becomes a file), the tracks of a file (each becomes
|
|
/// a track) or the segments of a track; waypoints, or all the waypoints of a file, among the
|
|
/// waypoints of a file.
|
|
#[wasm_bindgen]
|
|
pub fn move_elements(what: Selection, to: MoveTarget) -> Outcome {
|
|
// a negative index is the start, an infinite one is the end
|
|
match from_js::<api::Selection>(&what).zip(from_js::<api::MoveTarget>(&to)) {
|
|
Some((what, to)) => run(|e| api::move_elements(e, what, to)),
|
|
None => fail("the elements or the target are not valid"),
|
|
}
|
|
}
|