main 5041353

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}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close