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

Method showManagePluginsDialog

internal/ui/components/plugins_manager.go:14–228  ·  view source on GitHub ↗

showManagePluginsDialog displays a dialog for toggling plugins on or off.

()

Source from the content-addressed store, hash-verified

12
13// showManagePluginsDialog displays a dialog for toggling plugins on or off.
14func (a *App) showManagePluginsDialog() {
15 a.lastFocus = a.GetFocus()
16
17 infos := a.pluginCatalogSnapshot()
18 if len(infos) == 0 {
19 a.header.ShowError("No plugins available.")
20 return
21 }
22
23 type pluginEntry struct {
24 info PluginInfo
25 enabled bool
26 }
27
28 entries := make([]pluginEntry, len(infos))
29 enabledSet := make(map[string]struct{}, len(a.config.Plugins.Enabled))
30 for _, id := range a.config.Plugins.Enabled {
31 if id == "" {
32 continue
33 }
34 enabledSet[id] = struct{}{}
35 }
36
37 for i, info := range infos {
38 _, enabled := enabledSet[info.ID]
39 entries[i] = pluginEntry{
40 info: info,
41 enabled: enabled,
42 }
43 }
44
45 originalEnabled := append([]string(nil), a.config.Plugins.Enabled...)
46 sort.Strings(originalEnabled)
47
48 list := tview.NewList().
49 ShowSecondaryText(true)
50 list.SetBorder(false)
51 list.SetHighlightFullLine(true)
52 list.SetSelectedStyle(tcell.StyleDefault.Background(theme.Colors.Selection).Foreground(theme.Colors.Primary).Attributes(tcell.AttrReverse))
53
54 updateList := func() {
55 current := list.GetCurrentItem()
56 list.Clear()
57 checkedMarker := tview.Escape("[x]")
58 uncheckedMarker := tview.Escape("[ ]")
59 for _, entry := range entries {
60 marker := uncheckedMarker
61 if entry.enabled {
62 marker = checkedMarker
63 }
64 list.AddItem(marker+" "+entry.info.Name, entry.info.Description, 0, nil)
65 }
66 if current >= 0 && current < len(entries) {
67 list.SetCurrentItem(current)
68 }
69 }
70
71 toggleAt := func(index int) {

Callers 1

ShowGlobalContextMenuMethod · 0.95

Calls 14

pluginCatalogSnapshotMethod · 0.95
SetSelectedFuncMethod · 0.80
SetTextColorMethod · 0.80
ShowErrorMethod · 0.65
GetCurrentItemMethod · 0.65
ClearMethod · 0.65
SetCurrentItemMethod · 0.65
SetFocusMethod · 0.65
ErrorMethod · 0.65
ShowSuccessMethod · 0.65

Tested by

no test coverage detected