From 72e525eb714a67acfd4e3c15c9a74e4971c41478 Mon Sep 17 00:00:00 2001 From: terwer Date: Fri, 27 Oct 2023 17:11:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=95=B4=E5=90=88=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=EF=BC=8C=E4=B8=93=E6=B3=A8=E6=A0=B8=E5=BF=83=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- siyuan/i18n/en_US.json | 2 + siyuan/i18n/zh_CN.json | 8 +-- siyuan/topbar.ts | 120 ++++++++++++++++++++++------------------- 3 files changed, 72 insertions(+), 58 deletions(-) diff --git a/siyuan/i18n/en_US.json b/siyuan/i18n/en_US.json index a5107436..54b5a5fe 100644 --- a/siyuan/i18n/en_US.json +++ b/siyuan/i18n/en_US.json @@ -2,7 +2,9 @@ "publishTool": "Publisher", "publish": "Publish", "preview": "Preview", + "picmanage": "Picture manage", "picbed": "Upload picture to picbed", + "aitool": "AI tool", "setting": "Setting", "settingGeneral": "General setting", "settingPicbed": "Picbed manage", diff --git a/siyuan/i18n/zh_CN.json b/siyuan/i18n/zh_CN.json index b6d51f5c..4eae367b 100644 --- a/siyuan/i18n/zh_CN.json +++ b/siyuan/i18n/zh_CN.json @@ -2,13 +2,15 @@ "publishTool": "发布工具", "publish": "发布", "preview": "发布预览", + "picmanage": "图床管理", "picbed": "上传图片到图床", - "setting": "设置", + "aitool": "智能工具", + "setting": "通用设置", "settingGeneral": "偏好设置", "settingPicbed": "图床设置", "settingPublish": "发布设置", "settingPlatform": "平台设置", - "settingAbout": "关于", + "settingAbout": "关于作者", "copyPageId": "复制文档ID", "publisherWidget": "挂件版", "cancel": "取消", @@ -18,5 +20,5 @@ "publishNormal": "常规发布", "extendFunction": "扩展功能", "aiChat": "AI聊天", - "aiChatTab": "AI聊天(Tab版)" + "aiChatTab": "新页签AI聊天" } diff --git a/siyuan/topbar.ts b/siyuan/topbar.ts index f41e061f..32d2e812 100644 --- a/siyuan/topbar.ts +++ b/siyuan/topbar.ts @@ -85,7 +85,7 @@ export class Topbar { dynJsonCfg.totalCfg?.forEach((config: any) => { let icon = `${config.platformIcon}` // 修复图片不展示问题 - if (/^\ -1) { + if (/^ -1) { icon = config.platformIcon.replace( /\.\/images/g, `${window.location.origin}/plugins/siyuan-plugin-publisher/images` @@ -116,9 +116,7 @@ export class Topbar { private async getExtendMenus() { const isBlogInstalled = await this.pluginInvoke.preCheckBlogPlugin() - const isPicgoInstalled = await this.pluginInvoke.preCheckPicgoPlugin() this.logger.info(`isBlogInstalled=>${isBlogInstalled}`) - this.logger.info(`isPicgoInstalled=>${isPicgoInstalled}`) const extmenus = [] if (isBlogInstalled) { @@ -132,33 +130,30 @@ export class Topbar { } extmenus.push(extPreviewMenu) } - if (isPicgoInstalled) { - // 图床 - const extPicBedMenu = { - iconHTML: icons.iconPicture, - label: this.pluginInstance.i18n.picbed, - click: async () => { - await this.pluginInvoke.showPicbedDialog() - }, - } - extmenus.push(extPicBedMenu) - const extPicBedSettingMenu = { - iconHTML: icons.iconPicbed, - label: this.pluginInstance.i18n.settingPicbed, - click: async () => { - await this.pluginInvoke.showPicbedSettingDialog() - }, - } - extmenus.push(extPicBedSettingMenu) + // 当前文档ID + const pageId = PageUtil.getPageId() + const docIdMenu = { + iconHTML: icons.iconOl, + label: this.pluginInstance.i18n.copyPageId, + click: async () => { + await HtmlUtils.copyToClipboard(pageId) + this.pluginInstance.kernelApi.pushMsg({ + msg: `当前文档ID已复制=>${pageId}`, + timeout: 3000, + }) + this.logger.info("当前文档ID已复制", pageId) + }, } + extmenus.push(docIdMenu) + if (extmenus.length == 0) { return undefined } return extmenus } - private addMenu(rect: DOMRect, quickMenus: IMenuItemOption[], extendMenus: IMenuItemOption[]) { + private async addMenu(rect: DOMRect, quickMenus: IMenuItemOption[], extendMenus: IMenuItemOption[]) { const menu = new Menu("publisherMenu") // 一键发布 @@ -193,24 +188,55 @@ export class Topbar { }, }) - // AI聊天 - menu.addSeparator() - menu.addItem({ - iconHTML: ``, - label: this.pluginInstance.i18n.aiChat, - click: () => { - this.widgetInvoke.showPublisherAiChatDialog() - }, - }) + // 图床管理 + const isPicgoInstalled = await this.pluginInvoke.preCheckPicgoPlugin() + this.logger.info(`isPicgoInstalled=>${isPicgoInstalled}`) + if (isPicgoInstalled) { + menu.addSeparator() + // 图床 + menu.addItem({ + iconHTML: icons.iconPicbed, + label: this.pluginInstance.i18n.picmanage, + submenu: [ + { + iconHTML: icons.iconPicture, + label: this.pluginInstance.i18n.picbed, + click: async () => { + await this.pluginInvoke.showPicbedDialog() + }, + }, + { + iconHTML: icons.iconPicbed, + label: this.pluginInstance.i18n.settingPicbed, + click: async () => { + await this.pluginInvoke.showPicbedSettingDialog() + }, + }, + ], + }) + } - // AI聊天Tab版 + // AI工具 menu.addSeparator() menu.addItem({ - iconHTML: ``, - label: this.pluginInstance.i18n.aiChatTab, - click: () => { - this.widgetInvoke.showPublisherAiChatTab() - }, + iconHTML: icons.iconPicbed, + label: this.pluginInstance.i18n.aitool, + submenu: [ + { + iconHTML: ``, + label: this.pluginInstance.i18n.aiChat, + click: () => { + this.widgetInvoke.showPublisherAiChatDialog() + }, + }, + { + iconHTML: ``, + label: this.pluginInstance.i18n.aiChatTab, + click: () => { + this.widgetInvoke.showPublisherAiChatTab() + }, + }, + ], }) // 扩展功能 @@ -230,7 +256,7 @@ export class Topbar { }, }) - // 设置 + // 通用设置 menu.addSeparator() menu.addItem({ icon: "iconSettings", @@ -254,23 +280,7 @@ export class Topbar { ], }) - // 当前文档ID - const pageId = PageUtil.getPageId() - menu.addSeparator() - menu.addItem({ - iconHTML: icons.iconOl, - label: this.pluginInstance.i18n.copyPageId, - click: async () => { - await HtmlUtils.copyToClipboard(pageId) - this.pluginInstance.kernelApi.pushMsg({ - msg: `当前文档ID已复制=>${pageId}`, - timeout: 3000, - }) - this.logger.info("当前文档ID已复制", pageId) - }, - }) - - // slogan + // 关于作者 menu.addSeparator() menu.addItem({ icon: "iconSparkles",