Skip to content

Commit

Permalink
add: itemBox examples
Browse files Browse the repository at this point in the history
  • Loading branch information
windingwind committed Feb 9, 2023
1 parent 47fdd99 commit 080736c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Search `@example` in `src/examples.ts`. The examples are called in `src/hooks.ts
- registerWindowMenuWithSeprator
- registerExtraColumn
- registerExtraColumnWithCustomCell
- registerCustomItemBoxRow
- registerCustomCellRenderer
- registerLibraryTabPanel
- registerReaderTabPanel
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"homepage": "https://github.com/windingwind/zotero-addon-template#readme",
"dependencies": {
"zotero-plugin-toolkit": "^2.0.0"
"zotero-plugin-toolkit": "^2.0.1"
},
"devDependencies": {
"@types/node": "^18.11.17",
Expand All @@ -51,4 +51,4 @@
"typescript": "^4.9.4",
"zotero-types": "^1.0.6"
}
}
}
4 changes: 3 additions & 1 deletion src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ async function onStartup() {

UIExampleFactory.registerRightClickMenuPopup();

UIExampleFactory.registerWindowMenuWithSeprator();
UIExampleFactory.registerWindowMenuWithSeparator();

await UIExampleFactory.registerExtraColumn();

await UIExampleFactory.registerExtraColumnWithCustomCell();

await UIExampleFactory.registerCustomCellRenderer();

await UIExampleFactory.registerCustomItemBoxRow();

UIExampleFactory.registerLibraryTabPanel();

await UIExampleFactory.registerReaderTabPanel();
Expand Down
44 changes: 41 additions & 3 deletions src/modules/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export class UIExampleFactory {
}

@example
static registerWindowMenuWithSeprator() {
static registerWindowMenuWithSeparator() {
ztoolkit.Menu.register("menuFile", {
tag: "menuseparator",
});
Expand Down Expand Up @@ -302,11 +302,49 @@ export class UIExampleFactory {
return span;
}
);
// @ts-ignore
// This is a private method. Make it public in toolkit.
await ztoolkit.ItemTree.refresh();
}

@example
static async registerCustomItemBoxRow() {
await ztoolkit.ItemBox.register(
"itemBoxFieldEditable",
"Editable Custom Field",
(field, unformatted, includeBaseMapped, item, original) => {
return (
ztoolkit.ExtraField.getExtraField(item, "itemBoxFieldEditable") || ""
);
},
{
editable: true,
setFieldHook: (field, value, loadIn, item, original) => {
window.alert("Custom itemBox value is changed and saved to extra!");
ztoolkit.ExtraField.setExtraField(
item,
"itemBoxFieldEditable",
value
);
return true;
},
index: 1,
}
);

await ztoolkit.ItemBox.register(
"itemBoxFieldNonEditable",
"Non-Editable Custom Field",
(field, unformatted, includeBaseMapped, item, original) => {
return (
"[CANNOT EDIT THIS]" + (item.getField("title") as string).slice(0, 10)
);
},
{
editable: false,
index: 2,
}
);
}

@example
static registerLibraryTabPanel() {
const tabId = ztoolkit.LibraryTabPanel.register(
Expand Down

0 comments on commit 080736c

Please sign in to comment.