rework file actions, closes #3

This commit is contained in:
vcoppe
2024-07-01 11:08:28 +02:00
parent a96d911f36
commit 8e446ec74a
4 changed files with 50 additions and 20 deletions

View File

@@ -10,7 +10,6 @@
Undo2,
Redo2,
Trash2,
Upload,
Heart,
Map,
Layers2,
@@ -38,7 +37,10 @@
ClipboardCopy,
Scissors,
ClipboardPaste,
PaintBucket
PaintBucket,
FolderOpen,
FileStack,
FileX
} from 'lucide-svelte';
import {
@@ -149,8 +151,8 @@
</Menubar.Item>
<Menubar.Separator />
<Menubar.Item on:click={triggerFileInput}>
<Upload size="16" class="mr-1" />
{$_('menu.load_desktop')}
<FolderOpen size="16" class="mr-1" />
{$_('menu.open')}
<Shortcut key="O" ctrl={true} />
</Menubar.Item>
<Menubar.Separator />
@@ -160,6 +162,17 @@
<Shortcut key="D" ctrl={true} />
</Menubar.Item>
<Menubar.Separator />
<Menubar.Item on:click={dbUtils.deleteSelectedFiles} disabled={$selection.size == 0}>
<FileX size="16" class="mr-1" />
{$_('menu.close')}
<Shortcut key="⌫" ctrl={true} />
</Menubar.Item>
<Menubar.Item on:click={dbUtils.deleteAllFiles} disabled={$fileObservers.size == 0}>
<FileX size="16" class="mr-1" />
{$_('menu.close_all')}
<Shortcut key="⌫" ctrl={true} shift={true} />
</Menubar.Item>
<Menubar.Separator />
<Menubar.Item
on:click={() => ($exportState = ExportState.SELECTION)}
disabled={$selection.size == 0}
@@ -236,7 +249,7 @@
</Menubar.Item>
<Menubar.Separator />
<Menubar.Item on:click={selectAll}>
<span class="w-4 mr-1"></span>
<FileStack size="16" class="mr-1" />
{$_('menu.select_all')}
<Shortcut key="A" ctrl={true} />
</Menubar.Item>
@@ -270,15 +283,6 @@
{$_('menu.delete')}
<Shortcut key="⌫" ctrl={true} />
</Menubar.Item>
<Menubar.Item
class="text-destructive data-[highlighted]:text-destructive"
on:click={dbUtils.deleteAllFiles}
disabled={$fileObservers.size == 0}
>
<Trash2 size="16" class="mr-1" />
{$_('menu.delete_all')}
<Shortcut key="⌫" ctrl={true} shift={true} />
</Menubar.Item>
</Menubar.Content>
</Menubar.Menu>
<Menubar.Menu>
@@ -459,7 +463,6 @@
<svelte:window
on:keydown={(e) => {
console.log(e);
let targetInput =
e.target.tagName === 'INPUT' ||
e.target.tagName === 'TEXTAREA' ||

View File

@@ -15,7 +15,9 @@
EyeOff,
ClipboardCopy,
ClipboardPaste,
Scissors
Scissors,
FileStack,
FileX
} from 'lucide-svelte';
import {
ListFileItem,
@@ -30,6 +32,7 @@
copySelection,
cutSelection,
pasteSelection,
selectAll,
selectItem,
selection
} from './Selection';
@@ -261,6 +264,14 @@
<ContextMenu.Separator />
{/if}
{/if}
{#if item.level !== ListLevel.WAYPOINTS}
<ContextMenu.Item on:click={selectAll}>
<FileStack size="16" class="mr-1" />
{$_('menu.select_all')}
<Shortcut key="A" ctrl={true} />
</ContextMenu.Item>
<ContextMenu.Separator />
{/if}
{#if $verticalFileView}
<ContextMenu.Item on:click={dbUtils.duplicateSelection}>
<Copy size="16" class="mr-1" />
@@ -292,8 +303,13 @@
<ContextMenu.Separator />
{/if}
<ContextMenu.Item on:click={dbUtils.deleteSelection}>
<Trash2 size="16" class="mr-1" />
{$_('menu.delete')}
{#if item instanceof ListFileItem}
<FileX size="16" class="mr-1" />
{$_('menu.close')}
{:else}
<Trash2 size="16" class="mr-1" />
{$_('menu.delete')}
{/if}
<Shortcut key="⌫" ctrl={true} />
</ContextMenu.Item>
</ContextMenu.Content>

View File

@@ -908,6 +908,16 @@ export const dbUtils = {
});
});
},
deleteSelectedFiles: () => {
if (get(selection).size === 0) {
return;
}
applyGlobal((draft) => {
applyToOrderedSelectedItemsFromFile((fileId, level, items) => {
draft.delete(fileId);
});
});
},
deleteAllFiles: () => {
applyGlobal((draft) => {
draft.clear();

View File

@@ -9,8 +9,10 @@
"new_file": "New file",
"new_track": "New track",
"new_segment": "New segment",
"load_desktop": "Load...",
"open": "Open...",
"duplicate": "Duplicate",
"close": "Close",
"close_all": "Close all",
"copy": "Copy",
"paste": "Paste",
"cut": "Cut",
@@ -24,7 +26,6 @@
"undo": "Undo",
"redo": "Redo",
"delete": "Delete",
"delete_all": "Delete all",
"select_all": "Select all",
"view": "View",
"elevation_profile": "Elevation profile",