MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / ShowNodeContextMenu

Method ShowNodeContextMenu

internal/ui/components/node_menu.go:19–102  ·  view source on GitHub ↗

ShowNodeContextMenu displays the context menu for node actions.

()

Source from the content-addressed store, hash-verified

17
18// ShowNodeContextMenu displays the context menu for node actions.
19func (a *App) ShowNodeContextMenu() {
20 node := a.nodeList.GetSelectedNode()
21 if node == nil {
22 return
23 }
24
25 // Store last focused primitive
26 a.lastFocus = a.GetFocus()
27
28 type menuEntry struct {
29 label string
30 shortcut rune
31 handler func()
32 }
33
34 entries := []menuEntry{
35 {label: nodeActionOpenShell, shortcut: 's', handler: func() { a.openNodeShell() }},
36 {label: nodeActionOpenVNC, shortcut: 'v', handler: func() { a.openNodeVNC() }},
37 {label: nodeActionCreateVM, shortcut: 'c', handler: func() { a.showVMCreateForm(node) }},
38 {label: nodeActionCreateLXC, shortcut: 'l', handler: func() { a.showLXCCreateForm(node) }},
39 }
40
41 if a.pluginRegistry != nil {
42 for _, pluginAction := range a.pluginRegistry.NodeActionsForNode(node) {
43 pa := pluginAction
44 entries = append(entries, menuEntry{
45 label: pa.Label,
46 shortcut: pa.Shortcut,
47 handler: func() {
48 if pa.Handler == nil {
49 return
50 }
51
52 if err := pa.Handler(a.ctx, a, node); err != nil {
53 a.showMessageSafe(fmt.Sprintf("%s failed: %v", pa.Label, err))
54 }
55 },
56 })
57 }
58 }
59
60 entries = append(entries, menuEntry{label: nodeActionRefresh, shortcut: 'r', handler: func() {
61 a.refreshNodeData(node)
62 }})
63
64 menuItems := make([]string, len(entries))
65 shortcuts := make([]rune, len(entries))
66 for i, entry := range entries {
67 menuItems[i] = entry.label
68 shortcuts[i] = entry.shortcut
69 }
70
71 menu := NewContextMenuWithShortcuts(" Node Actions ", menuItems, shortcuts, func(index int, action string) {
72 a.CloseContextMenu()
73
74 if index >= 0 && index < len(entries) {
75 handler := entries[index].handler
76 if handler != nil {

Callers 1

setupKeyboardHandlersMethod · 0.95

Calls 13

openNodeShellMethod · 0.95
openNodeVNCMethod · 0.95
showVMCreateFormMethod · 0.95
showLXCCreateFormMethod · 0.95
showMessageSafeMethod · 0.95
refreshNodeDataMethod · 0.95
CloseContextMenuMethod · 0.95
showContextMenuPageMethod · 0.95
NodeActionsForNodeMethod · 0.80
GetSelectedNodeMethod · 0.65
SetAppMethod · 0.65

Tested by

no test coverage detected