mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-10-28 10:47:17 +00:00
clarify name handling
This commit is contained in:
1 parent
45f877ec78
commit
3f8e2a0c56
14 files changed
+204
-251
No files matched your search
@@ -205,8 +205,8 @@ pub fn load_files<H: History>(
|
||||
}
|
||||
|
||||
/// Brings changes of the files from the outside in (see [`engine::SyncFiles`]): each file is
|
||||
/// `(id, data, name)`, and replaces the file of that id, or is added if there is none; it is called
|
||||
/// `name`, whatever its data says. The files to `remove` are deleted. The selection is left alone.
|
||||
/// `(id, data, name)`, and replaces the file of that id, or is added if there is none; `name` is
|
||||
/// its name when its data has none. The files to `remove` are deleted. The selection is left alone.
|
||||
pub fn sync_files<H: History>(
|
||||
engine: &mut Engine<H>,
|
||||
files: &[(Uuid, &[u8], &str)],
|
||||
|
||||
@@ -7,8 +7,8 @@ use crate::{Apply, CommandError, FileId, Load, State};
|
||||
pub struct ExternalFile<'a> {
|
||||
pub id: FileId,
|
||||
pub data: &'a [u8],
|
||||
/// Name of the file outside (the name of the file on the disk, without its extension), which
|
||||
/// is its name here whatever the data says: a file has a single name.
|
||||
/// Name of the file when the data has none (the name of the file on the disk, without its
|
||||
/// extension).
|
||||
pub name: &'a str,
|
||||
}
|
||||
|
||||
@@ -16,8 +16,7 @@ pub struct ExternalFile<'a> {
|
||||
/// that are given replace the ones of the same id (which stay where they are in the order, and keep
|
||||
/// their id), or are added at the end if there are none; the ones to `remove` are deleted.
|
||||
///
|
||||
/// Unlike [`crate::LoadFiles`], the files are named as they are outside (see [`ExternalFile`]), and
|
||||
/// the selection is left alone (what it holds of a file that was
|
||||
/// Unlike [`crate::LoadFiles`], the selection is left alone (what it holds of a file that was
|
||||
/// replaced or deleted is dropped by the engine afterwards, as with any edit).
|
||||
///
|
||||
/// The files that cannot be read are skipped, and the files that are here stay as they are. It is an
|
||||
@@ -40,9 +39,6 @@ impl Apply for SyncFiles<'_> {
|
||||
match load.parse(state.categories) {
|
||||
Ok(mut file) => {
|
||||
file.id = external.id;
|
||||
if !external.name.trim().is_empty() {
|
||||
file.info.name = external.name.to_owned();
|
||||
}
|
||||
if state.files.insert(external.id, Rc::new(file)).is_none() {
|
||||
state.order.0.push(external.id);
|
||||
}
|
||||
@@ -107,8 +103,8 @@ mod tests {
|
||||
.apply(&mut fx.state())
|
||||
.unwrap();
|
||||
assert_eq!(fx.order.0, [first, second]);
|
||||
// named as it is outside, not as the data says
|
||||
assert_eq!(fx.files[&first].info.name, "name");
|
||||
// named as the data says, the name outside is only for a file that has none
|
||||
assert_eq!(fx.files[&first].info.name, "from disk");
|
||||
assert_eq!(fx.files[&first].id, first);
|
||||
// the selection is not changed
|
||||
assert_eq!(fx.selected_files(), [second].into());
|
||||
|
||||
Reference in new issue
Block a user