︙ | | |
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
# This is not run until needed to speed up command line error reporting.
proc Init {} {
package require Tk 8.4
catch {package require textSearch}
package require wcb
package require snit
package require tablelist_tile
# Patch tablelist to add cellbodyindex subcommand
lappend ::tablelist::cmdOpts cellbodyindex
proc tablelist::cellbodyindexSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win cellbodyindex cellIndex"
}
synchronize $win
foreach {row col} [cellIndex $win [lindex $argList 0] 1] {}
findTabs $win [expr {$row + 1}] $col $col tabIdx1 tabIdx2
upvar ::tablelist::ns${win}::data data
set cIdx1 [$data(body) index "$tabIdx1 + 1 char"]
set cIdx2 [$data(body) index "$tabIdx2 - 1 char"]
return [list $cIdx1 $cIdx2]
}
if {[catch {package require psballoon}]} {
# Add a dummy if it does not exist.
proc addBalloon {args} {}
} else {
namespace import -force psballoon::addBalloon
}
|
︙ | | |
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
|
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
}
set ::tmpfiles {}
}
}
# Insert lineno and text
proc insertLine {top n line text {tag {equal}} {linetag {}}} {
if {$::eskil($top,view) eq "table"} {
set RE $::eskil($top,separator)
set words [split $text $RE]
set col 0
set id [$::widgets($top,wTable) insert end {}]
foreach w $words {
$::widgets($top,wTable) cellconfigure $id,$col -text $w
if {$tag ne "equal"} {
lassign [$::widgets($top,wTable) cellbodyindex $id,$col] \
cIdx1 cIdx2
set body [$::widgets($top,wTable) bodypath]
$body tag add new$n "$cIdx1" "$cIdx2 + 1 char"
}
incr col
}
return
}
$::widgets($top,wDiff$n) insert end "$text\n" $tag
if {$linetag ne ""} {
append tag " $linetag"
}
if {$tag != "equal"} {
set tag "hl$::HighLightCount $tag"
}
$::widgets($top,wLine$n) insert end [myFormL $line] $tag
}
# Insert an empty line on one side of the diff.
proc emptyLine {top n {highlight 1}} {
if {$::eskil($top,view) eq "table"} {
# This should be ignored for table
return
}
if {$highlight} {
$::widgets($top,wLine$n) insert end "\n" hl$::HighLightCount
} else {
$::widgets($top,wLine$n) insert end "*****\n"
}
$::widgets($top,wDiff$n) insert end "\n" padding
}
|
︙ | | |
445
446
447
448
449
450
451
452
453
454
455
456
457
458
|
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
return $res
}
# Insert one line in each text widget.
# Mark them as changed, and optionally parse them.
proc insertMatchingLines {top line1 line2} {
global doingLine1 doingLine2
if {$::eskil($top,view) eq "table"} {
set opts $::Pref(ignore)
if {$::Pref(nocase)} {lappend opts -nocase}
if {$::Pref(lineparsewords)} {lappend opts -words}
set RE $::eskil($top,separator)
set words1 [split $line1 $RE]
set words2 [split $line2 $RE]
set col 0
set id [$::widgets($top,wTable) insert end {}]
foreach w1 $words1 w2 $words2 {
set r [DiffUtil::diffStrings {*}$opts $w1 $w2]
if {[llength $r] <= 2} {
# Equal
$::widgets($top,wTable) cellconfigure $id,$col -text $w1
} else {
# TBD TABLE, simple display for now
$::widgets($top,wTable) cellconfigure $id,$col -text $w1$w2
lassign [$::widgets($top,wTable) cellbodyindex $id,$col] \
cIdx1 cIdx2
set body [$::widgets($top,wTable) bodypath]
set l1 [string length $w1]
set l2 [expr {$l1 + 1}]
set l3 [expr {$l1 + [string length $w2]}]
$body tag add new1 "$cIdx1" "$cIdx1 + $l1 char"
$body tag add new2 "$cIdx1 + $l1 char" "$cIdx1 + $l3 char"
}
incr col
}
incr doingLine1
incr doingLine2
return
}
# FIXA: fully implement filter
if {$::eskil(filter) != ""} {
if {[regexp $::eskil(filter) $line1]} {
insertLine $top 1 $doingLine1 $line1
insertLine $top 2 $doingLine2 $line2
incr doingLine1
|
︙ | | |
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
|
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
|
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
|
incr t2
} elseif {$c eq "C"} {
# This is two lines that the block matching considered
# too different to use line parsing on them.
# Marked the whole line as deleted/inserted
set textline1 [lindex $block1 $t1]
set textline2 [lindex $block2 $t2]
if {$::eskil($top,view) eq "table"} {
# Fall back to proc that handles table
insertMatchingLines $top $textline1 $textline2
} else {
$::widgets($top,wLine1) insert end [myFormL $doingLine1] \
"hl$::HighLightCount change"
$::widgets($top,wDiff1) insert end "$textline1\n" new1
$::widgets($top,wLine2) insert end [myFormL $doingLine2] \
"hl$::HighLightCount change"
$::widgets($top,wDiff2) insert end "$textline2\n" new2
$::widgets($top,wLine1) insert end [myFormL $doingLine1] \
"hl$::HighLightCount change"
$::widgets($top,wDiff1) insert end "$textline1\n" new1
$::widgets($top,wLine2) insert end [myFormL $doingLine2] \
"hl$::HighLightCount change"
$::widgets($top,wDiff2) insert end "$textline2\n" new2
incr doingLine1
incr doingLine2
}
if {$finegrain} {
addChange $top 1 change [expr {$line1 + $t1}] 1 \
[expr {$line2 + $t2}] 1
nextHighlight $top
}
incr doingLine1
incr doingLine2
incr t1
incr t2
} elseif {$c eq "d"} {
set bepa [lindex $block1 $t1]
if {$::eskil($top,view) eq "table"} {
insertLine $top 1 $doingLine1 $bepa new1
} else {
$::widgets($top,wLine1) insert end [myFormL $doingLine1] \
"hl$::HighLightCount change"
$::widgets($top,wDiff1) insert end "$bepa\n" new1
emptyLine $top 2
$::widgets($top,wLine1) insert end [myFormL $doingLine1] \
"hl$::HighLightCount change"
$::widgets($top,wDiff1) insert end "$bepa\n" new1
emptyLine $top 2
}
incr doingLine1
if {$finegrain} {
addChange $top 1 new1 [expr {$line1 + $t1}] 1 \
[expr {$line2 + $t2}] 0
nextHighlight $top
}
incr t1
} elseif {$c eq "a"} {
set bepa [lindex $block2 $t2]
if {$::eskil($top,view) eq "table"} {
insertLine $top 2 $doingLine2 $bepa new2
} else {
$::widgets($top,wLine2) insert end [myFormL $doingLine2] \
"hl$::HighLightCount change"
$::widgets($top,wDiff2) insert end "$bepa\n" new2
emptyLine $top 1
$::widgets($top,wLine2) insert end [myFormL $doingLine2] \
"hl$::HighLightCount change"
$::widgets($top,wDiff2) insert end "$bepa\n" new2
emptyLine $top 1
}
incr doingLine2
if {$finegrain} {
addChange $top 1 new2 [expr {$line1 + $t1}] 0 \
[expr {$line2 + $t2}] 1
nextHighlight $top
}
incr t2
|
︙ | | |
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
|
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
|
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
|
if {$line2 > 0 && $doingLine2 > $line2} break
insertLine $top 2 $doingLine2 $apa
incr doingLine2
addMapLines $top 1
incr t
if {$limit >= 0 && $t >= $limit} break
}
if {$::eskil($top,view) ne "table"} {
set t 0
while {[gets $ch1 apa] != -1} {
if {$line1 > 0 && $doingLine1 > $line1} break
insertLine $top 1 $doingLine1 $apa
incr doingLine1
incr t
if {$limit >= 0 && $t >= $limit} break
set t 0
while {[gets $ch1 apa] != -1} {
if {$line1 > 0 && $doingLine1 > $line1} break
insertLine $top 1 $doingLine1 $apa
incr doingLine1
incr t
if {$limit >= 0 && $t >= $limit} break
}
}
}
return
}
# Is this a change block, a delete block or an insert block?
if {$n1 == 0} {set tag2 new2} else {set tag2 change}
|
︙ | | |
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
|
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
|
+
-
+
+
|
set t 0
while {$doingLine1 < $line1} {
gets $ch1 apa
gets $ch2 bepa
if {$limit < 0 || ($t < $limit && $allowStartFill) || \
($line1 - $doingLine1) <= $limit} {
insertLine $top 1 $doingLine1 $apa
if {$::eskil($top,view) ne "table"} {
insertLine $top 2 $doingLine2 $bepa
insertLine $top 2 $doingLine2 $bepa
}
addMapLines $top 1
} elseif {$t == $limit && $allowStartFill} {
# If zero context is shown, skip the filler to keep display tight.
if {$limit > 0} {
emptyLine $top 1 0
emptyLine $top 2 0
addMapLines $top 1
|
︙ | | |
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
|
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
|
+
+
+
+
+
-
+
|
$w config -cursor watch
}
}
}
proc normalCursor {top} {
global oldcursor oldcursor2
if {$::eskil($top,view) eq "table"} {
set items wTable
} else {
set items {wLine1 wDiff1 wLine2 wDiff2}
}
$top config -cursor $oldcursor
foreach item {wLine1 wDiff1 wLine2 wDiff2} {
foreach item $items {
if {[info exists ::widgets($top,$item)]} {
set w $::widgets($top,$item)
$w config -cursor $oldcursor2
}
}
}
|
︙ | | |
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
|
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
|
+
+
+
+
+
+
+
+
+
-
-
-
-
-
|
} else {
# First lines are equal, treat them as header
# Consume table header line
gets $ch1 line1
incr doingLine1
gets $ch2 line
incr doingLine2
if {$::eskil($top,separator) eq ""} {
# Autodetect separator
# Any tab?
if {[regsub -all "\t" $line1 "\t" _] >= 2} {
set ::eskil($top,separator) "\t"
} elseif {[regsub -all "," $line1 "," _] >= 2} {
set ::eskil($top,separator) ","
}
}
set headings [split $line1 $::eskil($top,separator)]
set col {}
foreach heading $headings {
lappend col 0 $heading
}
$::widgets($top,wTable) configure -columns $col
}
}
# TBD TABLE, stop for now
if {$::eskil($top,view) eq "table"} {
return
}
# If there is a range, skip lines up to the range
if {[llength $range] != 0} {
disallowEdit $top
lassign $range start1 end1 start2 end2
while {$doingLine1 < $start1 && [gets $ch1 line] >= 0} {
incr doingLine1
}
|
︙ | | |
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
|
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
|
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
|
lassign $range start1 end1 start2 end2
} else {
set end1 0
set end2 0
}
doText $top $ch1 $ch2 0 0 $end1 $end2
if {$::eskil($top,view) ne "table"} {
# Make sure all text widgets have the same number of lines.
# The common y scroll doesn't work well if not.
set max 0.0
foreach item {wLine1 wDiff1 wLine2 wDiff2} {
set w $::widgets($top,$item)
if {[$w index end] > $max} {
set max [$w index end]
}
}
foreach item {wLine1 wDiff1 wLine2 wDiff2} {
set w $::widgets($top,$item)
set d [expr {int($max) - int([$w index end])}]
for {set t 0} {$t < $d} {incr t} {
$w insert end \n padding
# Make sure all text widgets have the same number of lines.
# The common y scroll doesn't work well if not.
set max 0.0
foreach item {wLine1 wDiff1 wLine2 wDiff2} {
set w $::widgets($top,$item)
if {[$w index end] > $max} {
set max [$w index end]
}
}
foreach item {wLine1 wDiff1 wLine2 wDiff2} {
set w $::widgets($top,$item)
set d [expr {int($max) - int([$w index end])}]
for {set t 0} {$t < $d} {incr t} {
$w insert end \n padding
}
}
}
close $ch1
close $ch2
# We can turn off editing in the text windows after everything
# is displayed.
noEdit $top
# Mark aligned lines
# Mark aligned lines TBD TABLE
if {[info exists ::eskil($top,aligns)] && \
[llength $::eskil($top,aligns)] > 0} {
foreach {align1 align2} $::eskil($top,aligns) {
set i [$::widgets($top,wLine1) search -regexp "\\m$align1\\M" 1.0]
if {$i != ""} {
$::widgets($top,wLine1) tag add align \
"$i linestart" "$i lineend"
}
set i [$::widgets($top,wLine2) search -regexp "\\m$align2\\M" 1.0]
if {$i != ""} {
$::widgets($top,wLine2) tag add align \
"$i linestart" "$i lineend"
}
}
}
drawMap $top -1
#drawEditButtons $top
if {$::eskil($top,view) ne "table"} {
foreach item {wLine1 wLine2 wTb} {
set w $::widgets($top,$item)
$w configure -state disabled
}
update idletasks
$::widgets($top,wLine2) see 1.0
foreach item {wLine1 wLine2 wTb} {
set w $::widgets($top,$item)
$w configure -state disabled
}
update idletasks
$::widgets($top,wLine2) see 1.0
}
normalCursor $top
showDiff $top 0
if {$::widgets($top,eqLabel) eq "!"} {
set ::widgets($top,eqLabel) " "
}
cleanupFiles $top
if {$::eskil($top,mode) eq "conflict"} {
if {$::widgets($top,eqLabel) != "="} {
makeMergeWin $top
}
} elseif {$::eskil($top,ancestorFile) ne ""} {
if {$::widgets($top,eqLabel) != "="} {
makeMergeWin $top
}
}
if {$::eskil($top,printFile) ne ""} {
# TBD TABLE
after idle "doPrint $top 1 ; cleanupAndExit all"
}
}
# This is the entrypoint to do a diff via DDE or Send
proc remoteDiff {file1 file2} {
newDiff $file1 $file2
|
︙ | | |
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
|
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
|
+
+
|
$::widgets($top,wLine2) tag configure hl$::eskil($top,currHighLight) \
-background yellow
}
}
# Highlight a diff and scroll windows to it.
proc showDiff {top num} {
# TBD TABLE
if {$::eskil($top,view) eq "table"} return
highLightChange $top $num
set change [lindex $::eskil($top,changes) $::eskil($top,currHighLight)]
set line1 [lindex $change 0]
if {$::eskil($top,currHighLight) < 0} {
set line1 1.0
|
︙ | | |
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
|
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
|
+
+
+
+
|
set ::eskil($top,nopopup) 1
tk_popup .lpm $X $Y
after idle [list after 1 [list set "::eskil($top,nopopup)" 0]]
}
proc nextHighlight {top} {
# TBD TABLE, stop for now?
if {$::eskil($top,view) eq "table"} {
return
}
set tag hl$::HighLightCount
foreach n {1 2} {
$::widgets($top,wLine$n) tag bind $tag <ButtonPress-3> \
"hlPopup $top $n $::HighLightCount %X %Y %x %y ; break"
$::widgets($top,wLine$n) tag bind $tag <ButtonPress-1> \
"hlSelect $top $::HighLightCount"
}
|
︙ | | |
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
|
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
|
-
+
+
+
+
+
+
+
|
# Single frame for contents
ttk::frame $top.ft -borderwidth 2 -relief sunken
grid $top.l1 $top.l2 -row 1 -sticky news
grid $top.ft - -row 2 -sticky news
grid columnconfigure $top "$top.ft" -weight 1
grid rowconfigure $top $top.ft -weight 1
# TBD TABLE
tablelist::tablelist $top.ft.tab -height 20 \
tablelist::tablelist $top.ft.tab -height 20 -width 80 \
-movablecolumns no -setgrid no -showseparators no \
-fullseparators yes -selectmode none
ttk::scrollbar $top.ft.vsb -orient vertical \
-command "$top.ft.tab yview"
ttk::scrollbar $top.ft.hsb -orient horizontal \
-command "$top.ft.tab xview"
$top.ft.tab configure -yscrollcommand "$top.ft.vsb set" \
-xscrollcommand "$top.ft.hsb set"
set body [$top.ft.tab bodypath]
$body tag configure new1 -foreground $::Pref(colornew1) \
-background $::Pref(bgnew1)
$body tag configure new2 -foreground $::Pref(colornew2) \
-background $::Pref(bgnew2)
set bg [ttk::style configure . -background]
set map [createMap $top $bg]
grid $top.ft.tab $top.ft.vsb $map -sticky news
grid $top.ft.hsb x x -sticky news
grid columnconfigure $top.ft 0 -weight 1
grid rowconfigure $top.ft 0 -weight 1
grid $map -pady [expr {[winfo reqwidth $top.ft.vsb] - 2}]
set ::widgets($top,wTable) $top.ft.tab
} else {
ttk::frame $top.ft1 -borderwidth 2 -relief sunken
text $top.ft1.tl -height $::Pref(lines) -width 5 -wrap none \
-font myfont -borderwidth 0 -padx 0 -highlightthickness 0 \
-takefocus 0
text $top.ft1.tt -height $::Pref(lines) -width $::Pref(linewidth) \
|
︙ | | |