Fossil SCM

Combine all diffs into a single display in Tk diff.

joel 2013-07-10 18:06 UTC sbsreloaded
Commit 0a41e2b3dc24ebee8ac1ad45e833e61c8e248b2b
1 file changed +36 -35
+36 -35
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -614,10 +614,13 @@
614614
@ ADD_BG #c0ffc0
615615
@ RM_BG #ffc0c0
616616
@ HR_FG #888888
617617
@ HR_PAD_TOP 4
618618
@ HR_PAD_BTM 8
619
+@ FN_BG #444444
620
+@ FN_FG #ffffff
621
+@ FN_PAD 5
619622
@ FONTS {{DejaVu Sans Mono} Consolas Monaco fixed}
620623
@ FONT_SIZE 9
621624
@ PADX 5
622625
@ WIDTH 81
623626
@ HEIGHT 45
@@ -641,13 +644,13 @@
641644
@ regexp {[a-z]+} $c type
642645
@ return $type
643646
@ }
644647
@
645648
@ proc readDiffs {cmd} {
646
-@ global gDiffs
647649
@ set in [open $cmd r]
648650
@ set idx -1
651
+@ array set widths {txt 0 ln 0 mkr 0}
649652
@ while {[gets $in line] != -1} {
650653
@ if {![regexp {^=+\s+(.*?)\s+=+$} $line all fn]} {
651654
@ continue
652655
@ }
653656
@
@@ -656,14 +659,26 @@
656659
@ }
657660
@
658661
@ incr idx
659662
@ .files.menu add radiobutton -variable gIdx -value $idx -label $fn \
660663
@ -command "viewDiff $idx"
661
-@ array set widths {txt 0 ln 0 mkr 0}
662664
@
663665
@ foreach c [cols] {
664666
@ 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
+@ }
678
+@ $c insert end \n -
679
+@
665680
@ set type [colType $c]
666681
@ # A tab character is appended to each line in a txt column. This,
667682
@ # along with the -tabs text widget option, allows us to equalize line
668683
@ # lengths in order to:
669684
@ # (a) scroll to the same horizontal position on both sides and
@@ -679,54 +694,36 @@
679694
@ set widths($type) $len
680695
@ }
681696
@ append str $line$tab\n
682697
@ }
683698
@
684
-@ set str [string range $str 0 end-1]
685
-@ set colData {}
686699
@ set re {<span class="diff([a-z]+)">([^<]*)</span>}
687700
@ # Use \r as separator since it can't appear in the diff output (it gets
688701
@ # converted to a space).
689702
@ set str [regsub -all $re $str "\r\\1\r\\2\r"]
690703
@ foreach {pre class mid} [split $str \r] {
691704
@ if {$class ne ""} {
692
-@ lappend colData [dehtml $pre] - [dehtml $mid] [list $class -]
705
+@ $c insert end [dehtml $pre] - [dehtml $mid] [list $class -]
693706
@ } else {
694
-@ lappend colData [dehtml $pre] -
707
+@ $c insert end [dehtml $pre] -
695708
@ }
696709
@ }
697
-@ set gDiffs($idx,$c) $colData
698
-@ }
699
-@
700
-@ foreach {type width} [array get widths] {
701
-@ set gDiffs($idx,$type-width) $width
702710
@ }
703711
@ }
704712
@ close $in
713
+@
714
+@ foreach c {.lnA .mkr .lnB} {
715
+@ $c config -width $widths([colType $c])
716
+@ }
717
+@ foreach c {.txtA .txtB} {
718
+@ $c config -tabs [expr {[font measure mono 0]*($widths(txt)+1)}]
719
+@ }
705720
@ }
706721
@
707722
@ proc viewDiff {idx} {
708
-@ global gDiffs
709723
@ .files config -text [.files.menu entrycget $idx -label]
710
-@
711
-@ foreach c [cols] {
712
-@ $c config -state normal
713
-@ $c delete 1.0 end
714
-@ foreach {content tag} $gDiffs($idx,$c) {
715
-@ $c insert end $content $tag
716
-@ }
717
-@ $c config -state disabled
718
-@ }
719
-@
720
-@ foreach c {.lnA .lnB .mkr} {
721
-@ $c config -width $gDiffs($idx,[colType $c]-width)
722
-@ }
723
-@
724
-@ set width $gDiffs($idx,txt-width)
725
-@ foreach c {.txtA .txtB} {
726
-@ $c config -tabs [expr {[font measure mono 0]*($width+1)}]
727
-@ }
724
+@ .txtA yview diff$idx
728725
@ }
729726
@
730727
@ proc cycleDiffs {{inc 1}} {
731728
@ global gIdx
732729
@ .files.menu invoke [expr {($gIdx+$inc) % ([.files.menu index last]+1)}]
@@ -778,15 +775,10 @@
778775
@ bind . <Shift-$key> continue
779776
@ }
780777
@
781778
@ ::ttk::menubutton .files -menu .files.menu
782779
@ menu .files.menu -tearoff 0
783
-@ readDiffs $cmd
784
-@ if {[.files.menu index 0] eq "none"} {
785
-@ tk_messageBox -type ok -title $CFG(TITLE) -message "No changes"
786
-@ exit
787
-@ }
788780
@
789781
@ foreach side {A B} {
790782
@ set ln .ln$side
791783
@ text $ln
792784
@ $ln tag config - -justify right
@@ -796,10 +788,12 @@
796788
@ -xscroll {scrollSync x {.sbxA .sbxB}}
797789
@ foreach tag {add rm chng} {
798790
@ $txt tag config $tag -background $CFG([string toupper $tag]_BG)
799791
@ $txt tag lower $tag
800792
@ }
793
+@ $txt tag config fn -background $CFG(FN_BG) -foreground $CFG(FN_FG) \
794
+@ -justify center
801795
@ bind $txt <<Copy>> {copyText %W; break}
802796
@ bind $txt <<Cut>> {copyText %W; break}
803797
@ }
804798
@ text .mkr
805799
@
@@ -814,17 +808,24 @@
814808
@ set keyPrefix [string toupper [colType $c]]_COL_
815809
@ $c config -bg $CFG(${keyPrefix}BG) -fg $CFG(${keyPrefix}FG) -borderwidth 0 \
816810
@ -font mono -padx $CFG(PADX) -insertontime 0 -yscroll {scrollSync y .sby}
817811
@ $c tag config hr -spacing1 $CFG(HR_PAD_TOP) -spacing3 $CFG(HR_PAD_BTM) \
818812
@ -foreground $CFG(HR_FG)
813
+@ $c tag config fn -spacing1 $CFG(FN_PAD) -spacing3 $CFG(FN_PAD)
819814
@ bindtags $c ". $c Text all"
820815
@ bind $c <1> {focus %W}
821816
@ }
822817
@
823818
@ ::ttk::scrollbar .sby -command {.txtA yview} -orient vertical
824819
@ ::ttk::scrollbar .sbxA -command {.txtA xview} -orient horizontal
825820
@ ::ttk::scrollbar .sbxB -command {.txtA xview} -orient horizontal
821
+@
822
+@ readDiffs $cmd
823
+@ if {[.files.menu index 0] eq "none"} {
824
+@ tk_messageBox -type ok -title $CFG(TITLE) -message "No changes"
825
+@ exit
826
+@ }
826827
@
827828
@ grid rowconfigure . 1 -weight 1
828829
@ grid columnconfigure . 1 -weight 1
829830
@ grid columnconfigure . 4 -weight 1
830831
@ grid .files -columnspan 6
831832
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -614,10 +614,13 @@
614 @ ADD_BG #c0ffc0
615 @ RM_BG #ffc0c0
616 @ HR_FG #888888
617 @ HR_PAD_TOP 4
618 @ HR_PAD_BTM 8
 
 
 
