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.

joel 2013-07-11 00:37 UTC sbsreloaded
Commit 90fa060178f4ca280ee6443dde02c2778010338f
1 file changed +29 -20
+29 -20
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -645,33 +645,29 @@
645645
@ return $type
646646
@ }
647647
@
648648
@ proc readDiffs {cmd} {
649649
@ set in [open $cmd r]
650
-@ set idx -1
650
+@ set nDiffs 0
651651
@ array set widths {txt 0 ln 0 mkr 0}
652652
@ while {[gets $in line] != -1} {
653653
@ if {![regexp {^=+\s+(.*?)\s+=+$} $line all fn]} {
654654
@ continue
655655
@ }
656
-@
657656
@ if {[string compare -length 6 [gets $in] "<table"]} {
658657
@ continue
659658
@ }
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"
664662
@
665663
@ foreach c [cols] {
666664
@ while {[gets $in] ne "<pre>"} continue
667665
@
668
-@ if {$idx > 0} {
666
+@ if {$nDiffs > 1} {
669667
@ $c insert end \n -
670668
@ }
671
-@ $c mark set diff$idx {end -1c}
672
-@ $c mark gravity diff$idx left
673669
@ if {[colType $c] eq "txt"} {
674670
@ $c insert end $fn\n fn
675671
@ } else {
676672
@ $c insert end \n fn
677673
@ }
@@ -711,26 +707,40 @@
711707
@ }
712708
@ close $in
713709
@
714710
@ foreach c [cols] {
715711
@ 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)}]
717713
@ } else {
718714
@ $c config -width $widths([colType $c])
719715
@ }
720716
@ $c config -state disabled
721717
@ }
718
+@ return $nDiffs
722719
@ }
723720
@
724721
@ 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
727724
@ }
728725
@
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
+@ }
732742
@ }
733743
@
734744
@ proc scrollSync {axis sbs first last} {
735745
@ foreach c [cols] {
736746
@ $c ${axis}view moveto $first
@@ -755,11 +765,11 @@
755765
@ wm withdraw .
756766
@ wm title . $CFG(TITLE)
757767
@ wm iconname . $CFG(TITLE)
758768
@ bind . <q> exit
759769
@ bind . <Tab> {cycleDiffs; break}
760
-@ bind . <<PrevWindow>> {cycleDiffs -1; break}
770
+@ bind . <<PrevWindow>> {cycleDiffs 1; break}
761771
@ bind . <Return> {
762772
@ event generate .files <1>
763773
@ event generate .files <ButtonRelease-1>
764774
@ break
765775
@ }
@@ -775,11 +785,11 @@
775785
@ } {
776786
@ bind . <$key> ".txtA ${axis}view $args; break"
777787
@ bind . <Shift-$key> continue
778788
@ }
779789
@
780
-@ ::ttk::menubutton .files -menu .files.menu
790
+@ ::ttk::menubutton .files -menu .files.menu -text "Files"
781791
@ menu .files.menu -tearoff 0
782792
@
783793
@ foreach side {A B} {
784794
@ set ln .ln$side
785795
@ text $ln
@@ -819,12 +829,12 @@
819829
@
820830
@ ::ttk::scrollbar .sby -command {.txtA yview} -orient vertical
821831
@ ::ttk::scrollbar .sbxA -command {.txtA xview} -orient horizontal
822832
@ ::ttk::scrollbar .sbxB -command {.txtA xview} -orient horizontal
823833
@
824
-@ readDiffs $cmd
825
-@ if {[.files.menu index 0] eq "none"} {
834
+@
835
+@ if {[readDiffs $cmd] == 0} {
826836
@ tk_messageBox -type ok -title $CFG(TITLE) -message "No changes"
827837
@ exit
828838
@ }
829839
@
830840
@ grid rowconfigure . 1 -weight 1
@@ -833,11 +843,10 @@
833843
@ grid .files -columnspan 6
834844
@ eval grid [cols] .sby -sticky nsew
835845
@ grid .sbxA -row 2 -column 0 -columnspan 2 -sticky ew
836846
@ grid .sbxB -row 2 -column 3 -columnspan 2 -sticky ew
837847
@
838
-@ .files.menu invoke 0
839848
@ wm deiconify .
840849
;
841850
842851
/*
843852
** Show diff output in a Tcl/Tk window, in response to the --tk option
844853
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button