require File::Spec;
require File::Basename;
require File::Path;
require Cwd;

use Glib qw/TRUE FALSE/;
use Gtk2 '-init';

use Data::Dumper;

use strict;

my $_tool_name;
my $_tool_path;
($_tool_name, $_tool_path, undef) = File::Basename::fileparse($0);


my $_info_marker = "$_tool_name :INFO:";
my $_warning_marker = "$_tool_name :WARNING:";
my $_error_marker = "$_tool_name :ERROR:";


sub create_top_level_window();
sub create_load_state_gui($);


my $_top_level_window = create_top_level_window();

$_top_level_window->show;

create_load_state_gui($_top_level_window);

Gtk2->main;




###########################
sub create_top_level_window()
###########################
  {
  my $this = Gtk2::Window->new('toplevel');

  $this->signal_connect
    (
    destroy =>
      sub()
        {
        Gtk2->main_quit;
        }
    );

  $this->signal_connect
    (
    delete_event =>
      sub()
        {
        Gtk2->main_quit;
        return FALSE;
        }
    );

  $this;
  } # sub create_top_level_window
  #------------------------------


#########################
sub create_load_state_gui($)
#########################
  {
  my(
    $parent,
    ) = @_;

  my $this = Gtk2::FileChooserDialog->new_with_backend
               (
               'Choose file to load state from',
               $parent,
               'open',
               'backend',
               'gtk-cancel' => 'cancel',
               'gtk-ok' => 'ok'
               );
  $this->show;


  $this->signal_connect
    (
    'selection-changed' =>
      sub
        {
        warn "selection changed";
        my $current_folder = $this->get_current_folder; warn "\$current_folder=$current_folder";
        }
    );

 $this->signal_connect
    (
    'update-preview' =>
      sub
        {
        warn "update-preview called";
        }
    );


  if($this->run eq 'ok')
    {
    # you can get the user's selection as a filename or a uri.
    my $uri = $this->get_uri;
    warn "$_info_marker uri $uri\n";
    my $filename = $this->get_filename; warn "\$filename=$filename";
    }

  $this->destroy;
  } # sub create_load_state_gui
  #----------------------------