619 @ FONTS {{DejaVu Sans Mono} Consolas Monaco fixed}
620 @ FONT_SIZE 9
621 @ PADX 5
622 @ WIDTH 81
623 @ HEIGHT 45
@@ -641,13 +644,13 @@
641 @ regexp {[a-z]+} $c type
642 @ return $type
643 @ }
644 @
645 @ proc readDiffs {cmd} {
646 @ global gDiffs
647 @ set in [open $cmd r]
648 @ set idx -1
 
649 @ while {[gets $in line] != -1} {
650 @ if {![regexp {^=+\s+(.*?)\s+=+$} $line all fn]} {
651 @ continue
652 @ }
653 @
@@ -656,14 +659,26 @@
656 @ }
657 @
658 @ incr idx
659 @ .files.menu add radiobutton -variable gIdx -value $idx -label $fn \
660 @ -command "viewDiff $idx"
661 @ array set widths {txt 0 ln 0 mkr 0}
662 @
663 @ foreach c [cols] {
664 @ while {[gets $in] ne "<pre>"} continue
 
 
 
 
 
 
 
 
 
 
 
 
 
665 @ set type [colType $c]
666 @ # A tab character is appended to each line in a txt column. This,
667 @ # along with the -tabs text widget option, allows us to equalize line
668 @ # lengths in order to:
669 @ # (a) scroll to the same horizontal position on both sides and
@@ -679,54 +694,36 @@
679 @ set widths($type) $len
680 @ }
681 @ append str $line$tab\n
682 @ }
683 @
684 @ set str [string range $str 0 end-1]
685 @ set colData {}
686 @ set re {<span class="diff([a-z]+)">([^<]*)</span>}
687 @ # Use \r as separator since it can't appear in the diff output (it gets
688 @ # converted to a space).
689 @ set str [regsub -all $re $str "\r\\1\r\\2\r"]
690 @ foreach {pre class mid} [split $str \r] {
691 @ if {$class ne ""} {
692 @ lappend colData [dehtml $pre] - [dehtml $mid] [list $class -]
693 @ } else {
694 @ lappend colData [dehtml $pre] -
695 @ }
696 @ }
697 @ set gDiffs($idx,$c) $colData
698 @ }
699 @
700 @ foreach {type width} [array get widths] {
701 @ set gDiffs($idx,$type-width) $width
702 @ }
703 @ }
704 @ close $in
 
 
 
 
 
 
 
