From 980bd8b79ae7576e86151e1030c1c3e0ea00f41b Mon Sep 17 00:00:00 2001 From: vcoppe Date: Fri, 24 May 2024 22:53:30 +0200 Subject: [PATCH] progress --- gpx/src/gpx.ts | 4 +-- website/src/lib/components/Menu.svelte | 8 +++--- .../src/lib/components/file-list/Selection.ts | 28 +++++++++++-------- website/src/lib/stores.ts | 14 ++++------ website/src/locales/en.json | 2 +- 5 files changed, 29 insertions(+), 27 deletions(-) diff --git a/gpx/src/gpx.ts b/gpx/src/gpx.ts index b4c062e9..2b0385b0 100644 --- a/gpx/src/gpx.ts +++ b/gpx/src/gpx.ts @@ -110,8 +110,8 @@ export class GPXFiles extends GPXTreeNode { export class GPXFile extends GPXTreeNode{ [immerable] = true; - readonly attributes: GPXFileAttributes; - readonly metadata: Metadata; + attributes: GPXFileAttributes; + metadata: Metadata; readonly wpt: ReadonlyArray>; readonly trk: ReadonlyArray; diff --git a/website/src/lib/components/Menu.svelte b/website/src/lib/components/Menu.svelte index 1323a415..6d1f807a 100644 --- a/website/src/lib/components/Menu.svelte +++ b/website/src/lib/components/Menu.svelte @@ -95,7 +95,7 @@
@@ -104,8 +104,8 @@ - {$_('menu.new')} - + {$_('menu.create')} + @@ -295,7 +295,7 @@ { - if (e.key === 'n' && (e.metaKey || e.ctrlKey)) { + if (e.key === 'c' && (e.metaKey || e.ctrlKey)) { createFile(); e.preventDefault(); } else if (e.key === 'o' && (e.metaKey || e.ctrlKey)) { diff --git a/website/src/lib/components/file-list/Selection.ts b/website/src/lib/components/file-list/Selection.ts index 546203cd..651f3a21 100644 --- a/website/src/lib/components/file-list/Selection.ts +++ b/website/src/lib/components/file-list/Selection.ts @@ -66,30 +66,34 @@ export function selectAll() { }); } -export function applyToOrderedSelectedItemsFromFile(callback: (fileId: string, level: ListLevel | undefined, items: ListItem[]) => void) { +export function applyToOrderedSelectedItemsFromFile(callback: (fileId: string, level: ListLevel | undefined, items: ListItem[]) => void, reverse: boolean = true) { get(settings.fileOrder).forEach((fileId) => { let level: ListLevel | undefined = undefined; let items: ListItem[] = []; get(selection).forEach((item) => { if (item.getFileId() === fileId) { level = item.level; - if (item instanceof ListTrackItem || item instanceof ListTrackSegmentItem || item instanceof ListWaypointItem) { + if (item instanceof ListFileItem || item instanceof ListTrackItem || item instanceof ListTrackSegmentItem || item instanceof ListWaypointItem) { items.push(item); } } }); - items.sort((a, b) => { // Process the items in reverse order to avoid index conflicts - if (a instanceof ListTrackItem && b instanceof ListTrackItem) { - return b.getTrackIndex() - a.getTrackIndex(); - } else if (a instanceof ListTrackSegmentItem && b instanceof ListTrackSegmentItem) { - return b.getSegmentIndex() - a.getSegmentIndex(); - } else if (a instanceof ListWaypointItem && b instanceof ListWaypointItem) { - return b.getWaypointIndex() - a.getWaypointIndex(); + if (items.length > 0) { + if (reverse) { + items.sort((a, b) => { // Process the items in reverse order to avoid index conflicts + if (a instanceof ListTrackItem && b instanceof ListTrackItem) { + return b.getTrackIndex() - a.getTrackIndex(); + } else if (a instanceof ListTrackSegmentItem && b instanceof ListTrackSegmentItem) { + return b.getSegmentIndex() - a.getSegmentIndex(); + } else if (a instanceof ListWaypointItem && b instanceof ListWaypointItem) { + return b.getWaypointIndex() - a.getWaypointIndex(); + } + return b.level - a.level; + }); } - return b.level - a.level; - }); - callback(fileId, level, items); + callback(fileId, level, items); + } }); } \ No newline at end of file diff --git a/website/src/lib/stores.ts b/website/src/lib/stores.ts index e1ba32ee..b7123f10 100644 --- a/website/src/lib/stores.ts +++ b/website/src/lib/stores.ts @@ -5,8 +5,8 @@ import { GPXFile, buildGPX, parseGPX, GPXStatistics, type Coordinates } from 'gp import { tick } from 'svelte'; import { _ } from 'svelte-i18n'; import type { GPXLayer } from '$lib/components/gpx-layer/GPXLayer'; -import { settings, dbUtils, fileObservers } from './db'; -import { selectFile, selection } from '$lib/components/file-list/Selection'; +import { dbUtils, fileObservers } from './db'; +import { applyToOrderedSelectedItemsFromFile, selectFile, selection } from '$lib/components/file-list/Selection'; import { ListFileItem, ListWaypointItem } from '$lib/components/file-list/FileList'; import type { RoutingControls } from '$lib/components/toolbar/tools/routing/RoutingControls'; @@ -15,17 +15,15 @@ export const selectFiles = writable<{ [key: string]: (fileId?: string) => void } export const gpxStatistics: Writable = writable(new GPXStatistics()); -const { fileOrder } = settings; - function updateGPXData() { let statistics = new GPXStatistics(); - get(fileOrder).forEach((fileId) => { // Get statistics in the order of the file list + applyToOrderedSelectedItemsFromFile((fileId, level, items) => { let fileStore = get(fileObservers).get(fileId); if (fileStore) { let stats = get(fileStore)?.statistics; - if (stats !== undefined) { + if (stats) { let first = true; - get(selection).getChild(fileId)?.getSelected().forEach((item) => { // Get statistics for selected items within the file + items.forEach((item) => { if (!(item instanceof ListWaypointItem) || first) { statistics.mergeWith(stats.getStatisticsFor(item)); first = false; @@ -33,7 +31,7 @@ function updateGPXData() { }); } } - }); + }, false); gpxStatistics.set(statistics); } diff --git a/website/src/locales/en.json b/website/src/locales/en.json index 6f12e74a..a73dde9f 100644 --- a/website/src/locales/en.json +++ b/website/src/locales/en.json @@ -1,7 +1,7 @@ { "menu": { "file": "File", - "new": "New", + "create": "Create", "new_filename": "new", "load_desktop": "Load from desktop...", "load_drive": "Load from Google Drive...",