Shortcuts now settable to a context.

This commit is contained in:
PeekabooSteam
2023-10-15 09:43:26 +01:00
parent 203a981fed
commit fdcff53697
8 changed files with 132 additions and 14 deletions

View File

@@ -0,0 +1,22 @@
import { ShortcutManager } from "../shortcut/shortcutmanager";
export interface ContextInterface {
}
export class Context {
#shortcutManager: ShortcutManager;
constructor( config:ContextInterface ) {
this.#shortcutManager = new ShortcutManager();
}
getShortcutManager() {
return this.#shortcutManager;
}
}

View File

@@ -0,0 +1,43 @@
import { Manager } from "../other/manager";
import { Context, ContextInterface } from "./context";
export class ContextManager extends Manager {
#currentContext!:string;
constructor() {
super();
}
add( name:string, contextConfig:ContextInterface ) {
super.add( name, new Context( contextConfig ) );
if ( Object.values( this.getAll() ).length === 1 ) {
this.#currentContext = name;
}
return this;
}
currentContextIs( contextName:string ) {
return contextName === this.#currentContext;
}
getCurrentContext() {
const contexts = this.getAll();
return ( contexts.hasOwnProperty( this.#currentContext ) ) ? contexts[this.#currentContext] : false;
}
setContext( contextName:string ) {
if ( !this.get( contextName ) ) {
console.error( `setContext(): context name "${contextName}" does not exist.` );
return false;
}
this.#currentContext = contextName;
console.log( `Setting context to "${this.#currentContext}".` );
}
}

View File

@@ -0,0 +1,15 @@
import { ContextMenu } from "../contextmenus/contextmenu";
import { Manager } from "../other/manager";
export class ContextMenuManager extends Manager {
constructor() {
super();
}
add( name:string, contextMenu:ContextMenu ) {
super.add( name, contextMenu );
return this;
}
}