@matheusbsbs / matheus-bagliano / commits / 047d94d505
Fork 0

git-gui: Properly set the state of "Stage/Unstage Hunk" action

Today I found yet another way for the "Stage Hunk" and "Unstage Hunk" context menu actions to leave the wrong state enabled in the UI. The problem this time was that I connected the state determination to the value of $::current_diff_side (the side the diff is from). When the user was last looking at a diff from the index side and unstages everything the diff panel goes empty, but the action stayed enabled as we always assumed unstaging was a valid action. This change moves the logic for determining when the action is enabled away from the individual side selection, as they really are two unrelated concepts. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Sep 2, 2007 at 15:38 UTC 047d94d505c9837a60c28e121de65471dadce74b
1 file changed +6 -9
git-gui.sh
+6 -9
@@ -2441,20 +2441,17 @@ proc popup_diff_menu {ctxm x y X Y} {
2441 set ::cursorX $x
2442 set ::cursorY $y
2443 if {$::ui_index eq $::current_diff_side} {
2444 - set s normal
2444 set l "Unstage Hunk From Commit"
2445 } else {
2447 - if {$current_diff_path eq {}
2448 - || ![info exists file_states($current_diff_path)]
2449 - || {_O} eq [lindex $file_states($current_diff_path) 0]} {
2450 - set s disabled
2451 - } else {
2452 - set s normal
2453 - }
2446 set l "Stage Hunk For Commit"
2447 }
2456 - if {$::is_3way_diff} {
2448 + if {$::is_3way_diff
2449 + || $current_diff_path eq {}
2450 + || ![info exists file_states($current_diff_path)]
2451 + || {_O} eq [lindex $file_states($current_diff_path) 0]} {
2452 set s disabled
2453 + } else {
2454 + set s normal
2455 }
2456 $ctxm entryconf $::ui_diff_applyhunk -state $s -label $l
2457 tk_popup $ctxm $X $Y