Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 31 additions & 24 deletions app/src/menus/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,28 @@ import {emitOpenMenu} from "../plugin/EventBus";
import {openByMobile} from "../protyle/util/compatibility";
import {addFilesToDatabase} from "../protyle/render/av/addToDatabase";

const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
const fileItemElement = Array.from(selectItemElements).find(item => {
if (item.getAttribute("data-type") === "navigation-file") {
return true;
}
});
if (!fileItemElement) {
return window.siyuan.menus.menu;
}
const initMultiMenu = (selectItemElements: Element[], app: App) => {
const items: { id: string, path: string }[] = [];
const blockIDs: string[] = [];
selectItemElements.forEach(item => {
const fileItemElements = selectItemElements.filter(item => {
if (item.getAttribute("data-type") === "navigation-file") {
const id = item.getAttribute("data-node-id");
if (id) {
const path = item.getAttribute("data-path");
if (id && path) {
items.push({
id: id,
path: path,
});
blockIDs.push(id);
}
return true;
}
return false;
});

if (fileItemElements.length === 0) {
return window.siyuan.menus.menu;
}

if (blockIDs.length > 0) {
window.siyuan.menus.menu.append(new MenuItem({
Expand All @@ -69,19 +75,15 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
}])
}).element);
}

window.siyuan.menus.menu.append(movePathToMenu(getTopPaths(
Array.from(selectItemElements)
)));

window.siyuan.menus.menu.append(movePathToMenu(getTopPaths(fileItemElements)));
if (blockIDs.length > 0) {
window.siyuan.menus.menu.append(new MenuItem({
id: "addToDatabase",
label: window.siyuan.languages.addToDatabase,
accelerator: window.siyuan.config.keymap.general.addToDatabase.custom,
icon: "iconDatabase",
click: () => {
addFilesToDatabase(Array.from(selectItemElements));
addFilesToDatabase(fileItemElements);
}
}).element);
}
Expand All @@ -91,13 +93,14 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
label: window.siyuan.languages.delete,
accelerator: "⌦",
click: () => {
deleteFiles(Array.from(selectItemElements));
deleteFiles(fileItemElements);
}
}).element);

if (blockIDs.length === 0) {
return window.siyuan.menus.menu;
}

window.siyuan.menus.menu.append(new MenuItem({id: "separator_1", type: "separator"}).element);
if (!window.siyuan.config.readonly) {
const riffCardMenu = [{
Expand Down Expand Up @@ -176,8 +179,9 @@ const initMultiMenu = (selectItemElements: NodeListOf<Element>, app: App) => {
plugins: app.plugins,
type: "open-menu-doctree",
detail: {
elements: selectItemElements,
type: "docs"
elements: fileItemElements,
type: "docs",
items,
},
separatorPosition: "top",
});
Expand All @@ -199,7 +203,7 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => {
});
liElement.classList.add("b3-list-item--focus");
}
const selectItemElements = fileElement.querySelectorAll(".b3-list-item--focus");
const selectItemElements = Array.from(fileElement.querySelectorAll(".b3-list-item--focus"));
if (selectItemElements.length > 1) {
return initMultiMenu(selectItemElements, app);
}
Expand Down Expand Up @@ -407,7 +411,8 @@ export const initNavigationMenu = (app: App, liElement: HTMLElement) => {
type: "open-menu-doctree",
detail: {
elements: selectItemElements,
type: "notebook"
type: "notebook",
items: [{id: notebookId, path: "/"}],
},
separatorPosition: "top",
});
Expand All @@ -429,11 +434,12 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
});
liElement.classList.add("b3-list-item--focus");
}
const selectItemElements = fileElement.querySelectorAll(".b3-list-item--focus");
const selectItemElements = Array.from(fileElement.querySelectorAll(".b3-list-item--focus"));
if (selectItemElements.length > 1) {
return initMultiMenu(selectItemElements, app);
}
const id = liElement.getAttribute("data-node-id");
const path = liElement.getAttribute("data-path");
let name = liElement.getAttribute("data-name");
name = getDisplayName(name, false, true);
if (!window.siyuan.config.readonly) {
Expand Down Expand Up @@ -701,7 +707,8 @@ export const initFileMenu = (app: App, notebookId: string, pathString: string, l
type: "open-menu-doctree",
detail: {
elements: selectItemElements,
type: "doc"
type: "doc",
items: [{id, path}],
},
separatorPosition: "top",
});
Expand Down