diff --git a/help.go b/help.go index 4c64ec2..fa011c6 100644 --- a/help.go +++ b/help.go @@ -15,6 +15,8 @@ import ( "github.com/awesome-gocui/gocui" log "go.wit.com/log" + "go.wit.com/toolkits/tree" + "go.wit.com/widget" ) /* @@ -86,37 +88,81 @@ func showHelp() error { } g.SetViewOnTop("help") me.helpLabel = help - if me.clock.tk == nil { - makeClock() - me.clock.tk.MoveToOffset(maxX-10, 1) - me.clock.tk.Hide() - me.clock.tk.Show() - } - if me.clock.tk != nil { - me.clock.tk.MoveToOffset(maxX-10, 1) - me.clock.tk.Hide() - me.clock.tk.Show() - } - if me.stdout.tk == nil { - makeOutputWidget(me.baseGui, "made this in showHelp()") - msg := fmt.Sprintf("test to stdout from in showHelp() %d\n", me.ecount) - me.stdout.Write([]byte(msg)) - log.Log(NOW, "log.log(NOW) test") + if me.treeRoot == nil { + log.Info("gogui makeClock() error. treeRoot == nil") + return nil + } else { + if me.notify.clock.tk == nil { + makeClock(me.notify.clock.wId) + me.notify.clock.tk.MoveToOffset(maxX-10, 1) + me.notify.clock.tk.Hide() + me.notify.clock.tk.Show() + } + if me.notify.clock.tk != nil { + me.notify.clock.tk.MoveToOffset(maxX-10, 1) + me.notify.clock.tk.Hide() + me.notify.clock.tk.Show() + } + if me.stdout.tk == nil { + makeOutputWidget(me.baseGui, "made this in showHelp()") + msg := fmt.Sprintf("test to stdout from in showHelp() %d\n", me.ecount) + me.stdout.Write([]byte(msg)) + log.Log(NOW, "log.log(NOW) test") + } } return nil } -func makeClock() { - me.clock.tk = makeNewFlagWidget(me.clock.wId) - me.clock.tk.dumpWidget("init() clock") +// create a new widget in the binary tree +func makeNewInternalWidget(wId int) *guiWidget { + if me.treeRoot == nil { + log.Info("GOGUI Init ERROR. treeRoot == nil") + return nil + } + n := new(tree.Node) + n.WidgetType = widget.Flag + n.WidgetId = wId + n.ParentId = 0 + + // store the internal toolkit information + tk := new(guiWidget) + tk.frame = true + + tk.node = n + tk.node.Parent = me.treeRoot + + // set the name used by gocui to the id + tk.cuiName = fmt.Sprintf("%d DR", wId) + + tk.setColorInput() + + // add this new widget on the binary tree + tk.parent = me.treeRoot.TK.(*guiWidget) + if tk.parent == nil { + panic("makeNewFlagWidget() didn't get treeRoot guiWidget") + } else { + tk.parent.children = append(tk.parent.children, tk) + } + + n.TK = tk + return tk +} + +func makeClock(wId int) { + if me.treeRoot == nil { + log.Info("gogui makeClock() error. treeRoot == nil") + return + } + me.notify.clock.tk = makeNewInternalWidget(wId) + me.notify.clock.tk.dumpWidget("init() clock") w, h := me.baseGui.MousePosition() - me.clock.tk.MoveToOffset(w, h) - me.clock.tk.labelN = time.Now().Format("15:04:05") - me.clock.tk.frame = false - me.clock.tk.setColorLabel() - me.clock.tk.Show() - me.clock.active = true - me.clock.tk.dumpWidget("showClock()") + me.notify.clock.tk.MoveToOffset(w, h) + me.notify.clock.tk.labelN = time.Now().Format("15:04:05") + me.notify.clock.tk.frame = false + me.notify.clock.tk.setColorLabel() + me.notify.clock.tk.Show() + me.notify.clock.active = true + me.notify.clock.tk.dumpWidget("showClock()") } // in the very end of redrawing things, this will place the help and stdout on the top or botton @@ -127,8 +173,8 @@ func setThingsOnTop() { } else { me.baseGui.SetViewOnTop("help") } - if me.clock.tk != nil { - me.baseGui.SetViewOnTop(me.clock.tk.v.Name()) + if me.notify.clock.tk != nil { + me.baseGui.SetViewOnTop(me.notify.clock.tk.v.Name()) } if me.stdout.tk == nil { diff --git a/init.go b/init.go index 5fcf589..ef29827 100644 --- a/init.go +++ b/init.go @@ -68,7 +68,8 @@ func initPlugin() { me.dropdown.wId = -77 me.textbox.wId = -55 me.stdout.wId = -4 - me.clock.wId = -5 + me.notify.clock.wId = -5 + me.notify.menu.wId = -5 Set(&me.dropdown, "default") // s := fmt.Sprintln("fake default check =", me.FakeW, "dropdown.Id", me.dropdown.Id) @@ -252,24 +253,24 @@ func refreshGocui() { // todo: add logic here to see if the application has changed anything // me.baseGui.UpdateAsync(testRefresh) // probably don't need this me.baseGui.Update(testRefresh) - if me.clock.tk != nil && !me.showHelp { + if me.notify.clock.tk != nil && !me.showHelp { // also double check the gocui view exists - if me.clock.tk.v != nil { - me.clock.tk.v.Clear() - me.clock.tk.labelN = time.Now().Format("15:04:05") - me.clock.tk.v.WriteString(me.clock.tk.labelN) + if me.notify.clock.tk.v != nil { + me.notify.clock.tk.v.Clear() + me.notify.clock.tk.labelN = time.Now().Format("15:04:05") + me.notify.clock.tk.v.WriteString(me.notify.clock.tk.labelN) } } lastRefresh = time.Now() } else { me.baseGui.Update(testRefresh) if time.Since(lastRefresh) > 3*time.Second { - if me.clock.tk != nil && !me.showHelp { + if me.notify.clock.tk != nil && !me.showHelp { // also double check the gocui view exists - if me.clock.tk.v != nil { - me.clock.tk.v.Clear() - me.clock.tk.labelN = time.Now().Format("15:04:05") - me.clock.tk.v.WriteString(me.clock.tk.labelN) + if me.notify.clock.tk.v != nil { + me.notify.clock.tk.v.Clear() + me.notify.clock.tk.labelN = time.Now().Format("15:04:05") + me.notify.clock.tk.v.WriteString(me.notify.clock.tk.labelN) } } lastRefresh = time.Now() diff --git a/structs.go b/structs.go index a9702a4..425698e 100644 --- a/structs.go +++ b/structs.go @@ -77,13 +77,14 @@ type config struct { stdout stdout // information for the STDOUT window dropdown dropdown // the dropdown menu textbox dropdown // the textbox popup window - clock dropdown // the textbox popup window - allwin []*guiWidget // for tracking which window is next - dark bool // use a 'dark' color palette - mouse mouse // mouse settings - showDebug bool // todo: move this into config struct - debug bool // todo: move this into config struct - starttime time.Time // checks how long it takes on startup + // clock dropdown // the textbox popup window + notify libnotify // emulates the desktop libnotify menu + allwin []*guiWidget // for tracking which window is next + dark bool // use a 'dark' color palette + mouse mouse // mouse settings + showDebug bool // todo: move this into config struct + debug bool // todo: move this into config struct + starttime time.Time // checks how long it takes on startup } // stuff controlling how the mouse works @@ -127,14 +128,23 @@ type dropdown struct { h int // the height active bool // is the dropdown menu currently in use? init bool // moves the window offscreen on startup - Id int `default:"-78"` // the widget id to use - wId int `default:"-78"` // the widget id to use + // Id int `default:"-78"` // the widget id to use + wId int `default:"-78"` // the widget id to use +} + +// settings for the dropdown window +type internalTK struct { + tk *guiWidget // where to show STDOUT + callerTK *guiWidget // which widget called the dropdown menu + wId int // the widget id to use + active bool // is the internal widget currently in use? } // the desktop libnotify menu type libnotify struct { - clock *guiWidget // where to show the clock - menu *guiWidget // where to show the clock + clock internalTK // widget for the clock + menu internalTK // libnotify menu icon + window internalTK // the libnotify menu } // this is the gocui way diff --git a/textbox.go b/textbox.go index ffc2812..73a8ed6 100644 --- a/textbox.go +++ b/textbox.go @@ -109,7 +109,7 @@ func textboxClosed() { me.textbox.tk.Hide() // log.Info("textbox closed with text:", newtext, me.textbox.callerTK.cuiName) - if me.clock.tk.v != nil { + if me.notify.clock.tk.v != nil { me.baseGui.SetCurrentView("help") } else { me.baseGui.SetCurrentView("msg")