]> asedeno.scripts.mit.edu Git - git.git/blobdiff - lib/blame.tcl
git-gui: Extract blame viewer status bar into mega-widget
[git.git] / lib / blame.tcl
index 0400d6effeca05aae2c0e49fd4036acbb93968aa..13bfab3352518af99f87186246d57982a4ac35ad 100644 (file)
@@ -21,7 +21,7 @@ field w_amov     ; # text column: annotations + move tracking
 field w_asim     ; # text column: annotations (simple computation)
 field w_file     ; # text column: actual file data
 field w_cviewer  ; # pane showing commit message
-field status     ; # text variable bound to status bar
+field status     ; # status mega-widget instance
 field old_height ; # last known height of $w.file_pane
 
 # Tk UI colors
@@ -33,6 +33,13 @@ variable group_colors {
        #ececec
 }
 
+# Switches for original location detection
+#
+variable original_options [list -C -C]
+if {[git-version >= 1.5.3]} {
+       lappend original_options -w ; # ignore indentation changes
+}
+
 # Current blame data; cleared/reset on each load
 #
 field commit               ; # input commit to blame
@@ -69,10 +76,10 @@ constructor new {i_commit i_path} {
        make_toplevel top w
        wm title $top "[appname] ([reponame]): File Viewer"
 
-       frame $w.header -background orange
+       frame $w.header -background gold
        label $w.header.commit_l \
                -text {Commit:} \
-               -background orange \
+               -background gold \
                -anchor w \
                -justify left
        set w_back $w.header.commit_b
@@ -81,8 +88,8 @@ constructor new {i_commit i_path} {
                -borderwidth 0 \
                -relief flat \
                -state disabled \
-               -background orange \
-               -activebackground orange
+               -background gold \
+               -activebackground gold
        bind $w_back <Button-1> "
                if {\[$w_back cget -state\] eq {normal}} {
                        [cb _history_menu]
@@ -90,17 +97,17 @@ constructor new {i_commit i_path} {
                "
        label $w.header.commit \
                -textvariable @commit \
-               -background orange \
+               -background gold \
                -anchor w \
                -justify left
        label $w.header.path_l \
                -text {File:} \
-               -background orange \
+               -background gold \
                -anchor w \
                -justify left
        set w_path $w.header.path
        label $w_path \
-               -background orange \
+               -background gold \
                -anchor w \
                -justify left
        pack $w.header.commit_l -side left
@@ -235,14 +242,7 @@ constructor new {i_commit i_path} {
        pack $w.file_pane.cm.sbx -side bottom -fill x
        pack $w_cviewer -expand 1 -fill both
 
-       frame $w.status \
-               -borderwidth 1 \
-               -relief sunken
-       label $w.status.l \
-               -textvariable @status \
-               -anchor w \
-               -justify left
-       pack $w.status.l -side left
+       set status [::status_bar::new $w.status]
 
        menu $w.ctxm -tearoff 0
        $w.ctxm add command \
@@ -272,6 +272,8 @@ constructor new {i_commit i_path} {
                        set cursorW %W
                        tk_popup $w.ctxm %X %Y
                "
+               bind $i <Shift-Tab> "[list focus $w_cviewer];break"
+               bind $i <Tab>       "[list focus $w_cviewer];break"
        }
 
        foreach i [concat $w_columns $w_cviewer] {
@@ -287,9 +289,10 @@ constructor new {i_commit i_path} {
                bind $i <Control-Key-f> {catch {%W yview scroll  1 pages};break}
        }
 
+       bind $w_cviewer <Shift-Tab> "[list focus $w_file];break"
+       bind $w_cviewer <Tab>       "[list focus $w_file];break"
        bind $w_cviewer <Button-1> [list focus $w_cviewer]
-       bind $top <Visibility> [list focus $top]
-       bind $w_file <Destroy> [list delete_this $this]
+       bind $w_file    <Visibility> [list focus $w_file]
 
        grid configure $w.header -sticky ew
        grid configure $w.file_pane -sticky nsew
@@ -301,8 +304,9 @@ constructor new {i_commit i_path} {
 
        set req_w [winfo reqwidth  $top]
        set req_h [winfo reqheight $top]
+       set scr_h [expr {[winfo screenheight $top] - 100}]
        if {$req_w < 600} {set req_w 600}
-       if {$req_h < 400} {set req_h 400}
+       if {$req_h < $scr_h} {set req_h $scr_h}
        set g "${req_w}x${req_h}"
        wm geometry $top $g
        update
@@ -349,19 +353,6 @@ method _load {jump} {
                set total_lines 0
        }
 
-       if {[winfo exists $w.status.c]} {
-               $w.status.c coords bar 0 0 0 20
-       } else {
-               canvas $w.status.c \
-                       -width 100 \
-                       -height [expr {int([winfo reqheight $w.status.l] * 0.6)}] \
-                       -borderwidth 1 \
-                       -relief groove \
-                       -highlightt 0
-               $w.status.c create rectangle 0 0 0 20 -tags bar -fill navy
-               pack $w.status.c -side right
-       }
-
        if {$history eq {}} {
                $w_back conf -state disabled
        } else {
@@ -375,7 +366,7 @@ method _load {jump} {
        set amov_data [list [list]]
        set asim_data [list [list]]
 
-       set status "Loading $commit:[escape_path $path]..."
+       $status show "Reading $commit:[escape_path $path]..."
        $w_path conf -text [escape_path $path]
        if {$commit eq {}} {
                set fd [open $path r]
@@ -484,7 +475,11 @@ method _read_file {fd jump} {
 } ifdeleted { catch {close $fd} }
 
 method _exec_blame {cur_w cur_d options cur_s} {
-       set cmd [list nice git blame]
+       set cmd [list]
+       if {![is_Windows] || [is_Cygwin]} {
+               lappend cmd nice
+       }
+       lappend cmd git blame
        set cmd [concat $cmd $options]
        lappend cmd --incremental
        if {$commit eq {}} {
@@ -495,15 +490,19 @@ method _exec_blame {cur_w cur_d options cur_s} {
        lappend cmd -- $path
        set fd [open "| $cmd" r]
        fconfigure $fd -blocking 0 -translation lf -encoding binary
-       fileevent $fd readable [cb _read_blame $fd $cur_w $cur_d $cur_s]
+       fileevent $fd readable [cb _read_blame $fd $cur_w $cur_d]
        set current_fd $fd
        set blame_lines 0
-       _status $this $cur_s
+
+       $status start \
+               "Loading$cur_s annotations..." \
+               {lines annotated}
 }
 
-method _read_blame {fd cur_w cur_d cur_s} {
+method _read_blame {fd cur_w cur_d} {
        upvar #0 $cur_d line_data
        variable group_colors
+       variable original_options
 
        if {$fd ne $current_fd} {
                catch {close $fd}
@@ -540,6 +539,10 @@ method _read_blame {fd cur_w cur_d cur_s} {
                        set a_name {}
                        catch {set a_name $header($cmit,author)}
                        while {$a_name ne {}} {
+                               if {$author_abbr ne {}
+                                       && [string index $a_name 0] eq {'}} {
+                                       regsub {^'[^']+'\s+} $a_name {} a_name
+                               }
                                if {![regexp {^([[:upper:]])} $a_name _a]} break
                                append author_abbr $_a
                                unset _a
@@ -673,30 +676,17 @@ method _read_blame {fd cur_w cur_d cur_s} {
                close $fd
                if {$cur_w eq $w_asim} {
                        _exec_blame $this $w_amov @amov_data \
-                               [list -M -C -C] \
+                               $original_options \
                                { original location}
                } else {
                        set current_fd {}
-                       set status {Annotation complete.}
-                       destroy $w.status.c
+                       $status stop {Annotation complete.}
                }
        } else {
-               _status $this $cur_s
+               $status update $blame_lines $total_lines
        }
 } ifdeleted { catch {close $fd} }
 
-method _status {cur_s} {
-       set have  $blame_lines
-       set total $total_lines
-       set pdone 0
-       if {$total} {set pdone [expr {100 * $have / $total}]}
-
-       set status [format \
-               "Loading%s annotations... %i of %i lines annotated (%2i%%)" \
-               $cur_s $have $total $pdone]
-       $w.status.c coords bar 0 0 $pdone 20
-}
-
 method _click {cur_w pos} {
        set lno [lindex [split [$cur_w index $pos] .] 0]
        _showcommit $this $cur_w $lno
@@ -731,12 +721,12 @@ method _showcommit {cur_w lno} {
                }
        }
 
-       if {$cur_w eq $w_amov} {
-               set dat [lindex $amov_data $lno]
-               set highlight_column $w_amov
-       } else {
+       if {$cur_w eq $w_asim} {
                set dat [lindex $asim_data $lno]
                set highlight_column $w_asim
+       } else {
+               set dat [lindex $amov_data $lno]
+               set highlight_column $w_amov
        }
 
        $w_cviewer conf -state normal
@@ -908,7 +898,9 @@ method _open_tooltip {cur_w} {
        $tooltip_t insert end "$summary"
 
        if {$org ne {} && [lindex $org 0] ne $cmit} {
-               $tooltip_t insert 0.0 "Copied/Moved Here By:\n" section_header
+               set save [$tooltip_t get 0.0 end]
+               $tooltip_t delete 0.0 end
+
                set cmit [lindex $org 0]
                set file [lindex $org 1]
                lappend tooltip_commit $cmit
@@ -923,17 +915,19 @@ method _open_tooltip {cur_w} {
                        -format {%Y-%m-%d %H:%M:%S}
                ]}
 
-               $tooltip_t insert end "\n\n"
                $tooltip_t insert end "Originally By:\n" section_header
                $tooltip_t insert end "commit $cmit\n"
                $tooltip_t insert end "$author_name  $author_time\n"
-               $tooltip_t insert end "$summary"
+               $tooltip_t insert end "$summary\n"
 
                if {$file ne $path} {
-                       $tooltip_t insert end "\n"
                        $tooltip_t insert end "In File: " section_header
-                       $tooltip_t insert end $file
+                       $tooltip_t insert end "$file\n"
                }
+
+               $tooltip_t insert end "\n"
+               $tooltip_t insert end "Copied Or Moved Here By:\n" section_header
+               $tooltip_t insert end $save
        }
 
        $tooltip_t conf -state disabled