fix tools

This commit is contained in:
vcoppe
2025-10-18 16:10:08 +02:00
parent 9fa8fe5767
commit c59cd66141
60 changed files with 1289 additions and 1161 deletions

View File

@@ -7,16 +7,16 @@
import { Slider } from '$lib/components/ui/slider';
import * as Select from '$lib/components/ui/select';
import { Separator } from '$lib/components/ui/separator';
import { gpxStatistics, slicedGPXStatistics } from '$lib/stores';
import { map } from '$lib/components/map/map';
import { get } from 'svelte/store';
import { i18n } from '$lib/i18n.svelte';
import { onDestroy, tick } from 'svelte';
import { Crop } from '@lucide/svelte';
import { dbUtils } from '$lib/db';
import { SplitControls } from './split-controls';
import { getURLForLanguage } from '$lib/utils';
import { selection } from '$lib/logic/selection';
import { fileActions } from '$lib/logic/file-actions';
import { gpxStatistics, slicedGPXStatistics } from '$lib/logic/statistics';
let props: {
class?: string;
@@ -26,16 +26,16 @@
let canCrop = $state(false);
$effect(() => {
if (map.current) {
if ($map) {
if (splitControls) {
splitControls.destroy();
}
splitControls = new SplitControls(map.current);
splitControls = new SplitControls($map);
}
});
let validSelection = $derived(
selection.value.hasAnyChildren(new ListRootItem(), true, ['waypoints']) &&
$selection.hasAnyChildren(new ListRootItem(), true, ['waypoints']) &&
$gpxStatistics.local.points.length > 0
);
@@ -120,7 +120,7 @@
<Button
variant="outline"
disabled={!validSelection || !canCrop}
onclick={() => dbUtils.cropSelection(sliderValues[0], sliderValues[1])}
onclick={() => fileActions.cropSelection(sliderValues[0], sliderValues[1])}
>
<Crop size="16" class="mr-1" />{i18n._('toolbar.scissors.crop')}
</Button>
@@ -129,9 +129,9 @@
<span class="shrink-0">
{i18n._('toolbar.scissors.split_as')}
</span>
<Select.Root bind:value={splitAs.current} type="single">
<Select.Root bind:value={$splitAs} type="single">
<Select.Trigger class="h-8 w-fit grow">
{i18n._('gpx.' + splitAs)}
{i18n._('gpx.' + $splitAs)}
</Select.Trigger>
<Select.Content>
{#each Object.values(SplitType) as splitType}

View File

@@ -1,12 +1,14 @@
import { TrackPoint, TrackSegment } from 'gpx';
import mapboxgl from 'mapbox-gl';
import { dbUtils, getFile } from '$lib/db';
import { ListTrackSegmentItem } from '$lib/components/file-list/file-list';
import { gpxStatistics } from '$lib/stores';
import { tool, Tool } from '$lib/components/toolbar/tools';
import { currentTool, Tool } from '$lib/components/toolbar/tools';
import { splitAs } from '$lib/components/toolbar/tools/scissors/scissors';
import { Scissors } from 'lucide-static';
import { selection } from '$lib/logic/selection';
import { gpxStatistics } from '$lib/logic/statistics';
import { get } from 'svelte/store';
import { fileStateCollection } from '$lib/logic/file-state';
import { fileActions } from '$lib/logic/file-actions';
export class SplitControls {
active: boolean = false;
@@ -22,13 +24,12 @@ export class SplitControls {
this.map = map;
this.unsubscribes.push(gpxStatistics.subscribe(this.addIfNeeded.bind(this)));
$effect(() => {
tool.current, selection.value, this.addIfNeeded.bind(this);
});
this.unsubscribes.push(currentTool.subscribe(this.addIfNeeded.bind(this)));
this.unsubscribes.push(selection.subscribe(this.addIfNeeded.bind(this)));
}
addIfNeeded() {
let scissors = tool.current === Tool.SCISSORS;
let scissors = get(currentTool) === Tool.SCISSORS;
if (!scissors) {
if (this.active) {
this.remove();
@@ -54,12 +55,12 @@ export class SplitControls {
// Update the markers when the files change
let controlIndex = 0;
selection.applyToOrderedSelectedItemsFromFile((fileId, level, items) => {
let file = getFile(fileId);
let file = fileStateCollection.getFile(fileId);
if (file) {
file.forEachSegment((segment, trackIndex, segmentIndex) => {
if (
selection.value.hasAnyParent(
get(selection).hasAnyParent(
new ListTrackSegmentItem(fileId, trackIndex, segmentIndex)
)
) {
@@ -163,8 +164,8 @@ export class SplitControls {
marker.getElement().addEventListener('click', (e) => {
e.stopPropagation();
dbUtils.split(
splitAs.current,
fileActions.split(
get(splitAs),
control.fileId,
control.trackIndex,
control.segmentIndex,