ShowVMContextMenu displays the context menu for VM actions.
()
| 30 | |
| 31 | // ShowVMContextMenu displays the context menu for VM actions. |
| 32 | func (a *App) ShowVMContextMenu() { |
| 33 | if a.guestSelectionCount() > 1 { |
| 34 | a.showBatchVMContextMenu() |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | vm := a.vmList.GetSelectedVM() |
| 39 | if vm == nil { |
| 40 | return |
| 41 | } |
| 42 | |
| 43 | // Get the node for this VM |
| 44 | node := a.vmList.GetNodeForVM(vm) |
| 45 | |
| 46 | // Check if this VM has a pending operation |
| 47 | var isPending bool |
| 48 | var pendingOperation string |
| 49 | if a.taskManager != nil { |
| 50 | if task := a.taskManager.GetActiveTaskForVM(vm.Node, vm.ID); task != nil { |
| 51 | isPending = true |
| 52 | pendingOperation = task.Type |
| 53 | if task.Status == taskmanager.StatusQueued { |
| 54 | pendingOperation += " (Queued)" |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // Store last focused primitive |
| 60 | a.lastFocus = a.GetFocus() |
| 61 | |
| 62 | // Create menu items based on VM state |
| 63 | menuItems := []string{ |
| 64 | vmActionOpenShell, |
| 65 | vmActionEditConfig, |
| 66 | vmActionSnapshots, |
| 67 | vmActionBackups, |
| 68 | vmActionRefresh, |
| 69 | } |
| 70 | |
| 71 | if (vm.Type == api.VMTypeQemu || vm.Type == api.VMTypeLXC) && vm.Status == api.VMStatusRunning { |
| 72 | menuItems = append(menuItems[:1], append([]string{vmActionOpenVNC}, menuItems[1:]...)...) |
| 73 | } |
| 74 | |
| 75 | // Add plugin-contributed guest actions |
| 76 | var pluginActions []GuestAction |
| 77 | if a.pluginRegistry != nil && node != nil { |
| 78 | pluginActions = a.pluginRegistry.GuestActionsForGuest(node, vm) |
| 79 | for _, action := range pluginActions { |
| 80 | menuItems = append(menuItems, action.Label) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // Always show lifecycle actions, allowing queuing |
| 85 | if vm.Status == api.VMStatusRunning { |
| 86 | // When running, offer graceful Shutdown, force Stop, and Restart |
| 87 | menuItems = append(menuItems, vmActionShutdown, vmActionStop, vmActionRestart) |
| 88 | // Hard Reset is QEMU-only |
| 89 | if vm.Type == api.VMTypeQemu { |
no test coverage detected