Fossil SCM
Add a simple "Search" button to the --tk diff widget.
Commit
cea60811508f85af03b462695049b2a53fc1d289
Parent
59bf47b2d5b0ed3…
1 file changed
+57
-1
+57
-1
| --- src/diff.tcl | ||
| +++ src/diff.tcl | ||
| @@ -372,17 +372,73 @@ | ||
| 372 | 372 | set clt [.mkr search -all < 1.0 end] |
| 373 | 373 | set cgt [.mkr search -all > 1.0 end] |
| 374 | 374 | foreach c $clt {.mkr replace $c "$c +1 chars" >} |
| 375 | 375 | foreach c $cgt {.mkr replace $c "$c +1 chars" <} |
| 376 | 376 | .mkr config -state disabled |
| 377 | +} | |
| 378 | +proc searchOnOff {} { | |
| 379 | + if {[info exists ::search]} { | |
| 380 | + unset ::search | |
| 381 | + .txtA tag remove search 1.0 end | |
| 382 | + .txtB tag remove search 1.0 end | |
| 383 | + pack forget .bb.sframe | |
| 384 | + } else { | |
| 385 | + set ::search .txtA | |
| 386 | + if {![winfo exists .bb.sframe]} { | |
| 387 | + frame .bb.sframe | |
| 388 | + ::ttk::entry .bb.sframe.e -width 10 | |
| 389 | + pack .bb.sframe.e -side left -fill y -expand 1 | |
| 390 | + ::ttk::button .bb.sframe.nx -text \u2193 -width 1 \ | |
| 391 | + -command {searchNext -forwards +1 1.0 end} | |
| 392 | + ::ttk::button .bb.sframe.pv -text \u2191 -width 1 \ | |
| 393 | + -command {searchNext -backwards -1 end 1.0} | |
| 394 | + pack .bb.sframe.nx .bb.sframe.pv -side left | |
| 395 | + } | |
| 396 | + pack .bb.sframe -side left | |
| 397 | + } | |
| 398 | +} | |
| 399 | +proc searchNext {direction incr start stop} { | |
| 400 | + set pattern [.bb.sframe.e get] | |
| 401 | + set count 0 | |
| 402 | + set w $::search | |
| 403 | + if {"$w"==".txtA"} {set other .txtB} {set other .txtA} | |
| 404 | + if {[lsearch [$w mark names] search]<0} { | |
| 405 | + $w mark set search $start | |
| 406 | + } | |
| 407 | + set idx [$w search -count count $direction -- \ | |
| 408 | + $pattern "search $incr chars" $stop] | |
| 409 | + if {"$idx"==""} { | |
| 410 | + set this $w | |
| 411 | + set w $other | |
| 412 | + set other $this | |
| 413 | + set idx [$w search -count count $direction -- $pattern $start $stop] | |
| 414 | + if {"$idx"==""} { | |
| 415 | + set this $w | |
| 416 | + set w $other | |
| 417 | + set other $this | |
| 418 | + set idx [$w search -count count $direction -- $pattern $start $stop] | |
| 419 | + } | |
| 420 | + } | |
| 421 | + $w tag remove search 1.0 end | |
| 422 | + $w mark unset search | |
| 423 | + $other tag remove search 1.0 end | |
| 424 | + $other mark unset search | |
| 425 | + if {"$idx"!=""} { | |
| 426 | + $w mark set search $idx | |
| 427 | + $w yview -pickplace $idx | |
| 428 | + $w tag add search search "$idx +$count chars" | |
| 429 | + $w tag config search -background {#fcc000} | |
| 430 | + } | |
| 431 | + set ::search $w | |
| 377 | 432 | } |
| 378 | 433 | ::ttk::button .bb.quit -text {Quit} -command exit |
| 379 | 434 | ::ttk::button .bb.invert -text {Invert} -command invertDiff |
| 380 | 435 | ::ttk::button .bb.save -text {Save As...} -command saveDiff |
| 436 | +::ttk::button .bb.search -text {Search} -command searchOnOff | |
| 381 | 437 | pack .bb.quit .bb.invert -side left |
| 382 | 438 | if {$fossilcmd!=""} {pack .bb.save -side left} |
| 383 | -pack .bb.files -side left | |
| 439 | +pack .bb.files .bb.search -side left | |
| 384 | 440 | grid rowconfigure . 1 -weight 1 |
| 385 | 441 | grid columnconfigure . 1 -weight 1 |
| 386 | 442 | grid columnconfigure . 4 -weight 1 |
| 387 | 443 | grid .bb -row 0 -columnspan 6 |
| 388 | 444 | eval grid [cols] -row 1 -sticky nsew |
| 389 | 445 |
| --- src/diff.tcl | |
| +++ src/diff.tcl | |
| @@ -372,17 +372,73 @@ | |
| 372 | set clt [.mkr search -all < 1.0 end] |
| 373 | set cgt [.mkr search -all > 1.0 end] |
| 374 | foreach c $clt {.mkr replace $c "$c +1 chars" >} |
| 375 | foreach c $cgt {.mkr replace $c "$c +1 chars" <} |
| 376 | .mkr config -state disabled |
| 377 | } |
| 378 | ::ttk::button .bb.quit -text {Quit} -command exit |
| 379 | ::ttk::button .bb.invert -text {Invert} -command invertDiff |
| 380 | ::ttk::button .bb.save -text {Save As...} -command saveDiff |
| 381 | pack .bb.quit .bb.invert -side left |
| 382 | if {$fossilcmd!=""} {pack .bb.save -side left} |
| 383 | pack .bb.files -side left |
| 384 | grid rowconfigure . 1 -weight 1 |
| 385 | grid columnconfigure . 1 -weight 1 |
| 386 | grid columnconfigure . 4 -weight 1 |
| 387 | grid .bb -row 0 -columnspan 6 |
| 388 | eval grid [cols] -row 1 -sticky nsew |
| 389 |
| --- src/diff.tcl | |
| +++ src/diff.tcl | |
| @@ -372,17 +372,73 @@ | |
| 372 | set clt [.mkr search -all < 1.0 end] |
| 373 | set cgt [.mkr search -all > 1.0 end] |
| 374 | foreach c $clt {.mkr replace $c "$c +1 chars" >} |
| 375 | foreach c $cgt {.mkr replace $c "$c +1 chars" <} |
| 376 | .mkr config -state disabled |
| 377 | } |
| 378 | proc searchOnOff {} { |
| 379 | if {[info exists ::search]} { |
| 380 | unset ::search |
| 381 | .txtA tag remove search 1.0 end |
| 382 | .txtB tag remove search 1.0 end |
| 383 | pack forget .bb.sframe |
| 384 | } else { |
| 385 | set ::search .txtA |
| 386 | if {![winfo exists .bb.sframe]} { |
| 387 | frame .bb.sframe |
| 388 | ::ttk::entry .bb.sframe.e -width 10 |
| 389 | pack .bb.sframe.e -side left -fill y -expand 1 |
| 390 | ::ttk::button .bb.sframe.nx -text \u2193 -width 1 \ |
| 391 | -command {searchNext -forwards +1 1.0 end} |
| 392 | ::ttk::button .bb.sframe.pv -text \u2191 -width 1 \ |
| 393 | -command {searchNext -backwards -1 end 1.0} |
| 394 | pack .bb.sframe.nx .bb.sframe.pv -side left |
| 395 | } |
| 396 | pack .bb.sframe -side left |
| 397 | } |
| 398 | } |
| 399 | proc searchNext {direction incr start stop} { |
| 400 | set pattern [.bb.sframe.e get] |
| 401 | set count 0 |
| 402 | set w $::search |
| 403 | if {"$w"==".txtA"} {set other .txtB} {set other .txtA} |
| 404 | if {[lsearch [$w mark names] search]<0} { |
| 405 | $w mark set search $start |
| 406 | } |
| 407 | set idx [$w search -count count $direction -- \ |
| 408 | $pattern "search $incr chars" $stop] |
| 409 | if {"$idx"==""} { |
| 410 | set this $w |
| 411 | set w $other |
| 412 | set other $this |
| 413 | set idx [$w search -count count $direction -- $pattern $start $stop] |
| 414 | if {"$idx"==""} { |
| 415 | set this $w |
| 416 | set w $other |
| 417 | set other $this |
| 418 | set idx [$w search -count count $direction -- $pattern $start $stop] |
| 419 | } |
| 420 | } |
| 421 | $w tag remove search 1.0 end |
| 422 | $w mark unset search |
| 423 | $other tag remove search 1.0 end |
| 424 | $other mark unset search |
| 425 | if {"$idx"!=""} { |
| 426 | $w mark set search $idx |
| 427 | $w yview -pickplace $idx |
| 428 | $w tag add search search "$idx +$count chars" |
| 429 | $w tag config search -background {#fcc000} |
| 430 | } |
| 431 | set ::search $w |
| 432 | } |
| 433 | ::ttk::button .bb.quit -text {Quit} -command exit |
| 434 | ::ttk::button .bb.invert -text {Invert} -command invertDiff |
| 435 | ::ttk::button .bb.save -text {Save As...} -command saveDiff |
| 436 | ::ttk::button .bb.search -text {Search} -command searchOnOff |
| 437 | pack .bb.quit .bb.invert -side left |
| 438 | if {$fossilcmd!=""} {pack .bb.save -side left} |
| 439 | pack .bb.files .bb.search -side left |
| 440 | grid rowconfigure . 1 -weight 1 |
| 441 | grid columnconfigure . 1 -weight 1 |
| 442 | grid columnconfigure . 4 -weight 1 |
| 443 | grid .bb -row 0 -columnspan 6 |
| 444 | eval grid [cols] -row 1 -sticky nsew |
| 445 |