diff --git a/editor/js/tools/menus/toolmenu.js b/editor/js/tools/menus/toolmenu.js index aeba38883633fe023d7fbc31af460af872947bd2..97d7f1534691328abb64998c111a0396ba4f0973 100644 --- a/editor/js/tools/menus/toolmenu.js +++ b/editor/js/tools/menus/toolmenu.js @@ -4,13 +4,66 @@ export default class ToolMenu { constructor(tool) { this.tool = tool; this.menuId = this.tool.getKey() + "-menu"; + this.warnings = false; + this.values = {}; } show() { - jQuery("#" + this.menuId).removeClass("hidden"); + this.getMenu().removeClass("hidden"); } hide() { - jQuery("#" + this.menuId).addClass("hidden"); + this.getMenu().addClass("hidden"); + } + + beforeGet(key) { + if (this.warnings) { + console.warn('Method "beforeGet" not implemented.'); + } + } + + afterSet(key, value) { + if (this.warnings) { + console.warn('Method "afterSet" not implemented.'); + } + } + + value(key, newValue) { + // If key not defined + // (be it by giving no arguments, or giving it an undefined value) + // Return all values as dict. + if (key === undefined) { + return this.values; + } + + // Is key valid? + // If not, create undefined entry + if (key in this.values == false) { + this.values[key] = undefined; + } + + // If value not defined, returned specified value. + if (newValue === undefined) { + newValue = this.beforeGet(key); + + if (newValue !== undefined) { + this.values[key] = newValue; + } + + return this.values[key]; + } + // If bot defined, store specified value. + else { + this.values[key] = newValue; + newValue = this.afterSet(key, newValue); + } + } + + getChildren(selector) { + return this.getMenu().children(selector); + } + + getMenu() { + return jQuery("#tool-menu #" + this.menuId); } }