create route file action

This commit is contained in:
vcoppe committed 2026-10-26 19:22:14 +01:00
1 parent 764d0b233a
commit 0f957fb1f2
60 files changed
+211 -85

No files matched your search

+3 -2
View File
@@ -54,7 +54,8 @@ export async function createTauriBackend(): Promise<Backend> {
cut: () => invoke('cut'),
paste: () => invoke('paste'),
new_file: (name, lng, lat, ele) => invoke('new_file', { name, lng, lat, ele }),
new_file: (name, lng, lat, ele, route) =>
invoke('new_file', { name, lng, lat, ele, route }),
load_files: (files) => {
const data = new Uint8Array(files.reduce((sum, file) => sum + file.data.length, 0));
let offset = 0;
@@ -225,7 +226,7 @@ export async function createTauriBackend(): Promise<Backend> {
invoke<boolean>('export_files', { fileIds, options }),
listFolder: (path) => invoke<FolderEntry[]>('list_folder', { path }),
openUrl: (url) => invoke('open_url', { url }),
newFile: (name, folder) => invoke<Outcome>('new_file', { name, folder }),
newFile: (name, folder, route) => invoke<Outcome>('new_file', { name, folder, route }),
createFolder: (parent, name) => invoke<string>('create_folder', { parent, name }),
renamePath: (path, name) => invoke<Outcome>('rename_path', { path, name }),
movePaths: (paths, folder) => invoke('move_paths', { paths, folder }),
+12 -3
View File
@@ -100,8 +100,11 @@ export interface DesktopFiles {
listFolder(path?: string): Promise<FolderEntry[]>;
/** Opens a web page (or an email to write) in the app of the system for it. */
openUrl(url: string): Promise<void>;
/** Makes a new file, written at once in `folder` (a folder of the open folder), and selects it. */
newFile(name: string, folder: string): Promise<Outcome>;
/**
* Makes a new file, written at once in `folder` (a folder of the open folder), and selects it.
* With `route`, it starts with an empty route.
*/
newFile(name: string, folder: string, route: boolean): Promise<Outcome>;
/** Makes a folder in a folder of the open folder (numbered if the name is taken): its path. */
createFolder(parent: string, name: string): Promise<string>;
/**
@@ -165,7 +168,13 @@ export interface Backend {
paste(): Promise<Outcome>;
// Files
new_file(name: string, lng?: number, lat?: number, ele?: number): Promise<Outcome>;
new_file(
name: string,
lng: number | undefined,
lat: number | undefined,
ele: number | undefined,
route: boolean
): Promise<Outcome>;
load_files(files: { data: Uint8Array; name: string }[]): Promise<Outcome>;
duplicate(): Promise<Outcome>;
delete(wholeFiles: boolean): Promise<Outcome>;
+9
View File
@@ -204,6 +204,15 @@ describe('selection', () => {
assert.equal(fileStates()[0].structure.routes.length, 3);
});
it('creates a file that starts with an empty route', async () => {
assert.equal(await engine.newFile('routes', undefined, true), true);
const [state] = fileStates();
assert.equal(state.structure.routes.length, 1);
assert.equal(state.structure.routes[0].segment.length, 0);
assert.equal(state.structure.tracks.length, 0);
assert.deepEqual(get(engine.selection), { type: 'file', fileIds: [state.structure.id] });
});
it('ignores what does not exist', async () => {
await load('simple');
const before = get(engine.selection);
+14 -7
View File
@@ -251,11 +251,18 @@ class Engine {
// Edits of the files
/**
* Creates a file, which gets selected. With a `trackpoint`, the file starts with a track and a
* segment that hold it, in the same undo step.
* Creates a file, which gets selected. With `route`, the file starts with a route. With a
* `trackpoint`, the file starts with a segment that holds it, the one of its route with `route`
* or of a track otherwise, in the same undo step.
*/
newFile(name: string, trackpoint?: { lng: number; lat: number; ele?: number }) {
return this.run((b) => b.new_file(name, trackpoint?.lng, trackpoint?.lat, trackpoint?.ele));
newFile(
name: string,
trackpoint?: { lng: number; lat: number; ele?: number },
route: boolean = false
) {
return this.run((b) =>
b.new_file(name, trackpoint?.lng, trackpoint?.lat, trackpoint?.ele, route)
);
}
/**
@@ -606,10 +613,10 @@ class Engine {
/**
* Makes a new file in a folder of the open folder, which is written there at once and selected.
* Resolves to its id.
* With `route`, it starts with an empty route. Resolves to its id.
*/
async newFileIn(name: string, folder: string): Promise<string | undefined> {
const [id] = await this.addedBy((b) => b.desktop!.newFile(name, folder), true);
async newFileIn(name: string, folder: string, route = false): Promise<string | undefined> {
const [id] = await this.addedBy((b) => b.desktop!.newFile(name, folder, route), true);
return id;
}