history_sidebar_widgets.go RawHistoryFolder
1package component
2
3import (
4 "fmt"
5
6 "github.com/bnema/puregotk/v4/gtk"
7)
8
9// =============================================================================
10// Widget creation
11// =============================================================================
12
13func (hs *HistorySidebar) createWidgets() error {
14 if err := hs.initOuterBox(); err != nil {
15 return err
16 }
17 if err := hs.initSearchBox(); err != nil {
18 return err
19 }
20 if err := hs.initListArea(); err != nil {
21 return err
22 }
23 return nil
24}
25
26func (hs *HistorySidebar) initOuterBox() error {
27 hs.outerBox = gtk.NewBox(gtk.OrientationVerticalValue, 0)
28 if hs.outerBox == nil {
29 return fmt.Errorf("history sidebar: outer box creation failed")
30 }
31 hs.outerBox.AddCssClass("sidebar-outer")
32 hs.outerBox.AddCssClass("history-sidebar-outer")
33 hs.outerBox.SetSizeRequest(sidebarMinWidth, -1)
34 hs.outerBox.SetHexpand(false)
35 hs.outerBox.SetVexpand(true)
36 hs.outerBox.SetVisible(false)
37 return nil
38}
39
40func (hs *HistorySidebar) initSearchBox() error {
41 hs.searchBox = gtk.NewBox(gtk.OrientationHorizontalValue, 4)
42 if hs.searchBox == nil {
43 return fmt.Errorf("history sidebar: search box creation failed")
44 }
45 hs.searchBox.AddCssClass("sidebar-search-box")
46 hs.searchBox.AddCssClass("history-sidebar-search-box")
47 hs.searchBox.SetHexpand(true)
48
49 hs.searchEntry = gtk.NewSearchEntry()
50 if hs.searchEntry == nil {
51 return fmt.Errorf("history sidebar: search entry creation failed")
52 }
53 hs.searchEntry.AddCssClass("sidebar-search")
54 hs.searchEntry.AddCssClass("history-sidebar-search")
55 hs.searchEntry.SetHexpand(true)
56 placeholder := "Search history..."
57 hs.searchEntry.SetPlaceholderText(&placeholder)
58
59 hs.searchBox.Append(&hs.searchEntry.Widget)
60 hs.outerBox.Append(&hs.searchBox.Widget)
61 return nil
62}
63
64func (hs *HistorySidebar) initListArea() error {
65 hs.scrolledWin = gtk.NewScrolledWindow()
66 if hs.scrolledWin == nil {
67 return fmt.Errorf("history sidebar: scrolled window creation failed")
68 }
69 hs.scrolledWin.SetVexpand(true)
70 hs.scrolledWin.SetHexpand(true)
71 hs.scrolledWin.SetPolicy(gtk.PolicyNeverValue, gtk.PolicyAutomaticValue)
72 hs.scrolledWin.AddCssClass("sidebar-list")
73 hs.scrolledWin.AddCssClass("history-sidebar-groups")
74
75 hs.listBox = gtk.NewListBox()
76 if hs.listBox == nil {
77 return fmt.Errorf("history sidebar: list box creation failed")
78 }
79 hs.listBox.AddCssClass("sidebar-list")
80 hs.listBox.AddCssClass("history-sidebar-groups")
81 hs.listBox.SetActivateOnSingleClick(true)
82 hs.listBox.SetSelectionMode(gtk.SelectionSingleValue)
83
84 // Connect row activation (single-click and keyboard activation)
85 rowActivatedCb := func(_ gtk.ListBox, rowPtr uintptr) {
86 row := gtk.ListBoxRowNewFromInternalPtr(rowPtr)
87 if row == nil {
88 return
89 }
90 hs.onRowActivated(row)
91 }
92 hs.retainedCallbacks = append(hs.retainedCallbacks, rowActivatedCb)
93 hs.listBox.ConnectRowActivated(&rowActivatedCb)
94
95 hs.scrolledWin.SetChild(&hs.listBox.Widget)
96 hs.outerBox.Append(&hs.scrolledWin.Widget)
97 return nil
98}