This commit is contained in:
Vanessa 2023-05-18 20:49:24 +08:00
parent fe3c6012c8
commit 839308173a
3 changed files with 24 additions and 7 deletions

View file

@ -82,6 +82,16 @@ export class Menu {
} }
} }
public addSeparator() {
this.addItem({type: "separator"});
}
public addItem(option: IMenu) {
const menuItem = new MenuItem(option);
this.append(menuItem.element);
return menuItem.element;
}
public remove() { public remove() {
if (window.siyuan.menus.menu.removeCB) { if (window.siyuan.menus.menu.removeCB) {
window.siyuan.menus.menu.removeCB(); window.siyuan.menus.menu.removeCB();
@ -170,7 +180,7 @@ export class MenuItem {
}); });
} }
let html = `<span class="b3-menu__label">${options.label}</span>`; let html = `<span class="b3-menu__label">${options.label}</span>`;
if (options.iconHTML) { if (typeof options.iconHTML === "string") {
html = options.iconHTML + html; html = options.iconHTML + html;
} else { } else {
html = `<svg class="b3-menu__icon${["HTML (SiYuan)", window.siyuan.languages.template].includes(options.label) ? " ft__error" : ""}" style="${options.icon === "iconClose" ? "height:10px;" : ""}"><use xlink:href="#${options.icon || ""}"></use></svg>${html}`; html = `<svg class="b3-menu__icon${["HTML (SiYuan)", window.siyuan.languages.template].includes(options.label) ? " ft__error" : ""}" style="${options.icon === "iconClose" ? "height:10px;" : ""}"><use xlink:href="#${options.icon || ""}"></use></svg>${html}`;

View file

@ -39,16 +39,14 @@ export class Menu {
if (this.isOpen) { if (this.isOpen) {
return; return;
} }
const menuItem = new MenuItem(option); return this.menu.addItem(option);
this.menu.append(menuItem.element);
return menuItem.element;
} }
addSeparator() { addSeparator() {
if (this.isOpen) { if (this.isOpen) {
return; return;
} }
this.addItem({type: "separator"}); this.menu.addSeparator();
} }
open(options: { x: number, y: number, h?: number, w?: number, isLeft: false }) { open(options: { x: number, y: number, h?: number, w?: number, isLeft: false }) {

View file

@ -708,6 +708,12 @@ export class Gutter {
} }
}).element); }).element);
} }
this.app?.plugins?.forEach((plugin) => {
plugin.eventBus.emit("click-blockicon", {
menu: window.siyuan.menus.menu,
blockElements: selectsElement,
});
});
return window.siyuan.menus.menu; return window.siyuan.menus.menu;
} }
@ -1501,8 +1507,11 @@ export class Gutter {
type: "readonly", type: "readonly",
label: `${updateHTML}${window.siyuan.languages.createdAt} ${dayjs(id.substr(0, 14)).format("YYYY-MM-DD HH:mm:ss")}`, label: `${updateHTML}${window.siyuan.languages.createdAt} ${dayjs(id.substr(0, 14)).format("YYYY-MM-DD HH:mm:ss")}`,
}).element); }).element);
this.app.plugins.forEach((plugin) => { this.app?.plugins?.forEach((plugin) => {
plugin.eventBus.emit("click-blockicon", [nodeElement]); plugin.eventBus.emit("click-blockicon", {
menu: window.siyuan.menus.menu,
blockElements: [nodeElement]
});
}); });
return window.siyuan.menus.menu; return window.siyuan.menus.menu;
} }