#!/usr/local/bin/perl -w

use strict;
use vars qw($VERSION $tk_opt $tree);

$VERSION = substr(q$Revision: 1.6 $ , 10) + 1 . "";

use Tk;
BEGIN { eval { require Tk::FcyEntry; }; };
use Tk::Pod;
use Getopt::Long;
#require Tk::ErrorDialog;

$tree = 1;
if (!GetOptions("tk" => \$tk_opt,
		"tree!" => \$tree,
	       )) {
    print STDERR <<EOT unless @ARGV;
Usage:	$0  [-tk] [[-no]tree] [directory]|name [...]

EOT
}

if (!@ARGV) {
    push @ARGV, "perl";
}

# Add 'Tk' subdirectories to search path so, e.g.,
# 'Scrolled' will find doc in 'Tk/Scrolled'
if ($tk_opt) {
   my $tkdir;
   foreach (reverse @INC) {
	$tkdir = "$_/Tk";
	unshift @ARGV, $tkdir if -d $tkdir;
   }
}

my $mw = MainWindow->new();
#eval 'use blib "/home/e/eserte/src/perl/Tk-App";require Tk::App::Debug';
$mw->withdraw;

# CDE use Font Settings if available
my $ufont = $mw->optionGet('userFont','UserFont');     # fixed width
my $sfont = $mw->optionGet('systemFont','SystemFont'); # proportional
if (defined($ufont) and defined($sfont)) {
    foreach ($ufont, $sfont) { s/:$//; };
    $mw->optionAdd('*Font',       $sfont);
    $mw->optionAdd('*Entry.Font', $ufont);
    $mw->optionAdd('*Text.Font',  $ufont);
}

$mw->optionAdd('*Menu.tearOff', $Tk::platform ne 'MSWin32' ? 1 : 0);

my $file;
foreach $file (@ARGV)
 {
  if (-d $file)
   {
    Tk::Pod->Dir($file);
   }
  else
   {
    my $tl = $mw->Pod(-file => $file, -tree => $tree);
    $tl->focus;
   }
 }

# xxx dirty but it works. A simple $mw->destroy if $mw->children
# does not work because Tk::ErrorDialogs could be created.
# (they are withdrawn after Ok instead of destory'ed I guess)

if ($mw->children) {
    $mw->repeat(1000, sub {
		# ErrorDialog is withdrawn not deleted :-(
		foreach ($mw->children) {
			return if "$_" =~ /^Tk::Pod/  # ->isa('Tk::Pod')
		}
		$mw->destroy;
	    });
} else {
    $mw->destroy;
}

MainLoop;

__END__

=head1 NAME

tkpod - Perl/Tk POD browser

=head1 SYNOPSIS

    tkpod  [-tk] [[-no]tree]  [directory]|name [...]


=head1 DESCRIPTION

B<tkpod> is a simple POD browser with hypertext capabilities.
POD (L<Plain Old Document|perlpod>) is a simple and readable
markup language that could be mixed with L<perl> code.

PODs are searched by default in C<@INC>.  Directories listed on
the command line are added to the default search path.

For each C<name> listed on the command line B<tkpod> tries to
to find POD in C<name, name.pod> and C<name.pm> in the search
path.  For each C<name> a new POD browser window is opened.


=head1 OPTIONS

=over 4

=item B<-tree>

By default, tkpod will show a tree window with all available PODs.
However, this is slow on startup. With the option B<-notree> only the
given POD will be shown and no tree view will be available.

=item B<-tk>

Useful for perl/Tk documentation.  When specified it adds all
C<Tk> subdirectories in C<@INC> to the POD search path.   This way
when C<Scrolled> is selected in the browser the C<Tk/Scrolled>
documentation is found.

=back


=head1 USAGE

How to navigate with the POD browser is described in L<Tk::Pod_usage>.
It's also accessible via the menu 'Help' -> 'Usage...'.


=head1 KNOWN BUGS

see L<Tk::Pod::Text>

=head1 SEE ALSO

L<perlpod|perlpod>
L<pod2man|pod2man>
L<pod2text|pod2text>
L<pod2html|pod2html>
L<Tk::Pod|Tk::Pod>
L<Tk::Pod::Text|Tk::Pod::Text>

=head1 AUTHOR

Nick Ing-Simmons <F<nick@ni-s.u-net.com>>

Former maintainer: Achim Bohnet <F<ach@mpe.mpg.de>>.

Code currently maintained by Slaven Rezic F<slaven.rezic@berlin.de>>.

Copyright (c) 1997-1998 Nick Ing-Simmons.  All rights reserved.  This program
is free software; you can redistribute it and/or modify it under the same
terms as Perl itself.

=cut

