Bundle-PBib

 view release on metacpan or  search on metacpan

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

sub initDropSite {
# I guess this doesn't qork jet under Win32 ...
  my ($self, $win) = @_;
  $win->DropSite(
	-entercommand => sub{print "enter @_\n";},
	-leavecommand  => sub{print "leave @_\n";},
	-motioncommand  => sub{print "motion @_\n";},
	-dropcommand  => sub{print "drop @_\n";},
	);
}


#
# button / menu methods
#

sub keyPressed {
  my ($self, $key, $mod, $list, $refsName) = @_;
  return if $mod && $mod ne '';
  my $refs = $self->{$refsName};
  my $idx = $self->indexOfRefStartingWith($refs, $key);
print "keyPressed $key ($mod) --> $idx\n";
  $list->focus();
  $list->activate($idx);
  $list->selectionClear(0, 'end');
  $list->selectionAnchor($idx);
  $list->selectionSet($idx);
  $list->see($idx);
  $self->selectionMove($list, undef);
}
sub indexOfRefStartingWith {
  my ($self, $refs, $char) = @_;
  return undef unless defined($char);
  my $idx = 0;
  for( ; $idx < scalar(@$refs); $idx++ ) {
###  print ord(lc($char)), ' ', ord(lc(substr($refs->[$idx], 0, 1))), " $idx - $refs->[$idx]\n";
    last if( ord(lc($char)) <= ord(lc(substr($refs->[$idx], 0, 1))) );
  }
  return $idx;
}

sub entryFocusAndSelectAll {
	my ($self, $list) = @_;
	$list->focus();
	$list->selectionRange(0, "end");
}

sub selectionMove {
	# called on UP and Down key presses to be able to adjust the printed ref.
	my ($self, $list, $inc) = @_;
	if( $list == $self->refList() ) {
		$self->updateExpandedSelectedBiblioReference();
	} else {
		$self->updateExpandedSelectedPaperReference();
	}
}


# updateing

sub updateBiblioRefs {
# re-load all refs and re-analyze paper!
  my $self = shift;
  my $litrefs = $self->litRefs();
  $litrefs->readRefs();
  $litrefs->analyzeFile($filename) if $filename;
  $self->updateLists();
}

sub updateLists {
  my $self = shift;
  $self->updateBiblioList();
  $self->updatePaperList();
  $self->{'conv'} = $self->make_converter();
  #  $self->conv()->setArgs(
	  #  'refs' => $self->refs(),
	  #  );
}
sub updateBiblioList {
# re-load all refs and everything!
  my $self = shift;
  $self->refList()->delete(0, "end");
  $self->addBiblioRefs();
}
sub updatePaperList {
# re-load all refs and everything!
  my $self = shift;
  $self->foundList()->delete(0, "end");
  $self->addPaperRefs();
}

# read/browse paper

sub readPaperFile {
  my $self = shift;
  $self->updateBiblioRefs();
#  my $litrefs = $self->litRefs();
#  $litrefs->analyzeFile($filename) if $filename;
#  $self->updateLists();
}
sub browsePaperFile {
  my $self = shift;
# orig:
#  $filename = $fileselect->Show;

  my $types = [
		['All Files',	'*'],
		['Text Files',	'.txt'],
		['TeX / LaTeX',	'.tex'],
		['Word Files',       ['.doc', '.rtf']],
	];
  print Dumper {
	'$filename' => $filename,
	'dir' => dirname($filename),
	'name' => basename($filename),
	-initialdir => $filename ? dirname($filename) : $ENV{'HOME'},
	};
  my $file = $self->window()->getOpenFile(
  	-filetypes => $types,
	-defaultextension => '.txt',
	-initialdir => $filename ? dirname($filename) : $ENV{'HOME'},
	-initialfile => basename($filename),
	-title => 'Select Document ...',
	);

  if( $file ) {
    $filename = $file;
    $self->updateBiblioRefs();
  }
}
sub writeNewRefs {
	my ($self, $file) = @_;
	$file = $filename unless defined $file;
	my $litrefs = $self->litRefs();
	my @refs = @{$litrefs->newrefs()};
	my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
	my $date = sprintf("%02d-%02d-%02d", ($year+1900) % 100, $mon+1, $mday);
	my $outfilename = "$filename-refs-$date.txt";
	print scalar(@refs), " new references found in $filename ($date)\n";
	open OUT,"> $outfilename";
	my $ref; my $i = 0;
	print OUT scalar(@refs), " new references found in $filename ($date)\n\n\n";
	foreach $ref (sort(@refs)) { print OUT "[", ++$i, "] $ref\n"; }
	close OUT;
	print "done.\n";

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

  }
  my $button = $$dialogRef->Show();
  return if( $button eq "Cancel" );
  my $pattern = $$patternRef;
  return if( not defined($pattern) or $pattern eq "" );
  my $q = new PBibTk::SearchDialog ($self, "$msg $pattern", "%$pattern%", $queryFields);
  $q->show();
}

