Hi
I have a procedure which should be called on error (if a directory doesn't exist a window pops up as follows;
foreach my $filesg (keys %{$changes}){
my ($filename,$dirname,$ext)=fileparse($changes->{$filesg}->{newname},qr/\.[^.]*/);
unless (-d $dirname){
$err{$dirname}=$errkey if not exists $err{$errkey};
$errkey++;
}
if (-e $changes->{$filesg}->{newname}){
$changes->{$filesg}->{newname}=$dirname.'/'.$filename.'_dup'.$ext;
}
}
if (scalar keys %err >0){
print '3045 ', keys %err,"\n";
&nodir(\%err);;
}
sub nodir {
my $err=shift;
my %error=reverse %{$err};
my $win =Gtk3::Window->new();
my $grid=Gtk3::Grid->new;
my $errtitle=Gtk3::Label->new;
my %newdirs;
$errtitle->set_text('The following Directories do not exist, please check Details');
my $rownum=1;
foreach my $dir (keys %error){
my $dirlabel=Gtk3::Label->new($error{$dir});
my $diropt=Gtk3::CheckButton->new_with_label('add');
$grid->attach($dirlabel,0,$rownum,1,1);
$grid->attach($diropt,1,$rownum,1,1);
$diropt->signal_connect('toggled'=>sub{
if ($diropt->get_active==1){
$newdirs{$dir}=$error{$dir};
}
else {
delete $newdirs{$dir};
}
foreach my $keys (keys %newdirs){
};
}
);
$rownum++;
}
my $close=Gtk3::Button->new('Close');
my $add=Gtk3::Button->new('Add Dir');
$add->set_halign('start');
$grid->attach($errtitle,0,0,3,1);
$grid->attach($close,1,$rownum+1,1,1);
$grid->attach($add,0,$rownum+1,1,1);
$add->signal_connect('clicked'=>sub{
use File::Path;
foreach my $dirs (keys %newdirs){
mkpath($newdirs{$dirs});
}
$win->close;
}
);
$close->signal_connect('clicked',sub{
$win->close;
}
);
$win->add($grid);
$win->show;
$win->show_all;
return 1
}
However the subroutine runs too late, so that code that depends on it fails.
If I put exactly the same code directly as follows, it runs as expected.
if (scalar keys %err >0){
print '3045 ', keys %err,"\n";
<code in her>
}
Any ideas appreciated
Mike