Files
gpx.studio/website/src/lib/components/toolbar/tools/Extract.svelte

60 lines
2.1 KiB
Svelte
Raw Normal View History

2024-06-15 18:44:17 +02:00
<script lang="ts">
import { Button } from '$lib/components/ui/button';
2025-06-21 21:07:36 +02:00
import { Ungroup } from '@lucide/svelte';
import {
ListFileItem,
ListTrackItem,
ListTrackSegmentItem,
ListWaypointItem,
ListWaypointsItem,
2025-10-05 19:34:05 +02:00
} from '$lib/components/file-list/file-list';
import Help from '$lib/components/Help.svelte';
2025-06-21 21:07:36 +02:00
import { i18n } from '$lib/i18n.svelte';
import { getURLForLanguage } from '$lib/utils';
2025-10-17 23:54:45 +02:00
import { selection } from '$lib/logic/selection';
import { fileStateCollection } from '$lib/logic/file-state';
import { fileActions } from '$lib/logic/file-actions';
2024-06-15 18:44:17 +02:00
2025-10-05 19:34:05 +02:00
let props: {
class?: string;
} = $props();
let validSelection = $derived(
2025-10-18 16:10:08 +02:00
$selection.size > 0 &&
$selection.getSelected().every((item) => {
2025-10-05 19:34:05 +02:00
if (
item instanceof ListWaypointsItem ||
item instanceof ListWaypointItem ||
item instanceof ListTrackSegmentItem
) {
return false;
}
let file = fileStateCollection.getFile(item.getFileId());
if (file) {
if (item instanceof ListFileItem) {
return file.getSegments().length > 1;
} else if (item instanceof ListTrackItem) {
if (item.getTrackIndex() < file.trk.length) {
return file.trk[item.getTrackIndex()].getSegments().length > 1;
}
}
}
2025-10-05 19:34:05 +02:00
return false;
})
);
2024-06-15 18:44:17 +02:00
</script>
2025-10-05 19:34:05 +02:00
<div class="flex flex-col gap-3 w-full max-w-80 {props.class ?? ''}">
<Button variant="outline" disabled={!validSelection} onclick={fileActions.extractSelection}>
2025-11-10 11:51:16 +01:00
<Ungroup size="16" />
2025-06-21 21:07:36 +02:00
{i18n._('toolbar.extract.button')}
</Button>
2025-06-21 21:07:36 +02:00
<Help link={getURLForLanguage(i18n.lang, '/help/toolbar/extract')}>
{#if validSelection}
2025-06-21 21:07:36 +02:00
{i18n._('toolbar.extract.help')}
{:else}
2025-06-21 21:07:36 +02:00
{i18n._('toolbar.extract.help_invalid_selection')}
{/if}
</Help>
2024-06-15 18:44:17 +02:00
</div>