Skip to content

Commit

Permalink
Replace Tool.extraButtons by Tool.queryExtraButtons
Browse files Browse the repository at this point in the history
  • Loading branch information
benlau committed Mar 10, 2024
1 parent 4bf8c1d commit 5a94ad1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
5 changes: 4 additions & 1 deletion src/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ export default class Panel {
}

async onLoaded() {
/// Triggered by DDDot.onLoad which may be called multiple times
/// e.g when the panel is hidden and shown again
const {
joplinService,
joplinRepo,
Expand All @@ -241,9 +243,10 @@ export default class Panel {
key,
title,
hasView,
extraButtons,
} = tool;

const extraButtons = await tool.queryExtraButtons();

const enabled = await tool.updateEnabledFromSetting();

if (enabled) {
Expand Down
27 changes: 18 additions & 9 deletions src/tools/outline/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,25 @@ export default class OutlineTool extends Tool {
};
}

get extraButtons() {
return [
{
tooltip: t("outline.resize_to_fit_tooltip"),
icon: "fas fa-expand-arrows-alt",
message: {
type: "outline.onAutoResizeClicked",
async queryExtraButtons() {
const resizeMode = await this.joplinRepo.settingsLoad(
OutlineResizeModeSettingKey,
OutlineToolResizeMode.Manual,
);

if (resizeMode === OutlineToolResizeMode.Manual) {
return [
{
tooltip: t("outline.resize_to_fit_tooltip"),
icon: "fas fa-expand-arrows-alt",
message: {
type: "outline.onAutoResizeClicked",
},
},
},
];
];
}

return [];
}

@blockDisabled
Expand Down
2 changes: 1 addition & 1 deletion src/tools/shortcuts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default class Shortcuts extends Tool {
return t("shortcuts.title");
}

get extraButtons() {
async queryExtraButtons() {
return [
{
tooltip: t("shortcuts.import_export_tooltip"),
Expand Down
8 changes: 4 additions & 4 deletions src/tools/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ export default class Tool {
return true;
}

get extraButtons(): ToolButton[] {
return [];
}

async updateEnabledFromSetting() {
const res = await this.joplinRepo.settingsLoad(this.genSettingKey("enabled"), true);
this.isEnabled = res as Boolean;
return res;
}

async queryExtraButtons(): Promise<ToolButton[]> {
return [];
}

genSettingKey(key: string) {
return `dddot.settings.${this.key}.${key}`;
}
Expand Down

0 comments on commit 5a94ad1

Please sign in to comment.