#######################################################################
# This software has been created by Genome Research Limited (GRL).    # 
# GRL hereby grants permission to use, copy, modify and distribute    # 
# this software and its documentation for non-commercial purposes     # 
# without fee at the user's own risk on the basis set out below.      #
# GRL neither undertakes nor accepts any duty whether contractual or  # 
# otherwise in connection with the software, its use or the use of    # 
# any derivative, and makes no representations or warranties, express #
# or implied, concerning the software, its suitability, fitness for   #
# a particular purpose or non-infringement.                           #
# In no event shall the authors of the software or GRL be responsible # 
# or liable for any loss or damage whatsoever arising in any way      # 
# directly or indirectly out of the use of this software or its       # 
# derivatives, even if advised of the possibility of such damage.     #
# Our software can be freely distributed under the conditions set out # 
# above, and must contain this copyright notice.                      #
#######################################################################

package ListPick;

use Tk::Dialog;
use Tk::ErrorDialog;
##############################################################################################
##
## Selects fro a list in a list box ..
##

my $FW;
my $Button;
my $Cancel;
my $frame;
my $scroll;
my $list;
my $w_sel;
#############################################################################################
sub FileChoose{

    my ($MW,$caption,$p) = @_;
    my @Flist;
    my $i;
    my $dir_name;
   
    
    push (@Flist,'..');
    do{
	$dir_name = $p;
	undef(@Flist);
	push(@Flist,'..');
	foreach $i (sort <$dir_name/*>) {
	    push(@Flist,$i);
	}
	$p = &ListPick($MW, $caption, @Flist);
    }while ($p eq '..');    


}
#############################################################################################



#############################################################################################
sub ListPick{

    my ($MW,$caption,@items) = @_;
    my $picked = "";
    my $ok = 'OK';
    my $can = 'Cancel';
    my $vis = 0;
   

    if(!$FW)
    {
	$FW = $MW->Dialog(
			  -title => 'List Pick',
			  -text => $caption,
			  -default_button => $can,
			  -buttons => [$ok,$can],
			  );
   
	

	
	my $w_spacer1 = $FW->Frame(-height => '3m', -width => 20);
	my $w_label = $FW->Label(-text => 'You Chose :');
	$w_sel = $FW->Entry(-width => 30, -textvariable => \$picked);
	
	
	my(@pl) = (-side => 'top',-expand => 'yes', -anchor => 'w');
	$w_spacer1->pack(@pl);
	$w_label->pack(@pl);
	$w_sel->pack(@pl);	
	$frame = $FW->Frame(-borderwidth => '.5c');
	$frame ->pack(-side => 'top',-expand =>'yes',-fill => 'y');
	$scroll = $frame->Scrollbar;
	$scroll->pack(-side => 'right', -fill => 'y');
	$list = $frame->Listbox(
				-yscrollcommand => [$scroll => 'set'],
				-setgrid => 1,
				-height  => 12,
				);
	$scroll->configure(-command => [$list => 'yview']);
	$list->pack(-side => 'left', -expand => 'yes', -fill => 'both');
	
	
    }
    $w_sel->configure(-textvariable => \$picked);
    $list->delete(0,$list->size);

    $list->bind('<Button-1>' => sub { $_[0]->activate($_[0]->curselection);$picked = $_[0]->get('active');},);
    my $i=0;

    foreach (@items)
    {
	$list->insert($i,$_);
        $i++;
    }
  
 
   $Button = $FW->Show;$vis =1;
   if($Button eq $ok){;}else{$picked = "";}
   $picked;
}


########################################################################################################
1;
