diff --git a/app/src/config/fileTree.ts b/app/src/config/fileTree.ts index 45e3a49c9..728e17512 100644 --- a/app/src/config/fileTree.ts +++ b/app/src/config/fileTree.ts @@ -27,6 +27,14 @@ export const fileTree = { + + + ${window.siyuan.languages.fileTree3} + ${window.siyuan.languages.fileTree4} + + + + ${window.siyuan.languages.fileTree12} @@ -60,6 +68,7 @@ export const fileTree = { createDocNameTemplate: (fileTree.element.querySelector("#createDocNameTemplate") as HTMLInputElement).value, openFilesUseCurrentTab: (fileTree.element.querySelector("#openFilesUseCurrentTab") as HTMLInputElement).checked, allowCreateDeeper: (fileTree.element.querySelector("#allowCreateDeeper") as HTMLInputElement).checked, + removeDocWithoutConfirm: (fileTree.element.querySelector("#removeDocWithoutConfirm") as HTMLInputElement).checked, maxListCount: parseInt((fileTree.element.querySelector("#maxListCount") as HTMLInputElement).value), }, response => { fileTree.onSetfiletree(response.data); diff --git a/app/src/config/search.ts b/app/src/config/search.ts index 4a2fd8775..95099c993 100644 --- a/app/src/config/search.ts +++ b/app/src/config/search.ts @@ -18,7 +18,7 @@ export const initConfigSearch = (element: HTMLElement) => { ]), // 文档树 - getLang(["selectOpen", "fileTree", "fileTree2", + getLang(["selectOpen", "fileTree", "fileTree2", "fileTree3", "fileTree4", "fileTree5", "fileTree6", "fileTree7", "fileTree8", "fileTree12", "fileTree13", "fileTree15", "fileTree16", "fileTree17"]), // 图片 diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts index 326edb87c..b04f5ab99 100644 --- a/app/src/editor/util.ts +++ b/app/src/editor/util.ts @@ -30,6 +30,7 @@ import { import {getPreviousHeading} from "../protyle/wysiwyg/getBlock"; import {lockFile, setTitle} from "../dialog/processSystem"; import {zoomOut} from "../menus/protyle"; +import {confirmDialog} from "../dialog/confirmDialog"; export const openOutline = (protyle: IProtyle) => { const outlinePanel = getAllModels().outline.find(item => { @@ -539,3 +540,27 @@ export const openBy = (url: string, type: "folder" | "app") => { } /// #endif }; + +export const deleteFile = (notebookId: string, pathString: string, name: string) => { + if (window.siyuan.config.fileTree.removeDocWithoutConfirm) { + fetchPost("/api/filetree/removeDoc", { + notebook: notebookId, + path: pathString + }); + return; + } + fetchPost("/api/block/getDocInfo", { + id: getDisplayName(pathString, true, true) + }, (response) => { + let tip = `${window.siyuan.languages.confirmDelete} ${name}?`; + if (response.data.subFileCount > 0) { + tip = `${window.siyuan.languages.confirmDelete} ${name} ${window.siyuan.languages.andSubFile.replace("x", response.data.subFileCount)}?`; + } + confirmDialog(window.siyuan.languages.delete, tip, () => { + fetchPost("/api/filetree/removeDoc", { + notebook: notebookId, + path: pathString + }); + }); + }); +} diff --git a/app/src/menus/commonMenuItem.ts b/app/src/menus/commonMenuItem.ts index 775f7e020..9ec6395b7 100644 --- a/app/src/menus/commonMenuItem.ts +++ b/app/src/menus/commonMenuItem.ts @@ -19,7 +19,7 @@ import {setPosition} from "../util/setPosition"; import {updateTransaction} from "../protyle/wysiwyg/transaction"; import {Bookmark} from "../layout/dock/Bookmark"; import {rename} from "../editor/rename"; -import {openAsset, openBy} from "../editor/util"; +import {deleteFile, openAsset, openBy} from "../editor/util"; import {matchHotKey} from "../protyle/util/hotKey"; import * as dayjs from "dayjs"; import {Constants} from "../constants"; @@ -774,20 +774,7 @@ export const deleteMenu = (notebookId: string, name: string, pathString: string) label: window.siyuan.languages.delete, accelerator: "⌦", click: () => { - fetchPost("/api/block/getDocInfo", { - id: getDisplayName(pathString, true, true) - }, (response) => { - let tip = `${window.siyuan.languages.confirmDelete} ${name}?`; - if (response.data.subFileCount > 0) { - tip = `${window.siyuan.languages.confirmDelete} ${name} ${window.siyuan.languages.andSubFile.replace("x", response.data.subFileCount)}?`; - } - confirmDialog(window.siyuan.languages.delete, tip, () => { - fetchPost("/api/filetree/removeDoc", { - notebook: notebookId, - path: pathString - }); - }); - }); + deleteFile(notebookId, pathString, name); } }).element; }; diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts index 09337837a..d49a85b7c 100644 --- a/app/src/protyle/header/Title.ts +++ b/app/src/protyle/header/Title.ts @@ -17,9 +17,8 @@ import {hasClosestByClassName} from "../util/hasClosest"; import {matchHotKey} from "../util/hotKey"; import {updateHotkeyTip, writeText} from "../util/compatibility"; import {setPanelFocus} from "../../layout/util"; -import {confirmDialog} from "../../dialog/confirmDialog"; import {escapeHtml} from "../../util/escape"; -import {openBacklink, openGraph, openOutline, updatePanelByEditor} from "../../editor/util"; +import {deleteFile, openBacklink, openGraph, openOutline, updatePanelByEditor} from "../../editor/util"; import * as dayjs from "dayjs"; import {setTitle} from "../../dialog/processSystem"; import {getNoContainerElement} from "../wysiwyg/getBlock"; @@ -262,20 +261,7 @@ export class Title { icon: "iconTrashcan", label: window.siyuan.languages.delete, click: () => { - fetchPost("/api/block/getDocInfo", { - id: protyle.block.rootID - }, (response) => { - let tip = `${window.siyuan.languages.confirmDelete} ${escapeHtml(this.editElement.textContent)}?`; - if (response.data.subFileCount > 0) { - tip = `${window.siyuan.languages.confirmDelete} ${escapeHtml(this.editElement.textContent)} ${window.siyuan.languages.andSubFile.replace("x", response.data.subFileCount)}?`; - } - confirmDialog(window.siyuan.languages.delete, tip, () => { - fetchPost("/api/filetree/removeDoc", { - notebook: protyle.notebookId, - path: protyle.path - }); - }); - }); + deleteFile(protyle.notebookId, protyle.path, escapeHtml(this.editElement.textContent)) } }).element); } diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index c16ccf49f..d974df1c0 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -226,6 +226,7 @@ declare interface IAppearance { declare interface IFileTree { alwaysSelectOpenedFile: boolean openFilesUseCurrentTab: boolean + removeDocWithoutConfirm: boolean allowCreateDeeper: boolean refCreateSavePath: string createDocNameTemplate: string diff --git a/app/src/util/globalShortcut.ts b/app/src/util/globalShortcut.ts index 239cc291e..22cabe93f 100644 --- a/app/src/util/globalShortcut.ts +++ b/app/src/util/globalShortcut.ts @@ -24,7 +24,7 @@ import {goBack, goForward} from "./backForward"; import {onGet} from "../protyle/util/onGet"; import {getDisplayName, getNotebookName, movePathTo} from "./pathName"; import {confirmDialog} from "../dialog/confirmDialog"; -import {openFileById} from "../editor/util"; +import {deleteFile, openFileById} from "../editor/util"; import {getAllDocks, getAllModels, getAllTabs} from "../layout/getAll"; import {openGlobalSearch} from "../search/util"; import {getColIndex} from "../protyle/util/table"; @@ -815,21 +815,7 @@ const fileTreeKeydown = (event: KeyboardEvent) => { } if (event.key === "Delete" || (event.key === "Backspace" && isMac())) { if (isFile) { - fetchPost("/api/block/getDocInfo", { - id: getDisplayName(pathString, true, true) - }, (response) => { - const name = getDisplayName(liElement.getAttribute("data-name"), false, true); - let tip = `${window.siyuan.languages.confirmDelete} ${name}?`; - if (response.data.subFileCount > 0) { - tip = `${window.siyuan.languages.confirmDelete} ${name} ${window.siyuan.languages.andSubFile.replace("x", response.data.subFileCount)}?`; - } - confirmDialog(window.siyuan.languages.delete, tip, () => { - fetchPost("/api/filetree/removeDoc", { - notebook: notebookId, - path: pathString - }); - }); - }); + deleteFile(notebookId, pathString, getDisplayName(liElement.getAttribute("data-name"), false, true)); } else { confirmDialog(window.siyuan.languages.delete, `${window.siyuan.languages.confirmDelete} ${Lute.EscapeHTMLStr(getNotebookName(notebookId))}?`, () => {