mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-01 08:12:32 +00:00
create new track/segment in contextmenu
This commit is contained in:
@@ -2,19 +2,28 @@
|
|||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import * as ContextMenu from '$lib/components/ui/context-menu';
|
import * as ContextMenu from '$lib/components/ui/context-menu';
|
||||||
import Shortcut from '$lib/components/Shortcut.svelte';
|
import Shortcut from '$lib/components/Shortcut.svelte';
|
||||||
import { dbUtils, fileObservers } from '$lib/db';
|
import { dbUtils, fileObservers, settings } from '$lib/db';
|
||||||
import { Copy, MapPin, Trash2, Waypoints } from 'lucide-svelte';
|
import { Copy, MapPin, Plus, Trash2, Waypoints } from 'lucide-svelte';
|
||||||
import { ListLevel, ListWaypointItem, type ListItem } from './FileList';
|
import {
|
||||||
|
ListFileItem,
|
||||||
|
ListLevel,
|
||||||
|
ListTrackItem,
|
||||||
|
ListWaypointItem,
|
||||||
|
type ListItem
|
||||||
|
} from './FileList';
|
||||||
import { selectItem, selection } from './Selection';
|
import { selectItem, selection } from './Selection';
|
||||||
import { _ } from 'svelte-i18n';
|
import { _ } from 'svelte-i18n';
|
||||||
import { getContext } from 'svelte';
|
import { getContext } from 'svelte';
|
||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
import { gpxLayers } from '$lib/stores';
|
import { gpxLayers } from '$lib/stores';
|
||||||
|
import { Track, TrackSegment } from 'gpx';
|
||||||
|
|
||||||
export let item: ListItem;
|
export let item: ListItem;
|
||||||
export let label: string | undefined;
|
export let label: string | undefined;
|
||||||
|
|
||||||
let orientation = getContext<'vertical' | 'horizontal'>('orientation');
|
let orientation = getContext<'vertical' | 'horizontal'>('orientation');
|
||||||
|
|
||||||
|
const { verticalFileView } = settings;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
@@ -77,6 +86,41 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</ContextMenu.Trigger>
|
</ContextMenu.Trigger>
|
||||||
<ContextMenu.Content>
|
<ContextMenu.Content>
|
||||||
|
{#if $verticalFileView && $selection.size === 1}
|
||||||
|
{#if item instanceof ListFileItem}
|
||||||
|
<ContextMenu.Item
|
||||||
|
on:click={() =>
|
||||||
|
dbUtils.applyToFile(
|
||||||
|
item.getFileId(),
|
||||||
|
(file) => file.replaceTracks(file.trk.length, file.trk.length, [new Track()])[0]
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Plus size="16" class="mr-1" />
|
||||||
|
{$_('menu.new_track')}
|
||||||
|
</ContextMenu.Item>
|
||||||
|
<ContextMenu.Separator />
|
||||||
|
{:else if item instanceof ListTrackItem}
|
||||||
|
<ContextMenu.Item
|
||||||
|
on:click={() => {
|
||||||
|
let trackIndex = item.getTrackIndex();
|
||||||
|
dbUtils.applyToFile(
|
||||||
|
item.getFileId(),
|
||||||
|
(file) =>
|
||||||
|
file.replaceTrackSegments(
|
||||||
|
trackIndex,
|
||||||
|
file.trk[trackIndex].trkseg.length,
|
||||||
|
file.trk[trackIndex].trkseg.length,
|
||||||
|
[new TrackSegment()]
|
||||||
|
)[0]
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Plus size="16" class="mr-1" />
|
||||||
|
{$_('menu.new_segment')}
|
||||||
|
</ContextMenu.Item>
|
||||||
|
<ContextMenu.Separator />
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
{#if item.level !== ListLevel.WAYPOINTS}
|
{#if item.level !== ListLevel.WAYPOINTS}
|
||||||
<ContextMenu.Item on:click={dbUtils.duplicateSelection}>
|
<ContextMenu.Item on:click={dbUtils.duplicateSelection}>
|
||||||
<Copy size="16" class="mr-1" />
|
<Copy size="16" class="mr-1" />
|
||||||
|
@@ -9,7 +9,7 @@ import { toast } from "svelte-sonner";
|
|||||||
import { _ } from "svelte-i18n";
|
import { _ } from "svelte-i18n";
|
||||||
import { dbUtils, type GPXFileWithStatistics } from "$lib/db";
|
import { dbUtils, type GPXFileWithStatistics } from "$lib/db";
|
||||||
import { selection } from "$lib/components/file-list/Selection";
|
import { selection } from "$lib/components/file-list/Selection";
|
||||||
import { ListFileItem, ListTrackSegmentItem } from "$lib/components/file-list/FileList";
|
import { ListFileItem, ListTrackItem, ListTrackSegmentItem } from "$lib/components/file-list/FileList";
|
||||||
import { currentTool, Tool } from "$lib/stores";
|
import { currentTool, Tool } from "$lib/stores";
|
||||||
import { resetCursor, setCrosshairCursor, setGrabbingCursor } from "$lib/utils";
|
import { resetCursor, setCrosshairCursor, setGrabbingCursor } from "$lib/utils";
|
||||||
|
|
||||||
@@ -391,16 +391,25 @@ export class RoutingControls {
|
|||||||
|
|
||||||
if (!lastAnchor) {
|
if (!lastAnchor) {
|
||||||
dbUtils.applyToFile(this.fileId, (file) => {
|
dbUtils.applyToFile(this.fileId, (file) => {
|
||||||
|
let item = get(selection).getSelected()[0];
|
||||||
|
let trackIndex = file.trk.length > 0 ? file.trk.length - 1 : 0;
|
||||||
|
if (item instanceof ListTrackItem || item instanceof ListTrackSegmentItem) {
|
||||||
|
trackIndex = item.getTrackIndex();
|
||||||
|
}
|
||||||
|
let segmentIndex = file.trk[trackIndex].trkseg.length > 0 ? file.trk[trackIndex].trkseg.length - 1 : 0;
|
||||||
|
if (item instanceof ListTrackSegmentItem) {
|
||||||
|
segmentIndex = item.getSegmentIndex();
|
||||||
|
}
|
||||||
if (file.trk.length === 0) {
|
if (file.trk.length === 0) {
|
||||||
let track = new Track();
|
let track = new Track();
|
||||||
track = track.replaceTrackPoints(0, 0, 0, [newPoint]);
|
track = track.replaceTrackPoints(0, 0, 0, [newPoint]);
|
||||||
return file.replaceTracks(0, 0, [track])[0];
|
return file.replaceTracks(0, 0, [track])[0];
|
||||||
} else if (file.trk[0].trkseg.length === 0) {
|
} else if (file.trk[trackIndex].trkseg.length === 0) {
|
||||||
let segment = new TrackSegment();
|
let segment = new TrackSegment();
|
||||||
segment = segment.replaceTrackPoints(0, 0, [newPoint]);
|
segment = segment.replaceTrackPoints(0, 0, [newPoint]);
|
||||||
return file.replaceTrackSegments(0, 0, 0, [segment])[0];
|
return file.replaceTrackSegments(trackIndex, 0, 0, [segment])[0];
|
||||||
} else {
|
} else {
|
||||||
return file.replaceTrackPoints(0, 0, 0, 0, [newPoint]);
|
return file.replaceTrackPoints(trackIndex, segmentIndex, 0, 0, [newPoint]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
"menu": {
|
"menu": {
|
||||||
"new": "New",
|
"new": "New",
|
||||||
"new_filename": "new",
|
"new_filename": "new",
|
||||||
|
"new_track": "New track",
|
||||||
|
"new_segment": "New segment",
|
||||||
"load_desktop": "Load...",
|
"load_desktop": "Load...",
|
||||||
"load_drive": "Load from Google Drive...",
|
"load_drive": "Load from Google Drive...",
|
||||||
"duplicate": "Duplicate",
|
"duplicate": "Duplicate",
|
||||||
|
Reference in New Issue
Block a user