#!/usr/bin/perl
#
# Builder
# Demonstrates an interface loaded from a XML description.
#
# Perl version by Dave M <dave.nerd@gmail.com>
# with patches from Thierry Vignaud <thierry.vignaud@gmail.com>

use strict;
use warnings;

use Data::Dumper;

use Glib qw/TRUE FALSE/;
use Gtk3 '-init';
use File::Basename 'dirname';


my $glade_file = dirname($0) . "/glade_versuch04.glade";

my $builder_main  = Gtk3::Builder->new();
$builder_main->add_from_file($glade_file);

my $main_window = $builder_main->get_object('main_window');
$builder_main->connect_signals(undef);


my $edit_button = $builder_main->get_object("Button_to_call_sub_window");
$edit_button->signal_connect( clicked => \&edit_something );


$main_window->signal_connect( destroy => \&_main_quit );


$main_window->show_all();

Gtk3->main();

sub _main_quit {
    Gtk3->main_quit;
}

sub edit_something {

    my $editor = $builder_main->get_object("sub_window");
    ## print "Editor: ", $editor, "\n", Dumper($editor);

    my $bb = $builder_main->get_object("ButtonBox_Editor");
    ## print "ButtonBox: ", $bb, "\n", Dumper($bb);

    my $b_cancel = $builder_main->get_object("Edit_Cancel");
    ## print "Edit Cancel: ", $b_cancel, "\n", Dumper($b_cancel);

    my $b_OK = $builder_main->get_object("Edit_OK");
    ## print "Edit OK: ", $b_OK, "\n", Dumper($b_OK);

    $editor->set_transient_for($main_window);
    $editor->set_modal(TRUE);

    $editor->signal_connect( destroy => sub { print "Going to destroy editor now\n";
                                                      $editor->destroy() } );

    $editor->show_all();

}


#
# vim: tabstop=4 shiftwidth=4 expandtab 
