2024-05-21 13:22:14 +02:00
|
|
|
<script lang="ts">
|
2024-05-21 17:47:08 +02:00
|
|
|
import { Button } from '$lib/components/ui/button';
|
|
|
|
import * as ContextMenu from '$lib/components/ui/context-menu';
|
|
|
|
import Shortcut from '$lib/components/Shortcut.svelte';
|
2024-06-13 19:11:54 +02:00
|
|
|
import { dbUtils, fileObservers, settings } from '$lib/db';
|
|
|
|
import { Copy, MapPin, Plus, Trash2, Waypoints } from 'lucide-svelte';
|
|
|
|
import {
|
|
|
|
ListFileItem,
|
|
|
|
ListLevel,
|
|
|
|
ListTrackItem,
|
|
|
|
ListWaypointItem,
|
|
|
|
type ListItem
|
|
|
|
} from './FileList';
|
2024-05-23 14:44:07 +02:00
|
|
|
import { selectItem, selection } from './Selection';
|
2024-05-21 17:47:08 +02:00
|
|
|
import { _ } from 'svelte-i18n';
|
2024-05-21 13:22:14 +02:00
|
|
|
import { getContext } from 'svelte';
|
2024-05-23 14:44:07 +02:00
|
|
|
import { get } from 'svelte/store';
|
2024-05-24 13:16:41 +02:00
|
|
|
import { gpxLayers } from '$lib/stores';
|
2024-06-13 19:11:54 +02:00
|
|
|
import { Track, TrackSegment } from 'gpx';
|
2024-05-21 13:22:14 +02:00
|
|
|
|
2024-05-22 16:05:31 +02:00
|
|
|
export let item: ListItem;
|
2024-05-21 13:22:14 +02:00
|
|
|
export let label: string | undefined;
|
|
|
|
|
2024-05-21 17:47:08 +02:00
|
|
|
let orientation = getContext<'vertical' | 'horizontal'>('orientation');
|
2024-06-13 19:11:54 +02:00
|
|
|
|
|
|
|
const { verticalFileView } = settings;
|
2024-05-21 13:22:14 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
|
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
2024-05-23 14:44:07 +02:00
|
|
|
<ContextMenu.Root
|
|
|
|
onOpenChange={(open) => {
|
|
|
|
if (open && !get(selection).has(item)) {
|
|
|
|
selectItem(item);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
2024-05-21 17:47:08 +02:00
|
|
|
<ContextMenu.Trigger class="grow truncate">
|
|
|
|
<Button
|
|
|
|
variant="ghost"
|
|
|
|
class="w-full p-0 px-1 border-none focus-visible:ring-0 focus-visible:ring-offset-0 {orientation ===
|
|
|
|
'vertical'
|
|
|
|
? 'h-fit'
|
|
|
|
: 'h-9 px-1.5 shadow-md'}"
|
|
|
|
>
|
|
|
|
<span
|
2024-05-24 13:16:41 +02:00
|
|
|
class="w-full text-left truncate py-1 flex flex-row items-center"
|
2024-05-21 17:47:08 +02:00
|
|
|
on:contextmenu={(e) => {
|
|
|
|
if (e.ctrlKey) {
|
|
|
|
// Add to selection instead of opening context menu
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2024-05-22 16:05:31 +02:00
|
|
|
$selection.toggle(item);
|
2024-05-21 17:47:08 +02:00
|
|
|
}
|
|
|
|
}}
|
2024-05-24 13:16:41 +02:00
|
|
|
on:mouseenter={() => {
|
|
|
|
if (item instanceof ListWaypointItem) {
|
2024-05-24 20:23:49 +02:00
|
|
|
let layer = gpxLayers.get(item.getFileId());
|
2024-05-24 13:16:41 +02:00
|
|
|
let fileStore = get(fileObservers).get(item.getFileId());
|
|
|
|
if (layer && fileStore) {
|
|
|
|
let waypoint = get(fileStore)?.file.wpt[item.getWaypointIndex()];
|
|
|
|
if (waypoint) {
|
|
|
|
layer.showWaypointPopup(waypoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
on:mouseleave={() => {
|
|
|
|
if (item instanceof ListWaypointItem) {
|
2024-05-24 20:23:49 +02:00
|
|
|
let layer = gpxLayers.get(item.getFileId());
|
2024-05-24 13:16:41 +02:00
|
|
|
if (layer) {
|
|
|
|
layer.hideWaypointPopup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}}
|
2024-05-21 17:47:08 +02:00
|
|
|
>
|
2024-05-24 13:16:41 +02:00
|
|
|
{#if item.level === ListLevel.SEGMENT}
|
|
|
|
<Waypoints size="16" class="mr-1 shrink-0" />
|
|
|
|
{:else if item.level === ListLevel.WAYPOINT}
|
|
|
|
<MapPin size="16" class="mr-1 shrink-0" />
|
|
|
|
{/if}
|
|
|
|
<span class="grow truncate">
|
|
|
|
{label}
|
|
|
|
</span>
|
2024-05-21 17:47:08 +02:00
|
|
|
</span>
|
|
|
|
</Button>
|
|
|
|
</ContextMenu.Trigger>
|
|
|
|
<ContextMenu.Content>
|
2024-06-13 19:11:54 +02:00
|
|
|
{#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}
|
2024-05-24 13:16:41 +02:00
|
|
|
{#if item.level !== ListLevel.WAYPOINTS}
|
2024-05-23 14:44:07 +02:00
|
|
|
<ContextMenu.Item on:click={dbUtils.duplicateSelection}>
|
|
|
|
<Copy size="16" class="mr-1" />
|
|
|
|
{$_('menu.duplicate')}
|
|
|
|
<Shortcut key="D" ctrl={true} /></ContextMenu.Item
|
|
|
|
>
|
|
|
|
<ContextMenu.Separator />
|
|
|
|
{/if}
|
2024-05-22 16:05:31 +02:00
|
|
|
<ContextMenu.Item on:click={dbUtils.deleteSelection}
|
2024-05-21 17:47:08 +02:00
|
|
|
><Trash2 size="16" class="mr-1" />
|
|
|
|
{$_('menu.delete')}
|
|
|
|
<Shortcut key="⌫" ctrl={true} /></ContextMenu.Item
|
|
|
|
>
|
|
|
|
</ContextMenu.Content>
|
|
|
|
</ContextMenu.Root>
|