705 @ }
706 @
707 @ proc viewDiff {idx} {
708 @ global gDiffs
709 @ .files config -text [.files.menu entrycget $idx -label]
710 @
711 @ foreach c [cols] {
712 @ $c config -state normal
713 @ $c delete 1.0 end
714 @ foreach {content tag} $gDiffs($idx,$c) {
715 @ $c insert end $content $tag
716 @ }
717 @ $c config -state disabled
718 @ }
719 @
720 @ foreach c {.lnA .lnB .mkr} {
721 @ $c config -width $gDiffs($idx,[colType $c]-width)
722 @ }
723 @
724 @ set width $gDiffs($idx,txt-width)
725 @ foreach c {.txtA .txtB} {
726 @ $c config -tabs [expr {[font measure mono 0]*($width+1)}]
727 @ }
728 @ }
729 @
730 @ proc cycleDiffs {{inc 1}} {
731 @ global gIdx
732 @ .files.menu invoke [expr {($gIdx+$inc) % ([.files.menu index last]+1)}]
@@ -778,15 +775,10 @@
778 @ bind . <Shift-$key> continue
779 @ }
780 @
781 @ ::ttk::menubutton .files -menu .files.menu
782 @ menu .files.menu -tearoff 0
783 @ readDiffs $cmd
784 @ if {[.files.menu index 0] eq "none"} {
785 @ tk_messageBox -type ok -title $CFG(TITLE) -message "No changes"
786 @ exit
787 @ }
788 @
789 @ foreach side {A B} {
790 @ set ln .ln$side
791 @ text $ln
792 @ $ln tag config - -justify right
@@ -796,10 +788,12 @@
796 @ -xscroll {scrollSync x {.sbxA .sbxB}}
797 @ foreach tag {add rm chng} {
798 @ $txt tag config $tag -background $CFG([string toupper $tag]_BG)
799 @ $txt tag lower $tag
800 @ }
 
 
801 @ bind $txt <<Copy>> {copyText %W; break}
802 @ bind $txt <<Cut>> {copyText %W; break}
803 @ }
804 @ text .mkr
805 @
@@ -814,17 +808,24 @@
814 @ set keyPrefix [string toupper [colType $c]]_COL_
815 @ $c config -bg $CFG(${keyPrefix}BG) -fg $CFG(${keyPrefix}FG) -borderwidth 0 \
816 @ -font mono -padx $CFG(PADX) -insertontime 0 -yscroll {scrollSync y .sby}
817 @ $c tag config hr -spacing1 $CFG(HR_PAD_TOP) -spacing3 $CFG(HR_PAD_BTM) \
818 @ -foreground $CFG(HR_FG)
 
