Merge branch 'py/git-gui-do-quit'
[gitweb.git] / git-gui / git-gui.sh
index ed24aa9d2f16a4eb600fc3298ebeb931f9fb6c9c..6ec562d5da3cf07afb27f88b10763f1104134baf 100755 (executable)
@@ -2501,9 +2501,28 @@ proc toggle_or_diff {mode w args} {
                set pos [split [$w index @$x,$y] .]
                foreach {lno col} $pos break
        } else {
+               if {$mode eq "toggle"} {
+                       if {$w eq $ui_workdir} {
+                               do_add_selection
+                               set last_clicked {}
+                               return
+                       }
+                       if {$w eq $ui_index} {
+                               do_unstage_selection
+                               set last_clicked {}
+                               return
+                       }
+               }
+
                if {$last_clicked ne {}} {
                        set lno [lindex $last_clicked 1]
                } else {
+                       if {![info exists file_lists]
+                               || ![info exists file_lists($w)]
+                               || [llength $file_lists($w)] == 0} {
+                               set last_clicked {}
+                               return
+                       }
                        set lno [expr {int([lindex [$w tag ranges in_diff] 0])}]
                }
                if {$mode eq "toggle"} {
@@ -2514,7 +2533,13 @@ proc toggle_or_diff {mode w args} {
                }
        }
 
-       set path [lindex $file_lists($w) [expr {$lno - 1}]]
+       if {![info exists file_lists]
+               || ![info exists file_lists($w)]
+               || [llength $file_lists($w)] < $lno - 1} {
+               set path {}
+       } else {
+               set path [lindex $file_lists($w) [expr {$lno - 1}]]
+       }
        if {$path eq {}} {
                set last_clicked {}
                return
@@ -3005,8 +3030,23 @@ unset doc_path doc_url
 wm protocol . WM_DELETE_WINDOW do_quit
 bind all <$M1B-Key-q> do_quit
 bind all <$M1B-Key-Q> do_quit
-bind all <$M1B-Key-w> {destroy [winfo toplevel %W]}
-bind all <$M1B-Key-W> {destroy [winfo toplevel %W]}
+
+set m1b_w_script {
+       set toplvl_win [winfo toplevel %W]
+
+       # If we are destroying the main window, we should call do_quit to take
+       # care of cleanup before exiting the program.
+       if {$toplvl_win eq "."} {
+               do_quit
+       } else {
+               destroy $toplvl_win
+       }
+}
+
+bind all <$M1B-Key-w> $m1b_w_script
+bind all <$M1B-Key-W> $m1b_w_script
+
+unset m1b_w_script
 
 set subcommand_args {}
 proc usage {} {
@@ -3842,6 +3882,7 @@ bind .   <$M1B-Key-equal> {show_more_context;break}
 bind .   <$M1B-Key-plus> {show_more_context;break}
 bind .   <$M1B-Key-KP_Add> {show_more_context;break}
 bind .   <$M1B-Key-Return> do_commit
+bind .   <$M1B-Key-KP_Enter> do_commit
 foreach i [list $ui_index $ui_workdir] {
        bind $i <Button-1>       { toggle_or_diff click %W %x %y; break }
        bind $i <$M1B-Button-1>  { add_one_to_selection %W %x %y; break }