@@ -2,8 +2,8 @@ use crate::{
2
2
accessors,
3
3
cmdbar:: CommandBar ,
4
4
components:: {
5
- event_pump, BranchListComponent , CommandBlocking ,
6
- CommandInfo , CommitComponent , Component ,
5
+ event_pump, BlameFileComponent , BranchListComponent ,
6
+ CommandBlocking , CommandInfo , CommitComponent , Component ,
7
7
CreateBranchComponent , DrawableComponent ,
8
8
ExternalEditorComponent , HelpComponent ,
9
9
InspectCommitComponent , MsgComponent , PullComponent ,
@@ -41,6 +41,7 @@ pub struct App {
41
41
msg : MsgComponent ,
42
42
reset : ResetComponent ,
43
43
commit : CommitComponent ,
44
+ blame_file_popup : BlameFileComponent ,
44
45
stashmsg_popup : StashMsgComponent ,
45
46
inspect_commit_popup : InspectCommitComponent ,
46
47
external_editor_popup : ExternalEditorComponent ,
@@ -93,6 +94,11 @@ impl App {
93
94
theme. clone ( ) ,
94
95
key_config. clone ( ) ,
95
96
) ,
97
+ blame_file_popup : BlameFileComponent :: new (
98
+ & strings:: blame_title ( & key_config) ,
99
+ theme. clone ( ) ,
100
+ key_config. clone ( ) ,
101
+ ) ,
96
102
stashmsg_popup : StashMsgComponent :: new (
97
103
queue. clone ( ) ,
98
104
theme. clone ( ) ,
@@ -363,6 +369,7 @@ impl App {
363
369
msg,
364
370
reset,
365
371
commit,
372
+ blame_file_popup,
366
373
stashmsg_popup,
367
374
inspect_commit_popup,
368
375
external_editor_popup,
@@ -488,48 +495,9 @@ impl App {
488
495
) -> Result < NeedsUpdate > {
489
496
let mut flags = NeedsUpdate :: empty ( ) ;
490
497
match ev {
491
- InternalEvent :: ConfirmedAction ( action) => match action {
492
- Action :: Reset ( r) => {
493
- if self . status_tab . reset ( & r) {
494
- flags. insert ( NeedsUpdate :: ALL ) ;
495
- }
496
- }
497
- Action :: StashDrop ( _) | Action :: StashPop ( _) => {
498
- if self . stashlist_tab . action_confirmed ( & action) {
499
- flags. insert ( NeedsUpdate :: ALL ) ;
500
- }
501
- }
502
- Action :: ResetHunk ( path, hash) => {
503
- sync:: reset_hunk ( CWD , & path, hash) ?;
504
- flags. insert ( NeedsUpdate :: ALL ) ;
505
- }
506
- Action :: ResetLines ( path, lines) => {
507
- sync:: discard_lines ( CWD , & path, & lines) ?;
508
- flags. insert ( NeedsUpdate :: ALL ) ;
509
- }
510
- Action :: DeleteBranch ( branch_ref) => {
511
- if let Err ( e) =
512
- sync:: delete_branch ( CWD , & branch_ref)
513
- {
514
- self . queue . borrow_mut ( ) . push_back (
515
- InternalEvent :: ShowErrorMsg (
516
- e. to_string ( ) ,
517
- ) ,
518
- )
519
- } else {
520
- flags. insert ( NeedsUpdate :: ALL ) ;
521
- self . select_branch_popup . update_branches ( ) ?;
522
- }
523
- }
524
- Action :: ForcePush ( branch, force) => self
525
- . queue
526
- . borrow_mut ( )
527
- . push_back ( InternalEvent :: Push ( branch, force) ) ,
528
- Action :: PullMerge { rebase, .. } => {
529
- self . pull_popup . try_conflict_free_merge ( rebase) ;
530
- flags. insert ( NeedsUpdate :: ALL ) ;
531
- }
532
- } ,
498
+ InternalEvent :: ConfirmedAction ( action) => {
499
+ self . process_confirmed_action ( action, & mut flags) ?;
500
+ }
533
501
InternalEvent :: ConfirmAction ( action) => {
534
502
self . reset . open ( action) ?;
535
503
flags. insert ( NeedsUpdate :: COMMANDS ) ;
@@ -548,6 +516,14 @@ impl App {
548
516
InternalEvent :: TagCommit ( id) => {
549
517
self . tag_commit_popup . open ( id) ?;
550
518
}
519
+ InternalEvent :: BlameFile ( path) => {
520
+ // Having to explicitly close another popup before showing a new
521
+ // one is not an optimal solution because this constraint can’t
522
+ // be automatically enforced.
523
+ self . inspect_commit_popup . hide ( ) ;
524
+ self . blame_file_popup . open ( & path) ?;
525
+ flags. insert ( NeedsUpdate :: ALL | NeedsUpdate :: COMMANDS )
526
+ }
551
527
InternalEvent :: CreateBranch => {
552
528
self . create_branch_popup . open ( ) ?;
553
529
}
@@ -560,6 +536,10 @@ impl App {
560
536
}
561
537
InternalEvent :: TabSwitch => self . set_tab ( 0 ) ?,
562
538
InternalEvent :: InspectCommit ( id, tags) => {
539
+ // Having to explicitly close another popup before showing a new
540
+ // one is not an optimal solution because this constraint can’t
541
+ // be automatically enforced.
542
+ self . blame_file_popup . hide ( ) ;
563
543
self . inspect_commit_popup . open ( id, tags) ?;
564
544
flags. insert ( NeedsUpdate :: ALL | NeedsUpdate :: COMMANDS )
565
545
}
@@ -586,6 +566,54 @@ impl App {
586
566
Ok ( flags)
587
567
}
588
568
569
+ fn process_confirmed_action (
570
+ & mut self ,
571
+ action : Action ,
572
+ flags : & mut NeedsUpdate ,
573
+ ) -> Result < ( ) > {
574
+ match action {
575
+ Action :: Reset ( r) => {
576
+ if self . status_tab . reset ( & r) {
577
+ flags. insert ( NeedsUpdate :: ALL ) ;
578
+ }
579
+ }
580
+ Action :: StashDrop ( _) | Action :: StashPop ( _) => {
581
+ if self . stashlist_tab . action_confirmed ( & action) {
582
+ flags. insert ( NeedsUpdate :: ALL ) ;
583
+ }
584
+ }
585
+ Action :: ResetHunk ( path, hash) => {
586
+ sync:: reset_hunk ( CWD , & path, hash) ?;
587
+ flags. insert ( NeedsUpdate :: ALL ) ;
588
+ }
589
+ Action :: ResetLines ( path, lines) => {
590
+ sync:: discard_lines ( CWD , & path, & lines) ?;
591
+ flags. insert ( NeedsUpdate :: ALL ) ;
592
+ }
593
+ Action :: DeleteBranch ( branch_ref) => {
594
+ if let Err ( e) = sync:: delete_branch ( CWD , & branch_ref)
595
+ {
596
+ self . queue . borrow_mut ( ) . push_back (
597
+ InternalEvent :: ShowErrorMsg ( e. to_string ( ) ) ,
598
+ )
599
+ } else {
600
+ flags. insert ( NeedsUpdate :: ALL ) ;
601
+ self . select_branch_popup . update_branches ( ) ?;
602
+ }
603
+ }
604
+ Action :: ForcePush ( branch, force) => self
605
+ . queue
606
+ . borrow_mut ( )
607
+ . push_back ( InternalEvent :: Push ( branch, force) ) ,
608
+ Action :: PullMerge { rebase, .. } => {
609
+ self . pull_popup . try_conflict_free_merge ( rebase) ;
610
+ flags. insert ( NeedsUpdate :: ALL ) ;
611
+ }
612
+ } ;
613
+
614
+ Ok ( ( ) )
615
+ }
616
+
589
617
fn commands ( & self , force_all : bool ) -> Vec < CommandInfo > {
590
618
let mut res = Vec :: new ( ) ;
591
619
@@ -637,6 +665,7 @@ impl App {
637
665
|| self . msg . is_visible ( )
638
666
|| self . stashmsg_popup . is_visible ( )
639
667
|| self . inspect_commit_popup . is_visible ( )
668
+ || self . blame_file_popup . is_visible ( )
640
669
|| self . external_editor_popup . is_visible ( )
641
670
|| self . tag_commit_popup . is_visible ( )
642
671
|| self . create_branch_popup . is_visible ( )
@@ -666,6 +695,7 @@ impl App {
666
695
self . stashmsg_popup . draw ( f, size) ?;
667
696
self . help . draw ( f, size) ?;
668
697
self . inspect_commit_popup . draw ( f, size) ?;
698
+ self . blame_file_popup . draw ( f, size) ?;
669
699
self . external_editor_popup . draw ( f, size) ?;
670
700
self . tag_commit_popup . draw ( f, size) ?;
671
701
self . select_branch_popup . draw ( f, size) ?;
0 commit comments