Files
gpx.studio/website/src/lib/components/file-list/FileList.svelte

103 lines
4.0 KiB
Svelte
Raw Normal View History

2024-05-16 18:18:42 +02:00
<script lang="ts">
import { ScrollArea } from '$lib/components/ui/scroll-area/index';
import * as ContextMenu from '$lib/components/ui/context-menu';
import FileListNode from './FileListNode.svelte';
import { setContext } from 'svelte';
2025-10-05 19:34:05 +02:00
import { ListFileItem, ListLevel, ListRootItem, allowedPastes } from './file-list';
2025-06-21 21:07:36 +02:00
import { ClipboardPaste, FileStack, Plus } from '@lucide/svelte';
import Shortcut from '$lib/components/Shortcut.svelte';
2025-06-21 21:07:36 +02:00
import { i18n } from '$lib/i18n.svelte';
2025-10-17 23:54:45 +02:00
import { settings } from '$lib/logic/settings';
import { fileStateCollection } from '$lib/logic/file-state';
import { createFile, pasteSelection } from '$lib/logic/file-actions';
import { selection } from '$lib/logic/selection';
2024-05-21 13:22:14 +02:00
2025-06-21 21:07:36 +02:00
let {
orientation,
recursive = false,
class: className = '',
style = '',
}: {
orientation: 'vertical' | 'horizontal';
recursive?: boolean;
class?: string;
style?: string;
} = $props();
2024-05-21 13:22:14 +02:00
setContext('orientation', orientation);
setContext('recursive', recursive);
2024-05-24 20:23:49 +02:00
const { treeFileView } = settings;
2024-05-24 20:23:49 +02:00
2025-10-17 23:54:45 +02:00
// treeFileView.subscribe(($vertical) => {
// if ($vertical) {
// selection.update(($selection) => {
// $selection.forEach((item) => {
// if ($selection.hasAnyChildren(item, false)) {
// $selection.toggle(item);
// }
// });
// return $selection;
// });
// } else {
// selection.update(($selection) => {
// $selection.forEach((item) => {
// if (!(item instanceof ListFileItem)) {
// $selection.toggle(item);
// $selection.set(new ListFileItem(item.getFileId()), true);
// }
// });
// return $selection;
// });
// }
// });
2024-05-16 18:18:42 +02:00
</script>
<ScrollArea
class="shrink-0 {orientation === 'vertical' ? 'p-0 pr-3' : 'h-10 px-1'}"
{orientation}
scrollbarXClasses={orientation === 'vertical' ? '' : 'mt-1 h-2'}
scrollbarYClasses={orientation === 'vertical' ? '' : ''}
>
<div
class="flex {orientation === 'vertical'
? 'flex-col py-1 pl-1 min-h-screen'
2025-06-21 21:07:36 +02:00
: 'flex-row'} {className ?? ''}"
{style}
>
2025-10-17 23:54:45 +02:00
<FileListNode node={$fileStateCollection} item={new ListRootItem()} />
{#if orientation === 'vertical'}
<ContextMenu.Root>
<ContextMenu.Trigger class="grow" />
<ContextMenu.Content>
2025-06-21 21:07:36 +02:00
<ContextMenu.Item onclick={createFile}>
<Plus size="16" class="mr-1" />
2025-06-21 21:07:36 +02:00
{i18n._('menu.new_file')}
<Shortcut key="+" ctrl={true} />
</ContextMenu.Item>
<ContextMenu.Separator />
2025-10-17 23:54:45 +02:00
<ContextMenu.Item
onclick={() => selection.selectAll()}
disabled={$fileStateCollection.size === 0}
>
<FileStack size="16" class="mr-1" />
2025-06-21 21:07:36 +02:00
{i18n._('menu.select_all')}
<Shortcut key="A" ctrl={true} />
</ContextMenu.Item>
<ContextMenu.Separator />
<ContextMenu.Item
2025-10-17 23:54:45 +02:00
disabled={selection.copied === undefined ||
selection.copied.length === 0 ||
!allowedPastes[selection.copied[0].level].includes(ListLevel.ROOT)}
2025-06-21 21:07:36 +02:00
onclick={pasteSelection}
>
<ClipboardPaste size="16" class="mr-1" />
2025-06-21 21:07:36 +02:00
{i18n._('menu.paste')}
<Shortcut key="V" ctrl={true} />
</ContextMenu.Item>
</ContextMenu.Content>
</ContextMenu.Root>
{/if}
</div>
2024-05-16 18:18:42 +02:00
</ScrollArea>