use strict;
use warnings;
use Gtk2 '-init';
use Data::Dumper;

my $suffix="testwithxFF\x{FF}"; #I get crashes when selecting this folder/file
$suffix="testwithxF3\x{F3}";

{	-d "dir$suffix" or mkdir "dir$suffix" or die;
	open my $out, '>', "dir$suffix/file$suffix" or die;
	print $out "hello\n";
}

my $dialog = Gtk2::FileChooserDialog->new
  ('Try Save', undef, 'save',
   'gtk-save'   => 'accept',
   'gtk-cancel' => 'cancel');

warn "new folder found\n" if -d $ENV{PWD}."/dir$suffix/";
$dialog->set_current_folder($ENV{PWD}."/dir$suffix/");		#doesn't work
#$dialog->set_filename($ENV{PWD}."/dir$suffix/file$suffix");	#works

$dialog->signal_connect(selection_changed => \&preview);
$dialog->signal_connect
  (response => sub {
     check('get_filename',$dialog->get_filename);
     #check('get_filenames',$_) for  $dialog->get_filenames;
     check('get_current_folder',$dialog->get_current_folder);
   });
$dialog->show;
Gtk2->main;


sub preview
{	my ($dialog,$file)=@_;
	check('get_filename',$dialog->get_filename);
	check('get_preview_filename',$dialog->get_preview_filename);
}

sub check
{	my ($what,$filename)=@_;
	return unless $filename;
	print "$what :\n";
	print "utf8: ",(utf8::is_utf8($filename) ? "yes" : "no"),"\n";
	print Data::Dumper->new([$filename],['filename'])->Dump;
	print -e $filename ? "file found\n" : "file not found\n";
	print "\n";
}
