diff --git a/addon/locale/en-US/addon.ftl b/addon/locale/en-US/addon.ftl index 69c0920..c1eaf48 100644 --- a/addon/locale/en-US/addon.ftl +++ b/addon/locale/en-US/addon.ftl @@ -85,6 +85,10 @@ workspace-notesPane-hint = PDF NotePane is not accesible if no PDF files are ope workspace-switchOutline = Swith Outline Mode workspace-saveOutlineImage = Save Image workspace-saveOutlineFreeMind = Save MindMap +workspace-emptyWorkspaceGuideInfo = No note opened in workspace. +workspace-emptyWorkspaceGuideOpen = Choose a note to open +workspace-emptyWorkspaceGuideOr = or +workspace-emptyWorkspaceGuideCreate = Create a new note editor-toolbar-main = Workspace Note editor-toolbar-settings-title = Workspace Settings diff --git a/addon/locale/ru-RU/addon.ftl b/addon/locale/ru-RU/addon.ftl index 30e87fc..407bc04 100644 --- a/addon/locale/ru-RU/addon.ftl +++ b/addon/locale/ru-RU/addon.ftl @@ -85,6 +85,10 @@ workspace-notesPane-hint=PDF панель заметок недоступна е workspace-switchOutline=Переключить режим Набросок workspace-saveOutlineImage=Сохранить изображение workspace-saveOutlineFreeMind=Сохранить MindMap +workspace-emptyWorkspaceGuideInfo = No note opened in workspace. +workspace-emptyWorkspaceGuideOpen = Choose a note to open +workspace-emptyWorkspaceGuideOr = or +workspace-emptyWorkspaceGuideCreate = Create a new note editor-toolbar-main=Заметка рабочего пространства editor-toolbar-settings-title=Настройки рабочего пространства diff --git a/addon/locale/zh-CN/addon.ftl b/addon/locale/zh-CN/addon.ftl index a6c8e85..f9ff82b 100644 --- a/addon/locale/zh-CN/addon.ftl +++ b/addon/locale/zh-CN/addon.ftl @@ -85,6 +85,10 @@ workspace-notesPane-hint=PDF笔记侧栏在没有PDF文件打开时不可访问- workspace-switchOutline=切换大纲模式 workspace-saveOutlineImage=保存图片 workspace-saveOutlineFreeMind=保存思维导图 +workspace-emptyWorkspaceGuideInfo = 没有打开的工作区笔记。您可以: +workspace-emptyWorkspaceGuideOpen = 打开现有笔记 +workspace-emptyWorkspaceGuideOr = 或 +workspace-emptyWorkspaceGuideCreate = 创建新笔记 editor-toolbar-main=工作区笔记 editor-toolbar-settings-title=工作区选项 diff --git a/package.json b/package.json index 6219fbc..5beaef3 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "unist-util-visit": "^5.0.0", "unist-util-visit-parents": "^6.0.1", "yamljs": "^0.3.0", - "zotero-plugin-toolkit": "^2.3.2" + "zotero-plugin-toolkit": "^2.3.9" }, "devDependencies": { "@esbuild-plugins/node-globals-polyfill": "^0.2.3", @@ -96,6 +96,6 @@ "release-it": "^16.1.5", "replace-in-file": "^7.0.1", "typescript": "^5.2.2", - "zotero-types": "^1.2.2" + "zotero-types": "^1.3.2" } } diff --git a/src/modules/workspace/content.ts b/src/modules/workspace/content.ts index 8cee1e1..4bb57aa 100644 --- a/src/modules/workspace/content.ts +++ b/src/modules/workspace/content.ts @@ -1,5 +1,6 @@ import { config } from "../../../package.json"; import { ICONS } from "../../utils/config"; +import { itemPicker } from "../../utils/itemPicker"; import { getString } from "../../utils/locale"; import { getNoteTreeFlattened } from "../../utils/note"; import { getPref } from "../../utils/prefs"; @@ -221,7 +222,7 @@ export function initWorkspace(container: XUL.Box | undefined) { } export async function initWorkspaceEditor( - container: XUL.Box | undefined, + container: XUL.Box, type: "main" | "preview", noteId: number, options: { @@ -231,12 +232,100 @@ export async function initWorkspaceEditor( ) { const noteItem = Zotero.Items.get(noteId); if (!noteItem || !noteItem.isNote()) { - if (window.confirm(getString("alert.notValidWorkspaceNote"))) { - await addon.hooks.onCreateWorkspaceNote(); - } + ztoolkit.UI.appendElement( + { + tag: "div", + id: makeId("emptyWorkspaceGuide"), + styles: { + position: "absolute", + top: "0", + left: "0", + width: "100%", + height: "100%", + display: "flex", + flexDirection: "column", + justifyContent: "center", + alignItems: "center", + textAlign: "center", + backgroundColor: "rgba(255,255,255,0.8)", + zIndex: "100", + }, + children: [ + { + tag: "div", + properties: { + innerHTML: getString("workspace-emptyWorkspaceGuideInfo"), + }, + styles: { + fontSize: "20px", + fontWeight: "bold", + color: "gray", + }, + }, + { + tag: "button", + namespace: "xul", + properties: { + label: getString("workspace-emptyWorkspaceGuideOpen"), + }, + styles: { + fontSize: "16px", + }, + listeners: [ + { + type: "command", + listener: async (ev) => { + const selectedIds = await itemPicker(); + if ( + selectedIds?.length === 1 && + Zotero.Items.get(selectedIds[0]).isNote() + ) { + addon.hooks.onSetWorkspaceNote(selectedIds[0], "main"); + addon.hooks.onOpenWorkspace(); + } else { + window.alert(getString("menuFile-openMainNote-error")); + } + }, + }, + ], + }, + { + tag: "div", + properties: { + innerHTML: getString("workspace-emptyWorkspaceGuideOr"), + }, + styles: { + fontSize: "16px", + color: "gray", + }, + }, + { + tag: "button", + namespace: "xul", + properties: { + label: getString("workspace-emptyWorkspaceGuideCreate"), + }, + styles: { + fontSize: "16px", + }, + listeners: [ + { + type: "command", + listener: () => { + addon.hooks.onCreateWorkspaceNote(); + }, + }, + ], + }, + ], + }, + container, + ); return; + } else { + container.querySelector(`#${makeId("emptyWorkspaceGuide")}`)?.remove(); } - const editorElem = container?.querySelector( + const editorElem = container.querySelector( `#${makeId("editor-" + type)}`, ) as EditorElement; await waitUtilAsync(() => Boolean(editorElem._initialized))