diff options
Diffstat (limited to 'perl-install/mygtk2.pm')
-rw-r--r-- | perl-install/mygtk2.pm | 64 |
1 files changed, 47 insertions, 17 deletions
diff --git a/perl-install/mygtk2.pm b/perl-install/mygtk2.pm index c66d1943f..6633decf3 100644 --- a/perl-install/mygtk2.pm +++ b/perl-install/mygtk2.pm @@ -22,10 +22,10 @@ sub init() { if_($::isRestore, 'draksnapshot'), if_($::isInstall, 'urpmi'), 'drakx-net', 'drakx-kbd-mouse-x11', # shared translation @::textdomains; - Gtk2->croak_execeptions; + Glib->enable_exceptions2; } init() unless $::no_ugtk_init; -Gtk2->croak_execeptions if $::isInstall; +Glib->enable_exceptions2 if $::isInstall; @@ -1177,7 +1177,7 @@ sub _gtknew_handle_children { foreach (@child) { my ($fill, $child) = @$_; - $fill eq '0' || $fill eq '1' || $fill eq 'fill' || $fill eq 'expand' or internal_error("odd {children} parameter must be 0 or 1 (got $fill)"); + member($fill, qw(0 1 fill expand)) or internal_error("odd {children} parameter must be 0 or 1 (got $fill)"); ref $child or $child = Gtk2::WrappedLabel->new($child); my $expand = $fill && $fill ne 'fill' ? 1 : 0; $w->pack_start($child, $expand, $fill, $padding || 0); @@ -1198,7 +1198,7 @@ sub mygtk2::MagicWindow::AUTOLOAD { my ($s1, @s2) = $meth eq 'show' ? ('real_window', 'banner', 'child') : - $meth eq 'destroy' || $meth eq 'hide' ? + member($meth, qw(destroy hide)) ? ($w->{pop_it} ? 'real_window' : ('child', 'banner')) : $meth eq 'get' && $args[0] eq 'window-position' || $for_real_window{$meth} || @@ -1212,6 +1212,43 @@ sub mygtk2::MagicWindow::AUTOLOAD { $w->{$s1}->$meth(@args); } +my $enable_quit_popup; +sub enable_quit_popup { + my ($bool) = @_; + $enable_quit_popup = $bool; +} + +state $in_callback; +sub quit_popup() { + return if !$enable_quit_popup; + if (!$in_callback) { + $in_callback = 1; + my $_guard = before_leaving { undef $in_callback }; + require ugtk2; + my $w = ugtk2->new(N("Confirmation"), grab => 1); + ugtk2::_ask_okcancel($w, N("Are you sure you want to quit?"), N("Quit"), N("Cancel")); + my $ret = ugtk2::main($w); + return 1 if !$ret; + } +} + +sub quit_callback { + my ($w) = @_; + + return 1 if quit_popup(); + if ($::isWizard) { + $w->destroy; + die 'wizcancel'; + } else { + if (Gtk2->main_level) { + Gtk2->main_quit; + } else { + # block window deletion if not in main loop (eg: while starting the GUI) + return 1; + } + } +} + sub _create_Window { my ($opts, $special_center) = @_; @@ -1232,19 +1269,7 @@ sub _create_Window { my $w = _gtk(undef, 'Window', 'gtknew', $opts); #- when the window is closed using the window manager "X" button (or alt-f4) - $w->signal_connect(delete_event => sub { - if ($::isWizard) { - $w->destroy; - die 'wizcancel'; - } else { - if (Gtk2->main_level) { - Gtk2->main_quit; - } else { - # block window deletion if not in main loop (eg: while starting the GUI) - return 1; - } - } - }); + $w->signal_connect(delete_event => \&quit_callback); if ($::isInstall && !$::isStandalone) { require install::gtk; #- for perl_checker @@ -1448,6 +1473,11 @@ sub sync_flush { } +sub register_main_window { + my ($w) = @_; + push @::main_windows, $::main_window = $w; +} + sub may_destroy { my ($w) = @_; return if !$w; |