Add interface languages and improve themes and workspace controls for 0.1.36
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { t } from "$lib/i18n";
|
||||
import { onMount, tick, untrack } from "svelte";
|
||||
import { createNote, noteTemplates, type NoteTemplate } from "$lib/workspace/templates";
|
||||
import { confirm } from "@tauri-apps/plugin-dialog";
|
||||
@@ -19,7 +20,6 @@
|
||||
import { moveMarks, replayMoveMarks } from "$lib/workspace/treeMoveHistory";
|
||||
import { actionEntries, selectionRoots, setSelectedMarks, runTreeActions } from "$lib/workspace/treeActions";
|
||||
import {
|
||||
dropHint,
|
||||
dropPlaceAt,
|
||||
joinRel,
|
||||
parentRel,
|
||||
@@ -478,7 +478,7 @@
|
||||
if (workspaceRoot !== operationRoot || error) return;
|
||||
}
|
||||
} else {
|
||||
const typed = await requestText("File name, including any extension", "Untitled");
|
||||
const typed = await requestText($t("File name, including any extension"), "Untitled");
|
||||
if (!typed) {
|
||||
return;
|
||||
}
|
||||
@@ -685,10 +685,10 @@
|
||||
async function deleteEntries(entries: TreeEntry[]) {
|
||||
const roots = selectionRoots(entries);
|
||||
const message = entries.length === 1
|
||||
? `Permanently delete ${entries[0].name}${entries[0].kind === "folder" ? " and everything inside it" : ""}?`
|
||||
: `Permanently delete ${entries.length} selected items${entries.some(entry => entry.kind === "folder") ? " and all contents of selected folders" : ""}?\n\n${roots.map(entry => entry.rel_path).join("\n")}`;
|
||||
? $t(entries[0].kind === "folder" ? "Permanently delete {name} and everything inside it?" : "Permanently delete {name}?", { name: entries[0].name })
|
||||
: $t(entries.some(entry => entry.kind === "folder") ? "Permanently delete {count} selected items and all contents of selected folders?" : "Permanently delete {count} selected items?", { count: entries.length }) + "\n\n" + roots.map(entry => entry.rel_path).join("\n");
|
||||
try {
|
||||
if (!await confirm(message, { title: "Delete from disk", kind: "warning" })) return;
|
||||
if (!await confirm(message, { title: $t("Delete from disk"), kind: "warning" })) return;
|
||||
const result = await runTreeActions(roots, async entry => {
|
||||
await workspaceDelete(entry.rel_path);
|
||||
forgetFolder(entry.rel_path);
|
||||
@@ -696,7 +696,7 @@
|
||||
});
|
||||
for (const parent of new Set(roots.map(entry => parentRel(entry.rel_path)))) await load(parent);
|
||||
error = result.failures.length ? result.failures.join("\n") : null;
|
||||
onStatus?.(`Deleted ${result.completed.length} of ${roots.length} items`);
|
||||
onStatus?.($t("Deleted {count} of {total} items", { count: result.completed.length, total: roots.length }));
|
||||
} catch (err) {
|
||||
error = err instanceof Error ? err.message : String(err);
|
||||
}
|
||||
@@ -713,16 +713,16 @@
|
||||
return [
|
||||
{
|
||||
kind: "action",
|
||||
label: "New file…",
|
||||
label: $t("New file…"),
|
||||
icon: "file-plus",
|
||||
run: () => { void createIn(parent, "file"); },
|
||||
},
|
||||
...(templates.length || onManageTemplates ? [{ kind: "group" as const, label: "New note", icon: "file-plus" as const, run: () => { void fromTemplate(); }, items: [
|
||||
{ kind: "action" as const, label: "Blank note", icon: "file-plus" as const, run: () => { void fromTemplate(); } },
|
||||
...(templates.length || onManageTemplates ? [{ kind: "group" as const, label: $t("New note"), icon: "file-plus" as const, run: () => { void fromTemplate(); }, items: [
|
||||
{ kind: "action" as const, label: $t("Blank note"), icon: "file-plus" as const, run: () => { void fromTemplate(); } },
|
||||
...templates.map(template => ({ kind: "action" as const, label: template.name, icon: "file-plus" as const, run: () => { void fromTemplate(template); } })),
|
||||
...(onManageTemplates ? [{ kind: "sep" as const }, { kind: "action" as const, label: "Manage templates…", icon: "copy" as const, run: onManageTemplates }] : []),
|
||||
] }] : [{ kind: "action" as const, label: "New note", icon: "file-plus" as const, run: () => { void fromTemplate(); } }]),
|
||||
{ kind: "action", label: "New folder", icon: "folder-plus", run: () => { void createIn(parent, "folder"); } },
|
||||
...(onManageTemplates ? [{ kind: "sep" as const }, { kind: "action" as const, label: $t("Manage templates…"), icon: "copy" as const, run: onManageTemplates }] : []),
|
||||
] }] : [{ kind: "action" as const, label: $t("New note"), icon: "file-plus" as const, run: () => { void fromTemplate(); } }]),
|
||||
{ kind: "action", label: $t("New folder"), icon: "folder-plus", run: () => { void createIn(parent, "folder"); } },
|
||||
...$pluginDocumentTypes.filter(item => item.type.create).map(({ owner, type }): MenuItem => ({
|
||||
kind: "action", label: type.create!.label, icon: type.icon === "kanban" ? "kanban" : "file-plus",
|
||||
run: () => { void (async () => {
|
||||
@@ -730,7 +730,7 @@
|
||||
const typed = await requestText(create.label, create.defaultName);
|
||||
if (typed === null) return;
|
||||
const name = typed.trim().replace(new RegExp(`\\.${create.extension}$`, "i"), "");
|
||||
if (!name || name.length > 100 || /[<>:"/\\|?*\x00-\x1f]/.test(name) || /[. ]$/.test(name) || /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(name)) { error = "Enter a valid document name."; return; }
|
||||
if (!name || name.length > 100 || /[<>:"/\\|?*\x00-\x1f]/.test(name) || /[. ]$/.test(name) || /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(name)) { error = $t("Enter a valid document name."); return; }
|
||||
const fileName = `${name}.${create.extension}`;
|
||||
const path = joinRel(parent, fileName);
|
||||
try {
|
||||
@@ -746,11 +746,11 @@
|
||||
|
||||
function folderActions(parent: string): MenuItem[] {
|
||||
return [
|
||||
{ kind: "action", label: "Open in terminal", icon: "terminal", run: () => { void workspaceOpenTerminal(parent).catch(reason => error = String(reason)); } },
|
||||
{ kind: "action", label: "Paste", icon: "paste", disabled: !clipboard || clipboard.root !== workspaceRoot || moving, run: () => { void pasteEntries(parent); } },
|
||||
{ kind: "action", label: $t("Open in terminal"), icon: "terminal", run: () => { void workspaceOpenTerminal(parent).catch(reason => error = String(reason)); } },
|
||||
{ kind: "action", label: $t("Paste"), icon: "paste", disabled: !clipboard || clipboard.root !== workspaceRoot || moving, run: () => { void pasteEntries(parent); } },
|
||||
{ kind: "sep" },
|
||||
{ kind: "action", label: undoMoves.at(-1)?.action === "rename" ? "Undo rename" : "Undo file move", icon: "undo", disabled: !undoMoves.length || moving, run: () => { void replayMoves(); } },
|
||||
{ kind: "action", label: redoMoves.at(-1)?.action === "rename" ? "Redo rename" : "Redo file move", icon: "redo", disabled: !redoMoves.length || moving, run: () => { void replayMoves(true); } },
|
||||
{ kind: "action", label: undoMoves.at(-1)?.action === "rename" ? $t("Undo rename") : $t("Undo file move"), icon: "undo", disabled: !undoMoves.length || moving, run: () => { void replayMoves(); } },
|
||||
{ kind: "action", label: redoMoves.at(-1)?.action === "rename" ? $t("Redo rename") : $t("Redo file move"), icon: "redo", disabled: !redoMoves.length || moving, run: () => { void replayMoves(true); } },
|
||||
];
|
||||
}
|
||||
|
||||
@@ -763,7 +763,7 @@
|
||||
{ kind: "sep" },
|
||||
{
|
||||
kind: "action",
|
||||
label: "Show in Explorer",
|
||||
label: $t("Show in Explorer"),
|
||||
icon: "folder",
|
||||
run: () => {
|
||||
void workspaceReveal("").catch((err) => {
|
||||
@@ -784,25 +784,25 @@
|
||||
return [
|
||||
...createItems,
|
||||
...(!multiple && entry.kind === "file" && /\.md$/i.test(entry.name) && onSaveTemplate ? [
|
||||
{ kind: "action" as const, label: "Save as template", icon: "copy" as const, run: () => onSaveTemplate?.(entry) },
|
||||
{ kind: "action" as const, label: $t("Save as template"), icon: "copy" as const, run: () => onSaveTemplate?.(entry) },
|
||||
] : []),
|
||||
...(!multiple && entry.kind === "file" ? [
|
||||
{ kind: "action" as const, label: "Open in new tab", icon: "file-plus" as const, run: () => onOpenFile(entry, true) },
|
||||
{ kind: "action" as const, label: "Open in default app", icon: "external" as const, run: () => { void workspaceOpenDefault(entry.rel_path).catch(reason => error = String(reason)); } },
|
||||
{ kind: "action" as const, label: $t("Open in new tab"), icon: "file-plus" as const, run: () => onOpenFile(entry, true) },
|
||||
{ kind: "action" as const, label: $t("Open in default app"), icon: "external" as const, run: () => { void workspaceOpenDefault(entry.rel_path).catch(reason => error = String(reason)); } },
|
||||
] : []),
|
||||
...folderActions(entry.kind === "folder" ? entry.rel_path : parentRel(entry.rel_path)),
|
||||
{ kind: "sep" },
|
||||
{ kind: "action", label: "Cut", icon: "cut", run: () => { clipboard = { root: workspaceRoot, paths: selectionRoots(entries).map(item => item.rel_path), cut: true }; } },
|
||||
{ kind: "action", label: "Copy", icon: "copy", run: () => { clipboard = { root: workspaceRoot, paths: selectionRoots(entries).map(item => item.rel_path), cut: false }; } },
|
||||
{ kind: "action", label: $t("Cut"), icon: "cut", run: () => { clipboard = { root: workspaceRoot, paths: selectionRoots(entries).map(item => item.rel_path), cut: true }; } },
|
||||
{ kind: "action", label: $t("Copy"), icon: "copy", run: () => { clipboard = { root: workspaceRoot, paths: selectionRoots(entries).map(item => item.rel_path), cut: false }; } },
|
||||
{
|
||||
kind: "action",
|
||||
label: multiple ? `Make copies (${entries.length})` : "Make a copy",
|
||||
label: multiple ? $t("Make copies ({count})", { count: entries.length }) : $t("Make a copy"),
|
||||
icon: "copy",
|
||||
run: () => { void copyEntries(entries); },
|
||||
},
|
||||
{
|
||||
kind: "action",
|
||||
label: bookmarked ? (multiple ? "Remove bookmarks" : "Remove bookmark") : "Bookmark",
|
||||
label: bookmarked ? (multiple ? $t("Remove bookmarks") : $t("Remove bookmark")) : $t("Bookmark"),
|
||||
icon: "bookmark",
|
||||
run: () => {
|
||||
void persistMarks({
|
||||
@@ -814,7 +814,7 @@
|
||||
{ kind: "sep" },
|
||||
{
|
||||
kind: "action",
|
||||
label: multiple ? "Copy workspace paths" : "Copy workspace path",
|
||||
label: multiple ? $t("Copy workspace paths") : $t("Copy workspace path"),
|
||||
icon: "copy",
|
||||
run: () => {
|
||||
void copyText(entries.map(item => item.rel_path).join("\n"), multiple ? "workspace paths" : "workspace path");
|
||||
@@ -822,7 +822,7 @@
|
||||
},
|
||||
{
|
||||
kind: "action",
|
||||
label: multiple ? "Copy system paths" : "Copy system path",
|
||||
label: multiple ? $t("Copy system paths") : $t("Copy system path"),
|
||||
icon: "copy",
|
||||
run: () => {
|
||||
void (async () => {
|
||||
@@ -837,7 +837,7 @@
|
||||
},
|
||||
{
|
||||
kind: "action",
|
||||
label: "Show in Explorer",
|
||||
label: $t("Show in Explorer"),
|
||||
icon: "folder",
|
||||
run: () => {
|
||||
void (async () => {
|
||||
@@ -849,7 +849,7 @@
|
||||
{ kind: "sep" },
|
||||
{
|
||||
kind: "action",
|
||||
label: pinned ? "Unpin" : "Pin",
|
||||
label: pinned ? $t("Unpin") : $t("Pin"),
|
||||
icon: "pin",
|
||||
run: () => {
|
||||
void persistMarks({
|
||||
@@ -860,7 +860,7 @@
|
||||
},
|
||||
{
|
||||
kind: "action",
|
||||
label: "Rename",
|
||||
label: $t("Rename"),
|
||||
icon: "rename",
|
||||
disabled: multiple,
|
||||
run: () => {
|
||||
@@ -869,7 +869,7 @@
|
||||
},
|
||||
{
|
||||
kind: "action",
|
||||
label: multiple ? `Delete (${entries.length})` : "Delete",
|
||||
label: multiple ? $t("Delete ({count})", { count: entries.length }) : $t("Delete"),
|
||||
icon: "trash",
|
||||
run: () => { void deleteEntries(entries); },
|
||||
},
|
||||
@@ -881,16 +881,16 @@
|
||||
|
||||
<div class="wrap">
|
||||
<div class="ribbon tree-tools">
|
||||
<IconButton icon="file-plus" label="New file" onclick={() => void createIn("", "file")} />
|
||||
<IconButton icon="folder-plus" label="New folder" onclick={() => void createIn("", "folder")} />
|
||||
<IconButton icon="file-plus" label={$t("New file")} onclick={() => void createIn("", "file")} />
|
||||
<IconButton icon="folder-plus" label={$t("New folder")} onclick={() => void createIn("", "folder")} />
|
||||
<IconButton
|
||||
icon="sort"
|
||||
label={sortMode === "custom" ? "Sort: custom" : sortMode === "name" ? "Sort: name" : "Sort: name Z-A"}
|
||||
label={sortMode === "custom" ? $t("Sort: custom") : sortMode === "name" ? $t("Sort: name") : $t("Sort: name Z-A")}
|
||||
onclick={cycleSort}
|
||||
/>
|
||||
<IconButton
|
||||
icon={allCollapsed ? "unfold" : "fold"}
|
||||
label={allCollapsed ? "Expand all" : "Collapse all"}
|
||||
label={allCollapsed ? $t("Expand all") : $t("Collapse all")}
|
||||
onclick={() => {
|
||||
if (allCollapsed) {
|
||||
void expandAll();
|
||||
@@ -905,7 +905,7 @@
|
||||
class="tree"
|
||||
tabindex="-1"
|
||||
role="navigation"
|
||||
aria-label="Workspace files"
|
||||
aria-label={$t("Workspace files")}
|
||||
oncontextmenu={(event) => {
|
||||
event.preventDefault();
|
||||
menu = { x: event.clientX, y: event.clientY, entry: null };
|
||||
@@ -915,10 +915,10 @@
|
||||
<p class="error">{error}</p>
|
||||
{/if}
|
||||
{#if loading && !childrenMap[""]}
|
||||
<p class="muted">Loading…</p>
|
||||
<p class="muted">{$t("Loading…")}</p>
|
||||
{/if}
|
||||
{#if childrenMap[""]}
|
||||
<ul role="tree" aria-label="Workspace files" aria-multiselectable="true">
|
||||
<ul role="tree" aria-label={$t("Workspace files")} aria-multiselectable="true">
|
||||
{#each childrenMap[""] as entry (entry.rel_path)}
|
||||
<TreeNode
|
||||
{entry}
|
||||
@@ -952,18 +952,18 @@
|
||||
{#if dragRel && dragPoint}
|
||||
{@const landing = dropTarget ? findEntry(dropTarget.rel) : null}
|
||||
<div class="drag-ghost" style:left="{dragPoint.x + 12}px" style:top="{dragPoint.y + 12}px">
|
||||
<span>{dragEntries.length > 1 ? `${dragEntries.length} items` : dragRel.split("/").pop()}</span>
|
||||
<span>{dragEntries.length > 1 ? $t("{count} items", { count: dragEntries.length }) : dragRel.split("/").pop()}</span>
|
||||
{#if imageLanding}
|
||||
<span class="hint">{isImagePath(dragRel ?? "") ? "Insert image" : "Insert link"}</span>
|
||||
<span class="hint">{isImagePath(dragRel ?? "") ? $t("Insert image") : $t("Insert link")}</span>
|
||||
{:else if landing && dropTarget}
|
||||
<span class="hint">{dropHint(landing.name, dropTarget.place)}</span>
|
||||
<span class="hint">{$t(dropTarget.place === "inside" ? "Into {name}" : dropTarget.place === "before" ? "Before {name}" : "After {name}", { name: landing.name })}</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if menu}
|
||||
<ContextMenu
|
||||
label="File actions"
|
||||
label={$t("File actions")}
|
||||
x={menu.x}
|
||||
y={menu.y}
|
||||
items={menuItems(menu.entry)}
|
||||
|
||||
Reference in New Issue
Block a user