Fossil SCM
In the "--tk" diff viewer, add a new "Context:" dropdown that lets the user select the amound of diff context. Change the default diff context from 5 to 6.
Commit
6ee7450f62753510be22a88461866b83bfa695f480ad9216981a9f5c9982fb03
Parent
83613064b853e70…
1 file changed
+111
-1
+111
-1
| --- src/diff.tcl | ||
| +++ src/diff.tcl | ||
| @@ -510,10 +510,116 @@ | ||
| 510 | 510 | } |
| 511 | 511 | bind .wfiles.lb <Motion> { |
| 512 | 512 | %W selection clear 0 end |
| 513 | 513 | %W selection set @%x,%y |
| 514 | 514 | } |
| 515 | + | |
| 516 | +# Return the context setting found in fossilcmd, or 6 (the default) | |
| 517 | +# if fossilcmd contains no -c or --context option. Negative values | |
| 518 | +# mean "All". | |
| 519 | +# | |
| 520 | +proc initContext {} { | |
| 521 | + set n 6 | |
| 522 | + set nn [llength $::fossilcmd] | |
| 523 | + for {set i 2} {$i<$nn} {incr i} { | |
| 524 | + set arg [lindex $::fossilcmd $i] | |
| 525 | + if {[regexp {^--?(c|context)$} $arg] && $i+1<$nn} { | |
| 526 | + set n [lindex $::fossilcmd [incr i]] | |
| 527 | + } elseif {[regexp {^--?(?:c|context)=(.*)$} $arg all val]} { | |
| 528 | + set n $val | |
| 529 | + } | |
| 530 | + } | |
| 531 | + if {![string is integer -strict $n]} {return 6} | |
| 532 | + if {$n<0} {return All} | |
| 533 | + return $n | |
| 534 | +} | |
| 535 | + | |
| 536 | +# Invoked whenever the ncontext variable changes. Rewrite fossilcmd | |
| 537 | +# to use the new context setting and reload the diff, keeping the | |
| 538 | +# file that was showing at the top of the window in view. | |
| 539 | +# | |
| 540 | +proc changeContext {args} { | |
| 541 | + global fossilcmd ncontext | |
| 542 | + set cmd [lrange $fossilcmd 0 1] | |
| 543 | + set nn [llength $fossilcmd] | |
| 544 | + for {set i 2} {$i<$nn} {incr i} { | |
| 545 | + set arg [lindex $fossilcmd $i] | |
| 546 | + if {[regexp {^--?(c|context)$} $arg]} { | |
| 547 | + incr i | |
| 548 | + } elseif {![regexp {^--?(c|context)=} $arg]} { | |
| 549 | + lappend cmd $arg | |
| 550 | + } | |
| 551 | + } | |
| 552 | + if {$ncontext eq "All"} { | |
| 553 | + lappend cmd -c -1 | |
| 554 | + } else { | |
| 555 | + lappend cmd -c $ncontext | |
| 556 | + } | |
| 557 | + set fossilcmd $cmd | |
| 558 | + set range [.txtA tag prevrange fn {@0,0 +1c} 1.0] | |
| 559 | + set iFile 0 | |
| 560 | + if {$range ne ""} { | |
| 561 | + set iFile [expr {[lsearch -exact [.txtA tag ranges fn] \ | |
| 562 | + [lindex $range 0]]/2}] | |
| 563 | + } | |
| 564 | + unset -nocomplain ::difftxt | |
| 565 | + readDiffs 1 | |
| 566 | + update | |
| 567 | + set idx [lindex [.txtA tag ranges fn] [expr {$iFile*2}]] | |
| 568 | + if {$idx eq ""} {set idx 1.0} | |
| 569 | + viewDiff $idx | |
| 570 | +} | |
| 571 | + | |
| 572 | +label .bb.ctxtag -text "Context:" | |
| 573 | +set context_choices {3 6 12 25 50 100 All} | |
| 574 | +if {$fossilcmd ne ""} { | |
| 575 | + set ncontext [initContext] | |
| 576 | + if {[lsearch -exact $context_choices $ncontext]<0} { | |
| 577 | + set context_choices [lsort -integer \ | |
| 578 | + [concat [lrange $context_choices 0 end-1] $ncontext]] | |
| 579 | + lappend context_choices All | |
| 580 | + } | |
| 581 | + trace add variable ncontext write changeContext | |
| 582 | +} | |
| 583 | +if {$tcl_platform(os)=="Darwin"} { | |
| 584 | + tk_optionMenu .bb.ctx ncontext {*}$context_choices | |
| 585 | +} else { | |
| 586 | + ::ttk::menubutton .bb.ctx -text [expr {[info exists ncontext]?$ncontext:""}] | |
| 587 | + if {[tk windowingsystem] eq "win32"} { | |
| 588 | + .bb.ctx configure -padding {20 1 10 2} | |
| 589 | + } | |
| 590 | + toplevel .wctx | |
| 591 | + wm withdraw .wctx | |
| 592 | + update idletasks | |
| 593 | + wm transient .wctx . | |
| 594 | + wm overrideredirect .wctx 1 | |
| 595 | + listbox .wctx.lb -width 0 -height [llength $context_choices] \ | |
| 596 | + -activestyle none | |
| 597 | + .wctx.lb insert end {*}$context_choices | |
| 598 | + pack .wctx.lb | |
| 599 | + bind .bb.ctx <1> { | |
| 600 | + set x [winfo rootx %W] | |
| 601 | + set y [expr {[winfo rooty %W]+[winfo height %W]}] | |
| 602 | + wm geometry .wctx +$x+$y | |
| 603 | + wm deiconify .wctx | |
| 604 | + focus .wctx.lb | |
| 605 | + } | |
| 606 | + bind .wctx <FocusOut> {wm withdraw .wctx} | |
| 607 | + bind .wctx <Escape> {focus .} | |
| 608 | + foreach evt {1 Return} { | |
| 609 | + bind .wctx.lb <$evt> { | |
| 610 | + set ::ncontext [lindex $::context_choices [%W curselection]] | |
| 611 | + .bb.ctx config -text $::ncontext | |
| 612 | + focus . | |
| 613 | + break | |
| 614 | + } | |
| 615 | + } | |
| 616 | + bind .wctx.lb <Motion> { | |
| 617 | + %W selection clear 0 end | |
| 618 | + %W selection set @%x,%y | |
| 619 | + } | |
| 620 | +} | |
| 515 | 621 | |
| 516 | 622 | foreach {side syncCol} {A .txtB B .txtA} { |
| 517 | 623 | set ln .ln$side |
| 518 | 624 | text $ln |
| 519 | 625 | $ln tag config - -justify right |
| @@ -676,11 +782,15 @@ | ||
| 676 | 782 | if {$fossilcmd ne ""} { |
| 677 | 783 | pack .bb.reload -side left |
| 678 | 784 | } |
| 679 | 785 | pack .bb.invert -side left |
| 680 | 786 | if {$fossilcmd!=""} {pack .bb.save -side left} |
| 681 | -pack .bb.files .bb.search -side left | |
| 787 | +pack .bb.files -side left | |
| 788 | +if {$fossilcmd ne ""} { | |
| 789 | + pack .bb.ctxtag .bb.ctx -side left | |
| 790 | +} | |
| 791 | +pack .bb.search -side left | |
| 682 | 792 | grid rowconfigure . 1 -weight 1 |
| 683 | 793 | grid columnconfigure . 1 -weight 1 |
| 684 | 794 | grid columnconfigure . 4 -weight 1 |
| 685 | 795 | grid .bb -row 0 -columnspan 6 |
| 686 | 796 | eval grid [cols] -row 1 -sticky nsew |
| 687 | 797 |
| --- src/diff.tcl | |
| +++ src/diff.tcl | |
| @@ -510,10 +510,116 @@ | |
| 510 | } |
| 511 | bind .wfiles.lb <Motion> { |
| 512 | %W selection clear 0 end |
| 513 | %W selection set @%x,%y |
| 514 | } |
| 515 | |
| 516 | foreach {side syncCol} {A .txtB B .txtA} { |
| 517 | set ln .ln$side |
| 518 | text $ln |
| 519 | $ln tag config - -justify right |
| @@ -676,11 +782,15 @@ | |
| 676 | if {$fossilcmd ne ""} { |
| 677 | pack .bb.reload -side left |
| 678 | } |
| 679 | pack .bb.invert -side left |
| 680 | if {$fossilcmd!=""} {pack .bb.save -side left} |
| 681 | pack .bb.files .bb.search -side left |
| 682 | grid rowconfigure . 1 -weight 1 |
| 683 | grid columnconfigure . 1 -weight 1 |
| 684 | grid columnconfigure . 4 -weight 1 |
| 685 | grid .bb -row 0 -columnspan 6 |
| 686 | eval grid [cols] -row 1 -sticky nsew |
| 687 |
| --- src/diff.tcl | |
| +++ src/diff.tcl | |
| @@ -510,10 +510,116 @@ | |
| 510 | } |
| 511 | bind .wfiles.lb <Motion> { |
| 512 | %W selection clear 0 end |
| 513 | %W selection set @%x,%y |
| 514 | } |
| 515 | |
| 516 | # Return the context setting found in fossilcmd, or 6 (the default) |
| 517 | # if fossilcmd contains no -c or --context option. Negative values |
| 518 | # mean "All". |
| 519 | # |
| 520 | proc initContext {} { |
| 521 | set n 6 |
| 522 | set nn [llength $::fossilcmd] |
| 523 | for {set i 2} {$i<$nn} {incr i} { |
| 524 | set arg [lindex $::fossilcmd $i] |
| 525 | if {[regexp {^--?(c|context)$} $arg] && $i+1<$nn} { |
| 526 | set n [lindex $::fossilcmd [incr i]] |
| 527 | } elseif {[regexp {^--?(?:c|context)=(.*)$} $arg all val]} { |
| 528 | set n $val |
| 529 | } |
| 530 | } |
| 531 | if {![string is integer -strict $n]} {return 6} |
| 532 | if {$n<0} {return All} |
| 533 | return $n |
| 534 | } |
| 535 | |
| 536 | # Invoked whenever the ncontext variable changes. Rewrite fossilcmd |
| 537 | # to use the new context setting and reload the diff, keeping the |
| 538 | # file that was showing at the top of the window in view. |
| 539 | # |
| 540 | proc changeContext {args} { |
| 541 | global fossilcmd ncontext |
| 542 | set cmd [lrange $fossilcmd 0 1] |
| 543 | set nn [llength $fossilcmd] |
| 544 | for {set i 2} {$i<$nn} {incr i} { |
| 545 | set arg [lindex $fossilcmd $i] |
| 546 | if {[regexp {^--?(c|context)$} $arg]} { |
| 547 | incr i |
| 548 | } elseif {![regexp {^--?(c|context)=} $arg]} { |
| 549 | lappend cmd $arg |
| 550 | } |
| 551 | } |
| 552 | if {$ncontext eq "All"} { |
| 553 | lappend cmd -c -1 |
| 554 | } else { |
| 555 | lappend cmd -c $ncontext |
| 556 | } |
| 557 | set fossilcmd $cmd |
| 558 | set range [.txtA tag prevrange fn {@0,0 +1c} 1.0] |
| 559 | set iFile 0 |
| 560 | if {$range ne ""} { |
| 561 | set iFile [expr {[lsearch -exact [.txtA tag ranges fn] \ |
| 562 | [lindex $range 0]]/2}] |
| 563 | } |
| 564 | unset -nocomplain ::difftxt |
| 565 | readDiffs 1 |
| 566 | update |
| 567 | set idx [lindex [.txtA tag ranges fn] [expr {$iFile*2}]] |
| 568 | if {$idx eq ""} {set idx 1.0} |
| 569 | viewDiff $idx |
| 570 | } |
| 571 | |
| 572 | label .bb.ctxtag -text "Context:" |
| 573 | set context_choices {3 6 12 25 50 100 All} |
| 574 | if {$fossilcmd ne ""} { |
| 575 | set ncontext [initContext] |
| 576 | if {[lsearch -exact $context_choices $ncontext]<0} { |
| 577 | set context_choices [lsort -integer \ |
| 578 | [concat [lrange $context_choices 0 end-1] $ncontext]] |
| 579 | lappend context_choices All |
| 580 | } |
| 581 | trace add variable ncontext write changeContext |
| 582 | } |
| 583 | if {$tcl_platform(os)=="Darwin"} { |
| 584 | tk_optionMenu .bb.ctx ncontext {*}$context_choices |
| 585 | } else { |
| 586 | ::ttk::menubutton .bb.ctx -text [expr {[info exists ncontext]?$ncontext:""}] |
| 587 | if {[tk windowingsystem] eq "win32"} { |
| 588 | .bb.ctx configure -padding {20 1 10 2} |
| 589 | } |
| 590 | toplevel .wctx |
| 591 | wm withdraw .wctx |
| 592 | update idletasks |
| 593 | wm transient .wctx . |
| 594 | wm overrideredirect .wctx 1 |
| 595 | listbox .wctx.lb -width 0 -height [llength $context_choices] \ |
| 596 | -activestyle none |
| 597 | .wctx.lb insert end {*}$context_choices |
| 598 | pack .wctx.lb |
| 599 | bind .bb.ctx <1> { |
| 600 | set x [winfo rootx %W] |
| 601 | set y [expr {[winfo rooty %W]+[winfo height %W]}] |
| 602 | wm geometry .wctx +$x+$y |
| 603 | wm deiconify .wctx |
| 604 | focus .wctx.lb |
| 605 | } |
| 606 | bind .wctx <FocusOut> {wm withdraw .wctx} |
| 607 | bind .wctx <Escape> {focus .} |
| 608 | foreach evt {1 Return} { |
| 609 | bind .wctx.lb <$evt> { |
| 610 | set ::ncontext [lindex $::context_choices [%W curselection]] |
| 611 | .bb.ctx config -text $::ncontext |
| 612 | focus . |
| 613 | break |
| 614 | } |
| 615 | } |
| 616 | bind .wctx.lb <Motion> { |
| 617 | %W selection clear 0 end |
| 618 | %W selection set @%x,%y |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | foreach {side syncCol} {A .txtB B .txtA} { |
| 623 | set ln .ln$side |
| 624 | text $ln |
| 625 | $ln tag config - -justify right |
| @@ -676,11 +782,15 @@ | |
| 782 | if {$fossilcmd ne ""} { |
| 783 | pack .bb.reload -side left |
| 784 | } |
| 785 | pack .bb.invert -side left |
| 786 | if {$fossilcmd!=""} {pack .bb.save -side left} |
| 787 | pack .bb.files -side left |
| 788 | if {$fossilcmd ne ""} { |
| 789 | pack .bb.ctxtag .bb.ctx -side left |
| 790 | } |
| 791 | pack .bb.search -side left |
| 792 | grid rowconfigure . 1 -weight 1 |
| 793 | grid columnconfigure . 1 -weight 1 |
| 794 | grid columnconfigure . 4 -weight 1 |
| 795 | grid .bb -row 0 -columnspan 6 |
| 796 | eval grid [cols] -row 1 -sticky nsew |
| 797 |