# show refs

sub showSelectedBiblioReference {
  my $self = shift;
  my $idx = $self->refListSelection();
  return if !defined($idx) || $idx eq "";
  my $paper = $self->litRefs()->queryPaperWithId($self->biblioRefAt($idx));
  PBibTk::RefDialog->new($self, $paper)->show();
}
sub showSelectedPaperReference {
  my $self = shift;
  my $idx = $self->foundListSelection();
  return if !defined($idx) || $idx eq "";
  my $paper = $self->litRefs()->queryPaperWithId($self->paperRefAt($idx));
  PBibTk::RefDialog->new($self, $paper)->show();
}

sub clipboardSelectedBiblioReferenceId {
  my $self = shift;
  my $idx = $self->refListSelection();
  return if !defined($idx) || $idx eq "";
  my $ref = $self->biblioRefAt($idx);
  Win32::Clipboard()->Set("[$ref]");
}
sub clipboardSelectedPaperReferenceId {
  my $self = shift;
  my $idx = $self->foundListSelection();
  return if !defined($idx) || $idx eq "";
  my $ref = $self->paperRefAt($idx);
  Win32::Clipboard()->Set("[$ref]");
}

sub searchSelectedBiblioReferenceId {
  my $self = shift;
  my $idx = $self->refListSelection();
  return if !defined($idx) || $idx eq "";
  $self->searchReferenceId($self->biblioRefAt($idx));
}
sub searchSelectedPaperReferenceId {
  my $self = shift;
  my $idx = $self->foundListSelection();
  return if !defined($idx) || $idx eq "";
  $self->searchReferenceId($self->paperRefAt($idx));
}
sub searchReferenceId {
  my ($self, $ref) = @_;
#  print "searchReferenceId {$filename, $ref)\n";
  searchInFile($filename, "[$ref]") if $filename && $ref;
}

#myline runter ---------------------------------------------------
sub updateExpandedSelectedBiblioReference {
  my ($self) = @_;
  my $idx = $self->refListSelection();
  return if !defined($idx) || $idx eq "";
  my $paper = $self->litRefs()->queryPaperWithId($self->biblioRefAt($idx));
  $self->updateExpandedSelectedReference($paper);
  $self->{'refList'}->focus();
}
sub updateExpandedSelectedPaperReference {
  my ($self) = @_;
  my $idx = $self->foundListSelection();
  return if !defined($idx) || $idx eq "";
  my $paper = $self->litRefs()->queryPaperWithId($self->paperRefAt($idx));
  $self->updateExpandedSelectedReference($paper);
  $self->{'foundList'}->focus();
}
sub updateExpandedSelectedReference {
  my ($self, $paper) = @_;
  return if !defined($paper) || $paper eq "";
  my @entry = PBibTk::RefDialog->new($self)->formatRefInfos($paper);
  $self->chosenLabel()->configure(-label => $entry[0]);
  my $list = $self->chosen();
  $list->delete("0.0", "end");
  $list->insert("end", $entry[1]);
}
sub chosen {
  my $self = shift;
  # access window first, to ensure it's created.
  $self->window();
  return $self->{'chosenfromlist'};
}
#myline hoch ---------------------------------------------------


#
# reference handling
#

sub addBiblioRefs {
# add for each ref a prefix with some additional information
# (like this ref's state)
  my $self = shift;
  my $litrefs = $self->litRefs();
  my $list = $self->refList();
### ToDO: sort case-independent!!
  my @refListIds = sort {uc($a) cmp uc($b)} @{$litrefs->refs()};
  $self->{'refListIds'} = \@refListIds;
  $list->insert("end", map($self->biblioRefLabel($_), @refListIds));
  $self->refListLabel()->configure(
	-label => ('Biblio Refs (' .
		scalar(@{$litrefs->refs()}) . ", " .
		scalar(@{$litrefs->used()}) . " used, " .
		scalar(@{$litrefs->unused()}) . " unused" .
		')')
	);
}
sub biblioRefLabel {
# return the label for a biblio ref
  my ($self, $ref) = @_;
  my $litrefs = $self->litRefs();
  my %status = %{$litrefs->statusOf($ref)};
  return ($status{'used'} ? '+' : '  ') .
          " $ref ($status{'occurances'})";
}
sub biblioRefAt {
# return reference at idx
  my ($self, $idx) = @_;
  return undef unless defined($idx);
  return $self->{'refListIds'}->[$idx];
}

sub addPaperRefs {
# add for each ref a prefix with some additional information
# (like this ref's state)
  my $self = shift;
  my $litrefs = $self->litRefs();
  my $list = $self->foundList();



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