Action button prototype
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user