diff --git a/debug.go b/debug.go index 84630f5..490b113 100644 --- a/debug.go +++ b/debug.go @@ -86,6 +86,9 @@ func (tk *guiWidget) dumpWidget(s string) { } else { end = fmt.Sprintf("%-8s %-8s %s", tk.WidgetType(), tk.cuiName, tk.String()) } + if tk.findParentTable() != nil { + end += " (table)" + } log.Log(GOCUI, s1, s, end) } diff --git a/eventBindingsStdout.go b/eventBindingsStdout.go index f48ed77..f1c574e 100644 --- a/eventBindingsStdout.go +++ b/eventBindingsStdout.go @@ -8,12 +8,14 @@ import ( "github.com/awesome-gocui/gocui" "go.wit.com/log" + "go.wit.com/toolkits/tree" ) func theStdout(g *gocui.Gui, v *gocui.View) error { // me.stdout.pager = 0 infos := fmt.Sprintf("pager=%d len(%d) ", me.stdout.pager, len(me.stdout.outputS)) infos += fmt.Sprintf("last(%d,%d)", me.stdout.lastW, me.stdout.lastH) + me.stdout.changed = true if me.stdout.outputOnTop { if me.stdout.outputOffscreen { @@ -22,18 +24,38 @@ func theStdout(g *gocui.Gui, v *gocui.View) error { me.stdout.lastW = me.stdout.tk.gocuiSize.w0 me.stdout.lastH = me.stdout.tk.gocuiSize.h0 relocateStdoutOffscreen() + new1 := new(tree.ToolkitConfig) + new1.Plugin = "gocui" + new1.Name = "stdoutoffscreen" + new1.Value = "true" + me.myTree.ConfigSave(new1) return nil } else { me.stdout.outputOffscreen = true log.Info("stdout moved on screen", infos) + new1 := new(tree.ToolkitConfig) + new1.Plugin = "gocui" + new1.Name = "stdoutoffscreen" + new1.Value = "false" + me.myTree.ConfigSave(new1) } // move the stdout window back onscreen me.stdout.tk.relocateStdout(me.stdout.lastW, me.stdout.lastH) me.stdout.outputOnTop = false setThingsOnTop() + new1 := new(tree.ToolkitConfig) + new1.Plugin = "gocui" + new1.Name = "stdoutlevel" + new1.Value = "bottom" + me.myTree.ConfigSave(new1) } else { me.stdout.outputOnTop = true setThingsOnTop() + new1 := new(tree.ToolkitConfig) + new1.Plugin = "gocui" + new1.Name = "stdoutlevel" + new1.Value = "top" + me.myTree.ConfigSave(new1) } return nil } diff --git a/eventMouseDrag.go b/eventMouseDrag.go index 5559fac..62aa916 100644 --- a/eventMouseDrag.go +++ b/eventMouseDrag.go @@ -48,6 +48,7 @@ func mouseMove(g *gocui.Gui) { // old hack. create the 'msg' view if it does not yet exist // TODO: put this somewhere more correct if widgetView, _ := g.View("msg"); widgetView == nil { + me.stdout.changed = true if createStdout(g) { return } @@ -138,5 +139,6 @@ func (tk *guiWidget) moveNew() { // log.Info("Resize false", w, h, newW, newH) } setThingsOnTop() // sets help, Stdout, etc on the top after windows have been redrawn + me.stdout.changed = true } } diff --git a/find.go b/find.go index 2cb94f3..13d9c0e 100644 --- a/find.go +++ b/find.go @@ -186,6 +186,20 @@ func (tk *guiWidget) findParentWindow() *guiWidget { return tk.parent.findParentWindow() } +func (tk *guiWidget) findParentTable() *guiWidget { + if tk.isTable { + log.Info("findParentTAble()", tk.labelN, tk.cuiName, tk.node.WidgetId) + return tk + } + if tk.node.WidgetId == 0 { + return nil + } + if tk.parent == nil { + return nil + } + return tk.parent.findParentWindow() +} + func (tk *guiWidget) findWidgetByName(name string) *guiWidget { if tk.cuiName == name { return tk diff --git a/init.go b/init.go index b13f634..2820bcf 100644 --- a/init.go +++ b/init.go @@ -14,10 +14,13 @@ import ( "runtime" "runtime/debug" "runtime/pprof" + "strconv" + "strings" "time" "github.com/awesome-gocui/gocui" "go.wit.com/log" + "go.wit.com/toolkits/tree" ) // sent via -ldflags @@ -184,6 +187,19 @@ func initPlugin() { me.stdout.lastW = 4 me.stdout.lastH = 20 + if val, err := me.myTree.ConfigFind("stdoutsize"); err == nil { + parts := strings.Fields(val) + if len(parts) == 4 { + log.Info("initial stdout settings:", parts) + me.stdout.w, _ = strconv.Atoi(parts[0]) + me.stdout.h, _ = strconv.Atoi(parts[1]) + me.stdout.lastW, _ = strconv.Atoi(parts[2]) + me.stdout.lastH, _ = strconv.Atoi(parts[3]) + } else { + log.Info("initial stdout settings parse error:", parts) + } + } + // just make up unique values for these me.dropdown.wId = -77 me.textbox.wId = -55 @@ -376,6 +392,18 @@ func refreshGocui() { me.newWindowTrigger <- me.treeRoot.TK.(*guiWidget) me.refresh = false } + if me.stdout.changed { + log.Log(NOW, "newWindowTrigger() TODO: gocui should save the stdout size & location here") + me.stdout.changed = false + me.stdout.tk.dumpWidget("save") + new1 := new(tree.ToolkitConfig) + new1.Plugin = "gocui" + new1.Name = "stdoutsize" + width := me.stdout.tk.gocuiSize.w1 - me.stdout.tk.gocuiSize.w0 + height := me.stdout.tk.gocuiSize.h1 - me.stdout.tk.gocuiSize.h0 + new1.Value = fmt.Sprintf("%d %d %d %d", width, height, me.stdout.tk.gocuiSize.w0, me.stdout.tk.gocuiSize.h0) + me.myTree.ConfigSave(new1) + } } // this code updates the clock diff --git a/plugin.go b/plugin.go index 7555c44..67def55 100644 --- a/plugin.go +++ b/plugin.go @@ -16,7 +16,7 @@ func newAdd(n *tree.Node) { return } if n.TK != nil { - log.Warn("Tree Add() sent a widget we aleady seem to have") + log.Log(INFO, "Tree Add() sent a widget we aleady seem to have") // this is done to protect the plugin being 'refreshed' with the // widget binary tree. TODO: find a way to keep them in sync return diff --git a/structs.go b/structs.go index fcd04cf..c9337b1 100644 --- a/structs.go +++ b/structs.go @@ -116,11 +116,10 @@ type stdout struct { disable bool // disable the stdout window. do not change os.Stdout & os.Stderr lastW int // the last 'w' location (used to move from offscreen to onscreen) lastH int // the last 'h' location (used to move from offscreen to onscreen) - // mouseOffsetW int // the current 'w' offset - // mouseOffsetH int // the current 'h' offset - init bool // moves the window offscreen on startup - outputS []string // the buffer of all the output - pager int // allows the user to page through the buffer + init bool // moves the window offscreen on startup + outputS []string // the buffer of all the output + pager int // allows the user to page through the buffer + changed bool // indicates the user has changed stdout. gocui should remember the state here } // settings for the dropdown window @@ -241,6 +240,7 @@ type guiWidget struct { color *colorT // what color to use colorLast colorT // the last color the widget had defaultColor *colorT // the default colors // TODO: make a function for this instead + isTable bool // is this a table? } // THIS IS GO COMPILER MAGIC diff --git a/table.go b/table.go index efc0b4e..df16fc2 100644 --- a/table.go +++ b/table.go @@ -13,20 +13,6 @@ import ( "go.wit.com/widget" ) -/* -func initGridPB(pb *guipb.Widget) *guiWidget { - var w *guiWidget - w = new(guiWidget) - - w.pb = pb - w.parent = me.treeRoot.TK.(*guiWidget) - w.wtype = widget.Window - w.cuiName = fmt.Sprintf("%d %s", pb.Id, "TK") - w.labelN = pb.Name - return w -} -*/ - func initGridPB(pb *guipb.Widget) *guiWidget { var w *guiWidget w = new(guiWidget) @@ -35,6 +21,7 @@ func initGridPB(pb *guipb.Widget) *guiWidget { w.wtype = widget.Grid w.cuiName = fmt.Sprintf("%d %s", pb.Id, "TK") w.labelN = pb.Name + w.isTable = true return w } diff --git a/treeAdd.go b/widgetAdd.go similarity index 100% rename from treeAdd.go rename to widgetAdd.go diff --git a/treeWidget.go b/widgetCommon.go similarity index 100% rename from treeWidget.go rename to widgetCommon.go diff --git a/treeDraw.go b/widgetDraw.go similarity index 100% rename from treeDraw.go rename to widgetDraw.go