Eskil

Diff
Login

Differences From Artifact [ec8138a89c]:

To Artifact [06a7954d30]:


18
19
20
21
22
23
24

25
26
27
28
29
30







31
32
33
34
35
36
37
38
39
40
41





































42
43
44
45
46
47


48
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92



































































93
94
95
96

97

98
99

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

145
146
147
148
149

150
151
152
153

154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

171
18
19
20
21
22
23
24
25






26
27
28
29
30
31
32











33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
79
80
81
82
83
84
85
86




87
88
89
90
91
92
93
94
95
96
97
98
99

























100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

172


173













































174





175




176

















177
178







+
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
-
-
-
-
+
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+

+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+




+
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+

#  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
#  Boston, MA 02111-1307, USA.
#
#----------------------------------------------------------------------
# $Revision$
#----------------------------------------------------------------------

# Top level dialog, for doing fourway diff
proc DoFourWayDiff {top} {
    # Copy to convenient local vars
    foreach field $::eskil(fw,fields) {
        set filename($field) $::eskil($top,$field)
        set rev($field)      $::eskil($top,rev,$field)
    }
snit::widget FourWay {
    hulltype toplevel
    widgetclass Toplevel
    variable fields
    variable files
    variable revs

    # Fill in defaults, if revisions are given for empty files
    foreach {from to} $::eskil(fw,fields) {
        if {$filename($to) eq "" && $rev($to) ne ""} {
            set filename($to) $::eskil($top,$from)
        }
        if {$filename($from) eq "" && $rev($from) ne ""} {
            set filename($from) $::eskil($top,$to)
        }
    }
    parray filename
}
    constructor {args} {
        eskilRegisterToplevel $win

        wm title $win "Four Way Diff"
        wm protocol $win WM_DELETE_WINDOW "cleanupAndExit $win"
        $hull configure -padx 3 -pady 3

        menu $win.m
        $hull configure -menu $win.m
        $win.m add cascade -menu $win.m.mf -label "File" -underline 0
        menu $win.m.mf
        $win.m.mf add command -label "Close" -underline 0 \
                -command [list cleanupAndExit $win]
        $win.m.mf add separator
        $win.m.mf add command -label "Quit" -underline 0 \
                -command [list cleanupAndExit all]

        # Four files, with optional revision
        set fields {base1 change1 base2 change2}
    
        ttk::label $win.l1 -text "Base 1"
        ttk::label $win.l2 -text "Changed 1"
        ttk::label $win.l3 -text "Base 2"
        ttk::label $win.l4 -text "Changed 2"
        set txt1 "First diff is made from Base 1 to Changed 1.\n If a file is empty\
                  and have a revision, the other file name is used."
        addBalloon $win.l1 $txt1
        addBalloon $win.l2 $txt1
        set txt2 [string map {1 2 First Second} $txt1]
        addBalloon $win.l3 $txt2
        addBalloon $win.l4 $txt2

        ttk::label $win.el -text "File path"
        ttk::label $win.rl -text "Rev"
        addBalloon $win.rl "If you want to use a revisioned controlled file instead\n of\
                            the one on disk, add a revision here. E.g. 0 can be used\n for\
                            latest commited revision."

# Browse for file
proc DoOpenFw {top field} {
    upvar \#0 ::eskil($top,$field) filename
    set initDir [pwd]
    if {$filename ne ""} {
        set n 0
        foreach field $fields {
        set initDir [file dirname $filename]
    } else {
        # Pick default dir from other files
        foreach other [lreverse $::eskil(fw,fields)] {
            if {$other eq $field} continue
            incr n
            ttk::entryX $win.e$n -width 60 -textvariable [myvar files($field)]
            ttk::button $win.b$n -text "Browse" -command [mymethod browseFile $field]
            ttk::entryX $win.r$n -width 6 -textvariable  [myvar revs($field)]
            puts $other
            if {$::eskil($top,$other) ne ""} {
                set initDir [file dirname $::eskil($top,$other)]
                puts $initDir
                break
            }
        }
    }
    set apa [myOpenFile -title "Select file" -initialdir $initDir \
                     -parent $top]
        }

        ttk::button $win.bd -text "Diff" -command [mymethod doFourWayDiff] -underline 0 \
                -width 8
        bind $win <Alt-d> [list $win.bd invoke]

        grid x       $win.el x       $win.rl -sticky w  -padx 3 -pady 3
        grid $win.l1 $win.e1 $win.b1 $win.r1 -sticky we -padx 3 -pady 3
        grid $win.l2 $win.e2 $win.b2 $win.r2 -sticky we -padx 3 -pady 3
        grid $win.l3 $win.e3 $win.b3 $win.r3 -sticky we -padx 3 -pady {10 3}
    if {$apa != ""} {
        set filename $apa
    }
}
        grid $win.l4 $win.e4 $win.b4 $win.r4 -sticky we -padx 3 -pady 3
        grid $win.bd -       -                  -padx 3 -pady {10 3}

        # Set up file dropping in entry windows if TkDnd is available
        if {![catch {package require tkdnd}]} {
            dnd bindtarget $win    text/uri-list <Drop> "[mymethod fileDrop any    ] %D"
            dnd bindtarget $win.e1 text/uri-list <Drop> "[mymethod fileDrop base1  ] %D"
            dnd bindtarget $win.e2 text/uri-list <Drop> "[mymethod fileDrop change1] %D"
            dnd bindtarget $win.e3 text/uri-list <Drop> "[mymethod fileDrop base2  ] %D"
            dnd bindtarget $win.e4 text/uri-list <Drop> "[mymethod fileDrop change2] %D"
        }
    }

# File drop using TkDnd
proc fileDropFw {top field files} {
    if {$field eq "any"} {
        # Dropped outside the entry widgets. Try to be clever.
        set todo {}
        # Drop in empty fields first
        foreach field $::eskil(fw,fields) {
            if {$::eskil($top,$field) eq ""} {
                lappend todo $field
            }
        }
        # Fill fields otherwise
        if {[llength $todo] == 0} {
            set todo $::eskil(fw,fields)
        }
    } else {
        set todo [list $field]
    }
    foreach fn $files field $todo {
        # Loop until any list ends
        if {$fn eq "" || $field eq ""} break
        # Sanity check
        if {[file exists $fn]} {
            set ::eskil($top,$field) $fn
        }
    # File drop using TkDnd
    method fileDrop {field files} {
        if {$field eq "any"} {
            # Dropped outside the entry widgets. Try to be clever.
            set todo {}
            # Drop in empty fields first
            foreach field $fields {
                if {$files($field) eq ""} {
                    lappend todo $field
                }
            }
            # Fill fields otherwise
            if {[llength $todo] == 0} {
                set todo $fields
            }
        } else {
            set todo [list $field]
        }
        foreach fn $files field $todo {
            # Loop until any list ends
            if {$fn eq "" || $field eq ""} break
            # Sanity check
            if {[file exists $fn]} {
                set fields($field) $fn
            }
        }
    }

    # Browse for file
    method browseFile {field} {
        set initDir [pwd]
        if {$files($field) ne ""} {
            set initDir [file dirname $files($field)]
        } else {
            # Pick default dir from other files
            foreach other [lreverse $fields] {
                if {$other eq $field} continue
                puts $other
                if {$files($other) ne ""} {
                    set initDir [file dirname $files($other)]
                    puts $initDir
                    break
                }
            }
        }
        set apa [myOpenFile -title "Select file" -initialdir $initDir \
                         -parent $win]
        if {$apa != ""} {
            set files($field) $apa
        }
    }

    method doFourWayDiff {} {
        # Copy to local vars to be able to replace with defaults
        foreach field $fields {
            set filename($field) $files($field)
        }
        # Fill in defaults, if revisions are given for empty files
        foreach {from to} $fields {
            if {$filename($to) eq "" && $revs($to) ne ""} {
                set filename($to) $files($from)
            }
            if {$filename($from) eq "" && $revs($from) ne ""} {
                set filename($from) $files($to)
            }
        }
        parray filename
    }
}

proc makeFourWayWin {} {
    set t 1
    set top .fourway
    set top .fourway$t

    if {[winfo exists $top] && [winfo toplevel $top] eq $top} {
    while {[winfo exists $top]} {
        raise $top
        focus -force $top
        return $top
    }
    destroy $top
    toplevel $top -padx 3 -pady 3
    eskilRegisterToplevel $top

    wm title $top "Four Way Diff"
    wm protocol $top WM_DELETE_WINDOW "cleanupAndExit $top"

    menu $top.m
    $top configure -menu $top.m
    $top.m add cascade -menu $top.m.mf -label "File" -underline 0
    menu $top.m.mf
    $top.m.mf add command -label "Close" -underline 0 \
            -command [list cleanupAndExit $top]
    $top.m.mf add separator
    $top.m.mf add command -label "Quit" -underline 0 \
            -command [list cleanupAndExit all]

    # Four files, with optional revision
    set ::eskil(fw,fields) {base1 change1 base2 change2}
    
    ttk::label $top.l1 -text "Base 1"
    ttk::label $top.l2 -text "Changed 1"
    ttk::label $top.l3 -text "Base 2"
    ttk::label $top.l4 -text "Changed 2"
    set txt1 "First diff is made from Base 1 to Changed 1.\n If a file is empty\
              and have a revision, the other file name is used."
    addBalloon $top.l1 $txt1
    addBalloon $top.l2 $txt1
    set txt2 [string map {1 2 First Second} $txt1]
    addBalloon $top.l3 $txt2
    addBalloon $top.l4 $txt2

    ttk::label $top.el -text "File path"
    ttk::label $top.rl -text "Rev"
    addBalloon $top.rl "If you want to use a revisioned controlled file instead\n of\
                        the one on disk, add a revision here. E.g. 0 can be used\n for\
                        latest commited revision."

    set n 0
    foreach field $::eskil(fw,fields) {
        incr n
        incr t
        ttk::entryX $top.e$n -width 60 -textvariable ::eskil($top,$field)
        ttk::button $top.b$n -text "Browse" -command [list DoOpenFw $top $field]
        ttk::entryX $top.r$n -width 6 -textvariable ::eskil($top,rev,$field)
    }

        set top .fourway$t
    ttk::button $top.bd -text "Diff" -command "DoFourWayDiff $top" -underline 0 \
            -width 8
    bind $top <Alt-d> [list $top.bd invoke]

    }
    grid x       $top.el x       $top.rl -sticky w  -padx 3 -pady 3
    grid $top.l1 $top.e1 $top.b1 $top.r1 -sticky we -padx 3 -pady 3
    grid $top.l2 $top.e2 $top.b2 $top.r2 -sticky we -padx 3 -pady 3
    grid $top.l3 $top.e3 $top.b3 $top.r3 -sticky we -padx 3 -pady {10 3}
    grid $top.l4 $top.e4 $top.b4 $top.r4 -sticky we -padx 3 -pady 3
    grid $top.bd -       -                  -padx 3 -pady {10 3}

    # Set up file dropping in entry windows if TkDnd is available
    if {![catch {package require tkdnd}]} {
        dnd bindtarget $top    text/uri-list <Drop> "fileDropFw $top any     %D"
        dnd bindtarget $top.e1 text/uri-list <Drop> "fileDropFw $top base1   %D"
        dnd bindtarget $top.e2 text/uri-list <Drop> "fileDropFw $top change1 %D"
        dnd bindtarget $top.e3 text/uri-list <Drop> "fileDropFw $top base2   %D"
        dnd bindtarget $top.e4 text/uri-list <Drop> "fileDropFw $top change2 %D"
    }

    return $top
    FourWay $top
}