lib / blame.tclon commit git-gui: added config gui.gcwarning to disable the gc hint message (af86768)
   1# git-gui blame viewer
   2# Copyright (C) 2006, 2007 Shawn Pearce
   3
   4class blame {
   5
   6image create photo ::blame::img_back_arrow -data {R0lGODlhGAAYAIUAAPwCBEzKXFTSZIz+nGzmhGzqfGTidIT+nEzGXHTqhGzmfGzifFzadETCVES+VARWDFzWbHzyjAReDGTadFTOZDSyRDyyTCymPARaFGTedFzSbDy2TCyqRCyqPARaDAyCHES6VDy6VCyiPAR6HCSeNByWLARyFARiDARqFGTifARiFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAALAAAAAAYABgAAAajQIBwSCwaj8ikcsk0BppJwRPqHEypQwHBis0WDAdEFyBIKBaMAKLBdjQeSkFBYTBAIvgEoS6JmhUTEwIUDQ4VFhcMGEhyCgoZExoUaxsWHB0THkgfAXUGAhoBDSAVFR0XBnCbDRmgog0hpSIiDJpJIyEQhBUcJCIlwA22SSYVogknEg8eD82qSigdDSknY0IqJQXPYxIl1dZCGNvWw+Dm510GQQAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMgcmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7}
   7
   8# Persistant data (survives loads)
   9#
  10field history {}; # viewer history: {commit path}
  11field header    ; # array commit,key -> header field
  12
  13# Tk UI control paths
  14#
  15field w          ; # top window in this viewer
  16field w_back     ; # our back button
  17field w_path     ; # label showing the current file path
  18field w_columns  ; # list of all column widgets in the viewer
  19field w_line     ; # text column: all line numbers
  20field w_amov     ; # text column: annotations + move tracking
  21field w_asim     ; # text column: annotations (simple computation)
  22field w_file     ; # text column: actual file data
  23field w_cviewer  ; # pane showing commit message
  24field finder     ; # find mini-dialog frame
  25field gotoline   ; # line goto mini-dialog frame
  26field status     ; # status mega-widget instance
  27field old_height ; # last known height of $w.file_pane
  28
  29
  30# Tk UI colors
  31#
  32variable active_color #c0edc5
  33variable group_colors {
  34        #d6d6d6
  35        #e1e1e1
  36        #ececec
  37}
  38
  39# Current blame data; cleared/reset on each load
  40#
  41field commit               ; # input commit to blame
  42field path                 ; # input filename to view in $commit
  43
  44field current_fd        {} ; # background process running
  45field highlight_line    -1 ; # current line selected
  46field highlight_column  {} ; # current commit column selected
  47field highlight_commit  {} ; # sha1 of commit selected
  48
  49field total_lines       0  ; # total length of file
  50field blame_lines       0  ; # number of lines computed
  51field amov_data            ; # list of {commit origfile origline}
  52field asim_data            ; # list of {commit origfile origline}
  53
  54field r_commit             ; # commit currently being parsed
  55field r_orig_line          ; # original line number
  56field r_final_line         ; # final line number
  57field r_line_count         ; # lines in this region
  58
  59field tooltip_wm        {} ; # Current tooltip toplevel, if open
  60field tooltip_t         {} ; # Text widget in $tooltip_wm
  61field tooltip_timer     {} ; # Current timer event for our tooltip
  62field tooltip_commit    {} ; # Commit(s) in tooltip
  63
  64constructor new {i_commit i_path i_jump} {
  65        global cursor_ptr M1B M1T have_tk85 use_ttk NS
  66        variable active_color
  67        variable group_colors
  68
  69        set commit $i_commit
  70        set path   $i_path
  71
  72        make_toplevel top w
  73        wm title $top [append "[appname] ([reponame]): " [mc "File Viewer"]]
  74
  75        set font_w [font measure font_diff "0"]
  76
  77        gold_frame $w.header
  78        tlabel $w.header.commit_l \
  79                -text [mc "Commit:"] \
  80                -background gold \
  81                -foreground black \
  82                -anchor w \
  83                -justify left
  84        set w_back $w.header.commit_b
  85        tlabel $w_back \
  86                -image ::blame::img_back_arrow \
  87                -borderwidth 0 \
  88                -relief flat \
  89                -state disabled \
  90                -background gold \
  91                -foreground black \
  92                -activebackground gold
  93        bind $w_back <Button-1> "
  94                if {\[$w_back cget -state\] eq {normal}} {
  95                        [cb _history_menu]
  96                }
  97                "
  98        tlabel $w.header.commit \
  99                -textvariable @commit \
 100                -background gold \
 101                -foreground black \
 102                -anchor w \
 103                -justify left
 104        tlabel $w.header.path_l \
 105                -text [mc "File:"] \
 106                -background gold \
 107                -foreground black \
 108                -anchor w \
 109                -justify left
 110        set w_path $w.header.path
 111        tlabel $w_path \
 112                -background gold \
 113                -foreground black \
 114                -anchor w \
 115                -justify left
 116        pack $w.header.commit_l -side left
 117        pack $w_back -side left
 118        pack $w.header.commit -side left
 119        pack $w_path -fill x -side right
 120        pack $w.header.path_l -side right
 121
 122        panedwindow $w.file_pane -orient vertical -borderwidth 0 -sashwidth 3
 123        frame $w.file_pane.out -relief flat -borderwidth 1
 124        frame $w.file_pane.cm -relief sunken -borderwidth 1
 125        $w.file_pane add $w.file_pane.out \
 126                -sticky nsew \
 127                -minsize 100 \
 128                -height 100 \
 129                -width 100
 130        $w.file_pane add $w.file_pane.cm \
 131                -sticky nsew \
 132                -minsize 25 \
 133                -height 25 \
 134                -width 100
 135
 136        set w_line $w.file_pane.out.linenumber_t
 137        text $w_line \
 138                -takefocus 0 \
 139                -highlightthickness 0 \
 140                -padx 0 -pady 0 \
 141                -background white \
 142                -foreground black \
 143                -borderwidth 0 \
 144                -state disabled \
 145                -wrap none \
 146                -height 40 \
 147                -width 6 \
 148                -font font_diff
 149        $w_line tag conf linenumber -justify right -rmargin 5
 150
 151        set w_amov $w.file_pane.out.amove_t
 152        text $w_amov \
 153                -takefocus 0 \
 154                -highlightthickness 0 \
 155                -padx 0 -pady 0 \
 156                -background white \
 157                -foreground black \
 158                -borderwidth 0 \
 159                -state disabled \
 160                -wrap none \
 161                -height 40 \
 162                -width 5 \
 163                -font font_diff
 164        $w_amov tag conf author_abbr -justify right -rmargin 5
 165        $w_amov tag conf curr_commit
 166        $w_amov tag conf prior_commit -foreground blue -underline 1
 167        $w_amov tag bind prior_commit \
 168                <Button-1> \
 169                "[cb _load_commit $w_amov @amov_data @%x,%y];break"
 170
 171        set w_asim $w.file_pane.out.asimple_t
 172        text $w_asim \
 173                -takefocus 0 \
 174                -highlightthickness 0 \
 175                -padx 0 -pady 0 \
 176                -background white \
 177                -foreground black \
 178                -borderwidth 0 \
 179                -state disabled \
 180                -wrap none \
 181                -height 40 \
 182                -width 4 \
 183                -font font_diff
 184        $w_asim tag conf author_abbr -justify right
 185        $w_asim tag conf curr_commit
 186        $w_asim tag conf prior_commit -foreground blue -underline 1
 187        $w_asim tag bind prior_commit \
 188                <Button-1> \
 189                "[cb _load_commit $w_asim @asim_data @%x,%y];break"
 190
 191        set w_file $w.file_pane.out.file_t
 192        text $w_file \
 193                -takefocus 0 \
 194                -highlightthickness 0 \
 195                -padx 0 -pady 0 \
 196                -background white \
 197                -foreground black \
 198                -borderwidth 0 \
 199                -state disabled \
 200                -wrap none \
 201                -height 40 \
 202                -width 80 \
 203                -xscrollcommand [list $w.file_pane.out.sbx set] \
 204                -font font_diff
 205        if {$have_tk85} {
 206                $w_file configure -inactiveselectbackground darkblue
 207        }
 208        $w_file tag conf found \
 209                -background yellow
 210
 211        set w_columns [list $w_amov $w_asim $w_line $w_file]
 212
 213        ${NS}::scrollbar $w.file_pane.out.sbx \
 214                -orient h \
 215                -command [list $w_file xview]
 216        ${NS}::scrollbar $w.file_pane.out.sby \
 217                -orient v \
 218                -command [list scrollbar2many $w_columns yview]
 219        eval grid $w_columns $w.file_pane.out.sby -sticky nsew
 220        grid conf \
 221                $w.file_pane.out.sbx \
 222                -column 0 \
 223                -columnspan [expr {[llength $w_columns] + 1}] \
 224                -sticky we
 225        grid columnconfigure \
 226                $w.file_pane.out \
 227                [expr {[llength $w_columns] - 1}] \
 228                -weight 1
 229        grid rowconfigure $w.file_pane.out 0 -weight 1
 230
 231        set finder [::searchbar::new \
 232                $w.file_pane.out.ff $w_file \
 233                -column 0 \
 234                -columnspan [expr {[llength $w_columns] + 1}] \
 235                ]
 236
 237        set gotoline [::linebar::new \
 238                $w.file_pane.out.lf $w_file \
 239                -column 0 \
 240                -columnspan [expr {[llength $w_columns] + 1}] \
 241                ]
 242
 243        set w_cviewer $w.file_pane.cm.t
 244        text $w_cviewer \
 245                -background white \
 246                -foreground black \
 247                -borderwidth 0 \
 248                -state disabled \
 249                -wrap none \
 250                -height 10 \
 251                -width 80 \
 252                -xscrollcommand [list $w.file_pane.cm.sbx set] \
 253                -yscrollcommand [list $w.file_pane.cm.sby set] \
 254                -font font_diff
 255        $w_cviewer tag conf still_loading \
 256                -font font_uiitalic \
 257                -justify center
 258        $w_cviewer tag conf header_key \
 259                -tabs {3c} \
 260                -background $active_color \
 261                -font font_uibold
 262        $w_cviewer tag conf header_val \
 263                -background $active_color \
 264                -font font_ui
 265        $w_cviewer tag raise sel
 266        ${NS}::scrollbar $w.file_pane.cm.sbx \
 267                -orient h \
 268                -command [list $w_cviewer xview]
 269        ${NS}::scrollbar $w.file_pane.cm.sby \
 270                -orient v \
 271                -command [list $w_cviewer yview]
 272        pack $w.file_pane.cm.sby -side right -fill y
 273        pack $w.file_pane.cm.sbx -side bottom -fill x
 274        pack $w_cviewer -expand 1 -fill both
 275
 276        set status [::status_bar::new $w.status]
 277
 278        menu $w.ctxm -tearoff 0
 279        $w.ctxm add command \
 280                -label [mc "Copy Commit"] \
 281                -command [cb _copycommit]
 282        $w.ctxm add separator
 283        $w.ctxm add command \
 284                -label [mc "Find Text..."] \
 285                -accelerator F7 \
 286                -command [cb _show_finder]
 287        $w.ctxm add command \
 288                -label [mc "Goto Line..."] \
 289                -accelerator "Ctrl-G" \
 290                -command [cb _show_linebar]
 291        menu $w.ctxm.enc
 292        build_encoding_menu $w.ctxm.enc [cb _setencoding]
 293        $w.ctxm add cascade \
 294                -label [mc "Encoding"] \
 295                -menu $w.ctxm.enc
 296        $w.ctxm add command \
 297                -label [mc "Do Full Copy Detection"] \
 298                -command [cb _fullcopyblame]
 299        $w.ctxm add separator
 300        $w.ctxm add command \
 301                -label [mc "Show History Context"] \
 302                -command [cb _gitkcommit]
 303        $w.ctxm add command \
 304                -label [mc "Blame Parent Commit"] \
 305                -command [cb _blameparent]
 306
 307        foreach i $w_columns {
 308                for {set g 0} {$g < [llength $group_colors]} {incr g} {
 309                        $i tag conf color$g -background [lindex $group_colors $g]
 310                }
 311
 312                if {$i eq $w_file} {
 313                        $w_file tag raise found
 314                }
 315                $i tag raise sel
 316
 317                $i conf -cursor $cursor_ptr
 318                $i conf -yscrollcommand \
 319                        "[list ::searchbar::scrolled $finder]
 320                         [list many2scrollbar $w_columns yview $w.file_pane.out.sby]"
 321                bind $i <Button-1> "
 322                        [cb _hide_tooltip]
 323                        [cb _click $i @%x,%y]
 324                        focus $i
 325                "
 326                bind $i <Any-Motion>  [cb _show_tooltip $i @%x,%y]
 327                bind $i <Any-Enter>   [cb _hide_tooltip]
 328                bind $i <Any-Leave>   [cb _hide_tooltip]
 329                bind_button3 $i "
 330                        [cb _hide_tooltip]
 331                        set cursorX %x
 332                        set cursorY %y
 333                        set cursorW %W
 334                        tk_popup $w.ctxm %X %Y
 335                "
 336                bind $i <Shift-Tab> "[list focus $w_cviewer];break"
 337                bind $i <Tab>       "[cb _focus_search $w_cviewer];break"
 338        }
 339
 340        foreach i [concat $w_columns $w_cviewer] {
 341                bind $i <Key-Up>        {catch {%W yview scroll -1 units};break}
 342                bind $i <Key-Down>      {catch {%W yview scroll  1 units};break}
 343                bind $i <Key-Left>      {catch {%W xview scroll -1 units};break}
 344                bind $i <Key-Right>     {catch {%W xview scroll  1 units};break}
 345                bind $i <Key-k>         {catch {%W yview scroll -1 units};break}
 346                bind $i <Key-j>         {catch {%W yview scroll  1 units};break}
 347                bind $i <Key-h>         {catch {%W xview scroll -1 units};break}
 348                bind $i <Key-l>         {catch {%W xview scroll  1 units};break}
 349                bind $i <Control-Key-b> {catch {%W yview scroll -1 pages};break}
 350                bind $i <Control-Key-f> {catch {%W yview scroll  1 pages};break}
 351        }
 352
 353        bind $w_cviewer <Shift-Tab> "[cb _focus_search $w_file];break"
 354        bind $w_cviewer <Tab>       "[list focus $w_file];break"
 355        bind $w_cviewer <Button-1>   [list focus $w_cviewer]
 356        bind $w_file    <Visibility> [cb _focus_search $w_file]
 357        bind $top       <F7>         [cb _show_finder]
 358        bind $top       <Key-slash>  [cb _show_finder]
 359        bind $top    <Control-Key-s> [cb _show_finder]
 360        bind $top       <Escape>     [list searchbar::hide $finder]
 361        bind $top       <F3>         [list searchbar::find_next $finder]
 362        bind $top       <Shift-F3>   [list searchbar::find_prev $finder]
 363        bind $top    <Control-Key-g> [cb _show_linebar]
 364        catch { bind $top <Shift-Key-XF86_Switch_VT_3> [list searchbar::find_prev $finder] }
 365
 366        grid configure $w.header -sticky ew
 367        grid configure $w.file_pane -sticky nsew
 368        grid configure $w.status -sticky ew
 369        grid columnconfigure $top 0 -weight 1
 370        grid rowconfigure $top 0 -weight 0
 371        grid rowconfigure $top 1 -weight 1
 372        grid rowconfigure $top 2 -weight 0
 373
 374        set req_w [winfo reqwidth  $top]
 375        set req_h [winfo reqheight $top]
 376        set scr_w [expr {[winfo screenwidth $top] - 40}]
 377        set scr_h [expr {[winfo screenheight $top] - 120}]
 378        set opt_w [expr {$font_w * (80 + 5*3 + 3)}]
 379        if {$req_w < $opt_w} {set req_w $opt_w}
 380        if {$req_w > $scr_w} {set req_w $scr_w}
 381        set opt_h [expr {$req_w*4/3}]
 382        if {$req_h < $scr_h} {set req_h $scr_h}
 383        if {$req_h > $opt_h} {set req_h $opt_h}
 384        set g "${req_w}x${req_h}"
 385        wm geometry $top $g
 386        update
 387
 388        set old_height [winfo height $w.file_pane]
 389        $w.file_pane sash place 0 \
 390                [lindex [$w.file_pane sash coord 0] 0] \
 391                [expr {int($old_height * 0.80)}]
 392        bind $w.file_pane <Configure> \
 393        "if {{$w.file_pane} eq {%W}} {[cb _resize %h]}"
 394
 395        wm protocol $top WM_DELETE_WINDOW "destroy $top"
 396        bind $top <Destroy> [cb _handle_destroy %W]
 397
 398        _load $this $i_jump
 399}
 400
 401method _focus_search {win} {
 402        if {[searchbar::visible $finder]} {
 403                focus [searchbar::editor $finder]
 404        } else {
 405                focus $win
 406        }
 407}
 408
 409method _handle_destroy {win} {
 410        if {$win eq $w} {
 411                _kill $this
 412                delete_this
 413        }
 414}
 415
 416method _kill {} {
 417        if {$current_fd ne {}} {
 418                kill_file_process $current_fd
 419                catch {close $current_fd}
 420                set current_fd {}
 421        }
 422}
 423
 424method _load {jump} {
 425        variable group_colors
 426
 427        _hide_tooltip $this
 428
 429        if {$total_lines != 0 || $current_fd ne {}} {
 430                _kill $this
 431
 432                foreach i $w_columns {
 433                        $i conf -state normal
 434                        $i delete 0.0 end
 435                        foreach g [$i tag names] {
 436                                if {[regexp {^g[0-9a-f]{40}$} $g]} {
 437                                        $i tag delete $g
 438                                }
 439                        }
 440                        $i conf -state disabled
 441                }
 442
 443                $w_cviewer conf -state normal
 444                $w_cviewer delete 0.0 end
 445                $w_cviewer conf -state disabled
 446
 447                set highlight_line -1
 448                set highlight_column {}
 449                set highlight_commit {}
 450                set total_lines 0
 451        }
 452
 453        if {$history eq {}} {
 454                $w_back conf -state disabled
 455        } else {
 456                $w_back conf -state normal
 457        }
 458
 459        # Index 0 is always empty.  There is never line 0 as
 460        # we use only 1 based lines, as that matches both with
 461        # git-blame output and with Tk's text widget.
 462        #
 463        set amov_data [list [list]]
 464        set asim_data [list [list]]
 465
 466        $status show [mc "Reading %s..." "$commit:[escape_path $path]"]
 467        $w_path conf -text [escape_path $path]
 468
 469        set do_textconv 0
 470        if {![is_config_false gui.textconv] && [git-version >= 1.7.2]} {
 471                set filter [gitattr $path diff set]
 472                set textconv [get_config [join [list diff $filter textconv] .]]
 473                if {$filter ne {set} && $textconv ne {}} {
 474                        set do_textconv 1
 475                }
 476        }
 477        if {$commit eq {}} {
 478                if {$do_textconv ne 0} {
 479                        # Run textconv with sh -c "..." to allow it to
 480                        # contain command + arguments. On windows, just
 481                        # call the filter command.
 482                        if {![file executable [shellpath]]} {
 483                                set fd [open |[linsert $textconv end $path] r]
 484                        } else {
 485                                set fd [open |[list [shellpath] -c "$textconv \"\$0\"" $path] r]
 486                        }
 487                } else {
 488                        set fd [open $path r]
 489                }
 490                fconfigure $fd -eofchar {}
 491        } else {
 492                if {$do_textconv ne 0} {
 493                        set fd [git_read cat-file --textconv "$commit:$path"]
 494                } else {
 495                        set fd [git_read cat-file blob "$commit:$path"]
 496                }
 497        }
 498        fconfigure $fd \
 499                -blocking 0 \
 500                -translation lf \
 501                -encoding [get_path_encoding $path]
 502        fileevent $fd readable [cb _read_file $fd $jump]
 503        set current_fd $fd
 504}
 505
 506method _history_menu {} {
 507        set m $w.backmenu
 508        if {[winfo exists $m]} {
 509                $m delete 0 end
 510        } else {
 511                menu $m -tearoff 0
 512        }
 513
 514        for {set i [expr {[llength $history] - 1}]
 515                } {$i >= 0} {incr i -1} {
 516                set e [lindex $history $i]
 517                set c [lindex $e 0]
 518                set f [lindex $e 1]
 519
 520                if {[regexp {^[0-9a-f]{40}$} $c]} {
 521                        set t [string range $c 0 8]...
 522                } elseif {$c eq {}} {
 523                        set t {Working Directory}
 524                } else {
 525                        set t $c
 526                }
 527                if {![catch {set summary $header($c,summary)}]} {
 528                        append t " $summary"
 529                        if {[string length $t] > 70} {
 530                                set t [string range $t 0 66]...
 531                        }
 532                }
 533
 534                $m add command -label $t -command [cb _goback $i]
 535        }
 536        set X [winfo rootx $w_back]
 537        set Y [expr {[winfo rooty $w_back] + [winfo height $w_back]}]
 538        tk_popup $m $X $Y
 539}
 540
 541method _goback {i} {
 542        set dat [lindex $history $i]
 543        set history [lrange $history 0 [expr {$i - 1}]]
 544        set commit [lindex $dat 0]
 545        set path [lindex $dat 1]
 546        _load $this [lrange $dat 2 5]
 547}
 548
 549method _read_file {fd jump} {
 550        if {$fd ne $current_fd} {
 551                catch {close $fd}
 552                return
 553        }
 554
 555        foreach i $w_columns {$i conf -state normal}
 556        while {[gets $fd line] >= 0} {
 557                regsub "\r\$" $line {} line
 558                incr total_lines
 559                lappend amov_data {}
 560                lappend asim_data {}
 561
 562                if {$total_lines > 1} {
 563                        foreach i $w_columns {$i insert end "\n"}
 564                }
 565
 566                $w_line insert end "$total_lines" linenumber
 567                $w_file insert end "$line"
 568        }
 569
 570        set ln_wc [expr {[string length $total_lines] + 2}]
 571        if {[$w_line cget -width] < $ln_wc} {
 572                $w_line conf -width $ln_wc
 573        }
 574
 575        foreach i $w_columns {$i conf -state disabled}
 576
 577        if {[eof $fd]} {
 578                close $fd
 579
 580                # If we don't force Tk to update the widgets *right now*
 581                # none of our jump commands will cause a change in the UI.
 582                #
 583                update
 584
 585                if {[llength $jump] == 1} {
 586                        set highlight_line [lindex $jump 0]
 587                        $w_file see "$highlight_line.0"
 588                } elseif {[llength $jump] == 4} {
 589                        set highlight_column [lindex $jump 0]
 590                        set highlight_line [lindex $jump 1]
 591                        $w_file xview moveto [lindex $jump 2]
 592                        $w_file yview moveto [lindex $jump 3]
 593                }
 594
 595                _exec_blame $this $w_asim @asim_data \
 596                        [list] \
 597                        [mc "Loading copy/move tracking annotations..."]
 598        }
 599} ifdeleted { catch {close $fd} }
 600
 601method _exec_blame {cur_w cur_d options cur_s} {
 602        lappend options --incremental --encoding=utf-8
 603        if {$commit eq {}} {
 604                lappend options --contents $path
 605        } else {
 606                lappend options $commit
 607        }
 608        lappend options -- $path
 609        set fd [eval git_read --nice blame $options]
 610        fconfigure $fd -blocking 0 -translation lf -encoding utf-8
 611        fileevent $fd readable [cb _read_blame $fd $cur_w $cur_d]
 612        set current_fd $fd
 613        set blame_lines 0
 614
 615        $status start \
 616                $cur_s \
 617                [mc "lines annotated"]
 618}
 619
 620method _read_blame {fd cur_w cur_d} {
 621        upvar #0 $cur_d line_data
 622        variable group_colors
 623
 624        if {$fd ne $current_fd} {
 625                catch {close $fd}
 626                return
 627        }
 628
 629        $cur_w conf -state normal
 630        while {[gets $fd line] >= 0} {
 631                if {[regexp {^([a-z0-9]{40}) (\d+) (\d+) (\d+)$} $line line \
 632                        cmit original_line final_line line_count]} {
 633                        set r_commit     $cmit
 634                        set r_orig_line  $original_line
 635                        set r_final_line $final_line
 636                        set r_line_count $line_count
 637                } elseif {[string match {filename *} $line]} {
 638                        set file [string range $line 9 end]
 639                        set n    $r_line_count
 640                        set lno  $r_final_line
 641                        set oln  $r_orig_line
 642                        set cmit $r_commit
 643
 644                        if {[regexp {^0{40}$} $cmit]} {
 645                                set commit_abbr work
 646                                set commit_type curr_commit
 647                        } elseif {$cmit eq $commit} {
 648                                set commit_abbr this
 649                                set commit_type curr_commit
 650                        } else {
 651                                set commit_type prior_commit
 652                                set commit_abbr [string range $cmit 0 3]
 653                        }
 654
 655                        set author_abbr {}
 656                        set a_name {}
 657                        catch {set a_name $header($cmit,author)}
 658                        while {$a_name ne {}} {
 659                                if {$author_abbr ne {}
 660                                        && [string index $a_name 0] eq {'}} {
 661                                        regsub {^'[^']+'\s+} $a_name {} a_name
 662                                }
 663                                if {![regexp {^([[:upper:]])} $a_name _a]} break
 664                                append author_abbr $_a
 665                                unset _a
 666                                if {![regsub \
 667                                        {^[[:upper:]][^\s]*\s+} \
 668                                        $a_name {} a_name ]} break
 669                        }
 670                        if {$author_abbr eq {}} {
 671                                set author_abbr { |}
 672                        } else {
 673                                set author_abbr [string range $author_abbr 0 3]
 674                        }
 675                        unset a_name
 676
 677                        set first_lno $lno
 678                        while {
 679                           $first_lno > 1
 680                        && $cmit eq [lindex $line_data [expr {$first_lno - 1}] 0]
 681                        && $file eq [lindex $line_data [expr {$first_lno - 1}] 1]
 682                        } {
 683                                incr first_lno -1
 684                        }
 685
 686                        set color {}
 687                        if {$first_lno < $lno} {
 688                                foreach g [$w_file tag names $first_lno.0] {
 689                                        if {[regexp {^color[0-9]+$} $g]} {
 690                                                set color $g
 691                                                break
 692                                        }
 693                                }
 694                        } else {
 695                                set i [lsort [concat \
 696                                        [$w_file tag names "[expr {$first_lno - 1}].0"] \
 697                                        [$w_file tag names "[expr {$lno + $n}].0"] \
 698                                        ]]
 699                                for {set g 0} {$g < [llength $group_colors]} {incr g} {
 700                                        if {[lsearch -sorted -exact $i color$g] == -1} {
 701                                                set color color$g
 702                                                break
 703                                        }
 704                                }
 705                        }
 706                        if {$color eq {}} {
 707                                set color color0
 708                        }
 709
 710                        while {$n > 0} {
 711                                set lno_e "$lno.0 lineend + 1c"
 712                                if {[lindex $line_data $lno] ne {}} {
 713                                        set g [lindex $line_data $lno 0]
 714                                        foreach i $w_columns {
 715                                                $i tag remove g$g $lno.0 $lno_e
 716                                        }
 717                                }
 718                                lset line_data $lno [list $cmit $file $oln]
 719
 720                                $cur_w delete $lno.0 "$lno.0 lineend"
 721                                if {$lno == $first_lno} {
 722                                        $cur_w insert $lno.0 $commit_abbr $commit_type
 723                                } elseif {$lno == [expr {$first_lno + 1}]} {
 724                                        $cur_w insert $lno.0 $author_abbr author_abbr
 725                                } else {
 726                                        $cur_w insert $lno.0 { |}
 727                                }
 728
 729                                foreach i $w_columns {
 730                                        if {$cur_w eq $w_amov} {
 731                                                for {set g 0} \
 732                                                        {$g < [llength $group_colors]} \
 733                                                        {incr g} {
 734                                                        $i tag remove color$g $lno.0 $lno_e
 735                                                }
 736                                                $i tag add $color $lno.0 $lno_e
 737                                        }
 738                                        $i tag add g$cmit $lno.0 $lno_e
 739                                }
 740
 741                                if {$highlight_column eq $cur_w} {
 742                                        if {$highlight_line == -1
 743                                         && [lindex [$w_file yview] 0] == 0} {
 744                                                $w_file see $lno.0
 745                                                set highlight_line $lno
 746                                        }
 747                                        if {$highlight_line == $lno} {
 748                                                _showcommit $this $cur_w $lno
 749                                        }
 750                                }
 751
 752                                incr n -1
 753                                incr lno
 754                                incr oln
 755                                incr blame_lines
 756                        }
 757
 758                        while {
 759                           $cmit eq [lindex $line_data $lno 0]
 760                        && $file eq [lindex $line_data $lno 1]
 761                        } {
 762                                $cur_w delete $lno.0 "$lno.0 lineend"
 763
 764                                if {$lno == $first_lno} {
 765                                        $cur_w insert $lno.0 $commit_abbr $commit_type
 766                                } elseif {$lno == [expr {$first_lno + 1}]} {
 767                                        $cur_w insert $lno.0 $author_abbr author_abbr
 768                                } else {
 769                                        $cur_w insert $lno.0 { |}
 770                                }
 771
 772                                if {$cur_w eq $w_amov} {
 773                                        foreach i $w_columns {
 774                                                for {set g 0} \
 775                                                        {$g < [llength $group_colors]} \
 776                                                        {incr g} {
 777                                                        $i tag remove color$g $lno.0 $lno_e
 778                                                }
 779                                                $i tag add $color $lno.0 $lno_e
 780                                        }
 781                                }
 782
 783                                incr lno
 784                        }
 785
 786                } elseif {[regexp {^([a-z-]+) (.*)$} $line line key data]} {
 787                        set header($r_commit,$key) $data
 788                }
 789        }
 790        $cur_w conf -state disabled
 791
 792        if {[eof $fd]} {
 793                close $fd
 794                if {$cur_w eq $w_asim} {
 795                        # Switches for original location detection
 796                        set threshold [get_config gui.copyblamethreshold]
 797                        set original_options [list "-C$threshold"]
 798
 799                        if {![is_config_true gui.fastcopyblame]} {
 800                                # thorough copy search; insert before the threshold
 801                                set original_options [linsert $original_options 0 -C]
 802                        }
 803                        if {[git-version >= 1.5.3]} {
 804                                lappend original_options -w ; # ignore indentation changes
 805                        }
 806
 807                        _exec_blame $this $w_amov @amov_data \
 808                                $original_options \
 809                                [mc "Loading original location annotations..."]
 810                } else {
 811                        set current_fd {}
 812                        $status stop [mc "Annotation complete."]
 813                }
 814        } else {
 815                $status update $blame_lines $total_lines
 816        }
 817} ifdeleted { catch {close $fd} }
 818
 819method _find_commit_bound {data_list start_idx delta} {
 820        upvar #0 $data_list line_data
 821        set pos $start_idx
 822        set limit       [expr {[llength $line_data] - 1}]
 823        set base_commit [lindex $line_data $pos 0]
 824
 825        while {$pos > 0 && $pos < $limit} {
 826                set new_pos [expr {$pos + $delta}]
 827                if {[lindex $line_data $new_pos 0] ne $base_commit} {
 828                        return $pos
 829                }
 830
 831                set pos $new_pos
 832        }
 833
 834        return $pos
 835}
 836
 837method _fullcopyblame {} {
 838        if {$current_fd ne {}} {
 839                tk_messageBox \
 840                        -icon error \
 841                        -type ok \
 842                        -title [mc "Busy"] \
 843                        -message [mc "Annotation process is already running."]
 844
 845                return
 846        }
 847
 848        # Switches for original location detection
 849        set threshold [get_config gui.copyblamethreshold]
 850        set original_options [list -C -C "-C$threshold"]
 851
 852        if {[git-version >= 1.5.3]} {
 853                lappend original_options -w ; # ignore indentation changes
 854        }
 855
 856        # Find the line range
 857        set pos @$::cursorX,$::cursorY
 858        set lno [lindex [split [$::cursorW index $pos] .] 0]
 859        set min_amov_lno [_find_commit_bound $this @amov_data $lno -1]
 860        set max_amov_lno [_find_commit_bound $this @amov_data $lno 1]
 861        set min_asim_lno [_find_commit_bound $this @asim_data $lno -1]
 862        set max_asim_lno [_find_commit_bound $this @asim_data $lno 1]
 863
 864        if {$min_asim_lno < $min_amov_lno} {
 865                set min_amov_lno $min_asim_lno
 866        }
 867
 868        if {$max_asim_lno > $max_amov_lno} {
 869                set max_amov_lno $max_asim_lno
 870        }
 871
 872        lappend original_options -L "$min_amov_lno,$max_amov_lno"
 873
 874        # Clear lines
 875        for {set i $min_amov_lno} {$i <= $max_amov_lno} {incr i} {
 876                lset amov_data $i [list ]
 877        }
 878
 879        # Start the back-end process
 880        _exec_blame $this $w_amov @amov_data \
 881                $original_options \
 882                [mc "Running thorough copy detection..."]
 883}
 884
 885method _click {cur_w pos} {
 886        set lno [lindex [split [$cur_w index $pos] .] 0]
 887        _showcommit $this $cur_w $lno
 888}
 889
 890method _setencoding {enc} {
 891        force_path_encoding $path $enc
 892        _load $this [list \
 893                $highlight_column \
 894                $highlight_line \
 895                [lindex [$w_file xview] 0] \
 896                [lindex [$w_file yview] 0] \
 897                ]
 898}
 899
 900method _load_commit {cur_w cur_d pos} {
 901        upvar #0 $cur_d line_data
 902        set lno [lindex [split [$cur_w index $pos] .] 0]
 903        set dat [lindex $line_data $lno]
 904        if {$dat ne {}} {
 905                _load_new_commit $this  \
 906                        [lindex $dat 0] \
 907                        [lindex $dat 1] \
 908                        [list [lindex $dat 2]]
 909        }
 910}
 911
 912method _load_new_commit {new_commit new_path jump} {
 913        lappend history [list \
 914                $commit $path \
 915                $highlight_column \
 916                $highlight_line \
 917                [lindex [$w_file xview] 0] \
 918                [lindex [$w_file yview] 0] \
 919                ]
 920
 921        set commit $new_commit
 922        set path   $new_path
 923        _load $this $jump
 924}
 925
 926method _showcommit {cur_w lno} {
 927        global repo_config
 928        variable active_color
 929
 930        if {$highlight_commit ne {}} {
 931                foreach i $w_columns {
 932                        $i tag conf g$highlight_commit -background {}
 933                        $i tag lower g$highlight_commit
 934                }
 935        }
 936
 937        if {$cur_w eq $w_asim} {
 938                set dat [lindex $asim_data $lno]
 939                set highlight_column $w_asim
 940        } else {
 941                set dat [lindex $amov_data $lno]
 942                set highlight_column $w_amov
 943        }
 944
 945        $w_cviewer conf -state normal
 946        $w_cviewer delete 0.0 end
 947
 948        if {$dat eq {}} {
 949                set cmit {}
 950                $w_cviewer insert end [mc "Loading annotation..."] still_loading
 951        } else {
 952                set cmit [lindex $dat 0]
 953                set file [lindex $dat 1]
 954
 955                foreach i $w_columns {
 956                        $i tag conf g$cmit -background $active_color
 957                        $i tag raise g$cmit
 958                        if {$i eq $w_file} {
 959                                $w_file tag raise found
 960                        }
 961                        $i tag raise sel
 962                }
 963
 964                set author_name {}
 965                set author_email {}
 966                set author_time {}
 967                catch {set author_name $header($cmit,author)}
 968                catch {set author_email $header($cmit,author-mail)}
 969                catch {set author_time [format_date $header($cmit,author-time)]}
 970
 971                set committer_name {}
 972                set committer_email {}
 973                set committer_time {}
 974                catch {set committer_name $header($cmit,committer)}
 975                catch {set committer_email $header($cmit,committer-mail)}
 976                catch {set committer_time [format_date $header($cmit,committer-time)]}
 977
 978                if {[catch {set msg $header($cmit,message)}]} {
 979                        set msg {}
 980                        catch {
 981                                set fd [git_read cat-file commit $cmit]
 982                                fconfigure $fd -encoding binary -translation lf
 983                                # By default commits are assumed to be in utf-8
 984                                set enc utf-8
 985                                while {[gets $fd line] > 0} {
 986                                        if {[string match {encoding *} $line]} {
 987                                                set enc [string tolower [string range $line 9 end]]
 988                                        }
 989                                }
 990                                set msg [read $fd]
 991                                close $fd
 992
 993                                set enc [tcl_encoding $enc]
 994                                if {$enc ne {}} {
 995                                        set msg [encoding convertfrom $enc $msg]
 996                                }
 997                                set msg [string trim $msg]
 998                        }
 999                        set header($cmit,message) $msg
1000                }
1001
1002                $w_cviewer insert end "commit $cmit\n" header_key
1003                $w_cviewer insert end [strcat [mc "Author:"] "\t"] header_key
1004                $w_cviewer insert end "$author_name $author_email" header_val
1005                $w_cviewer insert end "  $author_time\n" header_val
1006
1007                $w_cviewer insert end [strcat [mc "Committer:"] "\t"] header_key
1008                $w_cviewer insert end "$committer_name $committer_email" header_val
1009                $w_cviewer insert end "  $committer_time\n" header_val
1010
1011                if {$file ne $path} {
1012                        $w_cviewer insert end [strcat [mc "Original File:"] "\t"] header_key
1013                        $w_cviewer insert end "[escape_path $file]\n" header_val
1014                }
1015
1016                $w_cviewer insert end "\n$msg"
1017        }
1018        $w_cviewer conf -state disabled
1019
1020        set highlight_line $lno
1021        set highlight_commit $cmit
1022
1023        if {[lsearch -exact $tooltip_commit $highlight_commit] != -1} {
1024                _hide_tooltip $this
1025        }
1026}
1027
1028method _get_click_amov_info {} {
1029        set pos @$::cursorX,$::cursorY
1030        set lno [lindex [split [$::cursorW index $pos] .] 0]
1031        return [lindex $amov_data $lno]
1032}
1033
1034method _copycommit {} {
1035        set dat [_get_click_amov_info $this]
1036        if {$dat ne {}} {
1037                clipboard clear
1038                clipboard append \
1039                        -format STRING \
1040                        -type STRING \
1041                        -- [lindex $dat 0]
1042        }
1043}
1044
1045method _format_offset_date {base offset} {
1046        set exval [expr {$base + $offset*24*60*60}]
1047        return [clock format $exval -format {%Y-%m-%d}]
1048}
1049
1050method _gitkcommit {} {
1051        global nullid
1052
1053        set dat [_get_click_amov_info $this]
1054        if {$dat ne {}} {
1055                set cmit [lindex $dat 0]
1056
1057                # If the line belongs to the working copy, use HEAD instead
1058                if {$cmit eq $nullid} {
1059                        if {[catch {set cmit [git rev-parse --verify HEAD]} err]} {
1060                                error_popup [strcat [mc "Cannot find HEAD commit:"] "\n\n$err"]
1061                                return;
1062                        }
1063                }
1064
1065                set radius [get_config gui.blamehistoryctx]
1066                set cmdline [list --select-commit=$cmit]
1067
1068                if {$radius > 0} {
1069                        set author_time {}
1070                        set committer_time {}
1071
1072                        catch {set author_time $header($cmit,author-time)}
1073                        catch {set committer_time $header($cmit,committer-time)}
1074
1075                        if {$committer_time eq {}} {
1076                                set committer_time $author_time
1077                        }
1078
1079                        set after_time [_format_offset_date $this $committer_time [expr {-$radius}]]
1080                        set before_time [_format_offset_date $this $committer_time $radius]
1081
1082                        lappend cmdline --after=$after_time --before=$before_time
1083                }
1084
1085                lappend cmdline $cmit
1086
1087                set base_rev "HEAD"
1088                if {$commit ne {}} {
1089                        set base_rev $commit
1090                }
1091
1092                if {$base_rev ne $cmit} {
1093                        lappend cmdline $base_rev
1094                }
1095
1096                do_gitk $cmdline
1097        }
1098}
1099
1100method _blameparent {} {
1101        global nullid
1102
1103        set dat [_get_click_amov_info $this]
1104        if {$dat ne {}} {
1105                set cmit [lindex $dat 0]
1106                set new_path [lindex $dat 1]
1107
1108                # Allow using Blame Parent on lines modified in the working copy
1109                if {$cmit eq $nullid} {
1110                        set parent_ref "HEAD"
1111                } else {
1112                        set parent_ref "$cmit^"
1113                }
1114                if {[catch {set cparent [git rev-parse --verify $parent_ref]} err]} {
1115                        error_popup [strcat [mc "Cannot find parent commit:"] "\n\n$err"]
1116                        return;
1117                }
1118
1119                _kill $this
1120
1121                # Generate a diff between the commit and its parent,
1122                # and use the hunks to update the line number.
1123                # Request zero context to simplify calculations.
1124                if {$cmit eq $nullid} {
1125                        set diffcmd [list diff-index --unified=0 $cparent -- $new_path]
1126                } else {
1127                        set diffcmd [list diff-tree --unified=0 $cparent $cmit -- $new_path]
1128                }
1129                if {[catch {set fd [eval git_read $diffcmd]} err]} {
1130                        $status stop [mc "Unable to display parent"]
1131                        error_popup [strcat [mc "Error loading diff:"] "\n\n$err"]
1132                        return
1133                }
1134
1135                set r_orig_line [lindex $dat 2]
1136
1137                fconfigure $fd \
1138                        -blocking 0 \
1139                        -encoding binary \
1140                        -translation binary
1141                fileevent $fd readable [cb _read_diff_load_commit \
1142                        $fd $cparent $new_path $r_orig_line]
1143                set current_fd $fd
1144        }
1145}
1146
1147method _read_diff_load_commit {fd cparent new_path tline} {
1148        if {$fd ne $current_fd} {
1149                catch {close $fd}
1150                return
1151        }
1152
1153        while {[gets $fd line] >= 0} {
1154                if {[regexp {^@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@} $line line \
1155                        old_line osz old_size new_line nsz new_size]} {
1156
1157                        if {$osz eq {}} { set old_size 1 }
1158                        if {$nsz eq {}} { set new_size 1 }
1159
1160                        if {$new_line <= $tline} {
1161                                if {[expr {$new_line + $new_size}] > $tline} {
1162                                        # Target line within the hunk
1163                                        set line_shift [expr {
1164                                                ($new_size-$old_size)*($tline-$new_line)/$new_size
1165                                                }]
1166                                } else {
1167                                        set line_shift [expr {$new_size-$old_size}]
1168                                }
1169
1170                                set r_orig_line [expr {$r_orig_line - $line_shift}]
1171                        }
1172                }
1173        }
1174
1175        if {[eof $fd]} {
1176                close $fd;
1177                set current_fd {}
1178
1179                _load_new_commit $this  \
1180                        $cparent        \
1181                        $new_path       \
1182                        [list $r_orig_line]
1183        }
1184} ifdeleted { catch {close $fd} }
1185
1186method _show_tooltip {cur_w pos} {
1187        if {$tooltip_wm ne {}} {
1188                _open_tooltip $this $cur_w
1189        } elseif {$tooltip_timer eq {}} {
1190                set tooltip_timer [after 1000 [cb _open_tooltip $cur_w]]
1191        }
1192}
1193
1194method _open_tooltip {cur_w} {
1195        set tooltip_timer {}
1196        set pos_x [winfo pointerx $cur_w]
1197        set pos_y [winfo pointery $cur_w]
1198        if {[winfo containing $pos_x $pos_y] ne $cur_w} {
1199                _hide_tooltip $this
1200                return
1201        }
1202
1203        if {$tooltip_wm ne "$cur_w.tooltip"} {
1204                _hide_tooltip $this
1205
1206                set tooltip_wm [toplevel $cur_w.tooltip -borderwidth 1]
1207                catch {wm attributes $tooltip_wm -type tooltip}
1208                wm overrideredirect $tooltip_wm 1
1209                wm transient $tooltip_wm [winfo toplevel $cur_w]
1210                set tooltip_t $tooltip_wm.label
1211                text $tooltip_t \
1212                        -takefocus 0 \
1213                        -highlightthickness 0 \
1214                        -relief flat \
1215                        -borderwidth 0 \
1216                        -wrap none \
1217                        -background lightyellow \
1218                        -foreground black
1219                $tooltip_t tag conf section_header -font font_uibold
1220                pack $tooltip_t
1221        } else {
1222                $tooltip_t conf -state normal
1223                $tooltip_t delete 0.0 end
1224        }
1225
1226        set pos @[join [list \
1227                [expr {$pos_x - [winfo rootx $cur_w]}] \
1228                [expr {$pos_y - [winfo rooty $cur_w]}]] ,]
1229        set lno [lindex [split [$cur_w index $pos] .] 0]
1230        if {$cur_w eq $w_amov} {
1231                set dat [lindex $amov_data $lno]
1232                set org {}
1233        } else {
1234                set dat [lindex $asim_data $lno]
1235                set org [lindex $amov_data $lno]
1236        }
1237
1238        if {$dat eq {}} {
1239                _hide_tooltip $this
1240                return
1241        }
1242
1243        set cmit [lindex $dat 0]
1244        set tooltip_commit [list $cmit]
1245
1246        set author_name {}
1247        set summary     {}
1248        set author_time {}
1249        catch {set author_name $header($cmit,author)}
1250        catch {set summary     $header($cmit,summary)}
1251        catch {set author_time [format_date $header($cmit,author-time)]}
1252
1253        $tooltip_t insert end "commit $cmit\n"
1254        $tooltip_t insert end "$author_name  $author_time\n"
1255        $tooltip_t insert end "$summary"
1256
1257        if {$org ne {} && [lindex $org 0] ne $cmit} {
1258                set save [$tooltip_t get 0.0 end]
1259                $tooltip_t delete 0.0 end
1260
1261                set cmit [lindex $org 0]
1262                set file [lindex $org 1]
1263                lappend tooltip_commit $cmit
1264
1265                set author_name {}
1266                set summary     {}
1267                set author_time {}
1268                catch {set author_name $header($cmit,author)}
1269                catch {set summary     $header($cmit,summary)}
1270                catch {set author_time [format_date $header($cmit,author-time)]}
1271
1272                $tooltip_t insert end [strcat [mc "Originally By:"] "\n"] section_header
1273                $tooltip_t insert end "commit $cmit\n"
1274                $tooltip_t insert end "$author_name  $author_time\n"
1275                $tooltip_t insert end "$summary\n"
1276
1277                if {$file ne $path} {
1278                        $tooltip_t insert end [strcat [mc "In File:"] " "] section_header
1279                        $tooltip_t insert end "$file\n"
1280                }
1281
1282                $tooltip_t insert end "\n"
1283                $tooltip_t insert end [strcat [mc "Copied Or Moved Here By:"] "\n"] section_header
1284                $tooltip_t insert end $save
1285        }
1286
1287        $tooltip_t conf -state disabled
1288        _position_tooltip $this
1289
1290        # On MacOS raising a window causes it to acquire focus.
1291        # Tk 8.5 on MacOS seems to properly support wm transient,
1292        # so we can safely counter the effect there.
1293        if {$::have_tk85 && [is_MacOSX]} {
1294                update
1295                if {$w eq {}} {
1296                        raise .
1297                } else {
1298                        raise $w
1299                }
1300        }
1301}
1302
1303method _position_tooltip {} {
1304        set max_h [lindex [split [$tooltip_t index end] .] 0]
1305        set max_w 0
1306        for {set i 1} {$i <= $max_h} {incr i} {
1307                set c [lindex [split [$tooltip_t index "$i.0 lineend"] .] 1]
1308                if {$c > $max_w} {set max_w $c}
1309        }
1310        $tooltip_t conf -width $max_w -height $max_h
1311
1312        set req_w [winfo reqwidth  $tooltip_t]
1313        set req_h [winfo reqheight $tooltip_t]
1314        set pos_x [expr {[winfo pointerx .] +  5}]
1315        set pos_y [expr {[winfo pointery .] + 10}]
1316
1317        set g "${req_w}x${req_h}"
1318        if {[tk windowingsystem] eq "win32" || $pos_x >= 0} {append g +}
1319        append g $pos_x
1320        if {[tk windowingsystem] eq "win32" || $pos_y >= 0} {append g +}
1321        append g $pos_y
1322
1323        wm geometry $tooltip_wm $g
1324        if {![is_MacOSX]} {
1325                raise $tooltip_wm
1326        }
1327}
1328
1329method _hide_tooltip {} {
1330        if {$tooltip_wm ne {}} {
1331                destroy $tooltip_wm
1332                set tooltip_wm {}
1333                set tooltip_commit {}
1334        }
1335        if {$tooltip_timer ne {}} {
1336                after cancel $tooltip_timer
1337                set tooltip_timer {}
1338        }
1339}
1340
1341method _resize {new_height} {
1342        set diff [expr {$new_height - $old_height}]
1343        if {$diff == 0} return
1344
1345        set my [expr {[winfo height $w.file_pane] - 25}]
1346        set o [$w.file_pane sash coord 0]
1347        set ox [lindex $o 0]
1348        set oy [expr {[lindex $o 1] + $diff}]
1349        if {$oy < 0}   {set oy 0}
1350        if {$oy > $my} {set oy $my}
1351        $w.file_pane sash place 0 $ox $oy
1352
1353        set old_height $new_height
1354}
1355
1356method _show_finder {} {
1357        linebar::hide $gotoline
1358        searchbar::show $finder
1359}
1360
1361method _show_linebar {} {
1362        searchbar::hide $finder
1363        linebar::show $gotoline
1364}
1365
1366}