Bundle-PBib

 view release on metacpan or  search on metacpan

lib/PBibTk/SearchDialog.pm  view on Meta::CPAN

    'pattern' => $pattern,
  };
  return bless $dialog, $class;
}

sub show {
  my $self = shift;
  $self->window()->focus();
}

#
# access methods
#

sub window {
  my $self = shift;
  my $win = $self->{'window'};
  return $win if defined($win);
  
  my $ui = $self->pBibTkUI();
  my $title = $self->{'title'};
  $win = $ui->rootWindow()->Toplevel();
  $win->configure(
	-title => $self->title(),
	-width => 700,
	-height => 600,
	);
  $self->{'window'} = $win;
  $self->initWidgets($win);
  $self->updateResults();
  return $win;
}

# sub litRefs { my $self = shift; return $self->litUI()->litRefs(); }
sub biblio { my $self = shift; return $self->pBibTkUI()->biblio(); }
sub pBibTkUI { my $self = shift; return $self->{'pBibTkUI'}; }
sub title { my $self = shift; my $title = $self->{'title'};
		return defined($title) ? $title : "Search Results"; }
sub pattern { my $self = shift; return $self->{'pattern'}; }
sub queryFields { my $self = shift; return $self->{'queryFields'}; }
sub resultFields { my $self = shift; return $self->{'resultFields'}; }
sub results { my $self = shift; return $self->{'results'}; }

sub conv { my $self = shift; return $self->pBibTkUI()->conv(@_); }

#
# widgets
#


sub initWidgets {
  my ($self, $win) = @_;
  my $cmd;

  # menu inside a menu frame

#  my $mf = $win->Frame()->grid(-sticky => 'ew');
#  $mf->gridColumnconfigure(1, -weight => 1);
##  my $mf = $win->Frame()->pack(qw/-fill x -side top/);
##  $mf->gridColumnconfigure(1, -weight => 1);
  my $mf = $win->Menu(-type => 'menubar');
  $win->configure(-menu => $mf);
  $self->initMenu($mf, $win);

  # result list

  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();
}



( run in 1.060 second using v1.01-cache-2.11-cpan-39bf76dae61 )