Bundle-PBib
view release on metacpan or search on metacpan
lib/PBibTk/SearchDialog.pm view on Meta::CPAN
my $list = $win->Scrolled('Listbox',
-scrollbars => 'se',
-width => $defwidth_list,
-height => $defheight_list,
)->form(
-t => ['%0', 0],
-l => ['%0', 0],
-r => ['%100', 0],
#-b => [$do, 0],
);
$self->{'resultList'} = $list;
$cmd = [$self, 'showSelectedBiblioReference'];
$list->bind('<Double-Button-1>' => $cmd);
$list->bind('<Return>' => $cmd);
$list->bind('<Button-1>' => [$self, 'updateExpandedSelectedReference']); #myline
# $win->bind('<Return>' => $cmd); ## don't open two windows ...
$list->bind('<Up>' => [$self, 'selectionMove', $list, -1]);
$list->bind('<Down>' => [$self, 'selectionMove', $list, 1]);
$list->bind('<Control-Home>' => [$self, 'selectionMove', $list, 0]);
$list->bind('<Control-End>' => [$self, 'selectionMove', $list, 'end']);
for( my $c = ord('a'); $c <= ord('z'); $c++ ) {
$win->bind(('<Key-' . chr($c) . '>') => [$self, 'keyPressed', Ev('A'), Ev('s')]);
$list->bind(('<Key-' . chr($c) . '>') => [$self, 'keyPressed', Ev('A'), Ev('s')]);
}
#myline runter ---------------------------------------------------
# chosen frame
my $do=$win->LabFrame(-label => 'choose a Ref', -labelside => "acrosstop")->form(
-t => [$list, 0],
-l => ['%0', 0],
-r => ['%100', 0],
-b =>['%100', 0],
);#pack(qw/-expand yes -fill x -side bottom/); #myline
$self->{'searchchosen'} = $do;
$list = $do->Scrolled('TextUndo',
-scrollbars => 'se',
-wrap => 'word',
-setgrid => 'true',
-exportselection => 'true',
-height => 6,
)->form(
-t => ['%0',0],
-l => ['%0',0],
-r => ['%100',0],
-b => ['%100', 0]);
$self->{'chosenfromlist'} = $list;
# my $b3=$do->Frame()->form(
# -t => [$list,0],
# -l => ['%0',0],
# -r => ['%100',0],
# -b => ['%100',0]);
# my $bf3 = $b3->Frame()->pack();
#myline hoch ---------------------------------------------------
}
#myline runter ---------------------------------------------------
sub updateExpandedSelectedReference {
my $self = shift;
my $paper = $self->selectedBiblioReference();
return if !defined($paper) || $paper eq "";
my @entry = PBibTk::RefDialog->new($self->pBibTkUI())->formatRefInfos($paper);
$self->chosenLabel()->configure(-label => $entry[0]);
my $list = $self->chosen();
$list->delete("0.0", "end");
$list->insert("end", $entry[1]);
$self->resultList()->focus();
}
sub selectedBiblioReference {
my $self = shift;
my $list = $self->resultList();
my $idx = $list->curselection();
return if !defined($idx) || $idx eq "";
my $paper = $self->{'results'}->[$idx];
return $paper;
# print Dumper $paper;
}
sub chosenLabel { my $self = shift; return $self->{'searchchosen'}; }
sub chosen {
my $self = shift;
# access window first, to ensure it's created.
$self->window();
return $self->{'chosenfromlist'};
}
#myline hoch ---------------------------------------------------
sub initMenu {
my ($self, $mf, $win) = @_;
$self->pBibTkUI()->initBiblioMenu($mf, $win, $self);
}
sub resultList { return shift->{'resultList'}; }
sub refList { return shift->resultList(); }
#
# menu command methods
#
sub keyPressed {
my ($self, $key, $mod) = @_;
return if $mod && $mod ne '';
my $list = $self->resultList();
my $idx = $self->indexOfRefStartingWith($key); ##ord($key) - ord('a');
print "keyPressed $key ($mod) --> $idx\n";
$list->selectionClear(0, 'end');
$list->see($idx);
$list->activate($idx);
$list->selectionAnchor($idx);
$list->selectionSet($idx);
}
sub selectionMove {
# called on UP and Down key presses to be able to adjust the printed ref.
my ($self, $list, $inc) = @_;
$self->updateExpandedSelectedReference();
}
sub showSelectedBiblioReference {
my $self = shift;
my $paper = $self->selectedBiblioReference();
return unless defined($paper);
PBibTk::RefDialog
->new($self->pBibTkUI(), $paper)
->show();
}
sub clipboardSelectedBiblioReferenceId {
my $self = shift;
my $paper = $self->selectedBiblioReference();
return unless defined($paper);
my $ref = $paper->{'CiteKey'};
Win32::Clipboard()->Set("[$ref]");
}
sub searchSelectedBiblioReferenceId {
my $self = shift;
my $paper = $self->selectedBiblioReference();
return unless defined($paper);
$self->pBibTkUI()->searchReferenceId($paper->{'CiteKey'});
}
sub queryAuthor { my $self = shift;
$self->pBibTkUI()->queryAuthor();
}
sub queryKeyword { my $self = shift;
$self->pBibTkUI()->queryKeyword();
}
sub updateBiblioRefs { my $self = shift;
$self->updateResults();
}
#
# updating
#
sub updateResults {
my $self = shift;
my $list = $self->resultList();
$list->delete(0, "end");
my $papers = $self->biblio()->queryPapers($self->pattern(),
$self->queryFields(), $self->resultFields());
$self->{'refs'} = $papers;
my ($ref, $id, @results);
my @refIDs = sort(keys %$papers);
foreach $id (@refIDs) {
$ref = $papers->{$id};
push @results, $ref;
my $key = $ref->{'CiteKey'} || '<<no CiteKey!?>>';
my $cat = $ref->{'Category'} || '<<no Category>>';
my $title = $ref->{'Title'} || '';
my $author = $ref->{'Authors'} || $ref->{'Editors'} || $ref->{'Organization'} || '';
my $recom = $ref->{'Recommendation'};
my $year = $ref->{'Year'} || '';
if( length($title) > $maxlength_title )
{ $title = substr($title, 0, $maxlength_title) . ' ...' }
if( $author ) {
if( length($author) > $maxlength_author )
{ $author = substr($author, 0, $maxlength_author) . ' ...' }
if( $year )
{ $author .= ', '; }
}
my $text = $key . ($recom ? " ($recom)" : '') . " \"$title\" ($author$year) [$cat]";
$list->insert("end", $text);
}
$self->{'results'} = \@results;
$self->window()->configure(
-title => $self->title() . ' (' . scalar(@results) . ' found)',
);
my $height = $list->height();
if( scalar @results > $height ) {
# enlarge window
$height = scalar @results;
$height = $maxheight_list if $height > $maxheight_list;
$list->configure(-height => $height);
}
}
sub indexOfRefStartingWith {
my ($self, $char) = @_;
return undef unless defined($char);
my $refs = $self->{'results'};
my $idx = 0;
for( ; $idx < scalar(@$refs); $idx++ ) {
my $key = $refs->[$idx]->{'CiteKey'};
# print ord(lc($char)), ' ', ord(lc(substr($key, 0, 1))), " $idx - $key";
last if( ord(lc($char)) <= ord(lc(substr($key, 0, 1))) );
}
return $idx;
}
1;
#
# $Log: LitUI::SearchDialog.pm,v $
# Revision 1.15 2004/03/30 19:20:10 krugar
( run in 0.912 second using v1.01-cache-2.11-cpan-39bf76dae61 )