Fossil SCM
Tk diff: Cycle through diffs based on current location rather than the last one you selected in the menu. Menu button now has generic "Files" label.
Commit
90fa060178f4ca280ee6443dde02c2778010338f
Parent
302ab3a4e81ec12…
1 file changed
+29
-20
+29
-20
| --- src/diffcmd.c | ||
| +++ src/diffcmd.c | ||
| @@ -645,33 +645,29 @@ | ||
| 645 | 645 | @ return $type |
| 646 | 646 | @ } |
| 647 | 647 | @ |
| 648 | 648 | @ proc readDiffs {cmd} { |
| 649 | 649 | @ set in [open $cmd r] |
| 650 | -@ set idx -1 | |
| 650 | +@ set nDiffs 0 | |
| 651 | 651 | @ array set widths {txt 0 ln 0 mkr 0} |
| 652 | 652 | @ while {[gets $in line] != -1} { |
| 653 | 653 | @ if {![regexp {^=+\s+(.*?)\s+=+$} $line all fn]} { |
| 654 | 654 | @ continue |
| 655 | 655 | @ } |
| 656 | -@ | |
| 657 | 656 | @ if {[string compare -length 6 [gets $in] "<table"]} { |
| 658 | 657 | @ continue |
| 659 | 658 | @ } |
| 660 | -@ | |
| 661 | -@ incr idx | |
| 662 | -@ .files.menu add radiobutton -variable gIdx -value $idx -label $fn \ | |
| 663 | -@ -command "viewDiff $idx" | |
| 659 | +@ incr nDiffs | |
| 660 | +@ set idx [expr {$nDiffs > 1 ? [.txtA index end] : "1.0"}] | |
| 661 | +@ .files.menu add command -label $fn -command "viewDiff $idx" | |
| 664 | 662 | @ |
| 665 | 663 | @ foreach c [cols] { |
| 666 | 664 | @ while {[gets $in] ne "<pre>"} continue |
| 667 | 665 | @ |
| 668 | -@ if {$idx > 0} { | |
| 666 | +@ if {$nDiffs > 1} { | |
| 669 | 667 | @ $c insert end \n - |
| 670 | 668 | @ } |
| 671 | -@ $c mark set diff$idx {end -1c} | |
| 672 | -@ $c mark gravity diff$idx left | |
| 673 | 669 | @ if {[colType $c] eq "txt"} { |
| 674 | 670 | @ $c insert end $fn\n fn |
| 675 | 671 | @ } else { |
| 676 | 672 | @ $c insert end \n fn |
| 677 | 673 | @ } |
| @@ -711,26 +707,40 @@ | ||
| 711 | 707 | @ } |
| 712 | 708 | @ close $in |
| 713 | 709 | @ |
| 714 | 710 | @ foreach c [cols] { |
| 715 | 711 | @ if {[colType $c] eq "txt"} { |
| 716 | -@ $c config -tabs [expr {[font measure mono 0]*($widths(txt)+1)}] | |
| 712 | +@ $c config -tabs [expr {[font measure mono 0]*($widths(txt)+1)}] | |
| 717 | 713 | @ } else { |
| 718 | 714 | @ $c config -width $widths([colType $c]) |
| 719 | 715 | @ } |
| 720 | 716 | @ $c config -state disabled |
| 721 | 717 | @ } |
| 718 | +@ return $nDiffs | |
| 722 | 719 | @ } |
| 723 | 720 | @ |
| 724 | 721 | @ proc viewDiff {idx} { |
| 725 | -@ .files config -text [.files.menu entrycget $idx -label] | |
| 726 | -@ .txtA yview diff$idx | |
| 722 | +@ .txtA yview $idx | |
| 723 | +@ .txtA xview moveto 0 | |
| 727 | 724 | @ } |
| 728 | 725 | @ |
| 729 | -@ proc cycleDiffs {{inc 1}} { | |
| 730 | -@ global gIdx | |
| 731 | -@ .files.menu invoke [expr {($gIdx+$inc) % ([.files.menu index last]+1)}] | |
| 726 | +@ proc cycleDiffs {{reverse 0}} { | |
| 727 | +@ if {$reverse} { | |
| 728 | +@ set range [.txtA tag prevrange fn @0,0 1.0] | |
| 729 | +@ if {$range eq ""} { | |
| 730 | +@ viewDiff {fn.last -1c} | |
| 731 | +@ } else { | |
| 732 | +@ viewDiff [lindex $range 0] | |
| 733 | +@ } | |
| 734 | +@ } else { | |
| 735 | +@ set range [.txtA tag nextrange fn {@0,0 +1c} end] | |
| 736 | +@ if {$range eq "" || [lindex [.txtA yview] 1] == 1} { | |
| 737 | +@ viewDiff fn.first | |
| 738 | +@ } else { | |
| 739 | +@ viewDiff [lindex $range 0] | |
| 740 | +@ } | |
| 741 | +@ } | |
| 732 | 742 | @ } |
| 733 | 743 | @ |
| 734 | 744 | @ proc scrollSync {axis sbs first last} { |
| 735 | 745 | @ foreach c [cols] { |
| 736 | 746 | @ $c ${axis}view moveto $first |
| @@ -755,11 +765,11 @@ | ||
| 755 | 765 | @ wm withdraw . |
| 756 | 766 | @ wm title . $CFG(TITLE) |
| 757 | 767 | @ wm iconname . $CFG(TITLE) |
| 758 | 768 | @ bind . <q> exit |
| 759 | 769 | @ bind . <Tab> {cycleDiffs; break} |
| 760 | -@ bind . <<PrevWindow>> {cycleDiffs -1; break} | |
| 770 | +@ bind . <<PrevWindow>> {cycleDiffs 1; break} | |
| 761 | 771 | @ bind . <Return> { |
| 762 | 772 | @ event generate .files <1> |
| 763 | 773 | @ event generate .files <ButtonRelease-1> |
| 764 | 774 | @ break |
| 765 | 775 | @ } |
| @@ -775,11 +785,11 @@ | ||
| 775 | 785 | @ } { |
| 776 | 786 | @ bind . <$key> ".txtA ${axis}view $args; break" |
| 777 | 787 | @ bind . <Shift-$key> continue |
| 778 | 788 | @ } |
| 779 | 789 | @ |
| 780 | -@ ::ttk::menubutton .files -menu .files.menu | |
| 790 | +@ ::ttk::menubutton .files -menu .files.menu -text "Files" | |
| 781 | 791 | @ menu .files.menu -tearoff 0 |
| 782 | 792 | @ |
| 783 | 793 | @ foreach side {A B} { |
| 784 | 794 | @ set ln .ln$side |
| 785 | 795 | @ text $ln |
| @@ -819,12 +829,12 @@ | ||
| 819 | 829 | @ |
| 820 | 830 | @ ::ttk::scrollbar .sby -command {.txtA yview} -orient vertical |
| 821 | 831 | @ ::ttk::scrollbar .sbxA -command {.txtA xview} -orient horizontal |
| 822 | 832 | @ ::ttk::scrollbar .sbxB -command {.txtA xview} -orient horizontal |
| 823 | 833 | @ |
| 824 | -@ readDiffs $cmd | |
| 825 | -@ if {[.files.menu index 0] eq "none"} { | |
| 834 | +@ | |
| 835 | +@ if {[readDiffs $cmd] == 0} { | |
| 826 | 836 | @ tk_messageBox -type ok -title $CFG(TITLE) -message "No changes" |
| 827 | 837 | @ exit |
| 828 | 838 | @ } |
| 829 | 839 | @ |
| 830 | 840 | @ grid rowconfigure . 1 -weight 1 |
| @@ -833,11 +843,10 @@ | ||
| 833 | 843 | @ grid .files -columnspan 6 |
| 834 | 844 | @ eval grid [cols] .sby -sticky nsew |
| 835 | 845 | @ grid .sbxA -row 2 -column 0 -columnspan 2 -sticky ew |
| 836 | 846 | @ grid .sbxB -row 2 -column 3 -columnspan 2 -sticky ew |
| 837 | 847 | @ |
| 838 | -@ .files.menu invoke 0 | |
| 839 | 848 | @ wm deiconify . |
| 840 | 849 | ; |
| 841 | 850 | |
| 842 | 851 | /* |
| 843 | 852 | ** Show diff output in a Tcl/Tk window, in response to the --tk option |
| 844 | 853 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -645,33 +645,29 @@ | |
| 645 | @ return $type |
| 646 | @ } |
| 647 | @ |
| 648 | @ proc readDiffs {cmd} { |
| 649 | @ set in [open $cmd r] |
| 650 | @ set idx -1 |
| 651 | @ array set widths {txt 0 ln 0 mkr 0} |
| 652 | @ while {[gets $in line] != -1} { |
| 653 | @ if {![regexp {^=+\s+(.*?)\s+=+$} $line all fn]} { |
| 654 | @ continue |
| 655 | @ } |
| 656 | @ |
| 657 | @ if {[string compare -length 6 [gets $in] "<table"]} { |
| 658 | @ continue |
| 659 | @ } |
| 660 | @ |
| 661 | @ incr idx |
| 662 | @ .files.menu add radiobutton -variable gIdx -value $idx -label $fn \ |
| 663 | @ -command "viewDiff $idx" |
| 664 | @ |
| 665 | @ foreach c [cols] { |
| 666 | @ while {[gets $in] ne "<pre>"} continue |
| 667 | @ |
| 668 | @ if {$idx > 0} { |
| 669 | @ $c insert end \n - |
| 670 | @ } |
| 671 | @ $c mark set diff$idx {end -1c} |
| 672 | @ $c mark gravity diff$idx left |
| 673 | @ if {[colType $c] eq "txt"} { |
| 674 | @ $c insert end $fn\n fn |
| 675 | @ } else { |
| 676 | @ $c insert end \n fn |
| 677 | @ } |
| @@ -711,26 +707,40 @@ | |
| 711 | @ } |
| 712 | @ close $in |
| 713 | @ |
| 714 | @ foreach c [cols] { |
| 715 | @ if {[colType $c] eq "txt"} { |
| 716 | @ $c config -tabs [expr {[font measure mono 0]*($widths(txt)+1)}] |
| 717 | @ } else { |
| 718 | @ $c config -width $widths([colType $c]) |
| 719 | @ } |
| 720 | @ $c config -state disabled |
| 721 | @ } |
| 722 | @ } |
| 723 | @ |
| 724 | @ proc viewDiff {idx} { |
| 725 | @ .files config -text [.files.menu entrycget $idx -label] |
| 726 | @ .txtA yview diff$idx |
| 727 | @ } |
| 728 | @ |
| 729 | @ proc cycleDiffs {{inc 1}} { |
| 730 | @ global gIdx |
| 731 | @ .files.menu invoke [expr {($gIdx+$inc) % ([.files.menu index last]+1)}] |
| 732 | @ } |
| 733 | @ |
| 734 | @ proc scrollSync {axis sbs first last} { |
| 735 | @ foreach c [cols] { |
| 736 | @ $c ${axis}view moveto $first |
| @@ -755,11 +765,11 @@ | |
| 755 | @ wm withdraw . |
| 756 | @ wm title . $CFG(TITLE) |
| 757 | @ wm iconname . $CFG(TITLE) |
| 758 | @ bind . <q> exit |
| 759 | @ bind . <Tab> {cycleDiffs; break} |
| 760 | @ bind . <<PrevWindow>> {cycleDiffs -1; break} |
| 761 | @ bind . <Return> { |
| 762 | @ event generate .files <1> |
| 763 | @ event generate .files <ButtonRelease-1> |
| 764 | @ break |
| 765 | @ } |
| @@ -775,11 +785,11 @@ | |
| 775 | @ } { |
| 776 | @ bind . <$key> ".txtA ${axis}view $args; break" |
| 777 | @ bind . <Shift-$key> continue |
| 778 | @ } |
| 779 | @ |
| 780 | @ ::ttk::menubutton .files -menu .files.menu |
| 781 | @ menu .files.menu -tearoff 0 |
| 782 | @ |
| 783 | @ foreach side {A B} { |
| 784 | @ set ln .ln$side |
| 785 | @ text $ln |
| @@ -819,12 +829,12 @@ | |
| 819 | @ |
| 820 | @ ::ttk::scrollbar .sby -command {.txtA yview} -orient vertical |
| 821 | @ ::ttk::scrollbar .sbxA -command {.txtA xview} -orient horizontal |
| 822 | @ ::ttk::scrollbar .sbxB -command {.txtA xview} -orient horizontal |
| 823 | @ |
| 824 | @ readDiffs $cmd |
| 825 | @ if {[.files.menu index 0] eq "none"} { |
| 826 | @ tk_messageBox -type ok -title $CFG(TITLE) -message "No changes" |
| 827 | @ exit |
| 828 | @ } |
| 829 | @ |
| 830 | @ grid rowconfigure . 1 -weight 1 |
| @@ -833,11 +843,10 @@ | |
| 833 | @ grid .files -columnspan 6 |
| 834 | @ eval grid [cols] .sby -sticky nsew |
| 835 | @ grid .sbxA -row 2 -column 0 -columnspan 2 -sticky ew |
| 836 | @ grid .sbxB -row 2 -column 3 -columnspan 2 -sticky ew |
| 837 | @ |
| 838 | @ .files.menu invoke 0 |
| 839 | @ wm deiconify . |
| 840 | ; |
| 841 | |
| 842 | /* |
| 843 | ** Show diff output in a Tcl/Tk window, in response to the --tk option |
| 844 |
| --- src/diffcmd.c | |
| +++ src/diffcmd.c | |
| @@ -645,33 +645,29 @@ | |
| 645 | @ return $type |
| 646 | @ } |
| 647 | @ |
| 648 | @ proc readDiffs {cmd} { |
| 649 | @ set in [open $cmd r] |
| 650 | @ set nDiffs 0 |
| 651 | @ array set widths {txt 0 ln 0 mkr 0} |
| 652 | @ while {[gets $in line] != -1} { |
| 653 | @ if {![regexp {^=+\s+(.*?)\s+=+$} $line all fn]} { |
| 654 | @ continue |
| 655 | @ } |
| 656 | @ if {[string compare -length 6 [gets $in] "<table"]} { |
| 657 | @ continue |
| 658 | @ } |
| 659 | @ incr nDiffs |
| 660 | @ set idx [expr {$nDiffs > 1 ? [.txtA index end] : "1.0"}] |
| 661 | @ .files.menu add command -label $fn -command "viewDiff $idx" |
| 662 | @ |
| 663 | @ foreach c [cols] { |
| 664 | @ while {[gets $in] ne "<pre>"} continue |
| 665 | @ |
| 666 | @ if {$nDiffs > 1} { |
| 667 | @ $c insert end \n - |
| 668 | @ } |
| 669 | @ if {[colType $c] eq "txt"} { |
| 670 | @ $c insert end $fn\n fn |
| 671 | @ } else { |
| 672 | @ $c insert end \n fn |
| 673 | @ } |
| @@ -711,26 +707,40 @@ | |
| 707 | @ } |
| 708 | @ close $in |
| 709 | @ |
| 710 | @ foreach c [cols] { |
| 711 | @ if {[colType $c] eq "txt"} { |
| 712 | @ $c config -tabs [expr {[font measure mono 0]*($widths(txt)+1)}] |
| 713 | @ } else { |
| 714 | @ $c config -width $widths([colType $c]) |
| 715 | @ } |
| 716 | @ $c config -state disabled |
| 717 | @ } |
| 718 | @ return $nDiffs |
| 719 | @ } |
| 720 | @ |
| 721 | @ proc viewDiff {idx} { |
| 722 | @ .txtA yview $idx |
| 723 | @ .txtA xview moveto 0 |
| 724 | @ } |
| 725 | @ |
| 726 | @ proc cycleDiffs {{reverse 0}} { |
| 727 | @ if {$reverse} { |
| 728 | @ set range [.txtA tag prevrange fn @0,0 1.0] |
| 729 | @ if {$range eq ""} { |
| 730 | @ viewDiff {fn.last -1c} |
| 731 | @ } else { |
| 732 | @ viewDiff [lindex $range 0] |
| 733 | @ } |
| 734 | @ } else { |
| 735 | @ set range [.txtA tag nextrange fn {@0,0 +1c} end] |
| 736 | @ if {$range eq "" || [lindex [.txtA yview] 1] == 1} { |
| 737 | @ viewDiff fn.first |
| 738 | @ } else { |
| 739 | @ viewDiff [lindex $range 0] |
| 740 | @ } |
| 741 | @ } |
| 742 | @ } |
| 743 | @ |
| 744 | @ proc scrollSync {axis sbs first last} { |
| 745 | @ foreach c [cols] { |
| 746 | @ $c ${axis}view moveto $first |
| @@ -755,11 +765,11 @@ | |
| 765 | @ wm withdraw . |
| 766 | @ wm title . $CFG(TITLE) |
| 767 | @ wm iconname . $CFG(TITLE) |
| 768 | @ bind . <q> exit |
| 769 | @ bind . <Tab> {cycleDiffs; break} |
| 770 | @ bind . <<PrevWindow>> {cycleDiffs 1; break} |
| 771 | @ bind . <Return> { |
| 772 | @ event generate .files <1> |
| 773 | @ event generate .files <ButtonRelease-1> |
| 774 | @ break |
| 775 | @ } |
| @@ -775,11 +785,11 @@ | |
| 785 | @ } { |
| 786 | @ bind . <$key> ".txtA ${axis}view $args; break" |
| 787 | @ bind . <Shift-$key> continue |
| 788 | @ } |
| 789 | @ |
| 790 | @ ::ttk::menubutton .files -menu .files.menu -text "Files" |
| 791 | @ menu .files.menu -tearoff 0 |
| 792 | @ |
| 793 | @ foreach side {A B} { |
| 794 | @ set ln .ln$side |
| 795 | @ text $ln |
| @@ -819,12 +829,12 @@ | |
| 829 | @ |
| 830 | @ ::ttk::scrollbar .sby -command {.txtA yview} -orient vertical |
| 831 | @ ::ttk::scrollbar .sbxA -command {.txtA xview} -orient horizontal |
| 832 | @ ::ttk::scrollbar .sbxB -command {.txtA xview} -orient horizontal |
| 833 | @ |
| 834 | @ |
| 835 | @ if {[readDiffs $cmd] == 0} { |
| 836 | @ tk_messageBox -type ok -title $CFG(TITLE) -message "No changes" |
| 837 | @ exit |
| 838 | @ } |
| 839 | @ |
| 840 | @ grid rowconfigure . 1 -weight 1 |
| @@ -833,11 +843,10 @@ | |
| 843 | @ grid .files -columnspan 6 |
| 844 | @ eval grid [cols] .sby -sticky nsew |
| 845 | @ grid .sbxA -row 2 -column 0 -columnspan 2 -sticky ew |
| 846 | @ grid .sbxB -row 2 -column 3 -columnspan 2 -sticky ew |
| 847 | @ |
| 848 | @ wm deiconify . |
| 849 | ; |
| 850 | |
| 851 | /* |
| 852 | ** Show diff output in a Tcl/Tk window, in response to the --tk option |
| 853 |