moving cdashdisplay data handling to its backend
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package views
|
||||
|
||||
import (
|
||||
"esdi/tui/internal/models"
|
||||
"esdi/cdashdisplay"
|
||||
"fmt"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
@@ -20,8 +20,8 @@ func FindNodeByID(node *tview.TreeNode, id int16) *tview.TreeNode {
|
||||
return nil
|
||||
}
|
||||
|
||||
if ref, ok := node.GetReference().(*models.UIWindow); ok {
|
||||
if ref.IDX == id {
|
||||
if ref, ok := node.GetReference().(int16); ok {
|
||||
if ref == id {
|
||||
return node
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func NewLayoutTreeView() *LayoutTreeView {
|
||||
return view
|
||||
}
|
||||
|
||||
func (lt *LayoutTreeView) AddWindow(win *models.UIWindow) error {
|
||||
func (lt *LayoutTreeView) AddWindow(idx int16, win *cdashdisplay.UIWindow) error {
|
||||
root := lt.Tree.GetRoot()
|
||||
if root == nil {
|
||||
return fmt.Errorf("unable to get root of treeview")
|
||||
@@ -67,8 +67,8 @@ func (lt *LayoutTreeView) AddWindow(win *models.UIWindow) error {
|
||||
|
||||
// Create this new node
|
||||
newWindow := tview.NewTreeNode(
|
||||
windowInfoPageTitle(win.IDX, win.Window.Title.String()),
|
||||
).SetReference(win)
|
||||
windowInfoPageTitle(idx, win.Title.String()),
|
||||
).SetReference(idx)
|
||||
|
||||
root.AddChild(newWindow)
|
||||
|
||||
@@ -126,14 +126,14 @@ func NewLayoutToolView() *LayoutToolView {
|
||||
return view
|
||||
}
|
||||
|
||||
func (ltv *LayoutToolView) WindowCreatedSuccessfuly(win *models.UIWindow) error {
|
||||
func (ltv *LayoutToolView) WindowCreatedSuccessfuly(idx int16, win *cdashdisplay.UIWindow) error {
|
||||
updateWindowForm := NewWindowFormView(win)
|
||||
|
||||
// Update the pages ID
|
||||
ltv.LayoutActions.Pages.RemovePage(LayoutToolNewWindowID)
|
||||
AddAndShowPage(
|
||||
ltv.LayoutActions.Pages,
|
||||
windowInfoPageID(win.IDX),
|
||||
windowInfoPageID(idx),
|
||||
updateWindowForm.Form.Form,
|
||||
)
|
||||
|
||||
@@ -141,10 +141,10 @@ func (ltv *LayoutToolView) WindowCreatedSuccessfuly(win *models.UIWindow) error
|
||||
ltv.LayoutActions.CreateWindowView = nil
|
||||
|
||||
// Add this form thing to the quick access map
|
||||
ltv.FormQuickAccess[win.IDX] = updateWindowForm
|
||||
ltv.FormQuickAccess[idx] = updateWindowForm
|
||||
|
||||
// Add it to the tree view
|
||||
return ltv.LayoutTree.AddWindow(win)
|
||||
return ltv.LayoutTree.AddWindow(idx, win)
|
||||
}
|
||||
|
||||
func (ltv *LayoutToolView) ShowCreateWindowForm() {
|
||||
@@ -174,13 +174,13 @@ func (ltv *LayoutToolView) DeleteWindowByNode(node *tview.TreeNode) {
|
||||
|
||||
// We have to delete it from the map
|
||||
// This isn't very safe now is it?
|
||||
delete(ltv.FormQuickAccess, node.GetReference().(*models.UIWindow).IDX)
|
||||
delete(ltv.FormQuickAccess, node.GetReference().(int16))
|
||||
// Did we delete everything ???
|
||||
}
|
||||
|
||||
func (ltv *LayoutToolView) UpdateFormView(win *models.UIWindow) {
|
||||
func (ltv *LayoutToolView) UpdateFormView(idx int16, win *cdashdisplay.UIWindow) {
|
||||
// Update the form view
|
||||
ltv.FormQuickAccess[win.IDX].SetValues(win)
|
||||
ltv.FormQuickAccess[idx].SetValues(win)
|
||||
|
||||
// Update the treeview with the new title
|
||||
root := ltv.LayoutTree.Tree.GetRoot()
|
||||
@@ -189,10 +189,10 @@ func (ltv *LayoutToolView) UpdateFormView(win *models.UIWindow) {
|
||||
return
|
||||
}
|
||||
|
||||
node := FindNodeByID(root, win.IDX)
|
||||
node := FindNodeByID(root, idx)
|
||||
if node == nil {
|
||||
return
|
||||
}
|
||||
|
||||
node.SetText(windowInfoPageTitle(win.IDX, win.Window.Title.String()))
|
||||
node.SetText(windowInfoPageTitle(idx, win.Title.String()))
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package views
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"esdi/tui/internal/models"
|
||||
"esdi/cdashdisplay"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
@@ -90,7 +90,7 @@ type WindowFormView struct {
|
||||
UpdateBtn *tview.Button
|
||||
}
|
||||
|
||||
func NewWindowFormView(win *models.UIWindow) *WindowFormView {
|
||||
func NewWindowFormView(win *cdashdisplay.UIWindow) *WindowFormView {
|
||||
view := &WindowFormView{
|
||||
Form: NewCDashDisplayWindowFormView(),
|
||||
}
|
||||
@@ -106,17 +106,17 @@ func NewWindowFormView(win *models.UIWindow) *WindowFormView {
|
||||
return view
|
||||
}
|
||||
|
||||
func (fv *WindowFormView) SetValues(win *models.UIWindow) {
|
||||
fv.Form.X.SetText(fmt.Sprintf("%d", win.Window.Dims.X0))
|
||||
fv.Form.Y.SetText(fmt.Sprintf("%d", win.Window.Dims.Y0))
|
||||
fv.Form.Width.SetText(fmt.Sprintf("%d", win.Window.Dims.Width))
|
||||
fv.Form.Height.SetText(fmt.Sprintf("%d", win.Window.Dims.Height))
|
||||
fv.Form.Title.SetText(win.Window.Title.String())
|
||||
fv.Form.PreviewValue.SetText(win.Window.Opts.PreviewValue.String())
|
||||
fv.Form.ShowID.SetChecked(win.Window.Opts.ShowID == 1)
|
||||
func (fv *WindowFormView) SetValues(win *cdashdisplay.UIWindow) {
|
||||
fv.Form.X.SetText(fmt.Sprintf("%d", win.Dims.X0))
|
||||
fv.Form.Y.SetText(fmt.Sprintf("%d", win.Dims.Y0))
|
||||
fv.Form.Width.SetText(fmt.Sprintf("%d", win.Dims.Width))
|
||||
fv.Form.Height.SetText(fmt.Sprintf("%d", win.Dims.Height))
|
||||
fv.Form.Title.SetText(win.Title.String())
|
||||
fv.Form.PreviewValue.SetText(win.Opts.PreviewValue.String())
|
||||
fv.Form.ShowID.SetChecked(win.Opts.ShowID == 1)
|
||||
fv.Form.WinType.SetCurrentOption(0) // NOTE: this needs to set the correct option
|
||||
fv.Form.TitleSize.SetCurrentOption(int(win.Window.Decor.TitleSize))
|
||||
fv.Form.TextSize.SetCurrentOption(int(win.Window.Decor.TextSize))
|
||||
fv.Form.TitleSize.SetCurrentOption(int(win.Decor.TitleSize))
|
||||
fv.Form.TextSize.SetCurrentOption(int(win.Decor.TextSize))
|
||||
}
|
||||
|
||||
func windowInfoPageID(idx int16) string {
|
||||
|
||||
Reference in New Issue
Block a user