Skip to content

Commit

Permalink
feat: 整合菜单,专注核心功能
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Oct 27, 2023
1 parent 9689c55 commit 72e525e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 58 deletions.
2 changes: 2 additions & 0 deletions siyuan/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 5 additions & 3 deletions siyuan/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
"publishTool": "发布工具",
"publish": "发布",
"preview": "发布预览",
"picmanage": "图床管理",
"picbed": "上传图片到图床",
"setting": "设置",
"aitool": "智能工具",
"setting": "通用设置",
"settingGeneral": "偏好设置",
"settingPicbed": "图床设置",
"settingPublish": "发布设置",
"settingPlatform": "平台设置",
"settingAbout": "关于",
"settingAbout": "关于作者",
"copyPageId": "复制文档ID",
"publisherWidget": "挂件版",
"cancel": "取消",
Expand All @@ -18,5 +20,5 @@
"publishNormal": "常规发布",
"extendFunction": "扩展功能",
"aiChat": "AI聊天",
"aiChatTab": "AI聊天(Tab版)"
"aiChatTab": "新页签AI聊天"
}
120 changes: 65 additions & 55 deletions siyuan/topbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class Topbar {
dynJsonCfg.totalCfg?.forEach((config: any) => {
let icon = `<span class="iconfont-icon">${config.platformIcon}</span>`
// 修复图片不展示问题
if (/^\<img/.test(config.platformIcon) && config.platformIcon.indexOf("./images") > -1) {
if (/^<img/.test(config.platformIcon) && config.platformIcon.indexOf("./images") > -1) {
icon = config.platformIcon.replace(
/\.\/images/g,
`${window.location.origin}/plugins/siyuan-plugin-publisher/images`
Expand Down Expand Up @@ -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 = <IMenuItemOption[]>[]
if (isBlogInstalled) {
Expand All @@ -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")

// 一键发布
Expand Down Expand Up @@ -193,24 +188,55 @@ export class Topbar {
},
})

// AI聊天
menu.addSeparator()
menu.addItem({
iconHTML: `<svg class="b3-menu__icon" style=""><use xlink:href="#iconUsers"></use></svg>`,
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: `<svg class="b3-menu__icon" style=""><use xlink:href="#iconAccount"></use></svg>`,
label: this.pluginInstance.i18n.aiChatTab,
click: () => {
this.widgetInvoke.showPublisherAiChatTab()
},
iconHTML: icons.iconPicbed,
label: this.pluginInstance.i18n.aitool,
submenu: [
{
iconHTML: `<svg class="b3-menu__icon" style=""><use xlink:href="#iconUsers"></use></svg>`,
label: this.pluginInstance.i18n.aiChat,
click: () => {
this.widgetInvoke.showPublisherAiChatDialog()
},
},
{
iconHTML: `<svg class="b3-menu__icon" style=""><use xlink:href="#iconAccount"></use></svg>`,
label: this.pluginInstance.i18n.aiChatTab,
click: () => {
this.widgetInvoke.showPublisherAiChatTab()
},
},
],
})

// 扩展功能
Expand All @@ -230,7 +256,7 @@ export class Topbar {
},
})

// 设置
// 通用设置
menu.addSeparator()
menu.addItem({
icon: "iconSettings",
Expand All @@ -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",
Expand Down

0 comments on commit 72e525e

Please sign in to comment.