Eskil

Diff
Login

Differences From Artifact [46a3d48fad]:

To Artifact [70e3f1de23]:


303
304
305
306
307
308
309

310
311
312
313
314
315
316
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317







+







    option -leftdirvariable  -default "" -configuremethod SetDirOption
    option -rightdirvariable -default "" -configuremethod SetDirOption
    option -statusvar -default ""
    option -changelist -default ""

    variable AfterId ""
    variable DebugCh ""
    variable DebugTime {}
    variable PauseBgProcessing 0
    variable ScheduledRestart 0
    variable AfterTime 1
    variable IdleQueue {}
    variable IdleQueueArr
    variable leftMark ""
    variable rightMark ""
425
426
427
428
429
430
431

432
433
434


435
436
437
438
439
440
441
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445







+



+
+







        # Delete all idle processing
        if {$AfterId ne ""} {
            after cancel $AfterId
        }
        if {$DebugCh ne ""} {
            close $DebugCh
            set DebugCh ""
            set DebugTime {}
        }
        # Uncomment to activate debug logging
        #set DebugCh [open ~/dirdiff.log a]
        #$self DlogTablelist
        $self Dlog RESTART
        set AfterId ""
        set IdleQueue {}
        set ScheduledRestart 0
        array unset IdleQueueArr
        set protect {left 0 right 0}

        # Directory Diff only supports one plugin.
767
768
769
770
771
772
773
774

775


776







777
778
779
780
781
782
783
784

785

786








787
788
















789
790
791
792
793
794
795
796
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
771
772
773
774
775
776
777

778
779
780
781

782
783
784
785
786
787
788
789
790
791
792
793
794
795

796
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
858
859
860
861
862

863
864

865
866
867
868
869
870
871
872







-
+

+
+
-
+
+
+
+
+
+
+







-
+

+
-
+
+
+
+
+
+
+
+


+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+















-
+










-
+











-
+

-
+







            if {[winfo exists $w]} {
                $w configure -state disabled
            }
        }
        dict set widgets $side {}
    }

    method AddNodeToIdle {node} {
    method AddNodeToIdle {node {first 0}} {
        if {[info exists IdleQueueArr($node)]} { return }
        if {$first} {
            # Items are popped from the end, so last is first
        lappend IdleQueue $node
            lappend IdleQueue $node
        } else {
            # Avoid compiled linsert by having index in a variable
            set c0 0
            set IdleQueue [linsert $IdleQueue[set IdleQueue {}] $c0 $node]
        }

        set IdleQueueArr($node) 1

        if {$AfterId eq ""} {
            set AfterId [after $AfterTime [mymethod UpdateIdle]]
        }
    }
    # Debug logging
    method Dlog {msg} {
    method Dlog {args} {
        if {$DebugCh ne ""} {
            set msg [join $args]
            puts $DebugCh "[clock clicks -milliseconds] $msg"
            set now [clock clicks -milliseconds]
            set suffix ""
            if {[dict exists $DebugTime $msg]} {
                set delta [expr {$now - [dict get $DebugTime $msg]}]
                set suffix " (+$delta)"
            }
            dict set DebugTime $msg $now
            puts $DebugCh "$now $msg$suffix"
            flush $DebugCh
        }
    }
    method DlogTablelist {} {
        puts DlogTablelist
        foreach cmd [info commands ::tablelist::*] {
            set tail [namespace tail $cmd]
            #if {[string match *SubCmd $tail]} continue
            if {$tail in {
                synchronize
                tablelistWidgetCmd cleanupWindow getTablelistPath
                handleMotion handleMotionDelayed
                rowIndex isInteger keyToRow colIndex
            }} continue
            
            trace add execution $cmd enter [mymethod Dlog]
            puts "Traced $cmd"
        }
    }
    method UpdateIdle {} {
        $self Dlog UpdateIdle
        set AfterId "X"

        if {$PauseBgProcessing} {
            $self Dlog Pause
            set AfterId [after 200 [mymethod UpdateIdle]]
            return
        }

        set pre [clock clicks -milliseconds]
        set errors {}
        set count 0
        while {[llength $IdleQueue] > 0} {
            set node [lindex $IdleQueue 0]
            set node [lindex $IdleQueue end]
            # Always make a pause before a large file
            if {[$tree rowattrib $node type] ne "directory"} {
                if {[$tree rowattrib $node largefile]} {
                    if {$count > 0} {
                        $self Dlog "New Lap for large file"
                        break
                    }
                }
            }
            incr count
            set IdleQueue [lrange $IdleQueue 1 end]
            set IdleQueue [lrange $IdleQueue[set IdleQueue {}] 0 end-1]
            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 $node $err
                break
            }
            # Work for at least 50 ms to keep things efficient
            # Work for at least 200 ms to keep things efficient
            set post [clock clicks -milliseconds]
            if {($post - $pre) > 50} break
            if {($post - $pre) > 200} break
        }
        #if {($post - $pre) > 1000} {
            #puts "[expr $post - $pre] ms for [$tree set $node leftfull]"
        #}

        # Update the status variable to track progress
        if {$options(-statusvar) ne ""} {
852
853
854
855
856
857
858
859

860
861
862
863
864
865
866
888
889
890
891
892
893
894

895
896
897
898
899
900
901
902







-
+







                set statusvar ""
                set AfterId ""
                return
            }
        }

        if {[llength $IdleQueue] > 0} {
            set node [lindex $IdleQueue 0]
            set node [lindex $IdleQueue end]
            set leftfull [$tree rowattrib $node leftfull]
            set rightfull [$tree rowattrib $node rightfull]
            if {$leftfull ne ""} {
                set statusvar "$leftfull  ($count)"
            } else {
                set statusvar "$rightfull  ($count)"
            }
976
977
978
979
980
981
982
983

984
985
986
987
988
989
990
1012
1013
1014
1015
1016
1017
1018

1019
1020
1021
1022
1023
1024
1025
1026







-
+







            set name [file tail $df1]
        } else {
            set type $type2
            set name [file tail $df2]
        }
        set largeFile 0
        if {$type eq "directory"} {
            set values [list $name \
            set values [list $name/ \
                    "" "" \
                    "" \
                    "" ""]
        } else {
            set values [list $name \
                    $size1 $time1 \
                    "" \
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018

1019
1020
1021
1022
1023
1024
1025
1026
1044
1045
1046
1047
1048
1049
1050


1051

1052

1053
1054
1055
1056
1057
1058
1059







-
-

-
+
-







                $tree cellconfigure $id,command -window [mymethod addCmdCol]
            }
        }

        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 AddNodeToIdle $id
            $self AddNodeToIdle $id 1
            $tree cellconfigure $id,structure -image $::img(clsd)
        } elseif {$size1 == ""} {
            $self SetNodeStatus $id new
        } elseif {$size2 == ""} {
            $self SetNodeStatus $id old
        } else {
            $self SetNodeStatus $id unknown
            $self AddNodeToIdle $id