2022-05-26 15:18:53 +08:00
|
|
|
import {
|
|
|
|
|
copySubMenu,
|
|
|
|
|
exportMd,
|
|
|
|
|
movePathToMenu,
|
|
|
|
|
openFileAttr,
|
|
|
|
|
renameMenu,
|
|
|
|
|
} from "./commonMenuItem";
|
|
|
|
|
/// #if !BROWSER
|
|
|
|
|
import {FileFilter, shell} from "electron";
|
|
|
|
|
import {dialog as remoteDialog} from "@electron/remote";
|
|
|
|
|
import * as path from "path";
|
|
|
|
|
/// #endif
|
|
|
|
|
import {MenuItem} from "./Menu";
|
2023-02-06 21:54:26 +08:00
|
|
|
import {getDisplayName, getNotebookName, getTopPaths, pathPosix} from "../util/pathName";
|
2022-05-26 15:18:53 +08:00
|
|
|
import {hideMessage, showMessage} from "../dialog/message";
|
|
|
|
|
import {fetchPost} from "../util/fetch";
|
|
|
|
|
import {onGetnotebookconf} from "./onGetnotebookconf";
|
|
|
|
|
/// #if !MOBILE
|
|
|
|
|
import {openSearch} from "../search/spread";
|
2022-06-29 15:36:44 +08:00
|
|
|
import {openFileById} from "../editor/util";
|
2022-05-26 15:18:53 +08:00
|
|
|
/// #endif
|
|
|
|
|
import {Constants} from "../constants";
|
2022-07-01 22:08:00 +08:00
|
|
|
import {newFile} from "../util/newFile";
|
2022-11-06 21:33:34 +08:00
|
|
|
import {hasClosestByTag} from "../protyle/util/hasClosest";
|
2022-11-04 21:50:03 +08:00
|
|
|
import {deleteFiles} from "../editor/deleteFile";
|
2023-01-19 20:31:14 +08:00
|
|
|
import {getDockByType} from "../layout/util";
|
|
|
|
|
import {Files} from "../layout/dock/Files";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
2022-11-10 13:21:22 +08:00
|
|
|
const initMultiMenu = (selectItemElements: NodeListOf<Element>) => {
|
|
|
|
|
const fileItemElement = Array.from(selectItemElements).find(item => {
|
|
|
|
|
if (item.getAttribute("data-type") === "navigation-file") {
|
2022-11-10 15:46:22 +08:00
|
|
|
return true;
|
2022-11-10 13:21:22 +08:00
|
|
|
}
|
2022-11-10 15:46:22 +08:00
|
|
|
});
|
2022-11-10 13:21:22 +08:00
|
|
|
if (!fileItemElement) {
|
|
|
|
|
return window.siyuan.menus.menu;
|
|
|
|
|
}
|
|
|
|
|
window.siyuan.menus.menu.append(movePathToMenu(getTopPaths(
|
|
|
|
|
Array.from(selectItemElements)
|
|
|
|
|
)));
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
icon: "iconTrashcan",
|
|
|
|
|
label: window.siyuan.languages.delete,
|
|
|
|
|
accelerator: "⌦",
|
|
|
|
|
click: () => {
|
|
|
|
|
deleteFiles(Array.from(selectItemElements));
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
return window.siyuan.menus.menu;
|
2022-11-10 15:46:22 +08:00
|
|
|
};
|
2022-11-10 13:21:22 +08:00
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
export const initNavigationMenu = (liElement: HTMLElement) => {
|
2022-11-10 13:21:22 +08:00
|
|
|
window.siyuan.menus.menu.remove();
|
2022-11-06 21:33:34 +08:00
|
|
|
const fileElement = hasClosestByTag(liElement, "DIV");
|
2022-11-03 14:55:22 +08:00
|
|
|
if (!fileElement) {
|
2022-11-10 13:21:22 +08:00
|
|
|
return window.siyuan.menus.menu;
|
2022-11-03 14:55:22 +08:00
|
|
|
}
|
2022-11-03 10:32:59 +08:00
|
|
|
if (!liElement.classList.contains("b3-list-item--focus")) {
|
2022-11-03 14:55:22 +08:00
|
|
|
fileElement.querySelectorAll(".b3-list-item--focus").forEach(item => {
|
|
|
|
|
item.classList.remove("b3-list-item--focus");
|
2022-11-04 21:50:03 +08:00
|
|
|
item.removeAttribute("select-end");
|
|
|
|
|
item.removeAttribute("select-start");
|
|
|
|
|
});
|
2022-11-03 10:32:59 +08:00
|
|
|
liElement.classList.add("b3-list-item--focus");
|
|
|
|
|
}
|
2022-11-10 15:46:22 +08:00
|
|
|
const selectItemElements = fileElement.querySelectorAll(".b3-list-item--focus");
|
2022-11-10 13:21:22 +08:00
|
|
|
if (selectItemElements.length > 1) {
|
|
|
|
|
return initMultiMenu(selectItemElements);
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
const notebookId = liElement.parentElement.getAttribute("data-url");
|
|
|
|
|
const name = getNotebookName(notebookId);
|
|
|
|
|
if (!window.siyuan.config.readonly) {
|
|
|
|
|
window.siyuan.menus.menu.append(renameMenu({
|
|
|
|
|
path: "/",
|
|
|
|
|
notebookId,
|
|
|
|
|
name,
|
|
|
|
|
type: "notebook"
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.config,
|
|
|
|
|
icon: "iconSettings",
|
|
|
|
|
click: () => {
|
|
|
|
|
fetchPost("/api/notebook/getNotebookConf", {
|
|
|
|
|
notebook: notebookId
|
|
|
|
|
}, (data) => {
|
|
|
|
|
onGetnotebookconf(data.data);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
2023-02-04 17:27:43 +08:00
|
|
|
if (!window.siyuan.config.readonly) {
|
|
|
|
|
sortMenu("notebook", parseInt(liElement.parentElement.getAttribute("data-sortmode")), (sort) => {
|
|
|
|
|
fetchPost("/api/notebook/setNotebookConf", {
|
|
|
|
|
notebook: notebookId,
|
|
|
|
|
conf: {
|
|
|
|
|
sortMode: sort
|
|
|
|
|
}
|
|
|
|
|
}, () => {
|
|
|
|
|
liElement.parentElement.setAttribute("data-sortmode", sort.toString());
|
|
|
|
|
let files;
|
|
|
|
|
/// #if MOBILE
|
|
|
|
|
files = window.siyuan.mobile.files;
|
|
|
|
|
/// #else
|
|
|
|
|
files = (getDockByType("file").data["file"] as Files);
|
|
|
|
|
/// #endif
|
|
|
|
|
const toggleElement = liElement.querySelector(".b3-list-item__arrow--open");
|
|
|
|
|
if (toggleElement) {
|
|
|
|
|
toggleElement.classList.remove("b3-list-item__arrow--open");
|
|
|
|
|
liElement.nextElementSibling?.remove();
|
|
|
|
|
files.getLeaf(liElement, notebookId);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return true;
|
2023-02-06 21:54:26 +08:00
|
|
|
});
|
2023-02-04 17:27:43 +08:00
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
/// #if !MOBILE
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.search,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.general.search.custom,
|
|
|
|
|
icon: "iconSearch",
|
|
|
|
|
click() {
|
|
|
|
|
openSearch(window.siyuan.config.keymap.general.search.custom, undefined, notebookId);
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.replace,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.general.replace.custom,
|
|
|
|
|
click() {
|
|
|
|
|
openSearch(window.siyuan.config.keymap.general.replace.custom, undefined, notebookId);
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
/// #endif
|
|
|
|
|
if (!window.siyuan.config.readonly) {
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.close,
|
|
|
|
|
icon: "iconClose",
|
|
|
|
|
click: () => {
|
|
|
|
|
fetchPost("/api/notebook/closeNotebook", {
|
|
|
|
|
notebook: notebookId
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
icon: "iconTrashcan",
|
|
|
|
|
label: window.siyuan.languages.delete,
|
|
|
|
|
accelerator: "⌦",
|
|
|
|
|
click: () => {
|
2022-11-04 21:50:03 +08:00
|
|
|
deleteFiles(Array.from(fileElement.querySelectorAll(".b3-list-item--focus")));
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
}
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
2022-07-24 22:31:46 +08:00
|
|
|
/// #if !BROWSER
|
2022-05-26 15:18:53 +08:00
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.showInFolder,
|
|
|
|
|
click: () => {
|
2022-07-14 22:05:10 +08:00
|
|
|
shell.openPath(path.join(window.siyuan.config.system.dataDir, notebookId));
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
|
|
|
|
}).element);
|
2022-07-24 22:31:46 +08:00
|
|
|
/// #endif
|
2022-08-14 23:26:26 +08:00
|
|
|
genImportMenu(notebookId, "/");
|
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.export,
|
2022-07-24 22:31:46 +08:00
|
|
|
type: "submenu",
|
2022-05-26 15:18:53 +08:00
|
|
|
icon: "iconUpload",
|
2022-07-24 22:31:46 +08:00
|
|
|
submenu: [{
|
|
|
|
|
label: "Markdown",
|
|
|
|
|
icon: "iconMarkdown",
|
|
|
|
|
click: () => {
|
|
|
|
|
const msgId = showMessage(window.siyuan.languages.exporting, -1);
|
|
|
|
|
fetchPost("/api/export/batchExportMd", {
|
|
|
|
|
notebook: notebookId,
|
|
|
|
|
path: "/"
|
|
|
|
|
}, response => {
|
|
|
|
|
hideMessage(msgId);
|
|
|
|
|
window.open(response.data.zip);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
label: "SiYuan .sy.zip",
|
|
|
|
|
icon: "iconSiYuan",
|
|
|
|
|
click: () => {
|
|
|
|
|
const msgId = showMessage(window.siyuan.languages.exporting, -1);
|
|
|
|
|
fetchPost("/api/export/exportNotebookSY", {
|
|
|
|
|
id: notebookId,
|
|
|
|
|
}, response => {
|
|
|
|
|
hideMessage(msgId);
|
|
|
|
|
window.open(response.data.zip);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}]
|
2022-05-26 15:18:53 +08:00
|
|
|
}).element);
|
|
|
|
|
return window.siyuan.menus.menu;
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-01 22:12:43 +08:00
|
|
|
export const initFileMenu = (notebookId: string, pathString: string, liElement: Element) => {
|
2022-11-10 13:21:22 +08:00
|
|
|
window.siyuan.menus.menu.remove();
|
2022-11-06 21:33:34 +08:00
|
|
|
const fileElement = hasClosestByTag(liElement, "DIV");
|
2022-11-03 11:12:23 +08:00
|
|
|
if (!fileElement) {
|
2023-01-19 20:31:14 +08:00
|
|
|
return window.siyuan.menus.menu;
|
2022-11-03 11:12:23 +08:00
|
|
|
}
|
2022-11-03 10:32:59 +08:00
|
|
|
if (!liElement.classList.contains("b3-list-item--focus")) {
|
2022-11-03 11:12:23 +08:00
|
|
|
fileElement.querySelectorAll(".b3-list-item--focus").forEach(item => {
|
|
|
|
|
item.classList.remove("b3-list-item--focus");
|
2022-11-04 21:50:03 +08:00
|
|
|
item.removeAttribute("select-end");
|
|
|
|
|
item.removeAttribute("select-start");
|
|
|
|
|
});
|
2022-11-03 10:32:59 +08:00
|
|
|
liElement.classList.add("b3-list-item--focus");
|
|
|
|
|
}
|
2022-11-10 15:46:22 +08:00
|
|
|
const selectItemElements = fileElement.querySelectorAll(".b3-list-item--focus");
|
2022-11-10 13:21:22 +08:00
|
|
|
if (selectItemElements.length > 1) {
|
|
|
|
|
return initMultiMenu(selectItemElements);
|
|
|
|
|
}
|
2022-07-01 22:12:43 +08:00
|
|
|
const id = liElement.getAttribute("data-node-id");
|
|
|
|
|
let name = liElement.getAttribute("data-name");
|
2022-05-26 15:18:53 +08:00
|
|
|
name = getDisplayName(name, false, true);
|
|
|
|
|
if (!window.siyuan.config.readonly) {
|
2022-07-01 22:08:00 +08:00
|
|
|
if (window.siyuan.config.fileTree.sort === 6) {
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
icon: "iconBefore",
|
2022-07-01 22:50:11 +08:00
|
|
|
label: window.siyuan.languages.newDocAbove,
|
2022-07-01 22:08:00 +08:00
|
|
|
click: () => {
|
|
|
|
|
const paths: string[] = [];
|
|
|
|
|
Array.from(liElement.parentElement.children).forEach((item) => {
|
|
|
|
|
if (item.tagName === "LI") {
|
|
|
|
|
if (item.isSameNode(liElement)) {
|
2022-07-01 22:12:43 +08:00
|
|
|
paths.push(undefined);
|
2022-07-01 22:08:00 +08:00
|
|
|
}
|
|
|
|
|
paths.push(item.getAttribute("data-path"));
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-02-03 22:29:34 +08:00
|
|
|
newFile(notebookId, pathPosix().dirname(pathString), paths);
|
2022-07-01 22:08:00 +08:00
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
icon: "iconAfter",
|
2022-07-01 22:50:11 +08:00
|
|
|
label: window.siyuan.languages.newDocBelow,
|
2022-07-01 22:08:00 +08:00
|
|
|
click: () => {
|
|
|
|
|
const paths: string[] = [];
|
|
|
|
|
Array.from(liElement.parentElement.children).forEach((item) => {
|
|
|
|
|
if (item.tagName === "LI") {
|
|
|
|
|
paths.push(item.getAttribute("data-path"));
|
|
|
|
|
if (item.isSameNode(liElement)) {
|
|
|
|
|
paths.push(undefined);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-02-03 22:29:34 +08:00
|
|
|
newFile(notebookId, pathPosix().dirname(pathString), paths);
|
2022-07-01 22:08:00 +08:00
|
|
|
}
|
|
|
|
|
}).element);
|
2022-11-01 10:15:47 +08:00
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
2022-07-01 22:08:00 +08:00
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.copy,
|
|
|
|
|
type: "submenu",
|
|
|
|
|
icon: "iconCopy",
|
2022-10-14 09:36:02 +08:00
|
|
|
submenu: (copySubMenu(id, false) as IMenu[]).concat([{
|
2022-05-26 15:18:53 +08:00
|
|
|
label: window.siyuan.languages.duplicate,
|
2022-11-09 14:25:02 +08:00
|
|
|
accelerator: window.siyuan.config.keymap.editor.general.duplicate.custom,
|
2022-05-26 15:18:53 +08:00
|
|
|
click() {
|
|
|
|
|
fetchPost("/api/filetree/duplicateDoc", {
|
|
|
|
|
id
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}])
|
|
|
|
|
}).element);
|
2022-11-04 21:48:50 +08:00
|
|
|
window.siyuan.menus.menu.append(movePathToMenu(getTopPaths(
|
|
|
|
|
Array.from(fileElement.querySelectorAll(".b3-list-item--focus"))
|
|
|
|
|
)));
|
2022-11-03 11:12:23 +08:00
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
icon: "iconTrashcan",
|
|
|
|
|
label: window.siyuan.languages.delete,
|
|
|
|
|
accelerator: "⌦",
|
|
|
|
|
click: () => {
|
2022-11-04 21:50:03 +08:00
|
|
|
deleteFiles(Array.from(fileElement.querySelectorAll(".b3-list-item--focus")));
|
2022-11-03 11:12:23 +08:00
|
|
|
}
|
|
|
|
|
}).element);
|
2022-06-27 12:06:21 +08:00
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
2022-05-26 15:18:53 +08:00
|
|
|
window.siyuan.menus.menu.append(renameMenu({
|
|
|
|
|
path: pathString,
|
|
|
|
|
notebookId,
|
|
|
|
|
name,
|
|
|
|
|
type: "file"
|
|
|
|
|
}));
|
2022-06-27 12:06:21 +08:00
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.attr,
|
|
|
|
|
click() {
|
|
|
|
|
fetchPost("/api/block/getDocInfo", {
|
|
|
|
|
id
|
|
|
|
|
}, (response) => {
|
|
|
|
|
openFileAttr(response.data.ial, id);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
/// #if !MOBILE
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.search,
|
|
|
|
|
icon: "iconSearch",
|
|
|
|
|
accelerator: window.siyuan.config.keymap.general.search.custom,
|
|
|
|
|
click() {
|
|
|
|
|
openSearch(window.siyuan.config.keymap.general.search.custom, undefined, notebookId, getDisplayName(pathString, false, true));
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.replace,
|
|
|
|
|
accelerator: window.siyuan.config.keymap.general.replace.custom,
|
|
|
|
|
click() {
|
|
|
|
|
openSearch(window.siyuan.config.keymap.general.replace.custom, undefined, notebookId, getDisplayName(pathString, false, true));
|
|
|
|
|
}
|
|
|
|
|
}).element);
|
|
|
|
|
/// #endif
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({type: "separator"}).element);
|
|
|
|
|
}
|
2022-06-29 15:36:44 +08:00
|
|
|
/// #if !MOBILE
|
2022-05-26 15:18:53 +08:00
|
|
|
const openSubmenus: IMenu[] = [{
|
2022-10-24 22:18:53 +08:00
|
|
|
icon: "iconLayoutRight",
|
2022-05-26 15:18:53 +08:00
|
|
|
label: window.siyuan.languages.insertRight,
|
|
|
|
|
accelerator: "⌥Click",
|
|
|
|
|
click: () => {
|
|
|
|
|
openFileById({id, position: "right", action: [Constants.CB_GET_FOCUS]});
|
|
|
|
|
}
|
|
|
|
|
}, {
|
2022-10-24 22:18:53 +08:00
|
|
|
icon: "iconLayoutBottom",
|
2022-05-26 15:18:53 +08:00
|
|
|
label: window.siyuan.languages.insertBottom,
|
2022-11-07 21:57:02 +08:00
|
|
|
accelerator: "⇧Click",
|
2022-05-26 15:18:53 +08:00
|
|
|
click: () => {
|
|
|
|
|
openFileById({id, position: "bottom", action: [Constants.CB_GET_FOCUS]});
|
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
if (window.siyuan.config.fileTree.openFilesUseCurrentTab) {
|
|
|
|
|
openSubmenus.push({
|
|
|
|
|
label: window.siyuan.languages.openInNewTab,
|
2022-11-07 21:57:02 +08:00
|
|
|
accelerator: "⌥⌘Click",
|
2022-05-26 15:18:53 +08:00
|
|
|
click: () => {
|
2022-11-07 21:57:02 +08:00
|
|
|
openFileById({
|
|
|
|
|
id, action: [Constants.CB_GET_FOCUS],
|
|
|
|
|
removeCurrentTab: false
|
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
openSubmenus.push({type: "separator"});
|
|
|
|
|
openSubmenus.push({
|
|
|
|
|
icon: "iconPreview",
|
|
|
|
|
label: window.siyuan.languages.preview,
|
|
|
|
|
click: () => {
|
|
|
|
|
openFileById({id, mode: "preview"});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
/// #if !BROWSER
|
|
|
|
|
openSubmenus.push({type: "separator"});
|
|
|
|
|
if (!window.siyuan.config.readonly) {
|
|
|
|
|
openSubmenus.push({
|
|
|
|
|
label: window.siyuan.languages.showInFolder,
|
|
|
|
|
click: () => {
|
|
|
|
|
shell.showItemInFolder(path.join(window.siyuan.config.system.dataDir, notebookId, pathString));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/// #endif
|
2022-06-29 15:36:44 +08:00
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
label: window.siyuan.languages.openBy,
|
|
|
|
|
submenu: openSubmenus,
|
|
|
|
|
}).element);
|
|
|
|
|
/// #endif
|
2022-08-14 23:26:26 +08:00
|
|
|
genImportMenu(notebookId, pathString);
|
2022-05-30 15:53:21 +08:00
|
|
|
window.siyuan.menus.menu.append(exportMd(id));
|
2022-05-26 15:18:53 +08:00
|
|
|
return window.siyuan.menus.menu;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const genImportMenu = (notebookId: string, pathString: string) => {
|
|
|
|
|
if (!window.siyuan.config.readonly) {
|
2022-08-14 23:26:26 +08:00
|
|
|
/// #if !BROWSER
|
2022-05-26 15:18:53 +08:00
|
|
|
const importstdmd = (label: string, isDoc?: boolean) => {
|
|
|
|
|
return {
|
|
|
|
|
icon: isDoc ? "iconMarkdown" : "iconFolder",
|
|
|
|
|
label,
|
|
|
|
|
click: async () => {
|
|
|
|
|
let filters: FileFilter[] = [];
|
|
|
|
|
if (isDoc) {
|
|
|
|
|
filters = [{name: "Markdown", extensions: ["md", "markdown"]}];
|
|
|
|
|
}
|
|
|
|
|
const localPath = await remoteDialog.showOpenDialog({
|
|
|
|
|
defaultPath: window.siyuan.config.system.homeDir,
|
|
|
|
|
filters,
|
|
|
|
|
properties: [isDoc ? "openFile" : "openDirectory"],
|
|
|
|
|
});
|
|
|
|
|
if (localPath.filePaths.length === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fetchPost("/api/import/importStdMd", {
|
|
|
|
|
notebook: notebookId,
|
|
|
|
|
localPath: localPath.filePaths[0],
|
|
|
|
|
toPath: pathString,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
2022-08-14 23:26:26 +08:00
|
|
|
/// #endif
|
2022-05-26 15:18:53 +08:00
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
icon: "iconDownload",
|
|
|
|
|
label: window.siyuan.languages.import,
|
|
|
|
|
submenu: [{
|
|
|
|
|
icon: "iconSiYuan",
|
|
|
|
|
label: 'SiYuan .sy.zip<input class="b3-form__upload" type="file" accept="application/zip">',
|
|
|
|
|
bind: (element) => {
|
2023-02-04 17:27:43 +08:00
|
|
|
element.querySelector(".b3-form__upload").addEventListener("change", (event: InputEvent & {
|
|
|
|
|
target: HTMLInputElement
|
|
|
|
|
}) => {
|
2022-05-26 15:18:53 +08:00
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append("file", event.target.files[0]);
|
|
|
|
|
formData.append("notebook", notebookId);
|
|
|
|
|
formData.append("toPath", pathString);
|
2023-01-19 20:31:14 +08:00
|
|
|
fetchPost("/api/import/importSY", formData, () => {
|
2023-01-24 20:33:13 +08:00
|
|
|
let files;
|
2023-01-19 20:31:14 +08:00
|
|
|
/// #if MOBILE
|
2023-01-24 20:33:13 +08:00
|
|
|
files = window.siyuan.mobile.files;
|
2023-01-19 20:31:14 +08:00
|
|
|
/// #else
|
2023-01-19 21:27:16 +08:00
|
|
|
files = (getDockByType("file").data["file"] as Files);
|
2023-01-19 20:31:14 +08:00
|
|
|
/// #endif
|
2023-01-24 20:33:13 +08:00
|
|
|
const liElement = files.element.querySelector(`[data-path="${pathString}"]`);
|
2023-01-19 21:27:16 +08:00
|
|
|
const toggleElement = liElement.querySelector(".b3-list-item__arrow--open");
|
|
|
|
|
if (toggleElement) {
|
|
|
|
|
toggleElement.classList.remove("b3-list-item__arrow--open");
|
|
|
|
|
liElement.nextElementSibling?.remove();
|
|
|
|
|
}
|
|
|
|
|
files.getLeaf(liElement, notebookId);
|
2023-01-19 20:31:14 +08:00
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
});
|
2022-05-26 15:18:53 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-08-14 23:26:26 +08:00
|
|
|
/// #if !BROWSER
|
2022-05-26 15:18:53 +08:00
|
|
|
importstdmd("Markdown " + window.siyuan.languages.doc, true),
|
2022-08-14 23:26:26 +08:00
|
|
|
importstdmd("Markdown " + window.siyuan.languages.folder)
|
|
|
|
|
/// #endif
|
|
|
|
|
],
|
2022-05-26 15:18:53 +08:00
|
|
|
}).element);
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-02-04 17:27:43 +08:00
|
|
|
|
|
|
|
|
export const sortMenu = (type: "notebooks" | "notebook", sortMode: number, clickEvent: (sort: number) => void) => {
|
|
|
|
|
const submenu: IMenu[] = [{
|
|
|
|
|
icon: sortMode === 0 ? "iconSelect" : undefined,
|
|
|
|
|
label: window.siyuan.languages.fileNameASC,
|
|
|
|
|
click: () => {
|
|
|
|
|
clickEvent(0);
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
icon: sortMode === 1 ? "iconSelect" : undefined,
|
|
|
|
|
label: window.siyuan.languages.fileNameDESC,
|
|
|
|
|
click: () => {
|
|
|
|
|
clickEvent(1);
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
icon: sortMode === 4 ? "iconSelect" : undefined,
|
|
|
|
|
label: window.siyuan.languages.fileNameNatASC,
|
|
|
|
|
click: () => {
|
|
|
|
|
clickEvent(4);
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
icon: sortMode === 5 ? "iconSelect" : undefined,
|
|
|
|
|
label: window.siyuan.languages.fileNameNatDESC,
|
|
|
|
|
click: () => {
|
|
|
|
|
clickEvent(5);
|
|
|
|
|
}
|
|
|
|
|
}, {type: "separator"}, {
|
|
|
|
|
icon: sortMode === 9 ? "iconSelect" : undefined,
|
|
|
|
|
label: window.siyuan.languages.createdASC,
|
|
|
|
|
click: () => {
|
|
|
|
|
clickEvent(9);
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
icon: sortMode === 10 ? "iconSelect" : undefined,
|
|
|
|
|
label: window.siyuan.languages.createdDESC,
|
|
|
|
|
click: () => {
|
|
|
|
|
clickEvent(10);
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
icon: sortMode === 2 ? "iconSelect" : undefined,
|
|
|
|
|
label: window.siyuan.languages.modifiedASC,
|
|
|
|
|
click: () => {
|
|
|
|
|
clickEvent(2);
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
icon: sortMode === 3 ? "iconSelect" : undefined,
|
|
|
|
|
label: window.siyuan.languages.modifiedDESC,
|
|
|
|
|
click: () => {
|
|
|
|
|
clickEvent(3);
|
|
|
|
|
}
|
|
|
|
|
}, {type: "separator"}, {
|
|
|
|
|
icon: sortMode === 7 ? "iconSelect" : undefined,
|
|
|
|
|
label: window.siyuan.languages.refCountASC,
|
|
|
|
|
click: () => {
|
|
|
|
|
clickEvent(7);
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
icon: sortMode === 8 ? "iconSelect" : undefined,
|
|
|
|
|
label: window.siyuan.languages.refCountDESC,
|
|
|
|
|
click: () => {
|
|
|
|
|
clickEvent(8);
|
|
|
|
|
}
|
|
|
|
|
}, {type: "separator"}, {
|
|
|
|
|
icon: sortMode === 11 ? "iconSelect" : undefined,
|
|
|
|
|
label: window.siyuan.languages.docSizeASC,
|
|
|
|
|
click: () => {
|
|
|
|
|
clickEvent(11);
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
icon: sortMode === 12 ? "iconSelect" : undefined,
|
|
|
|
|
label: window.siyuan.languages.docSizeDESC,
|
|
|
|
|
click: () => {
|
|
|
|
|
clickEvent(12);
|
|
|
|
|
}
|
|
|
|
|
}, {type: "separator"}, {
|
|
|
|
|
icon: sortMode === 13 ? "iconSelect" : undefined,
|
|
|
|
|
label: window.siyuan.languages.subDocCountASC,
|
|
|
|
|
click: () => {
|
|
|
|
|
clickEvent(13);
|
|
|
|
|
}
|
|
|
|
|
}, {
|
|
|
|
|
icon: sortMode === 14 ? "iconSelect" : undefined,
|
|
|
|
|
label: window.siyuan.languages.subDocCountDESC,
|
|
|
|
|
click: () => {
|
|
|
|
|
clickEvent(14);
|
|
|
|
|
}
|
|
|
|
|
}, {type: "separator"}, {
|
|
|
|
|
icon: sortMode === 6 ? "iconSelect" : undefined,
|
|
|
|
|
label: window.siyuan.languages.customSort,
|
|
|
|
|
click: () => {
|
|
|
|
|
clickEvent(6);
|
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
if (type === "notebook") {
|
|
|
|
|
submenu.push({
|
|
|
|
|
icon: sortMode === 15 ? "iconSelect" : undefined,
|
|
|
|
|
label: window.siyuan.languages.sortByFiletree,
|
|
|
|
|
click: () => {
|
|
|
|
|
clickEvent(15);
|
|
|
|
|
}
|
2023-02-06 21:54:26 +08:00
|
|
|
});
|
2023-02-04 17:27:43 +08:00
|
|
|
}
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
icon: "iconSort",
|
|
|
|
|
label: window.siyuan.languages.sort,
|
|
|
|
|
type: "submenu",
|
|
|
|
|
submenu,
|
|
|
|
|
}).element);
|
2023-02-06 21:54:26 +08:00
|
|
|
};
|