git-gui: ensure the file in the diff pane is in the list of selected files
[gitweb.git] / lib / choose_rev.tcl
index bb6966eb93a308983e98e5829a1acdce123ef406..6dae7937d589c174132e9f8b9bd77133e189590f 100644 (file)
@@ -10,13 +10,14 @@ field w_list          ; # list of currently filtered specs
 field w_filter        ; # filter entry for $w_list
 
 field c_expr        {}; # current revision expression
-field filter          ; # current filter string
+field filter        ""; # current filter string
 field revtype     head; # type of revision chosen
 field cur_specs [list]; # list of specs for $revtype
 field spec_head       ; # list of all head specs
 field spec_trck       ; # list of all tracking branch specs
 field spec_tag        ; # list of all tag specs
 field tip_data        ; # array of tip commit info by refname
+field log_last        ; # array of reflog date by refname
 
 field tooltip_wm        {} ; # Current tooltip toplevel, if open
 field tooltip_t         {} ; # Text widget in $tooltip_wm
@@ -31,70 +32,74 @@ proc new_unmerged {path {title {}}} {
 }
 
 constructor _new {path unmerged_only title} {
-       global current_branch is_detached
+       global current_branch is_detached use_ttk NS
+
+       if {![info exists ::all_remotes]} {
+               load_all_remotes
+       }
 
        set w $path
 
        if {$title ne {}} {
-               labelframe $w -text $title
+               ${NS}::labelframe $w -text $title
        } else {
-               frame $w
+               ${NS}::frame $w
        }
        bind $w <Destroy> [cb _delete %W]
 
        if {$is_detached} {
-               radiobutton $w.detachedhead_r \
-                       -anchor w \
-                       -text {This Detached Checkout} \
+               ${NS}::radiobutton $w.detachedhead_r \
+                       -text [mc "This Detached Checkout"] \
                        -value HEAD \
                        -variable @revtype
+               if {!$use_ttk} {$w.detachedhead_r configure -anchor w}
                grid $w.detachedhead_r -sticky we -padx {0 5} -columnspan 2
        }
 
-       radiobutton $w.expr_r \
-               -text {Revision Expression:} \
+       ${NS}::radiobutton $w.expr_r \
+               -text [mc "Revision Expression:"] \
                -value expr \
                -variable @revtype
-       entry $w.expr_t \
-               -borderwidth 1 \
-               -relief sunken \
+       ${NS}::entry $w.expr_t \
                -width 50 \
                -textvariable @c_expr \
                -validate key \
                -validatecommand [cb _validate %d %S]
        grid $w.expr_r $w.expr_t -sticky we -padx {0 5}
 
-       frame $w.types
-       radiobutton $w.types.head_r \
-               -text {Local Branch} \
+       ${NS}::frame $w.types
+       ${NS}::radiobutton $w.types.head_r \
+               -text [mc "Local Branch"] \
                -value head \
                -variable @revtype
        pack $w.types.head_r -side left
-       radiobutton $w.types.trck_r \
-               -text {Tracking Branch} \
+       ${NS}::radiobutton $w.types.trck_r \
+               -text [mc "Tracking Branch"] \
                -value trck \
                -variable @revtype
        pack $w.types.trck_r -side left
-       radiobutton $w.types.tag_r \
-               -text {Tag} \
+       ${NS}::radiobutton $w.types.tag_r \
+               -text [mc "Tag"] \
                -value tag \
                -variable @revtype
        pack $w.types.tag_r -side left
        set w_filter $w.types.filter
-       entry $w_filter \
-               -borderwidth 1 \
-               -relief sunken \
+       ${NS}::entry $w_filter \
                -width 12 \
                -textvariable @filter \
                -validate key \
                -validatecommand [cb _filter %P]
        pack $w_filter -side right
-       pack [label $w.types.filter_icon \
+       pack [${NS}::label $w.types.filter_icon \
                -image ::choose_rev::img_find \
                ] -side right
        grid $w.types -sticky we -padx {0 5} -columnspan 2
 
-       frame $w.list
+       if {$use_ttk} {
+               ttk::frame $w.list -style SListbox.TFrame -padding 2
+       } else {
+               frame $w.list
+       }
        set w_list $w.list.l
        listbox $w_list \
                -font font_diff \
@@ -104,6 +109,9 @@ constructor _new {path unmerged_only title} {
                -exportselection false \
                -xscrollcommand [cb _sb_set $w.list.sbx h] \
                -yscrollcommand [cb _sb_set $w.list.sby v]
+       if {$use_ttk} {
+               $w_list configure -relief flat -highlightthickness 0 -borderwidth 0
+       }
        pack $w_list -fill both -expand 1
        grid $w.list -sticky nswe -padx {20 5} -columnspan 2
        bind $w_list <Any-Motion>  [cb _show_tooltip @%x,%y]
@@ -128,13 +136,13 @@ constructor _new {path unmerged_only title} {
        append fmt { %(objecttype)}
        append fmt { %(objectname)}
        append fmt { [concat %(taggername) %(authorname)]}
-       append fmt { [concat %(taggerdate) %(authordate)]}
+       append fmt { [reformat_date [concat %(taggerdate) %(authordate)]]}
        append fmt { %(subject)}
        append fmt {] [list}
        append fmt { %(*objecttype)}
        append fmt { %(*objectname)}
        append fmt { %(*authorname)}
-       append fmt { %(*authordate)}
+       append fmt { [reformat_date %(*authordate)]}
        append fmt { %(*subject)}
        append fmt {]}
        set all_refn [list]
@@ -230,11 +238,12 @@ constructor _new {path unmerged_only title} {
 }
 
 method none {text} {
+       global NS use_ttk
        if {![winfo exists $w.none_r]} {
-               radiobutton $w.none_r \
-                       -anchor w \
+               ${NS}::radiobutton $w.none_r \
                        -value none \
                        -variable @revtype
+               if {!$use_ttk} {$w.none_r configure -anchor w}
                grid $w.none_r -sticky we -padx {0 5} -columnspan 2
        }
        $w.none_r configure -text $text
@@ -309,7 +318,7 @@ method commit_or_die {} {
                }
 
                set top [winfo toplevel $w]
-               set msg "Invalid revision: [get $this]\n\n$err"
+               set msg [strcat [mc "Invalid revision: %s" [get $this]] "\n\n$err"]
                tk_messageBox \
                        -icon error \
                        -type ok \
@@ -330,7 +339,7 @@ method _expr {} {
                if {$i ne {}} {
                        return [lindex $cur_specs $i 1]
                } else {
-                       error "No revision selected."
+                       error [mc "No revision selected."]
                }
        }
 
@@ -338,7 +347,7 @@ method _expr {} {
                if {$c_expr ne {}} {
                        return $c_expr
                } else {
-                       error "Revision expression is empty."
+                       error [mc "Revision expression is empty."]
                }
        }
        HEAD { return HEAD                     }
@@ -420,6 +429,7 @@ method _delete {current} {
 }
 
 method _sb_set {sb orient first last} {
+       global NS
        set old_focus [focus -lastfor $w]
 
        if {$first == 0 && $last == 1} {
@@ -435,10 +445,10 @@ method _sb_set {sb orient first last} {
 
        if {![winfo exists $sb]} {
                if {$orient eq {h}} {
-                       scrollbar $sb -orient h -command [list $w_list xview]
+                       ${NS}::scrollbar $sb -orient h -command [list $w_list xview]
                        pack $sb -fill x -side bottom -before $w_list
                } else {
-                       scrollbar $sb -orient v -command [list $w_list yview]
+                       ${NS}::scrollbar $sb -orient v -command [list $w_list yview]
                        pack $sb -fill y -side right -before $w_list
                }
                if {$old_focus ne {}} {
@@ -446,7 +456,8 @@ method _sb_set {sb orient first last} {
                        focus $old_focus
                }
        }
-       $sb set $first $last
+
+       catch {$sb set $first $last}
 }
 
 method _show_tooltip {pos} {
@@ -486,6 +497,7 @@ method _open_tooltip {} {
 
        if {$tooltip_wm eq {}} {
                set tooltip_wm [toplevel $w_list.tooltip -borderwidth 1]
+               catch {wm attributes $tooltip_wm -type tooltip}
                wm overrideredirect $tooltip_wm 1
                wm transient $tooltip_wm [winfo toplevel $w_list]
                set tooltip_t $tooltip_wm.label
@@ -518,11 +530,18 @@ method _open_tooltip {} {
                set cmit [lindex $data 0]
        }
 
-       $tooltip_t insert end "[lindex $spec 0]\n"
+       $tooltip_t insert end [lindex $spec 0]
+       set last [_reflog_last $this [lindex $spec 1]]
+       if {$last ne {}} {
+               $tooltip_t insert end "\n"
+               $tooltip_t insert end [mc "Updated"]
+               $tooltip_t insert end " $last"
+       }
+       $tooltip_t insert end "\n"
 
        if {$tag ne {}} {
                $tooltip_t insert end "\n"
-               $tooltip_t insert end "tag" section_header
+               $tooltip_t insert end [mc "Tag"] section_header
                $tooltip_t insert end "  [lindex $tag 1]\n"
                $tooltip_t insert end [lindex $tag 2]
                $tooltip_t insert end " ([lindex $tag 3])\n"
@@ -532,7 +551,7 @@ method _open_tooltip {} {
 
        if {$cmit ne {}} {
                $tooltip_t insert end "\n"
-               $tooltip_t insert end "commit" section_header
+               $tooltip_t insert end [mc "Commit@@noun"] section_header
                $tooltip_t insert end "  [lindex $cmit 1]\n"
                $tooltip_t insert end [lindex $cmit 2]
                $tooltip_t insert end " ([lindex $cmit 3])\n"
@@ -541,11 +560,11 @@ method _open_tooltip {} {
 
        if {[llength $spec] > 2} {
                $tooltip_t insert end "\n"
-               $tooltip_t insert end "remote" section_header
+               $tooltip_t insert end [mc "Remote"] section_header
                $tooltip_t insert end "  [lindex $spec 2]\n"
-               $tooltip_t insert end "url"
+               $tooltip_t insert end [mc "URL"]
                $tooltip_t insert end " $remote_url([lindex $spec 2])\n"
-               $tooltip_t insert end "branch"
+               $tooltip_t insert end [mc "Branch"]
                $tooltip_t insert end " [lindex $spec 3]"
        }
 
@@ -553,6 +572,30 @@ method _open_tooltip {} {
        _position_tooltip $this
 }
 
+method _reflog_last {name} {
+       if {[info exists reflog_last($name)]} {
+               return reflog_last($name)
+       }
+
+       set last {}
+       if {[catch {set last [file mtime [gitdir $name]]}]
+       && ![catch {set g [open [gitdir logs $name] r]}]} {
+               fconfigure $g -translation binary
+               while {[gets $g line] >= 0} {
+                       if {[regexp {> ([1-9][0-9]*) } $line line when]} {
+                               set last $when
+                       }
+               }
+               close $g
+       }
+
+       if {$last ne {}} {
+               set last [format_date $last]
+       }
+       set reflog_last($name) $last
+       return $last
+}
+
 method _position_tooltip {} {
        set max_h [lindex [split [$tooltip_t index end] .] 0]
        set max_w 0
@@ -568,9 +611,9 @@ method _position_tooltip {} {
        set pos_y [expr {[winfo pointery .] + 10}]
 
        set g "${req_w}x${req_h}"
-       if {$pos_x >= 0} {append g +}
+       if {[tk windowingsystem] eq "win32" || $pos_x >= 0} {append g +}
        append g $pos_x
-       if {$pos_y >= 0} {append g +}
+       if {[tk windowingsystem] eq "win32" || $pos_y >= 0} {append g +}
        append g $pos_y
 
        wm geometry $tooltip_wm $g