2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
|
}
}
if {[llength $::diff($top,aligns)] == 0} {
disableAlign $top
}
}
# Mark a line as aligned.
proc markAlign {top n line text} {
set ::diff($top,align$n) $line
set ::diff($top,aligntext$n) $text
if {[info exists ::diff($top,align1)] && [info exists ::diff($top,align2)]} {
set level 2
if {![string equal $::diff($top,aligntext1) $::diff($top,aligntext2)]} {
set apa [tk_messageBox -icon question -title "Align" -type yesno \
-message "Those lines are not equal.\nReally align them?"]
if {$apa != "yes"} {
return
}
set level 3
}
lappend ::diff($top,aligns) $::diff($top,align1) $::diff($top,align2)
enableAlign $top
unset ::diff($top,align1)
unset ::diff($top,align2)
unset ::diff($top,aligntext1)
unset ::diff($top,aligntext2)
}
}
# Called by popup menus over row numbers to add command for alignment.
# Returns 1 if nothing was added.
proc alignMenu {m top n x y} {
# Get the row that was clicked
set w $::widgets($top,wLine$n)
set index [$w index @$x,$y]
set row [lindex [split $index "."] 0]
set data [$w get $row.0 $row.end]
if {![regexp {\d+} $data line]} {
return 1
}
set text [$::widgets($top,wDiff$n) get $row.0 $row.end]
set other [expr {$n == 1 ? 2 : 1}]
set cmd [list markAlign $top $n $line $text]
|
>
>
>
>
>
>
>
<
|
<
|
|
<
<
>
>
|
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
|
}
}
if {[llength $::diff($top,aligns)] == 0} {
disableAlign $top
}
}
proc NoMarkAlign {top} {
unset -nocomplain ::diff($top,align1)
unset -nocomplain ::diff($top,align2)
unset -nocomplain ::diff($top,aligntext1)
unset -nocomplain ::diff($top,aligntext2)
}
# Mark a line as aligned.
proc markAlign {top n line text} {
set ::diff($top,align$n) $line
set ::diff($top,aligntext$n) $text
if {[info exists ::diff($top,align1)] && [info exists ::diff($top,align2)]} {
if {![string equal $::diff($top,aligntext1) $::diff($top,aligntext2)]} {
set apa [tk_messageBox -icon question -title "Align" -type yesno \
-message "Those lines are not equal.\nReally align them?"]
if {$apa != "yes"} {
return 0
}
}
lappend ::diff($top,aligns) $::diff($top,align1) $::diff($top,align2)
enableAlign $top
NoMarkAlign $top
return 1
}
return 0
}
# Called by popup menus over row numbers to add command for alignment.
# Returns 1 if nothing was added.
proc alignMenu {m top n x y} {
# Get the row that was clicked
set w $::widgets($top,wLine$n)
set index [$w index @$x,$y]
set row [lindex [split $index "."] 0]
set data [$w get $row.0 $row.end]
# Must be a line number
if {![regexp {\d+} $data line]} {
return 1
}
set text [$::widgets($top,wDiff$n) get $row.0 $row.end]
set other [expr {$n == 1 ? 2 : 1}]
set cmd [list markAlign $top $n $line $text]
|
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
|
}
}
$m add command -label $label -command $cmd
return 0
}
###################
# Diff highlighting
###################
proc hlSelect {top hl} {
highLightChange $top $hl
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
|
}
}
$m add command -label $label -command $cmd
return 0
}
# Set up bindings to allow setting alignment using drag
proc SetupAlignDrag {top left right} {
bind $left <ButtonPress-1> [list startAlignDrag $top 1 %x %y %X %Y]\;break
bind $left <B1-Motion> [list motionAlignDrag $top 1 0 %x %y %X %Y]\;break
bind $left <Shift-B1-Motion> [list motionAlignDrag $top 1 1 %x %y %X %Y]\;break
bind $left <ButtonRelease-1> [list endAlignDrag $top 1 %x %y %X %Y]\;break
bind $left <B1-Leave> break
bind $right <ButtonPress-1> [list startAlignDrag $top 2 %x %y %X %Y]\;break
bind $right <B1-Motion> [list motionAlignDrag $top 2 0 %x %y %X %Y]\;break
bind $right <Shift-B1-Motion> [list motionAlignDrag $top 2 1 %x %y %X %Y]\;break
bind $right <ButtonRelease-1> [list endAlignDrag $top 2 %x %y %X %Y]\;break
bind $right <B1-Leave> break
}
# Button has been pressed over line window
proc startAlignDrag {top n x y X Y} {
# Get the row that was clicked
set w $::widgets($top,wLine$n)
set index [$w index @$x,$y]
set row [lindex [split $index "."] 0]
set data [$w get $row.0 $row.end]
set ::diff($top,alignDrag,state) none
# Must be a line number
if {![regexp {\d+} $data line]} {
return 1
}
# Set up information about start of drag
set text [$::widgets($top,wDiff$n) get $row.0 $row.end]
set other [expr {$n == 1 ? 2 : 1}]
set ::diff($top,alignDrag,X) $X
set ::diff($top,alignDrag,Y) $Y
set ::diff($top,alignDrag,from) $n
set ::diff($top,alignDrag,line$n) $line
set ::diff($top,alignDrag,text$n) $text
set ::diff($top,alignDrag,line$other) "?"
set ::diff($top,alignDrag,state) press
}
# Mouse moves with button down
proc motionAlignDrag {top n shift x y X Y} {
if {$::diff($top,alignDrag,state) eq "press"} {
# Have we moved enough to call it dragging?
set dX [expr {abs($X - $::diff($top,alignDrag,X))}]
set dY [expr {abs($Y - $::diff($top,alignDrag,Y))}]
if {$dX + $dY > 3} {
# Start a drag action
set w $top.alignDrag
destroy $w
toplevel $w
wm overrideredirect $w 1
label $w.l -borderwidth 1 -relief solid -justify left
pack $w.l
set ::diff($top,alignDrag,W) $w
set ::diff($top,alignDrag,state) "drag"
}
}
if {$::diff($top,alignDrag,state) eq "drag"} {
set w $::diff($top,alignDrag,W)
# Move drag label with cursor
wm geometry $w +[expr {$X + 1}]+[expr {$Y + 1}]
set n $::diff($top,alignDrag,from)
set other [expr {$n == 1 ? 2 : 1}]
set w2 $::widgets($top,wLine$other)
# Are we over the other line window?
if {[winfo containing $X $Y] eq $w2} {
set x [expr {$X - [winfo rootx $w2]}]
set y [expr {$Y - [winfo rooty $w2]}]
set index [$w2 index @$x,$y]
set row [lindex [split $index "."] 0]
set data [$w2 get $row.0 $row.end]
if {![regexp {\d+} $data line]} {
set ::diff($top,alignDrag,line$other) "?"
} else {
set ::diff($top,alignDrag,line$other) $line
set text [$::widgets($top,wDiff$other) get $row.0 $row.end]
set ::diff($top,alignDrag,text$other) $text
}
} else {
set ::diff($top,alignDrag,line$other) "?"
}
set txt "Align Left $::diff($top,alignDrag,line1)"
append txt "\nwith Right $::diff($top,alignDrag,line2)"
set ::diff($top,alignDrag,shift) $shift
if {$shift} {
append txt "\nAnd Redo Diff"
}
$w.l configure -text $txt
}
}
# Button has been released
proc endAlignDrag {top n x y X Y} {
if {$::diff($top,alignDrag,state) eq "drag"} {
destroy $::diff($top,alignDrag,W)
# Are both line numbers valid? I.e. is this a full align operation?
if {$::diff($top,alignDrag,line1) ne "?" && \
$::diff($top,alignDrag,line2) ne "?"} {
NoMarkAlign $top
markAlign $top 1 $::diff($top,alignDrag,line1) \
$::diff($top,alignDrag,text1)
set marked [markAlign $top 2 $::diff($top,alignDrag,line2) \
$::diff($top,alignDrag,text2)]
if {$::diff($top,alignDrag,shift) && $marked} {
redoDiff $top
}
}
}
set ::diff($top,alignDrag,state) none
}
###################
# Diff highlighting
###################
proc hlSelect {top hl} {
highLightChange $top $hl
|