@matheusbsbs / matheus-bagliano / commits / e210e67451
Fork 0

git-gui: Corrected keyboard bindings on Windows, improved state management.

When we are refreshing from the index or updating the index we shouldn't let the user cause other index based operations to occur as these would likely conflict with the currently running operations possibly causing some index changes to be lost. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Nov 6, 2006 at 19:12 UTC e210e67451f22f97c1476d6b78b6fa7fdd5817f9
1 file changed +75 -24
git-gui
+75 -24
@@ -7,34 +7,53 @@ exec wish "$0" -- "$@"
7 # and distributed under the terms of the GNU General Public Licence,
8 # either version 2, or (at your option) any later version.
9
10 -
10 ######################################################################
11 ##
13 -## status
12 +## task management
13
14 set status_active 0
15 set diff_active 0
16 set checkin_active 0
17 set update_index_fd {}
18
20 -proc is_busy {} {
21 - global status_active diff_active checkin_active update_index_fd
19 +set disable_on_lock [list]
20 +set index_lock_type none
21 +
22 +proc lock_index {type} {
23 + global index_lock_type disable_on_lock
24
23 - if {$status_active > 0
24 - || $diff_active
25 - || $checkin_active
26 - || $update_index_fd != {}} {
25 + if {$index_lock_type == {none}} {
26 + set index_lock_type $type
27 + foreach w $disable_on_lock {
28 + uplevel #0 $w disabled
29 + }
30 + return 1
31 + } elseif {$index_lock_type == {begin-update} && $type == {update}} {
32 + set index_lock_type $type
33 return 1
34 }
35 return 0
36 }
37
38 +proc unlock_index {} {
39 + global index_lock_type disable_on_lock
40 +
41 + set index_lock_type none
42 + foreach w $disable_on_lock {
43 + uplevel #0 $w normal
44 + }
45 +}
46 +
47 +######################################################################
48 +##
49 +## status
50 +
51 proc update_status {} {
52 global gitdir HEAD commit_type
53 global ui_index ui_other ui_status_value ui_comm
54 global status_active file_states
55
37 - if {[is_busy]} return
56 + if {$status_active || ![lock_index read]} return
57
58 array unset file_states
59 foreach w [list $ui_index $ui_other] {
@@ -160,6 +179,7 @@ proc status_eof {fd buf} {
179 set $buf {}
180 close $fd
181 if {[incr status_active -1] == 0} {
182 + unlock_index
183 set ui_status_value {Ready.}
184 if {$ui_fname_value != {}} {
185 show_diff $ui_fname_value
@@ -186,7 +206,7 @@ proc show_diff {path} {
206 global file_states HEAD diff_3way diff_active
207 global ui_diff ui_fname_value ui_fstatus_value ui_status_value
208
189 - if {[is_busy]} return
209 + if {$diff_active || ![lock_index read]} return
210
211 clear_diff
212 set s $file_states($path)
@@ -211,6 +231,7 @@ proc show_diff {path} {
231 close $fd
232 } err ]} {
233 set diff_active 0
234 + unlock_index
235 set ui_status_value "Unable to display $path"
236 error_popup "Error loading file:\n$err"
237 return
@@ -224,6 +245,7 @@ proc show_diff {path} {
245
246 if {[catch {set fd [open $cmd r]} err]} {
247 set diff_active 0
248 + unlock_index
249 set ui_status_value "Unable to display $path"
250 error_popup "Error loading diff:\n$err"
251 return
@@ -279,6 +301,7 @@ proc read_diff {fd} {
301 if {[eof $fd]} {
302 close $fd
303 set diff_active 0
304 + unlock_index
305 set ui_status_value {Ready.}
306 }
307 }
@@ -417,6 +440,7 @@ proc with_update_index {body} {
440 global update_index_fd
441
442 if {$update_index_fd == {}} {
443 + if {![lock_index update]} return
444 set update_index_fd [open \
445 "| git update-index --add --remove -z --stdin" \
446 w]
@@ -424,6 +448,7 @@ proc with_update_index {body} {
448 uplevel 1 $body
449 close $update_index_fd
450 set update_index_fd {}
451 + unlock_index
452 } else {
453 uplevel 1 $body
454 }
@@ -587,10 +612,17 @@ proc show_msg {w top msg} {
612 ##
613 ## ui commands
614
615 +set starting_gitk_msg {Please wait... Starting gitk...}
616 proc do_gitk {} {
591 - global tcl_platform ui_status_value
617 + global tcl_platform ui_status_value starting_gitk_msg
618 +
619 + set ui_status_value $starting_gitk_msg
620 + after 5000 {
621 + if {$ui_status_value == $starting_gitk_msg} {
622 + set ui_status_value {Ready.}
623 + }
624 + }
625
593 - set ui_status_value "Please wait... Starting gitk..."
626 if {$tcl_platform(platform) == "windows"} {
627 exec sh -c gitk &
628 } else {
@@ -623,7 +655,7 @@ proc do_rescan {} {
655 proc do_checkin_all {} {
656 global checkin_active ui_status_value
657
626 - if {[is_busy]} return
658 + if {$checkin_active || ![lock_index begin-update]} return
659
660 set checkin_active 1
661 set ui_status_value {Checking in all files...}
@@ -687,7 +719,7 @@ proc unclick {w x y} {
719 set path [$w get $lno.1 $lno.end]
720 if {$path == {}} return
721
690 - if {$col == 0 && ![is_busy]} {
722 + if {$col == 0} {
723 toggle_mode $path
724 }
725 }
@@ -700,6 +732,11 @@ set mainfont {Helvetica 10}
732 set difffont {Courier 10}
733 set maincursor [. cget -cursor]
734
735 +switch -- $tcl_platform(platform) {
736 +windows {set M1B Control; set M1T Ctrl}
737 +default {set M1B M1; set M1T M1}
738 +}
739 +
740 # -- Menu Bar
741 menu .mbar -tearoff 0
742 .mbar add cascade -label Project -menu .mbar.project
@@ -715,22 +752,33 @@ menu .mbar.project
752 -font $mainfont
753 .mbar.project add command -label Quit \
754 -command do_quit \
755 + -accelerator $M1T-Q \
756 -font $mainfont
757
758 # -- Commit Menu
759 menu .mbar.commit
760 .mbar.commit add command -label Rescan \
761 -command do_rescan \
762 + -accelerator F5 \
763 -font $mainfont
764 +lappend disable_on_lock \
765 + [list .mbar.commit entryconf [.mbar.commit index last] -state]
766 .mbar.commit add command -label {Check-in All Files} \
767 -command do_checkin_all \
768 + -accelerator $M1T-U \
769 -font $mainfont
770 +lappend disable_on_lock \
771 + [list .mbar.commit entryconf [.mbar.commit index last] -state]
772 .mbar.commit add command -label {Sign Off} \
773 -command do_signoff \
774 + -accelerator $M1T-S \
775 -font $mainfont
776 .mbar.commit add command -label Commit \
777 -command do_commit \
778 + -accelerator $M1T-Return \
779 -font $mainfont
780 +lappend disable_on_lock \
781 + [list .mbar.commit entryconf [.mbar.commit index last] -state]
782
783 # -- Fetch Menu
784 menu .mbar.fetch
@@ -849,11 +897,13 @@ button .vpane.commarea.buttons.rescan -text {Rescan} \
897 -command do_rescan \
898 -font $mainfont
899 pack .vpane.commarea.buttons.rescan -side top -fill x
900 +lappend disable_on_lock {.vpane.commarea.buttons.rescan conf -state}
901
902 button .vpane.commarea.buttons.ciall -text {Check-in All} \
903 -command do_checkin_all \
904 -font $mainfont
905 pack .vpane.commarea.buttons.ciall -side top -fill x
906 +lappend disable_on_lock {.vpane.commarea.buttons.ciall conf -state}
907
908 button .vpane.commarea.buttons.signoff -text {Sign Off} \
909 -command do_signoff \
@@ -864,6 +914,7 @@ button .vpane.commarea.buttons.commit -text {Commit} \
914 -command do_commit \
915 -font $mainfont
916 pack .vpane.commarea.buttons.commit -side top -fill x
917 +lappend disable_on_lock {.vpane.commarea.buttons.commit conf -state}
918
919 # -- Commit Message Buffer
920 frame .vpane.commarea.buffer
@@ -897,21 +948,21 @@ pack .status -anchor w -side bottom -fill x
948 # -- Key Bindings
949 bind . <Destroy> do_quit
950 bind . <Key-F5> do_rescan
900 -bind . <M1-Key-r> do_rescan
901 -bind . <M1-Key-R> do_rescan
902 -bind . <M1-Key-s> do_signoff
903 -bind . <M1-Key-S> do_signoff
904 -bind . <M1-Key-u> do_checkin_all
905 -bind . <M1-Key-U> do_checkin_all
906 -bind . <M1-Key-Return> do_commit
907 -bind . <M1-Key-q> do_quit
908 -bind . <M1-Key-Q> do_quit
951 +bind . <$M1B-Key-r> do_rescan
952 +bind . <$M1B-Key-R> do_rescan
953 +bind . <$M1B-Key-s> do_signoff
954 +bind . <$M1B-Key-S> do_signoff
955 +bind . <$M1B-Key-u> do_checkin_all
956 +bind . <$M1B-Key-U> do_checkin_all
957 +bind . <$M1B-Key-Return> do_commit
958 +bind . <$M1B-Key-q> do_quit
959 +bind . <$M1B-Key-Q> do_quit
960 foreach i [list $ui_index $ui_other] {
961 bind $i <Button-1> {click %W %x %y 1 %X %Y; break}
962 bind $i <Button-3> {click %W %x %y 3 %X %Y; break}
963 bind $i <ButtonRelease-1> {unclick %W %x %y; break}
964 }
914 -unset i
965 +unset i M1B M1T
966
967 ######################################################################
968 ##