2024-05-16 18:18:42 +02:00
|
|
|
<script lang="ts">
|
2025-02-02 11:17:22 +01:00
|
|
|
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';
|
2025-02-02 11:17:22 +01:00
|
|
|
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';
|
2025-10-18 09:36:55 +02:00
|
|
|
import { selection, copied } 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
|
|
|
|
2025-02-02 11:17:22 +01:00
|
|
|
setContext('orientation', orientation);
|
|
|
|
|
setContext('recursive', recursive);
|
2024-05-24 20:23:49 +02:00
|
|
|
|
2025-02-02 11:17:22 +01: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>
|
|
|
|
|
|
2024-05-21 17:47:08 +02:00
|
|
|
<ScrollArea
|
2025-02-02 11:17:22 +01:00
|
|
|
class="shrink-0 {orientation === 'vertical' ? 'p-0 pr-3' : 'h-10 px-1'}"
|
|
|
|
|
{orientation}
|
|
|
|
|
scrollbarXClasses={orientation === 'vertical' ? '' : 'mt-1 h-2'}
|
|
|
|
|
scrollbarYClasses={orientation === 'vertical' ? '' : ''}
|
2024-05-21 17:47:08 +02:00
|
|
|
>
|
2025-02-02 11:17:22 +01:00
|
|
|
<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-02-02 11:17:22 +01:00
|
|
|
>
|
2025-10-17 23:54:45 +02:00
|
|
|
<FileListNode node={$fileStateCollection} item={new ListRootItem()} />
|
2025-02-02 11:17:22 +01:00
|
|
|
{#if orientation === 'vertical'}
|
|
|
|
|
<ContextMenu.Root>
|
|
|
|
|
<ContextMenu.Trigger class="grow" />
|
|
|
|
|
<ContextMenu.Content>
|
2025-06-21 21:07:36 +02:00
|
|
|
<ContextMenu.Item onclick={createFile}>
|
2025-02-02 11:17:22 +01:00
|
|
|
<Plus size="16" class="mr-1" />
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('menu.new_file')}
|
2025-02-02 11:17:22 +01:00
|
|
|
<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}
|
|
|
|
|
>
|
2025-02-02 11:17:22 +01:00
|
|
|
<FileStack size="16" class="mr-1" />
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('menu.select_all')}
|
2025-02-02 11:17:22 +01:00
|
|
|
<Shortcut key="A" ctrl={true} />
|
|
|
|
|
</ContextMenu.Item>
|
|
|
|
|
<ContextMenu.Separator />
|
|
|
|
|
<ContextMenu.Item
|
2025-10-18 09:36:55 +02:00
|
|
|
disabled={$copied === undefined ||
|
|
|
|
|
$copied.length === 0 ||
|
|
|
|
|
!allowedPastes[$copied[0].level].includes(ListLevel.ROOT)}
|
2025-06-21 21:07:36 +02:00
|
|
|
onclick={pasteSelection}
|
2025-02-02 11:17:22 +01:00
|
|
|
>
|
|
|
|
|
<ClipboardPaste size="16" class="mr-1" />
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('menu.paste')}
|
2025-02-02 11:17:22 +01:00
|
|
|
<Shortcut key="V" ctrl={true} />
|
|
|
|
|
</ContextMenu.Item>
|
|
|
|
|
</ContextMenu.Content>
|
|
|
|
|
</ContextMenu.Root>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
2024-05-16 18:18:42 +02:00
|
|
|
</ScrollArea>
|