#
# Code for doing query or global replacements in Entry widgets
#

# Called when the first replace is requested.
proc th_Entry_replace_setup {w} {
  global auto_index
  set f [th_frame $w]
  if {([info procs th_Entry_register_undoable_cmd] != "") || \
     ([lsearch [array names auto_index] th_Entry_register_undoable_cmd] >= 0)} {
    th_Entry_register_undoable_cmd $w "Replace [$f.search.e get] with [$f.replace.e get]"
}}

# Does one replacement.
proc th_Entry_replace_one {w} {
  global TH auto_index
  set search $TH(Search,Select,[winfo class $w])
  set new_string [[th_frame $w].replace.e get]

  if {[catch "$w index sel.first" start]} {return}
  $w delete sel.first sel.last
  $w insert $start $new_string ; incr TH(Replace,Count,$w)
  set TH(Modified,$w) 1
}
