reflect window updates in the tree view
This commit is contained in:
@@ -3,7 +3,6 @@ package controllers
|
||||
|
||||
import (
|
||||
serv "esdi/tui/internal/services"
|
||||
"esdi/tui/internal/ui"
|
||||
"esdi/tui/internal/views"
|
||||
"fmt"
|
||||
|
||||
@@ -26,68 +25,6 @@ func NewDeviceController(base *Controller, devService *serv.CDashService) *Devic
|
||||
StreamStrl: NewStreamingCtrl(),
|
||||
}
|
||||
|
||||
mc.Bus.On(ui.RedrawEv{}, func(e any) {
|
||||
go func() {
|
||||
rev := e.(ui.RedrawEv)
|
||||
if rev.Fn != nil {
|
||||
mc.App.QueueUpdateDraw(e.(ui.RedrawEv).Fn)
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
mc.Bus.On(ui.TUILoaded{}, func(e any) {
|
||||
mc.Logger.Debug("Yo, we do get here!\n")
|
||||
mc.Main()
|
||||
mc.PrintToOutputWindow("TUI LOADED EVENT")
|
||||
})
|
||||
|
||||
mc.Bus.On(ui.ChangeFocusEv{}, func(e any) {
|
||||
mc.App.SetFocus(e.(ui.ChangeFocusEv).Target)
|
||||
})
|
||||
|
||||
mc.Bus.On(ui.LogEv{}, func(e any) {
|
||||
go func() {
|
||||
mc.App.QueueUpdateDraw(func() {
|
||||
mc.Bus.Emit(ui.PrintLogEv{Log: e.(ui.LogEv).Log})
|
||||
})
|
||||
}()
|
||||
})
|
||||
|
||||
// mc.Bus.On(ui.CreateWindowEv{}, func(e any) {
|
||||
// })
|
||||
|
||||
// mc.Bus.On(ui.UpdateWindowEv{}, func(e any) {
|
||||
// winModel := e.(ui.UpdateWindowEv)
|
||||
//
|
||||
// // Build a new UIWindow here I guess
|
||||
// curWindow, ok := mc.CDash.State.Layout.Windows[winModel.ID]
|
||||
// if !ok {
|
||||
// mc.Bus.Emit(ui.PrintLogEv{Log: "could not acquire window from display state"})
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // Need to use a better interface for this me things
|
||||
// // Update the dimensions
|
||||
// curWindow.Dims.X0 = winModel.Window.X
|
||||
// curWindow.Dims.Y0 = winModel.Window.Y
|
||||
// curWindow.Dims.Width = winModel.Window.Width
|
||||
// curWindow.Dims.Height = winModel.Window.Height
|
||||
// // Update the opts
|
||||
// curWindow.Opts.ShowID = winModel.Window.ShowID
|
||||
// curWindow.Opts.WinType = winModel.Window.Type
|
||||
// curWindow.Opts.PreviewValue = helper.B32(winModel.Window.PreviewValue)
|
||||
// // Update the decorations
|
||||
// curWindow.Decor.TitleSize = winModel.Window.TitleSize
|
||||
// curWindow.Decor.TextSize = winModel.Window.TextSize
|
||||
// // Update the title
|
||||
// curWindow.Title = helper.B32(winModel.Window.Title)
|
||||
//
|
||||
// err := mc.CDash.UpdateWindow(winModel.ID, curWindow)
|
||||
// if err != nil {
|
||||
// mc.Bus.Emit(ui.PrintLogEv{Log: "failed to update window"})
|
||||
// }
|
||||
// })
|
||||
|
||||
// mc.Bus.On(ui.DestroyWindowEv{}, func(e any) {
|
||||
// mc.Logger.Info(fmt.Sprintf("Called in to destroy win: %d", e.(ui.DestroyWindowEv).ID))
|
||||
// mc.CDash.DestroyWindow(e.(ui.DestroyWindowEv).ID)
|
||||
|
||||
@@ -194,6 +194,8 @@ func (lc *LayoutController) createWindow() {
|
||||
// altogether given we won't be able to manipulate it any further
|
||||
lc.Messages <- "failed to append window to views " + err.Error()
|
||||
}
|
||||
|
||||
lc.App.SetFocus(lc.LayoutToolView.LayoutTree.Tree)
|
||||
}
|
||||
|
||||
func (lc *LayoutController) updateFormView(win *models.UIWindow) error {
|
||||
@@ -287,6 +289,9 @@ func (lc *LayoutController) updateWindowAction(win *models.UIWindow) {
|
||||
lc.Messages <- "failed to update window due to " + err.Error() + "\n"
|
||||
return
|
||||
}
|
||||
|
||||
// I guess it was a success, we must update the view
|
||||
lc.LayoutToolView.UpdateFormView(win)
|
||||
}
|
||||
|
||||
func (lc *LayoutController) displayLoadedLayouts() {
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package views
|
||||
|
||||
import (
|
||||
"esdi/tui/internal/dom"
|
||||
"esdi/tui/internal/events"
|
||||
"esdi/tui/internal/models"
|
||||
"esdi/tui/internal/ui"
|
||||
"fmt"
|
||||
|
||||
"github.com/gdamore/tcell/v2"
|
||||
@@ -18,32 +15,29 @@ const (
|
||||
LayoutToolNewWindowID = "new-window-action-form"
|
||||
)
|
||||
|
||||
type windowReference struct {
|
||||
ID int16
|
||||
Form *dom.UINode
|
||||
}
|
||||
// type windowReference struct {
|
||||
// ID int16
|
||||
// Form *dom.UINode
|
||||
// }
|
||||
|
||||
func getWindowRefFromNode(node *tview.TreeNode) *windowReference {
|
||||
ref := node.GetReference()
|
||||
wRef, ok := ref.(*windowReference)
|
||||
// func getWindowRefFromNode(node *tview.TreeNode) *windowReference {
|
||||
// ref := node.GetReference()
|
||||
// wRef, ok := ref.(*windowReference)
|
||||
//
|
||||
// if !ok {
|
||||
// return nil
|
||||
// }
|
||||
//
|
||||
// return wRef
|
||||
// }
|
||||
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
return wRef
|
||||
}
|
||||
|
||||
func FindNodeByID(
|
||||
node *tview.TreeNode,
|
||||
id int16,
|
||||
) *tview.TreeNode {
|
||||
func FindNodeByID(node *tview.TreeNode, id int16) *tview.TreeNode {
|
||||
if node == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if ref, ok := node.GetReference().(*windowReference); ok {
|
||||
if ref.ID == id {
|
||||
if ref, ok := node.GetReference().(*models.UIWindow); ok {
|
||||
if ref.IDX == id {
|
||||
return node
|
||||
}
|
||||
}
|
||||
@@ -57,67 +51,6 @@ func FindNodeByID(
|
||||
return nil
|
||||
}
|
||||
|
||||
func BindWindowEvents(
|
||||
bus *events.Bus,
|
||||
doc *dom.DOM,
|
||||
tree *tview.TreeView,
|
||||
) {
|
||||
bus.On(ui.WindowDestroyedEv{}, func(e any) {
|
||||
root := tree.GetRoot()
|
||||
if root == nil {
|
||||
bus.Emit(ui.LogEv{Log: "unable to get current tree node"})
|
||||
}
|
||||
|
||||
node := FindNodeByID(root, e.(ui.WindowDestroyedEv).ID)
|
||||
if node != nil {
|
||||
root.RemoveChild(node)
|
||||
}
|
||||
|
||||
// NODE: add a log here in case it fails so we know whats going on
|
||||
bus.Emit(ui.ForceRedraw{})
|
||||
})
|
||||
|
||||
bus.On(ui.ErrorCreateWindowEv{}, func(e any) {
|
||||
go func() {
|
||||
bus.Emit(ui.LogEv{
|
||||
Log: fmt.Sprintf(
|
||||
"Error performing action: %s\n", e.(ui.ErrorCreateWindowEv).Error.Error(),
|
||||
)})
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
func getCurNodeRef(tree *tview.TreeView) (*windowReference, error) {
|
||||
curNode := tree.GetCurrentNode()
|
||||
|
||||
if curNode == nil {
|
||||
return nil, fmt.Errorf("unable to get current tree node")
|
||||
}
|
||||
|
||||
winRef := getWindowRefFromNode(curNode)
|
||||
if winRef == nil {
|
||||
return nil, fmt.Errorf("unable to get window reference from tree node")
|
||||
}
|
||||
|
||||
return winRef, nil
|
||||
}
|
||||
|
||||
func layoutToolTreeViewOnSelect(bus *events.Bus) func(node *tview.TreeNode) {
|
||||
return func(node *tview.TreeNode) {
|
||||
// Get the window reference which will have the ID for the form
|
||||
bus.Emit(ui.LogEv{Log: "PRESSED ENTER\n"})
|
||||
|
||||
ref := node.GetReference()
|
||||
if ref == nil {
|
||||
bus.Emit(ui.LogEv{Log: "Couldn't find reference for node\n"})
|
||||
return
|
||||
}
|
||||
|
||||
nodeWinRef := ref.(*windowReference)
|
||||
bus.Emit(ui.ChangeFocusEv{Target: nodeWinRef.Form.Self})
|
||||
}
|
||||
}
|
||||
|
||||
type LayoutTreeView struct {
|
||||
Tree *tview.TreeView
|
||||
InputCapture func(*tcell.EventKey) *tcell.EventKey
|
||||
@@ -266,5 +199,20 @@ func (ltv *LayoutToolView) DeleteWindowByNode(node *tview.TreeNode) {
|
||||
}
|
||||
|
||||
func (ltv *LayoutToolView) UpdateFormView(win *models.UIWindow) {
|
||||
// Update the form view
|
||||
ltv.FormQuickAccess[win.IDX].SetValues(win)
|
||||
|
||||
// Update the treeview with the new title
|
||||
root := ltv.LayoutTree.Tree.GetRoot()
|
||||
if root == nil {
|
||||
// NOTE: excuse me!?
|
||||
return
|
||||
}
|
||||
|
||||
node := FindNodeByID(root, win.IDX)
|
||||
if node == nil {
|
||||
return
|
||||
}
|
||||
|
||||
node.SetText(windowInfoPageTitle(win.IDX, win.Window.Title.String()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user