package Tk::HistEntry; use vars qw($VERSION); $VERSION = '0.001'; use base qw(Tk::Frame); use Tk::widgets qw(Frame Entry); Construct Tk::Widget 'HistEntry'; sub Populate { require Tk::Entry; # HistEntry constructor. # my($cw, $args) = @_; $cw->SUPER::Populate($args); # Advertised subwidgets: entry. my $e = $cw->Entry(); $e->pack('-expand' => 1, '-fill' => 'both'); $cw->Advertise('entry' => $e ); $cw->ConfigSpecs(DEFAULT => [$e]); $cw->Delegates(DEFAULT => $e); $cw->AddScrollbars($e) if (exists $args->{-scrollbars}); $e->{history} = { hlist => [], place => 0, }; $e->bind(""=> [ \&addHistory ]); $e->bind("" => [ \&upHistory ]); $e->bind("" => [ \&downHistory ]); } sub addHistory { my $entry = shift; my $hist = $entry->{history}; push @{$hist->{hlist}}, $entry->get() ; $hist->{place}++; } sub upHistory { my $entry = shift; my $hist = $entry->{history}; if ($hist->{place} <= 0) { $hist->{place} = $#{$hist->{hlist}} } else { $hist->{place}--; } $entry->delete('0','end'); $entry->insert('1',$hist->{hlist}[$hist->{place}]); } sub downHistory { my $entry = shift; my $hist = $entry->{history}; $entry->delete('0','end'); if ($hist->{place} == $#{$hist->{hlist}}) { $hist->{place} = -1; return } $hist->{place}++; $entry->insert('1',$hist->{hlist}[$hist->{place}]); } 1;