main 5041353

popup_window.go RawHistoryFolder

1package window
2
3import (
4	"context"
5
6	"github.com/bnema/dumber/internal/logging"
7	"github.com/bnema/puregotk/v4/gtk"
8	"github.com/rs/zerolog"
9)
10
11const (
12	popupWindowDefaultWidth  = 900
13	popupWindowDefaultHeight = 800
14)
15
16// PopupWindow is a lightweight top-level GTK host for native-required popup flows.
17type PopupWindow struct {
18	window         *gtk.ApplicationWindow
19	content        *gtk.Box
20	currentContent *gtk.Widget
21	logger         zerolog.Logger
22}
23
24func NewPopup(ctx context.Context, app *gtk.Application) (*PopupWindow, error) {
25	log := logging.FromContext(ctx)
26	pw := &PopupWindow{logger: log.With().Str("component", "popup-window").Logger()}
27
28	pw.window = gtk.NewApplicationWindow(app)
29	if pw.window == nil {
30		return nil, ErrWindowCreationFailed
31	}
32	pw.window.SetDefaultSize(popupWindowDefaultWidth, popupWindowDefaultHeight)
33	title := windowTitle
34	pw.window.SetTitle(&title)
35
36	pw.content = gtk.NewBox(gtk.OrientationVerticalValue, 0)
37	if pw.content == nil {
38		pw.window.Unref()
39		return nil, ErrWidgetCreationFailed("popupWindow.content")
40	}
41	pw.content.SetHexpand(true)
42	pw.content.SetVexpand(true)
43	pw.content.SetVisible(true)
44	pw.window.SetChild(&pw.content.Widget)
45	return pw, nil
46}
47
48func (pw *PopupWindow) SetContent(widget *gtk.Widget) {
49	if pw == nil || pw.content == nil {
50		return
51	}
52	if pw.currentContent != nil {
53		pw.content.Remove(pw.currentContent)
54		pw.currentContent = nil
55	}
56	if widget == nil {
57		return
58	}
59	widget.SetVisible(true)
60	pw.content.Append(widget)
61	pw.currentContent = widget
62}
63
64// DetachContent removes and returns the hosted widget without destroying it.
65// Callers must detach before reparenting the widget into another GTK host.
66func (pw *PopupWindow) DetachContent() *gtk.Widget {
67	if pw == nil || pw.content == nil || pw.currentContent == nil {
68		return nil
69	}
70	widget := pw.currentContent
71	pw.content.Remove(widget)
72	pw.currentContent = nil
73	return widget
74}
75
76func (pw *PopupWindow) Show() {
77	if pw == nil || pw.window == nil {
78		return
79	}
80	pw.window.Present()
81}
82
83func (pw *PopupWindow) Close() {
84	if pw == nil || pw.window == nil {
85		return
86	}
87	pw.window.Close()
88}
89
90func (pw *PopupWindow) Destroy() {
91	if pw == nil || pw.window == nil {
92		return
93	}
94	pw.window.Destroy()
95	pw.window = nil
96	pw.content = nil
97	pw.currentContent = nil
98}
99
100func (pw *PopupWindow) Window() *gtk.ApplicationWindow {
101	if pw == nil {
102		return nil
103	}
104	return pw.window
105}
106
107func (pw *PopupWindow) SetTitle(title string) {
108	if pw == nil || pw.window == nil {
109		return
110	}
111	pw.window.SetTitle(&title)
112}

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