819 @ bindtags $c ". $c Text all"
820 @ bind $c <1> {focus %W}
821 @ }
822 @
823 @ ::ttk::scrollbar .sby -command {.txtA yview} -orient vertical
824 @ ::ttk::scrollbar .sbxA -command {.txtA xview} -orient horizontal
825 @ ::ttk::scrollbar .sbxB -command {.txtA xview} -orient horizontal
 
 
 
 
 
 
826 @
827 @ grid rowconfigure . 1 -weight 1
828 @ grid columnconfigure . 1 -weight 1
829 @ grid columnconfigure . 4 -weight 1
830 @ grid .files -columnspan 6
831
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -614,10 +614,13 @@
614 @ ADD_BG #c0ffc0
615 @ RM_BG #ffc0c0
616 @ HR_FG #888888
617 @ HR_PAD_TOP 4
618 @ HR_PAD_BTM 8
619 @ FN_BG #444444
620 @ FN_FG #ffffff
621 @ FN_PAD 5
622 @ FONTS {{DejaVu Sans Mono} Consolas Monaco fixed}
623 @ FONT_SIZE 9
624 @ PADX 5
625 @ WIDTH 81
626 @ HEIGHT 45
@@ -641,13 +644,13 @@
644 @ regexp {[a-z]+} $c type
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 @
@@ -656,14 +659,26 @@
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 @ }
678 @ $c insert end \n -
679 @
680 @ set type [colType $c]
681 @ # A tab character is appended to each line in a txt column. This,
682 @ # along with the -tabs text widget option, allows us to equalize line
683 @ # lengths in order to:
684 @ # (a) scroll to the same horizontal position on both sides and
@@ -679,54 +694,36 @@
694 @ set widths($type) $len
695 @ }
696 @ append str $line$tab\n
697 @ }
698 @
 
 
699 @ set re {<span class="diff([a-z]+)">([^<]*)</span>}
700 @ # Use \r as separator since it can't appear in the diff output (it gets
701 @ # converted to a space).
702 @ set str [regsub -all $re $str "\r\\1\r\\2\r"]
703 @ foreach {pre class mid} [split $str \r] {
704 @ if {$class ne ""} {
705 @ $c insert end [dehtml $pre] - [dehtml $mid] [list $class -]
706 @ } else {
707 @ $c insert end [dehtml $pre] -
708 @ }
709 @ }
 
 
 
 
 
710 @ }
711 @ }
712 @ close $in
713 @
714 @ foreach c {.lnA .mkr .lnB} {
715 @ $c config -width $widths([colType $c])
716 @ }
717 @ foreach c {.txtA .txtB} {
718 @ $c config -tabs [expr {[font measure mono 0]*($widths(txt)+1)}]
719 @ }
720 @ }
721 @
722 @ proc viewDiff {idx} {
 
723 @ .files config -text [.files.menu entrycget $idx -label]
724 @ .txtA yview diff$idx
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
725 @ }
726 @
727 @ proc cycleDiffs {{inc 1}} {
728 @ global gIdx
729 @ .files.menu invoke [expr {($gIdx+$inc) % ([.files.menu index last]+1)}]
@@ -778,15 +775,10 @@
775 @ bind . <Shift-$key> continue
776 @ }
777 @
778 @ ::ttk::menubutton .files -menu .files.menu
779 @ menu .files.menu -tearoff 0
 
 
 
 
 
780 @
781 @ foreach side {A B} {
782 @ set ln .ln$side
783 @ text $ln
784 @ $ln tag config - -justify right
@@ -796,10 +788,12 @@
788 @ -xscroll {scrollSync x {.sbxA .sbxB}}
789 @ foreach tag {add rm chng} {
790 @ $txt tag config $tag -background $CFG([string toupper $tag]_BG)
791 @ $txt tag lower $tag
792 @ }
793 @ $txt tag config fn -background $CFG(FN_BG) -foreground $CFG(FN_FG) \
794 @ -justify center
795 @ bind $txt <<Copy>> {copyText %W; break}
796 @ bind $txt <<Cut>> {copyText %W; break}
797 @ }
798 @ text .mkr
799 @
@@ -814,17 +808,24 @@
808 @ set keyPrefix [string toupper [colType $c]]_COL_
809 @ $c config -bg $CFG(${keyPrefix}BG) -fg $CFG(${keyPrefix}FG) -borderwidth 0 \
810 @ -font mono -padx $CFG(PADX) -insertontime 0 -yscroll {scrollSync y .sby}
811 @ $c tag config hr -spacing1 $CFG(HR_PAD_TOP) -spacing3 $CFG(HR_PAD_BTM) \
812 @ -foreground $CFG(HR_FG)
813 @ $c tag config fn -spacing1 $CFG(FN_PAD) -spacing3 $CFG(FN_PAD)
814 @ bindtags $c ". $c Text all"
815 @ bind $c <1> {focus %W}
816 @ }
817 @
818 @ ::ttk::scrollbar .sby -command {.txtA yview} -orient vertical
819 @ ::ttk::scrollbar .sbxA -command {.txtA xview} -orient horizontal
820 @ ::ttk::scrollbar .sbxB -command {.txtA xview} -orient horizontal
821 @
822 @ readDiffs $cmd
823 @ if {[.files.menu index 0] eq "none"} {
824 @ tk_messageBox -type ok -title $CFG(TITLE) -message "No changes"
825 @ exit
826 @ }
827 @
828 @ grid rowconfigure . 1 -weight 1
829 @ grid columnconfigure . 1 -weight 1
830 @ grid columnconfigure . 4 -weight 1
831 @ grid .files -columnspan 6
832

Keyboard Shortcuts

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