Eskil

Check-in [16633c04b0]
Login

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

Overview
Comment:Rewrote fourway to snit widget
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 16633c04b0bc2539a77c98f21343ef74dd8e61a853f870d30ce7adbe4890c568
User & Date: peter 2018-05-12 20:17:03.308
Context
2018-05-12
22:22
Fixed bug in Fossil handling. Rev -1 did not work. check-in: f6025faa97 user: peter tags: trunk
20:17
Rewrote fourway to snit widget check-in: 16633c04b0 user: peter tags: trunk
19:49
Base design of fourway dialog check-in: 272dbc6a54 user: peter tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/eskil.syntax.
111
112
113
114
115
116
117










##nagelfar syntax ttk::entryX dc=_obj,entryX p*
##nagelfar option ttk::entryX -width -textvariable -style
##nagelfar option ttk::entryX\ -textvariable n
##nagelfar return ttk::entryX _obj,entryX
##nagelfar subcmd+ _obj,entryX text newLine

##nagelfar implicitvarns snit::widgetadaptor::ttk::entryX self\ _obj,entryX hull win self  options

















>
>
>
>
>
>
>
>
>
>
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
##nagelfar syntax ttk::entryX dc=_obj,entryX p*
##nagelfar option ttk::entryX -width -textvariable -style
##nagelfar option ttk::entryX\ -textvariable n
##nagelfar return ttk::entryX _obj,entryX
##nagelfar subcmd+ _obj,entryX text newLine

##nagelfar implicitvarns snit::widgetadaptor::ttk::entryX self\ _obj,entryX hull win self  options

# This is the annotation needed for this object definition

##nagelfar syntax FourWay dc=_obj,FourWay p*
###nagelfar option FourWay
##nagelfar return FourWay _obj,FourWay
###nagelfar subcmd+ _obj,FourWay text newLine

##nagelfar implicitvarns snit::widget::FourWay self\ _obj,FourWay fields files revs win hull

Changes to src/fourway.tcl.
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
#  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
#  Boston, MA 02111-1307, USA.
#
#----------------------------------------------------------------------
# $Revision$
#----------------------------------------------------------------------


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)
    }
    # 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





}






# Browse for file
proc DoOpenFw {top field} {
    upvar \#0 ::eskil($top,$field) filename
    set initDir [pwd]
    if {$filename ne ""} {
        set initDir [file dirname $filename]
    } else {
        # Pick default dir from other files
        foreach other [lreverse $::eskil(fw,fields)] {
            if {$other eq $field} continue
            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]
    if {$apa != ""} {
        set filename $apa
    }
}













# 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
        }










































    }
}

proc makeFourWayWin {} {

    set top .fourway

    if {[winfo exists $top] && [winfo toplevel $top] eq $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
        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)
    }

    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
}







>
|
|
>
|
|
|
|
<
<
|
|
|
|
>
>
|
>
>
>
>
>
>
>
>
>
|
>
>
|
>
>
>
>
>
|
>
>
>
>
>
|
>
>
>
>
>

<
<
<
|
|
<
|
|
|
|
<
<
<
<
<
|
|
>
>
>
|
>
>
|
|
<
<
<
<
>
>

>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




>
|
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
|
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|

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
snit::widget FourWay {
    hulltype toplevel
    widgetclass Toplevel
    variable fields
    variable files
    variable revs



    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."




        set n 0
        foreach field $fields {

            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)]





        }

        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}




        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
    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$t

    while {[winfo exists $top]} {












































        incr t




        set top .fourway$t



    }
















    FourWay $top
}