From 90a9f84f109800b820f5d15bad0b7ba146586edc Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 9 Feb 2025 12:34:53 -0600 Subject: [PATCH] more code cleanups --- eventMouse.go | 82 --------------------------------------------- eventMouseClick.go | 83 +++++++++++++++++++++++++--------------------- eventMouseDrag.go | 41 ----------------------- help.go | 2 +- 4 files changed, 47 insertions(+), 161 deletions(-) diff --git a/eventMouse.go b/eventMouse.go index 935f2b5..859ba84 100644 --- a/eventMouse.go +++ b/eventMouse.go @@ -10,7 +10,6 @@ import ( "github.com/awesome-gocui/gocui" "go.wit.com/log" - "go.wit.com/widget" ) func mouseUp(g *gocui.Gui, v *gocui.View) error { @@ -22,7 +21,6 @@ func mouseUp(g *gocui.Gui, v *gocui.View) error { */ me.mouse.mouseUp = true - // me.mouse.globalMouseDown = false me.mouse.currentDrag = nil if me.mouse.double && (time.Since(me.mouse.down) < me.mouse.doubletime) { @@ -46,7 +44,6 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error { if time.Since(me.mouse.down) < me.mouse.doubletime { me.mouse.double = true } - // me.mouse.globalMouseDown = true me.mouse.mouseUp = false me.mouse.down = time.Now() w, h := g.MousePosition() @@ -72,85 +69,6 @@ func mouseDown(g *gocui.Gui, v *gocui.View) error { } win.setAsDragging() } - return nil - } - - if time.Since(me.mouse.down) < me.mouse.clicktime { - log.Info("not yet") - return nil - } - - w, h := g.MousePosition() - - // if the dropdown is active, never do anything else - if me.dropdown.active { - log.Info("mouseDown() stopping here. dropdwon menu is in effect") - for _, tk := range findByXY(w, h) { - if (tk.node.WidgetType == widget.Flag) && (tk == me.dropdown.tk) { - // log.Info("SENDING CLICK TO Flag (dropdown)") - tk.doWidgetClick(w, h) - me.dropdown.active = false - return nil - } - } - log.Info("never found dropdown at", w, h) - return nil - } - - // if the textbox is active, never do anything else - if me.textbox.active { - log.Info("mouseDown() stopping here. textbox widget is open") - for _, tk := range findByXY(w, h) { - if (tk.node.WidgetType == widget.Flag) && (tk == me.textbox.tk) { - me.textbox.active = false - textboxClosed() - return nil - } - } - log.Info("never found textbox at", w, h) - return nil - } - // figre out what window this is - win := findWindowUnderMouse() - if win == nil { - log.Info("mouseDown() nothing to click on at", w, h) - return nil } return nil - // me.mouse.currentDrag = tk - - /* - if !tk.isWindowActive() { - tk.makeWindowActive() - return nil - } - - // log.Info("SENDING mouseDown() to findWindowUnderMouse()") - if tk.node.WidgetType == widget.Window { - // check to see if this is a direct click on a widget - for _, tk := range tk.findByXYreal(w, h) { - // tk.dumpWidget("mouseDown()") - if tk.node.WidgetType == widget.Button { - // log.Info("SENDING CLICK TO Button") - tk.doWidgetClick(w, h) - return nil - } - if tk.node.WidgetType == widget.Checkbox { - // log.Info("SENDING CLICK TO Checkbox") - tk.doWidgetClick(w, h) - return nil - } - if tk.node.WidgetType == widget.Dropdown { - // log.Info("SENDING CLICK TO Dropdown") - tk.doWidgetClick(w, h) - return nil - } - if tk.node.WidgetType == widget.Textbox { - // log.Info("SENDING CLICK TO Textbox") - tk.doWidgetClick(w, h) - return nil - } - } - } - */ } diff --git a/eventMouseClick.go b/eventMouseClick.go index 79809b0..54547af 100644 --- a/eventMouseClick.go +++ b/eventMouseClick.go @@ -77,48 +77,57 @@ func doMouseClick(w int, h int) { } win := findWindowUnderMouse() - if win != nil { - // look in this window for widgets - // widgets have priority. send the click here first - for _, tk := range win.findByXYreal(w, h) { - switch tk.node.WidgetType { - case widget.Checkbox: - if tk.node.State.Checked { - log.Log(WARN, "checkbox is being set to false") - tk.node.State.Checked = false - tk.setCheckbox() - } else { - log.Log(WARN, "checkbox is being set to true") - tk.node.State.Checked = true - tk.setCheckbox() - } - me.myTree.SendUserEvent(tk.node) - return - case widget.Button: - tk.doButtonClick() - return - case widget.Combobox: - tk.showDropdown() - return - case widget.Dropdown: - tk.showDropdown() - return - case widget.Textbox: - tk.showTextbox() - return - default: - // TODO: enable the GUI debugger in gocui - // tk.dumpWidget("undef click()") // enable this to debug widget clicks - } - } + if win == nil { + log.Log(GOCUI, "click() nothing was at:", w, h) + return + } + if !win.isWindowActive() { + win.makeWindowActive() + return + } else { + // potentally the user is closing the window if win.checkWindowClose(w, h) { return } - // log.Info("you clicked on a window, but not any widgets. check for title / close window here", win.cuiName) - win.makeWindowActive() - return } + // look in this window for widgets + // widgets have priority. send the click here first + for _, tk := range win.findByXYreal(w, h) { + switch tk.node.WidgetType { + case widget.Checkbox: + if tk.node.State.Checked { + log.Log(WARN, "checkbox is being set to false") + tk.node.State.Checked = false + tk.setCheckbox() + } else { + log.Log(WARN, "checkbox is being set to true") + tk.node.State.Checked = true + tk.setCheckbox() + } + me.myTree.SendUserEvent(tk.node) + return + case widget.Button: + tk.doButtonClick() + return + case widget.Combobox: + tk.showDropdown() + return + case widget.Dropdown: + tk.showDropdown() + return + case widget.Textbox: + tk.showTextbox() + return + default: + // TODO: enable the GUI debugger in gocui + // tk.dumpWidget("undef click()") // enable this to debug widget clicks + } + } + // log.Info("you clicked on a window, but not any widgets. check for title / close window here", win.cuiName) + // win.makeWindowActive() + // return + var found bool for _, tk := range findByXY(w, h) { diff --git a/eventMouseDrag.go b/eventMouseDrag.go index c52867b..649b755 100644 --- a/eventMouseDrag.go +++ b/eventMouseDrag.go @@ -74,12 +74,6 @@ func mouseMove(g *gocui.Gui) { return } - /* - if me.mouse.globalMouseDown && (me.dropdown.active || me.textbox.active) { - log.Info("can't drag while dropdown or textbox are active", w, h) - return - } - */ if me.mouse.mouseUp { return } @@ -92,41 +86,6 @@ func mouseMove(g *gocui.Gui) { } log.Info(fmt.Sprintf("gui toolkit error. nothing to drag at (%d,%d)", w, h)) return - - // if me.mouse.globalMouseDown { - // log.Info("msgMouseDown == true") - // plugin will segfault if you don't keep this inside a check for msgMouseDown - // don't move this code out of here - /* - // new function that is smarter - if tk := findWindowUnderMouse(); tk != nil { - tk.setAsDragging() - return - } - // first look for windows - for _, tk := range findByXY(w, h) { - if tk.node.WidgetType == widget.Window { - tk.setAsDragging() - return - } - } - - // now look for the STDOUT window - for _, tk := range findByXY(w, h) { - if tk.node.WidgetType == widget.Flag { - tk.setAsDragging() - return - } - } - for _, tk := range findByXY(w, h) { - if tk.node.WidgetType == widget.Stdout { - tk.setAsDragging() - // tk.moveNew() - return - } - found = true - } - */ } func (tk *guiWidget) setAsDragging() { diff --git a/help.go b/help.go index 067d841..db008a4 100644 --- a/help.go +++ b/help.go @@ -26,7 +26,7 @@ import ( var helpText []string = []string{"Help Menu", "", - "H: toggle z(H)elp", + "H: toggle (H)elp", "D: toggle light/dark mode", "Tab: toggle through windows", "q: quit()",