use gadgets.GenericWindow()

This commit is contained in:
Jeff Carr 2025-03-04 04:12:14 -06:00
parent eca95a62fc
commit 6cb34ae52c
3 changed files with 9 additions and 115 deletions

View File

@ -107,7 +107,7 @@ func drawWindow(win *gadgets.GenericWindow) {
grid := win.Group.RawGrid() grid := win.Group.RawGrid()
me.goSrcPwd = gadgets.NewOneLiner(grid, "repo src home") me.goSrcPwd = gadgets.NewOneLiner(grid, "repo src home")
grid.NewLabel("") grid.NewLabel("")
var howtoWin *GenericWindow var howtoWin *gadgets.GenericWindow
me.demoB = grid.NewButton("Howto", func() { me.demoB = grid.NewButton("Howto", func() {
if howtoWin != nil { if howtoWin != nil {
howtoWin.Toggle() howtoWin.Toggle()
@ -211,13 +211,13 @@ func drawWindow(win *gadgets.GenericWindow) {
me.modePatchW.Disable() me.modePatchW.Disable()
// the user mode "hack Window" // the user mode "hack Window"
var hackWin *GenericWindow var hackWin *gadgets.GenericWindow
me.modeUserW = gridM.NewButton("Hack Window", func() { me.modeUserW = gridM.NewButton("Hack Window", func() {
if hackWin != nil { if hackWin != nil {
hackWin.Toggle() hackWin.Toggle()
return return
} }
hackWin := NewGenericWindow("Hack / User Mode Window", "Things that might be wrong") hackWin := gadgets.NewGenericWindow("Hack / User Mode Window", "Things that might be wrong")
grid := hackWin.Group.RawGrid() grid := hackWin.Group.RawGrid()
grid.NewButton("git pull", func() { grid.NewButton("git pull", func() {
log.Info("todo: run git pull on each repo") log.Info("todo: run git pull on each repo")
@ -382,7 +382,7 @@ func makeReposWin() *gadgets.GenericWindow {
}) })
}) })
var writeWin *GenericWindow var writeWin *gadgets.GenericWindow
me.repoWritableB = grid.NewButton("writable", func() { me.repoWritableB = grid.NewButton("writable", func() {
// if the window exists, just toggle it open or closed // if the window exists, just toggle it open or closed
if writeWin != nil { if writeWin != nil {
@ -536,8 +536,8 @@ func makeStandardReposWindow(title string, pb *gitpb.Repos) (*gitpb.ReposTable,
return t, box return t, box
} }
func makeWritableWindow(pb *gitpb.Repos) (*GenericWindow, *gitpb.ReposTable) { func makeWritableWindow(pb *gitpb.Repos) (*gadgets.GenericWindow, *gitpb.ReposTable) {
win := NewGenericWindow("Repos You have write access to", "Configure") win := gadgets.NewGenericWindow("Repos You have write access to", "Configure")
t := pb.NewTable("testForgeRepos") t := pb.NewTable("testForgeRepos")
t.NewUuid() t.NewUuid()

View File

@ -1,107 +0,0 @@
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0
package main
// This model works for 99.9% of all windows
// This is the Default Standard Window Model
import (
"go.wit.com/lib/gadgets"
"go.wit.com/log"
"go.wit.com/gui"
)
type GenericWindow struct {
Win *gadgets.BasicWindow // the window widget itself
Shelf *gui.Node // the overall box: the shelf
Stack *gui.Node // the first box is a stack
Top *gui.Node // the first item in the stack is always a shelf like box
Group *gui.Node // the first item top box is always a group
Middle *gui.Node // the middle box (shelf style)
Bottom *gui.Node // the bottom box (stack style)
}
func (gw *GenericWindow) Hidden() bool {
if gw == nil {
return true
}
if gw.Win == nil {
return true
}
return gw.Win.Hidden()
}
func (gw *GenericWindow) Toggle() {
if gw.Hidden() {
gw.Show()
} else {
gw.Hide()
}
}
func (gw *GenericWindow) Show() {
if gw == nil {
return
}
if gw.Win == nil {
return
}
gw.Win.Show()
}
func (gw *GenericWindow) Hide() {
if gw == nil {
return
}
if gw.Win == nil {
return
}
gw.Win.Hide()
}
func (gw *GenericWindow) Disable() {
if gw == nil {
return
}
if gw.Shelf == nil {
return
}
gw.Shelf.Disable()
}
func (gw *GenericWindow) Enable() {
if gw == nil {
return
}
if gw.Shelf == nil {
return
}
gw.Shelf.Enable()
}
func NewGenericWindow(title string, grouptxt string) *GenericWindow {
gw := new(GenericWindow)
gw.Win = gadgets.RawBasicWindow(title)
gw.Win.Make()
gw.Win.Custom = func() {
log.Warn("Found Window close. setting hidden=true")
// sets the hidden flag to false so Toggle() works
gw.Win.Hide()
}
gw.Shelf = gw.Win.Box()
// gw.Shelf.Vertical().SetProgName("ShelfBox")
gw.Stack = gw.Shelf.NewVerticalBox("Stackbox")
gw.Top = gw.Stack.NewVerticalBox("Stackbox")
gw.Middle = gw.Stack.Box()
gw.Bottom = gw.Stack.Box()
gw.Group = gw.Top.NewGroup(grouptxt)
gw.Show()
return gw
}

View File

@ -9,12 +9,13 @@ import (
"os" "os"
"go.wit.com/lib/fhelp" "go.wit.com/lib/fhelp"
"go.wit.com/lib/gadgets"
"go.wit.com/lib/gui/shell" "go.wit.com/lib/gui/shell"
"go.wit.com/log" "go.wit.com/log"
) )
func makeHowtoWin() *GenericWindow { func makeHowtoWin() *gadgets.GenericWindow {
howtoWin := NewGenericWindow("Howto", "forge -- a GUI tool for git repostories") howtoWin := gadgets.NewGenericWindow("Howto", "forge -- a GUI tool for git repostories")
tmp := `A good way to see how forge works is to download forge tmp := `A good way to see how forge works is to download forge
This will 'git clone' a few things (~50 repos): This will 'git clone' a few things (~50 repos):