Action button prototype

This commit is contained in:
Zef Hemel
2022-05-06 18:55:04 +02:00
parent 3037dbe58a
commit 7e221ce5aa
20 changed files with 324 additions and 54 deletions
+25 -2
View File
@@ -1,6 +1,7 @@
import { Hook, Manifest } from "@plugos/plugos/types";
import { System } from "@plugos/plugos/system";
import { EventEmitter } from "@plugos/plugos/event";
import { ActionButton } from "../types";
export type CommandDef = {
name: string;
@@ -10,6 +11,14 @@ export type CommandDef = {
// Bind to keyboard shortcut
key?: string;
mac?: string;
// Action button
button?: ButtonDef;
};
export type ButtonDef = {
label: string;
tooltip?: string;
};
export type AppCommand = {
@@ -22,7 +31,10 @@ export type CommandHookT = {
};
export type CommandHookEvents = {
commandsUpdated(commandMap: Map<string, AppCommand>): void;
commandsUpdated(
commandMap: Map<string, AppCommand>,
appButtons: ActionButton[]
): void;
};
export class CommandHook
@@ -30,9 +42,11 @@ export class CommandHook
implements Hook<CommandHookT>
{
editorCommands = new Map<string, AppCommand>();
actionButtons: ActionButton[] = [];
buildAllCommands(system: System<CommandHookT>) {
this.editorCommands.clear();
this.actionButtons = [];
for (let plug of system.loadedPlugs.values()) {
for (const [name, functionDef] of Object.entries(
plug.manifest!.functions
@@ -47,9 +61,18 @@ export class CommandHook
return plug.invoke(name, []);
},
});
if (cmd.button) {
this.actionButtons.push({
label: cmd.button.label,
tooltip: cmd.button.tooltip,
run: () => {
return plug.invoke(name, []);
},
});
}
}
}
this.emit("commandsUpdated", this.editorCommands);
this.emit("commandsUpdated", this.editorCommands, this.actionButtons);
}
apply(system: System<CommandHookT>): void {