Debian Codegraph @

internal/gui/dynamickeybindings.go

raw symbols SCIP
1 package gui
2
3 import (
4 "github.com/jroimartin/gocui"
5 )
6
7 func (gui *Gui) updateDynamicKeybindings() error {
8 vd, err := gui.g.View(dynamicViewFeature.Name)
9 if err != nil {
10 return err
11 }
12 t := DynamicViewMode(vd.Title)
13
14 // the order is important here
15 _ = gui.generateKeybindings()
16 gui.g.DeleteKeybindings(vd.Name())
17
18 keybindings := []*KeyBinding{
19 {
20 View: dynamicViewFeature.Name,
21 Key: gocui.KeyTab,
22 Modifier: gocui.ModNone,
23 Handler: gui.focusBackToMain,
24 Display: "tab",
25 Description: "Back to Overview",
26 Vital: false,
27 }, {
28 View: dynamicViewFeature.Name,
29 Key: gocui.KeyArrowRight,
30 Modifier: gocui.ModNone,
31 Handler: gui.nextFocusView,
32 Display: "→",
33 Description: "Next Panel",
34 Vital: false,
35 }, {
36 View: dynamicViewFeature.Name,
37 Key: 'l',
38 Modifier: gocui.ModNone,
39 Handler: gui.nextFocusView,
40 Display: "l",
41 Description: "Next Panel",
42 Vital: false,
43 }, {
44 View: dynamicViewFeature.Name,
45 Key: gocui.KeyArrowLeft,
46 Modifier: gocui.ModNone,
47 Handler: gui.previousFocusView,
48 Display: "←",
49 Description: "Prev Panel",
50 Vital: false,
51 }, {
52 View: dynamicViewFeature.Name,
53 Key: 'h',
54 Modifier: gocui.ModNone,
55 Handler: gui.previousFocusView,
56 Display: "h",
57 Description: "Prev Panel",
58 Vital: false,
59 },
60 }
61
62 switch t {
63 case CommitStatMode:
64 caseBindings := []*KeyBinding{
65 {
66 View: dynamicViewFeature.Name,
67 Key: 'd',
68 Modifier: gocui.ModNone,
69 Handler: gui.commitDiff,
70 Display: "d",
71 Description: "diff",
72 Vital: true,
73 }, {
74 View: dynamicViewFeature.Name,
75 Key: gocui.KeyPgup,
76 Modifier: gocui.ModNone,
77 Handler: gui.dpageUp,
78 Display: "pg up",
79 Description: "Page up",
80 Vital: true,
81 }, {
82 View: dynamicViewFeature.Name,
83 Key: gocui.KeyPgdn,
84 Modifier: gocui.ModNone,
85 Handler: gui.dpageDown,
86 Display: "pg down",
87 Description: "Page Down",
88 Vital: true,
89 },
90 }
91 keybindings = append(keybindings, caseBindings...)
92 case CommitDiffMode:
93 caseBindings := []*KeyBinding{
94 {
95 View: dynamicViewFeature.Name,
96 Key: 's',
97 Modifier: gocui.ModNone,
98 Handler: gui.commitStat,
99 Display: "s",
100 Description: "stats",
101 Vital: true,
102 }, {
103 View: dynamicViewFeature.Name,
104 Key: gocui.KeyPgup,
105 Modifier: gocui.ModNone,
106 Handler: gui.dpageUp,
107 Display: "pg up",
108 Description: "Page up",
109 Vital: true,
110 }, {
111 View: dynamicViewFeature.Name,
112 Key: gocui.KeyPgdn,
113 Modifier: gocui.ModNone,
114 Handler: gui.dpageDown,
115 Display: "pg down",
116 Description: "Page Down",
117 Vital: true,
118 },
119 }
120 keybindings = append(keybindings, caseBindings...)
121 case StashDiffMode:
122 caseBindings := []*KeyBinding{
123 {
124 View: dynamicViewFeature.Name,
125 Key: 's',
126 Modifier: gocui.ModNone,
127 Handler: gui.commitDiff,
128 Display: "s",
129 Description: "stats",
130 Vital: true,
131 }, {
132 View: dynamicViewFeature.Name,
133 Key: gocui.KeyPgup,
134 Modifier: gocui.ModNone,
135 Handler: gui.dpageUp,
136 Display: "pg up",
137 Description: "Page up",
138 Vital: true,
139 }, {
140 View: dynamicViewFeature.Name,
141 Key: gocui.KeyPgdn,
142 Modifier: gocui.ModNone,
143 Handler: gui.dpageDown,
144 Display: "pg down",
145 Description: "Page Down",
146 Vital: true,
147 },
148 }
149 keybindings = append(keybindings, caseBindings...)
150 case StashStatMode:
151 caseBindings := []*KeyBinding{
152 {
153 View: dynamicViewFeature.Name,
154 Key: 'd',
155 Modifier: gocui.ModNone,
156 Handler: gui.commitDiff,
157 Display: "d",
158 Description: "diff",
159 Vital: true,
160 }, {
161 View: dynamicViewFeature.Name,
162 Key: gocui.KeyPgup,
163 Modifier: gocui.ModNone,
164 Handler: gui.dpageUp,
165 Display: "pg up",
166 Description: "Page up",
167 Vital: true,
168 }, {
169 View: dynamicViewFeature.Name,
170 Key: gocui.KeyPgdn,
171 Modifier: gocui.ModNone,
172 Handler: gui.dpageDown,
173 Display: "pg down",
174 Description: "Page Down",
175 Vital: true,
176 },
177 }
178 keybindings = append(keybindings, caseBindings...)
179 case StatusMode:
180 caseBindings := []*KeyBinding{
181 {
182 View: dynamicViewFeature.Name,
183 Key: 'd',
184 Modifier: gocui.ModNone,
185 Handler: gui.statusDiff,
186 Display: "d",
187 Description: "diff",
188 Vital: true,
189 }, {
190 View: dynamicViewFeature.Name,
191 Key: 'c',
192 Modifier: gocui.ModNone,
193 Handler: gui.openCommitMessageView,
194 Display: "c",
195 Description: "commit",
196 Vital: true,
197 }, {
198 View: dynamicViewFeature.Name,
199 Key: 't',
200 Modifier: gocui.ModNone,
201 Handler: gui.stashChanges,
202 Display: "t",
203 Description: "stash",
204 Vital: true,
205 }, {
206 View: dynamicViewFeature.Name,
207 Key: gocui.KeyArrowDown,
208 Modifier: gocui.ModNone,
209 Handler: gui.statusCursorDown,
210 Display: "↓",
211 Description: "Down",
212 Vital: false,
213 }, {
214 View: dynamicViewFeature.Name,
215 Key: gocui.KeyArrowUp,
216 Modifier: gocui.ModNone,
217 Handler: gui.statusCursorUp,
218 Display: "↑",
219 Description: "Up",
220 Vital: false,
221 }, {
222 View: dynamicViewFeature.Name,
223 Key: 'j',
224 Modifier: gocui.ModNone,
225 Handler: gui.statusCursorDown,
226 Display: "j",
227 Description: "Down",
228 Vital: false,
229 }, {
230 View: dynamicViewFeature.Name,
231 Key: 'k',
232 Modifier: gocui.ModNone,
233 Handler: gui.statusCursorUp,
234 Display: "k",
235 Description: "Up",
236 Vital: false,
237 }, {
238 View: dynamicViewFeature.Name,
239 Key: gocui.KeySpace,
240 Modifier: gocui.ModNone,
241 Handler: gui.statusAddReset,
242 Display: "space",
243 Description: "add/reset",
244 Vital: true,
245 }, {
246 View: dynamicViewFeature.Name,
247 Key: gocui.KeyCtrlA,
248 Modifier: gocui.ModNone,
249 Handler: gui.statusAddAll,
250 Display: "c-a",
251 Description: "add all",
252 Vital: true,
253 }, {
254 View: dynamicViewFeature.Name,
255 Key: gocui.KeyCtrlR,
256 Modifier: gocui.ModNone,
257 Handler: gui.statusResetAll,
258 Display: "c-r",
259 Description: "reset all",
260 Vital: true,
261 },
262 }
263 keybindings = append(keybindings, caseBindings...)
264 case FileDiffMode:
265 caseBindings := []*KeyBinding{
266 {
267 View: dynamicViewFeature.Name,
268 Key: 's',
269 Modifier: gocui.ModNone,
270 Handler: gui.statusStat,
271 Display: "s",
272 Description: "stats",
273 Vital: true,
274 }, {
275 View: dynamicViewFeature.Name,
276 Key: gocui.KeyPgup,
277 Modifier: gocui.ModNone,
278 Handler: gui.dpageUp,
279 Display: "pg up",
280 Description: "Page up",
281 Vital: true,
282 }, {
283 View: dynamicViewFeature.Name,
284 Key: gocui.KeyPgdn,
285 Modifier: gocui.ModNone,
286 Handler: gui.dpageDown,
287 Display: "pg down",
288 Description: "Page Down",
289 Vital: true,
290 },
291 }
292 keybindings = append(keybindings, caseBindings...)
293 default:
294
295 }
296 gui.KeyBindings = append(gui.KeyBindings, keybindings...)
297 for _, k := range keybindings {
298 if err := gui.g.SetKeybinding(k.View, k.Key, k.Modifier, k.Handler); err != nil {
299 return err
300 }
301 }
302 v := gui.g.CurrentView()
303 if v.Name() == dynamicViewFeature.Name {
304 _ = gui.updateKeyBindingsView(gui.g, dynamicViewFeature.Name)
305 }
306 return nil
307 }