This commit is contained in:
Vanessa 2022-06-18 23:34:14 +08:00
parent 19940e266b
commit 24709d29ad
7 changed files with 42 additions and 48 deletions

View file

@ -27,6 +27,14 @@ export const fileTree = {
<span class="fn__space"></span>
<input class="b3-switch fn__flex-center" id="allowCreateDeeper" type="checkbox"${window.siyuan.config.fileTree.allowCreateDeeper ? " checked" : ""}/>
</label>
<label class="fn__flex b3-label">
<div class="fn__flex-1">
${window.siyuan.languages.fileTree3}
<div class="b3-label__text">${window.siyuan.languages.fileTree4}</div>
</div>
<span class="fn__space"></span>
<input class="b3-switch fn__flex-center" id="removeDocWithoutConfirm" type="checkbox"${window.siyuan.config.fileTree.removeDocWithoutConfirm ? " checked" : ""}/>
</label>
<label class="fn__flex b3-label">
<div class="fn__flex-1">
${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);

View file

@ -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"]),
// 图片

View file

@ -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} <b>${name}</b>?`;
if (response.data.subFileCount > 0) {
tip = `${window.siyuan.languages.confirmDelete} <b>${name}</b> ${window.siyuan.languages.andSubFile.replace("x", response.data.subFileCount)}?`;
}
confirmDialog(window.siyuan.languages.delete, tip, () => {
fetchPost("/api/filetree/removeDoc", {
notebook: notebookId,
path: pathString
});
});
});
}

View file

@ -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} <b>${name}</b>?`;
if (response.data.subFileCount > 0) {
tip = `${window.siyuan.languages.confirmDelete} <b>${name}</b> ${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;
};

View file

@ -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} <b>${escapeHtml(this.editElement.textContent)}</b>?`;
if (response.data.subFileCount > 0) {
tip = `${window.siyuan.languages.confirmDelete} <b>${escapeHtml(this.editElement.textContent)}</b> ${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);
}

View file

@ -226,6 +226,7 @@ declare interface IAppearance {
declare interface IFileTree {
alwaysSelectOpenedFile: boolean
openFilesUseCurrentTab: boolean
removeDocWithoutConfirm: boolean
allowCreateDeeper: boolean
refCreateSavePath: string
createDocNameTemplate: string

View file

@ -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} <b>${name}</b>?`;
if (response.data.subFileCount > 0) {
tip = `${window.siyuan.languages.confirmDelete} <b>${name}</b> ${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} <b>${Lute.EscapeHTMLStr(getNotebookName(notebookId))}</b>?`, () => {