1
package Tk::Pod::Search;
4
use vars qw(@ISA $VERSION);
6
$VERSION = sprintf("%d.%02d", q$Revision: 5.3 $ =~ /(\d+)\.(\d+)/);
11
Construct Tk::Widget 'PodSearch';
14
my $searchfull_history;
21
require Tk::HistEntry;
25
require Tk::BrowseEntry;
26
$Entry = "BrowseEntry";
29
my $l = $cw->Scrolled('Listbox',-width=>40,-scrollbars=>$Tk::platform eq 'MSWin32'?'e':'w');
30
#xxx BrowseEntry V1.3 does not honour -label at creation time :-(
31
#my $e = $cw->BrowseEntry(-labelPack=>[-side=>'left'],-label=>'foo',
32
#-listcmd=> ['_logit', 'list'],
33
#-browsecmd=> ['_logit', 'browse'],
37
if ($e->can('history') && $searchfull_history) {
38
$e->history($searchfull_history);
42
$l->pack(-fill=>'both', -side=>'top', -expand=>1);
43
$f->pack(-fill => "x", -side => "top");
44
$s->pack(-anchor => 'e', -side=>'left');
45
$e->pack(-fill=>'x', -side=>'left', -expand=>1);
47
my $current_path = delete $args->{-currentpath};
48
$cw->{RestrictPod} = undef;
50
if (defined $current_path && $current_path ne "") {
51
$cb = $cw->Checkbutton(-variable => \$cw->{RestrictPod},
52
-text => "Restrict to $current_path",
54
-onvalue => $current_path,
61
$cw->Advertise( 'entry' => $e->Subwidget('entry') );
62
$cw->Advertise( 'listbox' => $l->Subwidget('listbox') );
63
$cw->Advertise( 'browse' => $e);
64
$cw->Advertise( 'restrict' => $cb) if $cb;
67
'focus' => $cw->Subwidget('entry'),
71
-label => [{-text=>$s}, 'label', 'Label', 'Search:'],
72
-indexdir => ['PASSIVE', 'indexDir', 'IndexDir', undef],
73
-command => ['CALLBACK', undef, undef, undef],
74
-search => ['METHOD', 'search', 'Search', ""],
78
foreach (qw/Return space 1/) {
79
$cw->Subwidget('listbox')->bind("<$_>", [\&_load_pod, $cw]);
81
$cw->Subwidget('entry')->bind('<Return>',[\&_search,$cw,$l]);
89
my $entry_or_browse = $w->Subwidget('browse');
90
if ($entry_or_browse->can('historyAdd')) {
91
$entry_or_browse->historyAdd($obj);
92
$searchfull_history = [ $entry_or_browse->history ];
94
$entry_or_browse->insert(0,$obj);
98
sub _logit { print "logit=|", join('|',@_),"|\n"; }
102
my $e = $cw->Subwidget('entry');
105
$search = join(' ', @$search) if ref($search) eq 'ARRAY';
107
$e->insert(0,$search);
118
my $pod = pretty2path( $l->get(($l->curselection)[0]));
120
$cw->Callback('-command', $pod, -searchterm => $cw->search());
130
$w->addHistory($find) if $find ne '';
133
if ($w->{RestrictPod}) {
134
$args{-restrictpod} = $w->{RestrictPod};
137
#xxx: always open/close DBM files???
140
require Tk::Pod::Search_db;
141
$idx = Tk::Pod::Search_db->new($w->{Configure}{-indexdir});
144
$e->messageBox(-icon => 'error',
145
-title => 'perlindex error',
147
Can't create Tk::Pod::Search_db object:
148
Is perlindex installed and did you run
153
my @hits = $idx->searchWords($find, %args);
157
$l->insert('end', sprintf("%6.3f %s", shift @hits,
158
path2pretty($idx->prefix . '/'. shift(@hits)) )
166
my $msg = "No Pod documentation in Library matches: '$find'";
167
$e->messageBox(-icon => "error",
168
-title => "No match",
174
# Converts /where/ever/it/it/Mod/Sub/Name.pm
175
# to Mod/Sub/Name.pm (/where/ever/it/is)
176
# and vice versa. Assumes that module subdirectories
177
# start with an upper case char. (xxx: Better solution
178
# when perlindex gives more infos.
181
my @path = split '/', shift, -1;
182
# shift @path if $path[0] eq ""; # due to leading /
183
my $pretty = pop(@path);
185
last if $path[-1] !~ /^[A-Z]/;
186
$pretty = pop(@path) . '/' . $pretty;
188
#xxx is there a min 40c_or_more format directive?
189
sprintf "%-40s (%s)", $pretty, join('/',@path);
194
/([^\s]+) \s+\( (.*) \)/x;
198
#$path = '/where/ever/it/is/Tk/Pod.pm'; print "orig|",$path, "|\n";
199
#$nice = path2pretty $path; print "nice|",$nice, "|\n";
200
#$path = pretty2path $nice; print "path|",$path, "|\n";
208
Tk::Pod::Search - Widget to access perlindex Pod full text index
210
=for section General Purpose Widget
216
$widget = $parent->PodSearch( ... );
218
$widget->configure( -search => WORDS_TO_SEARCH );
223
GUI interface to the full Pod text indexer B<perlindex>.
229
=item B<Class:> Search
231
=item B<Member:> search
233
=item B<Option:> -search
235
Expects a list of words (or a whitespace seperated list).
237
=item B<Class:> undef
239
=item B<Member:> undef
241
=item B<Option:> -command
243
Defines a call back that is called when the use selects
244
a Pod file. It gets the full path name of the Pod file
254
=item I<$widget>->B<method1>I<(...,?...?)>
261
Tk::Pod::Text, tkpod, perlindex, Tk::Pod, Tk::Pod::Search_db
265
widget, tk, pod, search, full text
269
Achim Bohnet <F<ach@mpe.mpg.de>>
271
Current maintainer is Slaven Rezic <F<slaven@rezic.de>>.
273
Copyright (c) 1997-1998 Achim Bohnet. All rights reserved. This program
274
is free software; you can redistribute it and/or modify it under the same
275
terms as Perl itself.