From 793639c69d3e58e694c99b218758e7cd1bb15f97 Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Wed, 22 Mar 2023 01:32:46 +0100 Subject: [PATCH] improved home context --- src/lib/HomeContext.hx | 55 ++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/src/lib/HomeContext.hx b/src/lib/HomeContext.hx index b3e8028..216c766 100644 --- a/src/lib/HomeContext.hx +++ b/src/lib/HomeContext.hx @@ -1,5 +1,6 @@ package lib; +import bin.KernelLog; import lib.ui.elements.UIElement; import lib.ui.elements.TextElement; import lib.ui.elements.RootElement; @@ -80,32 +81,56 @@ class HomeContext { } private function handleSelectContext(contextId:Int) { - if (workspaces[contextId] != null) { - focusContext(contextId); - } else { - var newContext = WindowManager.instance.createNewBufferedContext(); - - // Create new terminal - var term = new Terminal(); - term.invoke(newContext); - - addContextToWorkspace(newContext, contextId); - focusContext(contextId); + if (workspaces[contextId] == null) { + return; } + + focusContext(contextId); + } + + private function addTerminal(){ + var newContext = WindowManager.instance.createNewBufferedContext(); + + // Create new terminal + var term = new Terminal(); + term.invoke(newContext); + + var contextID = addContextNextWorkspace(newContext); + if (contextID == -1) { + return; + } + focusContext(contextID); + } + + + private function addLog(){ + var newContext = WindowManager.instance.createNewBufferedContext(); + + // Create new terminal + var term = new KernelLog(); + term.invoke(newContext); + + var contextID = addContextNextWorkspace(newContext); + if (contextID == -1) { + return; + } + focusContext(contextID); } private function render() { ctx.clear(); ctx.setCursorBlink(false); - var list = [ - for (i in 0...MAX_CONTEXT) workspaces.exists(i) ? 'Switch to context ${i}' : 'Create new Terminal on context ${i}' - ]; + var workspaceIDs:Array = [for (k=>v in workspaces) k]; + workspaceIDs.sort((a, b) -> a - b); var children:Array = [ - for (i => line in list) new TextElement(line, {onClick: this.handleSelectContext.bind(i)}) + for (i in workspaceIDs) new TextElement('Switch to ${i + 1}', {onClick: this.handleSelectContext.bind(i)}) ]; + children.push(new TextElement('Add Terminal', {onClick: this.addTerminal})); + children.push(new TextElement('Add Log', {onClick: this.addLog})); + renderer.setChildren(children); renderer.render().renderToContext(ctx);