Eskil

Check-in [79b9aabf5f]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Remade hidden columns into row attributes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | table-list
Files: files | file ages | folders
SHA1: 79b9aabf5f3e2ec5e2cc888f484fe6a13cc8c97d
User & Date: peter.spjuth@gmail.com 2010-06-23 21:23:48
Context
2010-06-23
21:28
Removed Name columns from dir diff. check-in: 0f4c63dfb2 user: peter.spjuth@gmail.com tags: table-list
21:23
Remade hidden columns into row attributes. check-in: 79b9aabf5f user: peter.spjuth@gmail.com tags: table-list
20:34
Trying out to use tablelist instead of ttk::treeview for dir diff. check-in: 17bdab9a27 user: peter.spjuth@gmail.com tags: table-list
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/dirdiff.tcl.

258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
...
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
...
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
...
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
...
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
...
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
...
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
...
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
...
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
...
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666

667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
...
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
...
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
    variable leftDir ""
    variable rightDir ""

    constructor {args} {
        variable color
        install tree using tablelist::tablelist $win.tree -height 20 \
                -movablecolumns no -setgrid no -showseparators yes \
                -columns {0 "Structure" 0 "" 0 "" 0 "" 0 Name 0 Size 0 Date 0 "" 0 Name 0 Size 0 Date}
        install vsb using scrollbar $win.vsb -orient vertical \
                -command "$tree yview"
        install hsb using scrollbar $win.hsb -orient horizontal \
                -command "$tree xview"

        set AfterId ""
        set IdleQueue {}

        $tree configure -yscrollcommand "$vsb set" -xscrollcommand "$hsb set"

        $tree columnconfigure 0 -name structure
        $tree columnconfigure 1 -name type -hide 1
        $tree columnconfigure 2 -name status -hide 1
        $tree columnconfigure 3 -name leftfull -hide 1
        $tree columnconfigure 4 -name leftname -hide 1
        $tree columnconfigure 5 -name leftsize -align right
        $tree columnconfigure 6 -name leftdate
        $tree columnconfigure 7 -name rightfull -hide 1
        $tree columnconfigure 8 -name rightname -hide 1
        $tree columnconfigure 9 -name rightsize -align right
        $tree columnconfigure 10 -name rightdate

        set color(unknown) grey
        set color(empty) grey
        set color(equal) {}
        set color(new) green
        set color(old) blue
        set color(change) red
................................................................................
        set d1 [file tail $leftDir]
        set d2 [file tail $rightDir]
        if {$d1 eq $d2} {
            $tree cellconfigure $topIndex,structure -text $d1
        } else {
            $tree cellconfigure $topIndex,structure -text "$d1 vs $d2"
        }
        $tree cellconfigure $topIndex,type -text directory
        $self SetNodeStatus $topIndex empty
        $tree cellconfigure $topIndex,leftfull  -text $leftDir             
        $tree cellconfigure $topIndex,leftname  -text [file tail $leftDir] 
        $tree cellconfigure $topIndex,rightfull -text $rightDir            
        $tree cellconfigure $topIndex,rightname -text [file tail $rightDir]

        $self UpdateDirNode $topIndex
    }

    # Format a time stamp for display
    proc FormatDate {date} {
................................................................................
    # Remove all equal nodes from tree
    method PruneEqual {} {
        set todo [$tree childkeys root]
        while {[llength $todo] > 0} {
            set todoNow $todo
            set todo {}
            foreach node $todoNow {
                set status [$tree cellcget $node,status -text]
                if {$status eq "equal"} {
                    $tree delete $node
                } else {
                    lappend todo {*}[$tree childkeys $node]
                }
            }
        }
................................................................................
        }
    }

    # Copy a file from one directory to the other
    method CopyFile {node from} {
        global dirdiff Pref

        set lf [$tree cellcget $node,leftfull -text]
        set rf [$tree cellcget $node,rightfull -text]
        set parent [$tree parent $node]
        set lp [$tree cellcget $parent,leftfull -text]
        set rp [$tree cellcget $parent,rightfull -text]

        if {$from eq "left"} {
            set src $lf
            if {$rf ne ""} {
                set dst $rf
            } elseif {$rp ne ""} {
                set dst [file join $rp [file tail $src]]
................................................................................
    }

    # React on double-click
    method DoubleClick {W x y} {
        foreach {W x y} [tablelist::convEventFields $W $x $y] break
        set node [$tree index @$x,$y]

        set lf [$tree cellcget $node,leftfull -text]
        set rf [$tree cellcget $node,rightfull -text]
        set type [$tree cellcget $node,type -text]

        # On a file that exists on both sides, start a file diff
        if {$type eq "file" && $lf ne "" && $rf ne ""} {
            set PauseBgProcessing 1
            newDiff $lf $rf
            set PauseBgProcessing 0
            # Stop the default bindings from running
................................................................................
        }
    }
    # React on Return key
    method KeyReturn {} {
        set node [$tree focus]
        if {$node eq ""} return

        set lf [$tree cellcget $node,leftfull -text]
        set rf [$tree cellcget $node,rightfull -text]
        set type [$tree cellcget $node,type -text]

        # On a file that exists on both sides, start a file diff
        if {$type eq "file" && $lf ne "" && $rf ne ""} {
            set PauseBgProcessing 1
            newDiff $lf $rf
            set PauseBgProcessing 0
            # Stop the default bindings from running
................................................................................
    method ContextMenu {W x y X Y} {
        foreach {W x y} [tablelist::convEventFields $W $x $y] break

        set node [$tree index @$x,$y]
        set col [$tree columnindex @$x,$y]
        set colname [$tree columncget $col -name]

        set lf [$tree cellcget $node,leftfull -text]
        set rf [$tree cellcget $node,rightfull -text]
        set type [$tree cellcget $node,type -text]
        set oneside [expr {($lf ne "") ^ ($rf ne "")}]

        set m $win.popup
        destroy $m
        menu $m
        
        if {$colname eq "structure"} {
................................................................................
        set pre [clock clicks -milliseconds]
        set errors {}
        while {[llength $IdleQueue] > 0} {
            set node [lindex $IdleQueue 0]
            set IdleQueue [lrange $IdleQueue 1 end]
            unset IdleQueueArr($node)

            if {[$tree cellcget $node,type -text] ne "directory"} {
                set sts [catch {$self UpdateFileNode $node} err]
            } else {
                set sts [catch {$self UpdateDirNode $node} err]
            }
            if {$sts} {
                lappend errors $err
            }
................................................................................
                set statusvar ""
                set AfterId ""
                return
            }
        }

        if {[llength $IdleQueue] > 0} {
            set leftfull [$tree cellcget $node,leftfull -text]
            set rightfull [$tree cellcget $node,rightfull -text]
            if {$leftfull ne ""} {
                set statusvar $leftfull
            } else {
                set statusvar $rightfull
            }

            set AfterId [after 1 [mymethod UpdateIdle]]
................................................................................
            set statusvar ""
            set AfterId ""
        }
    }

    method SetNodeStatus {node status} {
        variable color
        $tree cellconfigure $node,status -text $status
        $tree rowconfigure $node -foreground $color($status) \
                -selectforeground $color($status)
        #puts "Set [$tree item $node -text] to $status"

        # Loop through children to update parent
        set parent [$tree parentkey $node]
        if {$parent eq "" || $parent eq "root"} { return }

        # If this is only present on one side, there is no need to update
        set lf [$tree cellcget $parent,leftfull -text]
        set rf [$tree cellcget $parent,rightfull -text]
        if {$lf eq "" || $rf eq ""} { return }

        set pstatus equal
        foreach child [$tree childkeys $parent] {
            set status [$tree cellcget $child,status -text]
            switch $status {
                unknown {
                    set pstatus unknown
                    break
                }
                new - old - change {
                    set pstatus change

                }
            }
        }
        #puts "Setting parent [$tree set $parent leftname] to $pstatus"
        $self SetNodeStatus $parent $pstatus
    }

    method UpdateDirNode {node} {
        if {[$tree cellcget $node,type -text] ne "directory"} {
            return
        }
        if {[$tree cellcget $node,status -text] ne "empty"} {
            #puts "Dir [$tree set $node leftfull] already done"
            return
        }
        $tree delete [$tree childkeys $node]

        set leftfull [$tree cellcget $node,leftfull -text]
        set rightfull [$tree cellcget $node,rightfull -text]
        $self CompareDirs $leftfull $rightfull $node
    }

    method UpdateFileNode {node} {
        set leftfull [$tree cellcget $node,leftfull -text]
        set rightfull [$tree cellcget $node,rightfull -text]
        set equal [CompareFiles $leftfull $rightfull]
        if {$equal} {
            $self SetNodeStatus $node equal
        } else {
            $self SetNodeStatus $node change
        }
            
................................................................................
            set showleft ""
            set showright ""
            if {$df1 eq ""} {
                set showright $name/
            } elseif {$df2 eq ""} {
                set showleft $name/
            } 
            set values [list $name $type unknown \
                    $df1 $showleft "" "" \
                    $df2 $showright "" ""]
        } else {
            set name1 [file tail $df1]
            set name2 [file tail $df2]
            set values [list $name $type unknown \
                    $df1 $name1 $size1 $time1 \
                    $df2 $name2 $size2 $time2]
        }
        set id [$tree insertchild $node end $values]





        if {$type eq "directory"} {
            ## Make it so that this node is openable
            $tree collapse $id
            #$tree insertchild $id end dummy ;# a dummy
            $tree cellconfigure $id,structure -text $name/
            $self SetNodeStatus $id empty
................................................................................
            $self SetNodeStatus $id new
        } elseif {$size2 == ""} {
            $self SetNodeStatus $id old
        } else {
            $self SetNodeStatus $id unknown
            $self AddNodeToIdle $id
        }
        return [$tree cellcget $id,status -text]
    }

    # Compare two directories.
    method CompareDirs {dir1 dir2 node} {
        global Pref
        if {$dir1 eq ""} {
            set files1 {}







|











|
|
|
|
|
|
<
<
<
<







 







|

|

|







 







|







 







|
|

|
|







 







|
|
|







 







|
|
|







 







|
|
|







 







|







 







|
|







 







|









|
|




|



<



>








|


|





|
|




|
|







 







|
|
|



|
|
|


>
>
>
>







 







|







258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282




283
284
285
286
287
288
289
...
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
...
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
...
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
...
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
...
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
...
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
...
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
...
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
...
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658

659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
...
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
...
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
    variable leftDir ""
    variable rightDir ""

    constructor {args} {
        variable color
        install tree using tablelist::tablelist $win.tree -height 20 \
                -movablecolumns no -setgrid no -showseparators yes \
                -columns {0 "Structure" 0 Name 0 Size 0 Date 0 Name 0 Size 0 Date}
        install vsb using scrollbar $win.vsb -orient vertical \
                -command "$tree yview"
        install hsb using scrollbar $win.hsb -orient horizontal \
                -command "$tree xview"

        set AfterId ""
        set IdleQueue {}

        $tree configure -yscrollcommand "$vsb set" -xscrollcommand "$hsb set"

        $tree columnconfigure 0 -name structure
        $tree columnconfigure 1 -name leftname -hide 0
        $tree columnconfigure 2 -name leftsize -align right
        $tree columnconfigure 3 -name leftdate
        $tree columnconfigure 4 -name rightname -hide 0
        $tree columnconfigure 5 -name rightsize -align right
        $tree columnconfigure 6 -name rightdate





        set color(unknown) grey
        set color(empty) grey
        set color(equal) {}
        set color(new) green
        set color(old) blue
        set color(change) red
................................................................................
        set d1 [file tail $leftDir]
        set d2 [file tail $rightDir]
        if {$d1 eq $d2} {
            $tree cellconfigure $topIndex,structure -text $d1
        } else {
            $tree cellconfigure $topIndex,structure -text "$d1 vs $d2"
        }
        $tree rowattrib $topIndex type directory
        $self SetNodeStatus $topIndex empty
        $tree rowattrib $topIndex leftfull $leftDir             
        $tree cellconfigure $topIndex,leftname  -text [file tail $leftDir] 
        $tree rowattrib $topIndex rightfull $rightDir            
        $tree cellconfigure $topIndex,rightname -text [file tail $rightDir]

        $self UpdateDirNode $topIndex
    }

    # Format a time stamp for display
    proc FormatDate {date} {
................................................................................
    # Remove all equal nodes from tree
    method PruneEqual {} {
        set todo [$tree childkeys root]
        while {[llength $todo] > 0} {
            set todoNow $todo
            set todo {}
            foreach node $todoNow {
                set status [$tree rowattrib $node status]
                if {$status eq "equal"} {
                    $tree delete $node
                } else {
                    lappend todo {*}[$tree childkeys $node]
                }
            }
        }
................................................................................
        }
    }

    # Copy a file from one directory to the other
    method CopyFile {node from} {
        global dirdiff Pref

        set lf [$tree rowattrib $node leftfull]
        set rf [$tree rowattrib $node rightfull]
        set parent [$tree parent $node]
        set lp [$tree rowattrib $parent leftfull]
        set rp [$tree rowattrib $parent rightfull]

        if {$from eq "left"} {
            set src $lf
            if {$rf ne ""} {
                set dst $rf
            } elseif {$rp ne ""} {
                set dst [file join $rp [file tail $src]]
................................................................................
    }

    # React on double-click
    method DoubleClick {W x y} {
        foreach {W x y} [tablelist::convEventFields $W $x $y] break
        set node [$tree index @$x,$y]

        set lf [$tree rowattrib $node leftfull]
        set rf [$tree rowattrib $node rightfull]
        set type [$tree rowattrib $node type]

        # On a file that exists on both sides, start a file diff
        if {$type eq "file" && $lf ne "" && $rf ne ""} {
            set PauseBgProcessing 1
            newDiff $lf $rf
            set PauseBgProcessing 0
            # Stop the default bindings from running
................................................................................
        }
    }
    # React on Return key
    method KeyReturn {} {
        set node [$tree focus]
        if {$node eq ""} return

        set lf [$tree rowattrib $node leftfull]
        set rf [$tree rowattrib $node rightfull]
        set type [$tree rowattrib $node type]

        # On a file that exists on both sides, start a file diff
        if {$type eq "file" && $lf ne "" && $rf ne ""} {
            set PauseBgProcessing 1
            newDiff $lf $rf
            set PauseBgProcessing 0
            # Stop the default bindings from running
................................................................................
    method ContextMenu {W x y X Y} {
        foreach {W x y} [tablelist::convEventFields $W $x $y] break

        set node [$tree index @$x,$y]
        set col [$tree columnindex @$x,$y]
        set colname [$tree columncget $col -name]

        set lf [$tree rowattrib $node leftfull]
        set rf [$tree rowattrib $node rightfull]
        set type [$tree rowattrib $node type]
        set oneside [expr {($lf ne "") ^ ($rf ne "")}]

        set m $win.popup
        destroy $m
        menu $m
        
        if {$colname eq "structure"} {
................................................................................
        set pre [clock clicks -milliseconds]
        set errors {}
        while {[llength $IdleQueue] > 0} {
            set node [lindex $IdleQueue 0]
            set IdleQueue [lrange $IdleQueue 1 end]
            unset IdleQueueArr($node)

            if {[$tree rowattrib $node type] ne "directory"} {
                set sts [catch {$self UpdateFileNode $node} err]
            } else {
                set sts [catch {$self UpdateDirNode $node} err]
            }
            if {$sts} {
                lappend errors $err
            }
................................................................................
                set statusvar ""
                set AfterId ""
                return
            }
        }

        if {[llength $IdleQueue] > 0} {
            set leftfull [$tree rowattrib $node leftfull]
            set rightfull [$tree rowattrib $node rightfull]
            if {$leftfull ne ""} {
                set statusvar $leftfull
            } else {
                set statusvar $rightfull
            }

            set AfterId [after 1 [mymethod UpdateIdle]]
................................................................................
            set statusvar ""
            set AfterId ""
        }
    }

    method SetNodeStatus {node status} {
        variable color
        $tree rowattrib $node status $status
        $tree rowconfigure $node -foreground $color($status) \
                -selectforeground $color($status)
        #puts "Set [$tree item $node -text] to $status"

        # Loop through children to update parent
        set parent [$tree parentkey $node]
        if {$parent eq "" || $parent eq "root"} { return }

        # If this is only present on one side, there is no need to update
        set lf [$tree rowattrib $parent leftfull]
        set rf [$tree rowattrib $parent rightfull]
        if {$lf eq "" || $rf eq ""} { return }

        set pstatus equal
        foreach child [$tree childkeys $parent] {
            set status [$tree rowattrib $child status]
            switch $status {
                unknown {
                    set pstatus unknown

                }
                new - old - change {
                    set pstatus change
                    break
                }
            }
        }
        #puts "Setting parent [$tree set $parent leftname] to $pstatus"
        $self SetNodeStatus $parent $pstatus
    }

    method UpdateDirNode {node} {
        if {[$tree rowattrib $node type] ne "directory"} {
            return
        }
        if {[$tree rowattrib $node status] ne "empty"} {
            #puts "Dir [$tree set $node leftfull] already done"
            return
        }
        $tree delete [$tree childkeys $node]

        set leftfull [$tree rowattrib $node leftfull]
        set rightfull [$tree rowattrib $node rightfull]
        $self CompareDirs $leftfull $rightfull $node
    }

    method UpdateFileNode {node} {
        set leftfull [$tree rowattrib $node leftfull]
        set rightfull [$tree rowattrib $node rightfull]
        set equal [CompareFiles $leftfull $rightfull]
        if {$equal} {
            $self SetNodeStatus $node equal
        } else {
            $self SetNodeStatus $node change
        }
            
................................................................................
            set showleft ""
            set showright ""
            if {$df1 eq ""} {
                set showright $name/
            } elseif {$df2 eq ""} {
                set showleft $name/
            } 
            set values [list $name \
                    $showleft "" "" \
                    $showright "" ""]
        } else {
            set name1 [file tail $df1]
            set name2 [file tail $df2]
            set values [list $name \
                    $name1 $size1 $time1 \
                    $name2 $size2 $time2]
        }
        set id [$tree insertchild $node end $values]
        $tree rowattrib $id type $type
        $tree rowattrib $id status unknown
        $tree rowattrib $id leftfull $df1
        $tree rowattrib $id rightfull $df2

        if {$type eq "directory"} {
            ## Make it so that this node is openable
            $tree collapse $id
            #$tree insertchild $id end dummy ;# a dummy
            $tree cellconfigure $id,structure -text $name/
            $self SetNodeStatus $id empty
................................................................................
            $self SetNodeStatus $id new
        } elseif {$size2 == ""} {
            $self SetNodeStatus $id old
        } else {
            $self SetNodeStatus $id unknown
            $self AddNodeToIdle $id
        }
        return [$tree rowattrib $id status]
    }

    # Compare two directories.
    method CompareDirs {dir1 dir2 node} {
        global Pref
        if {$dir1 eq ""} {
            set files1 {}