2024-06-08 17:19:22 +02:00
|
|
|
<script lang="ts" context="module">
|
2025-02-02 11:17:22 +01:00
|
|
|
enum MergeType {
|
|
|
|
|
TRACES = 'traces',
|
|
|
|
|
CONTENTS = 'contents',
|
|
|
|
|
}
|
2024-06-08 17:19:22 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
2025-10-05 19:34:05 +02:00
|
|
|
import { ListFileItem, ListTrackItem } from '$lib/components/file-list/file-list';
|
2025-02-02 11:17:22 +01:00
|
|
|
import Help from '$lib/components/Help.svelte';
|
|
|
|
|
import { Button } from '$lib/components/ui/button';
|
|
|
|
|
import { Label } from '$lib/components/ui/label/index.js';
|
|
|
|
|
import { Checkbox } from '$lib/components/ui/checkbox';
|
|
|
|
|
import * as RadioGroup from '$lib/components/ui/radio-group';
|
2025-06-21 21:07:36 +02:00
|
|
|
import { i18n } from '$lib/i18n.svelte';
|
|
|
|
|
import { Group } from '@lucide/svelte';
|
2025-02-02 11:17:22 +01:00
|
|
|
import { getURLForLanguage } from '$lib/utils';
|
|
|
|
|
import Shortcut from '$lib/components/Shortcut.svelte';
|
|
|
|
|
import { gpxStatistics } from '$lib/stores';
|
2025-10-05 19:34:05 +02:00
|
|
|
import { selection } from '$lib/logic/selection.svelte';
|
|
|
|
|
import { fileStateCollection } from '$lib/logic/file-state.svelte';
|
|
|
|
|
import { fileActions } from '$lib/logic/file-actions.svelte';
|
2024-06-08 17:19:22 +02:00
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
let props: {
|
|
|
|
|
class?: string;
|
|
|
|
|
} = $props();
|
2024-06-08 17:19:22 +02:00
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
let canMergeTraces = $derived.by(() => {
|
|
|
|
|
if (selection.value.size > 1) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (selection.value.size === 1) {
|
|
|
|
|
let selected = selection.value.getSelected()[0];
|
|
|
|
|
if (selected instanceof ListFileItem) {
|
|
|
|
|
let file = fileStateCollection.getFile(selected.getFileId());
|
|
|
|
|
if (file) {
|
|
|
|
|
return file.getSegments().length > 1;
|
|
|
|
|
}
|
|
|
|
|
} else if (selected instanceof ListTrackItem) {
|
|
|
|
|
let trackIndex = selected.getTrackIndex();
|
|
|
|
|
let file = fileStateCollection.getFile(selected.getFileId());
|
|
|
|
|
if (file && trackIndex < file.trk.length) {
|
|
|
|
|
return file.trk[trackIndex].getSegments().length > 1;
|
|
|
|
|
}
|
2025-02-02 11:17:22 +01:00
|
|
|
}
|
2025-10-05 19:34:05 +02:00
|
|
|
return false;
|
2025-02-02 11:17:22 +01:00
|
|
|
}
|
2025-10-05 19:34:05 +02:00
|
|
|
});
|
2024-06-08 17:19:22 +02:00
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
let canMergeContents = $derived(
|
|
|
|
|
selection.value.size > 1 &&
|
|
|
|
|
selection.value
|
|
|
|
|
.getSelected()
|
|
|
|
|
.some((item) => item instanceof ListFileItem || item instanceof ListTrackItem)
|
|
|
|
|
);
|
2024-06-08 17:19:22 +02:00
|
|
|
|
2025-10-05 19:34:05 +02:00
|
|
|
let removeGaps = $state(false);
|
|
|
|
|
let mergeType = $state(MergeType.TRACES);
|
2024-06-08 17:19:22 +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 ?? ''}">
|
2025-02-02 11:17:22 +01:00
|
|
|
<RadioGroup.Root bind:value={mergeType}>
|
|
|
|
|
<Label class="flex flex-row items-center gap-1.5 leading-5">
|
|
|
|
|
<RadioGroup.Item value={MergeType.TRACES} />
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('toolbar.merge.merge_traces')}
|
2025-02-02 11:17:22 +01:00
|
|
|
</Label>
|
|
|
|
|
<Label class="flex flex-row items-center gap-1.5 leading-5">
|
|
|
|
|
<RadioGroup.Item value={MergeType.CONTENTS} />
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('toolbar.merge.merge_contents')}
|
2025-02-02 11:17:22 +01:00
|
|
|
</Label>
|
|
|
|
|
</RadioGroup.Root>
|
|
|
|
|
{#if mergeType === MergeType.TRACES && $gpxStatistics.global.time.total > 0}
|
|
|
|
|
<div class="flex flex-row items-center gap-1.5">
|
|
|
|
|
<Checkbox id="remove-gaps" bind:checked={removeGaps} />
|
2025-06-21 21:07:36 +02:00
|
|
|
<Label for="remove-gaps">{i18n._('toolbar.merge.remove_gaps')}</Label>
|
2025-02-02 11:17:22 +01:00
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
class="whitespace-normal h-fit"
|
|
|
|
|
disabled={(mergeType === MergeType.TRACES && !canMergeTraces) ||
|
|
|
|
|
(mergeType === MergeType.CONTENTS && !canMergeContents)}
|
2025-06-21 21:07:36 +02:00
|
|
|
onclick={() => {
|
2025-10-05 19:34:05 +02:00
|
|
|
fileActions.mergeSelection(
|
2025-02-02 11:17:22 +01:00
|
|
|
mergeType === MergeType.TRACES,
|
|
|
|
|
mergeType === MergeType.TRACES && $gpxStatistics.global.time.total > 0 && removeGaps
|
|
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Group size="16" class="mr-1 shrink-0" />
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('toolbar.merge.merge_selection')}
|
2025-02-02 11:17:22 +01:00
|
|
|
</Button>
|
2025-06-21 21:07:36 +02:00
|
|
|
<Help link={getURLForLanguage(i18n.lang, '/help/toolbar/merge')}>
|
2025-02-02 11:17:22 +01:00
|
|
|
{#if mergeType === MergeType.TRACES && canMergeTraces}
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('toolbar.merge.help_merge_traces')}
|
2025-02-02 11:17:22 +01:00
|
|
|
{:else if mergeType === MergeType.TRACES && !canMergeTraces}
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('toolbar.merge.help_cannot_merge_traces')}
|
|
|
|
|
{i18n._('toolbar.merge.selection_tip').split('{KEYBOARD_SHORTCUT}')[0]}
|
2025-02-02 11:17:22 +01:00
|
|
|
<Shortcut
|
|
|
|
|
ctrl={true}
|
|
|
|
|
click={true}
|
|
|
|
|
class="inline-flex text-muted-foreground text-xs border rounded p-0.5 gap-0"
|
|
|
|
|
/>
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('toolbar.merge.selection_tip').split('{KEYBOARD_SHORTCUT}')[1]}
|
2025-02-02 11:17:22 +01:00
|
|
|
{:else if mergeType === MergeType.CONTENTS && canMergeContents}
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('toolbar.merge.help_merge_contents')}
|
2025-02-02 11:17:22 +01:00
|
|
|
{:else if mergeType === MergeType.CONTENTS && !canMergeContents}
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('toolbar.merge.help_cannot_merge_contents')}
|
|
|
|
|
{i18n._('toolbar.merge.selection_tip').split('{KEYBOARD_SHORTCUT}')[0]}
|
2025-02-02 11:17:22 +01:00
|
|
|
<Shortcut
|
|
|
|
|
ctrl={true}
|
|
|
|
|
click={true}
|
|
|
|
|
class="inline-flex text-muted-foreground text-xs border rounded p-0.5 gap-0"
|
|
|
|
|
/>
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('toolbar.merge.selection_tip').split('{KEYBOARD_SHORTCUT}')[1]}
|
2025-02-02 11:17:22 +01:00
|
|
|
{/if}
|
|
|
|
|
</Help>
|
2024-06-08 17:19:22 +02:00
|
|
|
</div>
|