
# The following lines add a search function to the tkcon window
# We are using the textSearch from the filerunner library (only if it is available)

# If we have done this already, don't do anything.
if {1 || ![info exists ::tkcon::configSearchStrings]} {
  # frputs
  # first, force 'auto_load' to auto_index all known tclIndex files
  catch {AridiculousAndDumbProcName}

  if {[info exists ::auto_index(textSearch)]} {
    # here we fetch saved search strings...
    catch {
      source $::env(HOME)/.tkcon_SearchStrings
    } duh
    # frputs duh
    # if we did not get any, init to nil
    if {![info exists ::tkcon::configSearchStrings]} {
      set ::tkcon::configSearchStrings {}
    }
    # When they change, write the new ones to the disk
    trace add variable ::tkcon::configSearchStrings write ::tkcon::writeSearchStrings
    # We put the write routine in tkcons namespace to not mess with
    # other code...
    namespace eval ::tkcon {
      # this is very simple...
      proc writeSearchStrings {args} {
	catch {
	  set fid [open $::env(HOME)/.tkcon_SearchStrings w]
	  puts $fid "set ::tkcon::configSearchStrings [list $::tkcon::configSearchStrings]"
	  close $fid
	} duh
	# puts "$duh really $duh"
      }
    }
    # define the config value for the 'textSearch' code
    set ::tkcon::config [list values ::tkcon::configSearchStrings\
			     -bg  $::tkcon::COLOR(bg)\
			    ]
    # set up the old <3> option so it is still available, albeit one level down
    set old3 [string trim [bind .tkcon <<TkCon_Popup>>]]
    set old3 [regsub {%X} $old3 {[winfo pointerx .tkcon.tab1]}]
    set old3 [regsub {%Y} $old3 {[winfo pointery .tkcon.tab1]}]
    # after a bit, attach to the tkcon text window
    # Log "Adding  [list textSearch .tkcon.tab1 Tkcon ::tkcon::config {} ]"
    # we need to dum the location lib if not defined...
    if {[info proc ::_] == {}} {
      proc ::_ {str args} {format $str {*}$args}
    }
    textSearch .tkcon.tab1 Tkcon ::tkcon::config {} [list "old<3>" $old3]
    # now eliminate confusion around what button <3> does.. 
    event delete <<TkCon_Popup>> <Button-3>
  } else {
    # Log "textSearch not found in auto_index"
  }

  # if we have frputs, lets exclude 'us' from the reports...
  if {[info exists ::auto_index(frputsOps)]} {
    #frputsOps ~proc *tkcon*
  }
}  
