Skip to content

Commit

Permalink
add: empty workspace guide
Browse files Browse the repository at this point in the history
  • Loading branch information
windingwind committed Oct 19, 2023
1 parent 0b6e513 commit 5f0f574
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 7 deletions.
4 changes: 4 additions & 0 deletions addon/locale/en-US/addon.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions addon/locale/ru-RU/addon.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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=Настройки рабочего пространства
Expand Down
4 changes: 4 additions & 0 deletions addon/locale/zh-CN/addon.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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=工作区选项
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
99 changes: 94 additions & 5 deletions src/modules/workspace/content.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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: {
Expand All @@ -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))
Expand Down

0 comments on commit 5f0f574

Please sign in to comment.