2022-10-17 00:38:27 -05:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
2023-03-01 11:35:36 -06:00
|
|
|
"git.wit.org/wit/gui/toolkit"
|
2022-10-17 00:38:27 -05:00
|
|
|
)
|
|
|
|
|
2022-10-19 13:23:22 -05:00
|
|
|
// This function should make a new node with the parent and
|
|
|
|
// the 'tab' as a child
|
|
|
|
|
2022-11-13 08:53:03 -06:00
|
|
|
func (n *Node) NewTab(text string) *Node {
|
2023-04-23 14:18:34 -05:00
|
|
|
// check to make sure n is actually a window
|
|
|
|
|
2023-04-24 14:17:43 -05:00
|
|
|
|
2023-04-23 14:18:34 -05:00
|
|
|
if (n.WidgetType != toolkit.Window) {
|
|
|
|
// figure out what the actual window is
|
2023-04-24 08:45:30 -05:00
|
|
|
log(logError, "NewTab() is being requested on something that isn't a Window. node =", n)
|
2023-04-24 14:17:43 -05:00
|
|
|
if (n.parent == nil) {
|
2023-04-23 14:18:34 -05:00
|
|
|
// TODO: find a window. any window. never give up. never die.
|
2023-04-24 14:17:43 -05:00
|
|
|
log(logError, "NewTab() TODO: make a window here", n)
|
2023-04-23 14:18:34 -05:00
|
|
|
panic("NewTab did not get passed a window")
|
|
|
|
}
|
2023-04-24 14:17:43 -05:00
|
|
|
log(logError, "NewTab() parent =", n.parent)
|
|
|
|
if (n.parent.WidgetType == toolkit.Root) {
|
|
|
|
// also broken
|
|
|
|
log(logError, "NewTab() TODO: make a window here", n)
|
|
|
|
panic("NewTab did not get passed a window")
|
|
|
|
}
|
|
|
|
// go up the binary tree until we find a window widget to add a tab too
|
|
|
|
return n.parent.NewTab(text)
|
2023-04-23 14:18:34 -05:00
|
|
|
}
|
2023-04-08 11:06:50 -05:00
|
|
|
newNode := n.newNode(text, toolkit.Tab, nil)
|
2022-10-19 13:23:22 -05:00
|
|
|
|
2023-03-23 12:35:12 -05:00
|
|
|
var a toolkit.Action
|
2023-03-29 23:03:04 -05:00
|
|
|
a.ActionType = toolkit.Add
|
|
|
|
a.Name = text
|
|
|
|
a.Text = text
|
2023-03-23 12:35:12 -05:00
|
|
|
newaction(&a, newNode, n)
|
|
|
|
|
2023-04-06 14:16:59 -05:00
|
|
|
newBox := newNode.NewBox(text, true)
|
2023-03-29 23:03:04 -05:00
|
|
|
return newBox
|
2022-10-19 13:23:22 -05:00
|
|
|
}
|