NAME

Tk::HistEntry - Entry widget with history capability

SYNOPSIS

use Tk::HistEntry;

$hist1 = $top->HistEntry(-textvariable => \$var1);
$hist2 = $top->SimpleHistEntry(-textvariable => \$var2);

DESCRIPTION

Tk::HistEntry defines entry widgets with history capabilities. The widgets come in two flavours:

HistEntry (in package Tk::HistEntry::Browse) - with associated browse entry
SimpleHistEntry (in package Tk::HistEntry::Simple) - plain widget without browse entry

The user may browse with the Up and Down keys through the history list. New history entries may be added either manually by binding the Return key to historyAdd() or automatically by setting the -command option.

OPTIONS

HistEntry is an descendant of BrowseEntry and thus supports all of its standard options.

SimpleHistEntry is an descendant of Entry and supports all of the Entry options.

In addition, the widgets support following specific options:

-textvariable or -variable

Variable which is tied to the HistEntry widget. Either -textvariable (like in Entry) or -variable (like in BrowseEntry) may be used.

-command

Specifies a callback, which is executed when the Return key was pressed or the invoke method is called. The callback reveives three arguments: the reference to the HistEntry widget, the current textvariable value and a boolean value, which tells whether the string was added to the history list (e.g. duplicates and empty values are not added to the history list).

-dup

Specifies whether duplicate entries are allowed in the history list. Defaults to true.

-bell

If set to true, rings the bell if the user tries to move off of the history or if a search was not successful. Defaults to true.

-limit

Limits the number of history entries. Defaults to unlimited.

METHODS

historyAdd([string])

Adds string (or the current textvariable value if not set) manually to the history list.

invoke([string])

Invokes the command.

history([arrayref])

Without argument, gets the current history list. With argument (a reference to an array), replaces the history list.

KEY BINDINGS

Up, Control-p

Selects the previous history entry.

Down, Control-n

Selects the next history entry.

Control-r

The current content of the widget is searched backward in the history.

Control-s

The current content of the widget is searched forward in the history.

Return

If -command is set, adds current content to the history list and executes the associated callback.

EXAMPLE

use Tk;
use Tk::HistEntry;

$top = new MainWindow;
$he = $top->HistEntry(-textvariable => \$foo,
                      -command => sub {
                          # automatically adds $foo to history
                          print STDERR "Do something with $foo\n";
                      })->pack;
$b = $top->Button(-text => 'Do it',
                  -command => sub { $he->invoke })->pack;
MainLoop;

BUGS/TODO

- C-s/C-r do not work as nice as in gnu readline
- use -browsecmd from Tk::BrowseEntry

AUTHOR

Slaven Rezic <eserte@cs.tu-berlin.de>

COPYRIGHT

Copyright (c) 1997 Slaven Rezic. All rights reserved. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.