#!/afs/ece/usr/tcl/bin/wish -f

source "[file dirname [info script]]/../aux/teach.tcl"

# Help text.
set Help "" ; append Help {Historyth -- Extend Entries with History Menus

Perhaps you've encountered an entry you use often, but only give a handful of
values to, and you wish it would remember those values?

Historyth's duty is to give entries a 'memory', so you can save values you liked
in the entry to a menu. When you select those items in the menu, they reappear
in the entry. A '+' button allows you to add whatever's in the entry to the
menu. After hitting the 'Teach' button, you click on some remote widget, and
this program endows the remote widget(s) with these special features.


Widgets of Historyth

The Teach Button

Click on Teach to teach an entry widget. You can only teach one entry widget
at a time. After clicking on Teach, you may do one of two things.

1. Click on an entry widget, which will then bring up its own History menu and
'+' button, or

2. Click on a label that describes the entry (if there is one), then click on
the entry. The label will be replaced by the History menu and '+' button.

} $TH_Help {

Bugs / Limitations

None.
(I hope!)
}


set Potential_Menu ""
set Potential_App ""

# Extends the remote widget
proc extend_widget {x y b} {
  global Potential_Menu Potential_App
  if {![which_widget $x $y 1 app widget]} {toggle_grab ; th_beep ; return}
  set class [send $app winfo class $widget]
  if {$class != "Entry"} {
    set Potential_Menu $widget
    set Potential_App $app
  } else {
    if {($Potential_Menu != "") && ($app != $Potential_App)} {th_beep ; return}
    global TH_Dir
    include_files $app {history.tcl th_make_history_menu}
    do_cmd $app "th_make_history_menu $widget $Potential_Menu\n" 0 
    set Potential_Menu ""
    set Potential_App ""
    toggle_grab
}}


# These bindings only should take effect when historyth does a global grab.
bind all <Any-Button>				"extend_widget %X %Y %b"
