From 50fe92a1b184a12d25fe8f65c1743d6189498501 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Tue, 30 Jan 2024 01:20:36 -0600 Subject: [PATCH] delete window Signed-off-by: Jeff Carr --- plugin.go | 27 ++++++++++++++++++++++++++- view.go | 3 +++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/plugin.go b/plugin.go index ebe5ae3..223d4e5 100644 --- a/plugin.go +++ b/plugin.go @@ -75,12 +75,37 @@ func action(a widget.Action) { } else { // widget was already hidden } + case widget.Delete: + if w == nil { + return + } else { + w.hideWidgets() + w.deleteNode() + } + n.DeleteNode() + wRoot := me.treeRoot.TK.(*guiWidget) + wRoot.redoWindows(0, 0) default: - log.Log(ERROR, "action() ActionType =", a.ActionType, "WidgetType =", a.WidgetType, "Name =", a.ProgName) + log.Log(ERROR, "action() UNKNOWN Action Type =", a.ActionType, "WidgetType =", a.WidgetType, "Name =", a.ProgName) } log.Log(INFO, "action() END") } +func (w *guiWidget) deleteNode() { + p := w.parent + for i, child := range p.children { + log.Log(NOW, "parent has child:", i, child.cuiName, child.String()) + if w == child { + log.Log(NOW, "Found child ==", i, child.cuiName, child.String()) + log.Log(NOW, "Found n ==", i, w.cuiName, w.String()) + p.children = append(p.children[:i], p.children[i+1:]...) + } + } + for i, child := range p.children { + log.Log(NOW, "parent now has child:", i, child.cuiName, child.String()) + } +} + func (w *guiWidget) AddText(text string) { if w == nil { log.Log(NOW, "widget is nil") diff --git a/view.go b/view.go index 4da4ada..633eaa4 100644 --- a/view.go +++ b/view.go @@ -169,6 +169,9 @@ func (w *guiWidget) recreateView() { } func (w *guiWidget) hideWidgets() { + if w == nil { + return + } w.isCurrent = false switch w.node.WidgetType { case widget.Root: