@@ -180,6 +180,14 @@ impl Component for BranchListComponent {
180
180
self . local ,
181
181
) ) ;
182
182
183
+ out. push ( CommandInfo :: new (
184
+ strings:: commands:: branch_popup_rebase (
185
+ & self . key_config ,
186
+ ) ,
187
+ !self . selection_is_cur_branch ( ) ,
188
+ self . local ,
189
+ ) ) ;
190
+
183
191
out. push ( CommandInfo :: new (
184
192
strings:: commands:: rename_branch_popup (
185
193
& self . key_config ,
@@ -191,100 +199,91 @@ impl Component for BranchListComponent {
191
199
visibility_blocking ( self )
192
200
}
193
201
202
+ //TODO: cleanup
203
+ #[ allow( clippy:: cognitive_complexity) ]
194
204
fn event ( & mut self , ev : Event ) -> Result < EventState > {
195
- if self . visible {
196
- if let Event :: Key ( e) = ev {
197
- if e == self . key_config . exit_popup {
198
- self . hide ( ) ;
199
- } else if e == self . key_config . move_down {
200
- return self
201
- . move_selection ( ScrollType :: Up )
202
- . map ( Into :: into) ;
203
- } else if e == self . key_config . move_up {
204
- return self
205
- . move_selection ( ScrollType :: Down )
206
- . map ( Into :: into) ;
207
- } else if e == self . key_config . page_down {
208
- return self
209
- . move_selection ( ScrollType :: PageDown )
210
- . map ( Into :: into) ;
211
- } else if e == self . key_config . page_up {
212
- return self
213
- . move_selection ( ScrollType :: PageUp )
214
- . map ( Into :: into) ;
215
- } else if e == self . key_config . tab_toggle {
216
- self . local = !self . local ;
217
- self . update_branches ( ) ?;
218
- } else if e == self . key_config . enter {
219
- try_or_popup ! (
220
- self ,
221
- "switch branch error:" ,
222
- self . switch_to_selected_branch( )
223
- ) ;
224
- } else if e == self . key_config . create_branch
225
- && self . local
226
- {
227
- self . queue . push ( InternalEvent :: CreateBranch ) ;
228
- } else if e == self . key_config . rename_branch
229
- && self . valid_selection ( )
230
- {
231
- let cur_branch =
232
- & self . branches [ self . selection as usize ] ;
233
- self . queue . push ( InternalEvent :: RenameBranch (
234
- cur_branch. reference . clone ( ) ,
235
- cur_branch. name . clone ( ) ,
236
- ) ) ;
237
-
238
- self . update_branches ( ) ?;
239
- } else if e == self . key_config . delete_branch
240
- && !self . selection_is_cur_branch ( )
241
- && self . valid_selection ( )
242
- {
243
- self . queue . push ( InternalEvent :: ConfirmAction (
244
- Action :: DeleteBranch (
245
- self . branches [ self . selection as usize ]
246
- . reference
247
- . clone ( ) ,
248
- self . local ,
249
- ) ,
250
- ) ) ;
251
- } else if e == self . key_config . merge_branch
252
- && !self . selection_is_cur_branch ( )
253
- && self . valid_selection ( )
254
- {
255
- try_or_popup ! (
256
- self ,
257
- "merge branch error:" ,
258
- self . merge_branch( )
259
- ) ;
260
- self . queue . push ( InternalEvent :: Update (
261
- NeedsUpdate :: ALL ,
262
- ) ) ;
263
- } else if e == self . key_config . move_right
264
- && self . valid_selection ( )
265
- {
266
- self . hide ( ) ;
267
- if let Some ( b) = self . get_selected ( ) {
268
- self . queue . push (
269
- InternalEvent :: InspectCommit ( b, None ) ,
270
- ) ;
271
- }
272
- } else if e == self . key_config . compare_commits
273
- && self . valid_selection ( )
274
- {
275
- self . hide ( ) ;
276
- if let Some ( b) = self . get_selected ( ) {
277
- self . queue . push (
278
- InternalEvent :: CompareCommits ( b, None ) ,
279
- ) ;
280
- }
205
+ if !self . visible {
206
+ return Ok ( EventState :: NotConsumed ) ;
207
+ }
208
+
209
+ if let Event :: Key ( e) = ev {
210
+ if e == self . key_config . exit_popup {
211
+ self . hide ( ) ;
212
+ } else if e == self . key_config . move_down {
213
+ return self
214
+ . move_selection ( ScrollType :: Up )
215
+ . map ( Into :: into) ;
216
+ } else if e == self . key_config . move_up {
217
+ return self
218
+ . move_selection ( ScrollType :: Down )
219
+ . map ( Into :: into) ;
220
+ } else if e == self . key_config . page_down {
221
+ return self
222
+ . move_selection ( ScrollType :: PageDown )
223
+ . map ( Into :: into) ;
224
+ } else if e == self . key_config . page_up {
225
+ return self
226
+ . move_selection ( ScrollType :: PageUp )
227
+ . map ( Into :: into) ;
228
+ } else if e == self . key_config . tab_toggle {
229
+ self . local = !self . local ;
230
+ self . update_branches ( ) ?;
231
+ } else if e == self . key_config . enter {
232
+ try_or_popup ! (
233
+ self ,
234
+ "switch branch error:" ,
235
+ self . switch_to_selected_branch( )
236
+ ) ;
237
+ } else if e == self . key_config . create_branch && self . local
238
+ {
239
+ self . queue . push ( InternalEvent :: CreateBranch ) ;
240
+ } else if e == self . key_config . rename_branch
241
+ && self . valid_selection ( )
242
+ {
243
+ self . rename_branch ( ) ;
244
+ } else if e == self . key_config . delete_branch
245
+ && !self . selection_is_cur_branch ( )
246
+ && self . valid_selection ( )
247
+ {
248
+ self . delete_branch ( ) ;
249
+ } else if e == self . key_config . merge_branch
250
+ && !self . selection_is_cur_branch ( )
251
+ && self . valid_selection ( )
252
+ {
253
+ try_or_popup ! (
254
+ self ,
255
+ "merge branch error:" ,
256
+ self . merge_branch( )
257
+ ) ;
258
+ } else if e == self . key_config . rebase_branch
259
+ && !self . selection_is_cur_branch ( )
260
+ && self . valid_selection ( )
261
+ {
262
+ try_or_popup ! (
263
+ self ,
264
+ "rebase error:" ,
265
+ self . rebase_branch( )
266
+ ) ;
267
+ } else if e == self . key_config . move_right
268
+ && self . valid_selection ( )
269
+ {
270
+ self . hide ( ) ;
271
+ if let Some ( b) = self . get_selected ( ) {
272
+ self . queue
273
+ . push ( InternalEvent :: InspectCommit ( b, None ) ) ;
274
+ }
275
+ } else if e == self . key_config . compare_commits
276
+ && self . valid_selection ( )
277
+ {
278
+ self . hide ( ) ;
279
+ if let Some ( b) = self . get_selected ( ) {
280
+ self . queue
281
+ . push ( InternalEvent :: CompareCommits ( b, None ) ) ;
281
282
}
282
283
}
283
-
284
- Ok ( EventState :: Consumed )
285
- } else {
286
- Ok ( EventState :: NotConsumed )
287
284
}
285
+
286
+ Ok ( EventState :: Consumed )
288
287
}
289
288
290
289
fn is_visible ( & self ) -> bool {
@@ -368,6 +367,20 @@ impl BranchListComponent {
368
367
self . branches . get ( usize:: from ( self . selection ) )
369
368
{
370
369
sync:: merge_branch ( CWD , & branch. name ) ?;
370
+
371
+ self . queue . push ( InternalEvent :: Update ( NeedsUpdate :: ALL ) ) ;
372
+ }
373
+
374
+ Ok ( ( ) )
375
+ }
376
+
377
+ fn rebase_branch ( & self ) -> Result < ( ) > {
378
+ if let Some ( branch) =
379
+ self . branches . get ( usize:: from ( self . selection ) )
380
+ {
381
+ sync:: rebase_branch ( CWD , & branch. name ) ?;
382
+
383
+ self . queue . push ( InternalEvent :: Update ( NeedsUpdate :: ALL ) ) ;
371
384
}
372
385
373
386
Ok ( ( ) )
@@ -623,4 +636,23 @@ impl BranchListComponent {
623
636
624
637
Ok ( ( ) )
625
638
}
639
+
640
+ fn rename_branch ( & mut self ) {
641
+ let cur_branch = & self . branches [ self . selection as usize ] ;
642
+ self . queue . push ( InternalEvent :: RenameBranch (
643
+ cur_branch. reference . clone ( ) ,
644
+ cur_branch. name . clone ( ) ,
645
+ ) ) ;
646
+ }
647
+
648
+ fn delete_branch ( & mut self ) {
649
+ self . queue . push ( InternalEvent :: ConfirmAction (
650
+ Action :: DeleteBranch (
651
+ self . branches [ self . selection as usize ]
652
+ . reference
653
+ . clone ( ) ,
654
+ self . local ,
655
+ ) ,
656
+ ) ) ;
657
+ }
626
658
}
0 commit comments