Author: bdonlan
Date: 2004-07-06 19:14:59 -0400 (Tue, 06 Jul 2004)
New Revision: 307
Added:
trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ButtonDialog.pm
Modified:
trunk/clients/haver-gtk/TODO
trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ServerSelectDialog.pm
Log:
* haver-gtk/lib/Haver/UI/Gtk/ButtonDialog.pm: New confirmation/information
dialog framework.
* haver-gtk/lib/Haver/UI/Gtk/ServerSelectDialog.pm: Use ButtonDialog for
existing server replacement dialog. Also pop up an error when aborting
on missing server name.
* haver-gtk/TODO: Remove finished item.
Modified: trunk/clients/haver-gtk/TODO
===================================================================
--- trunk/clients/haver-gtk/TODO 2004-07-06 22:42:37 UTC (rev 306)
+++ trunk/clients/haver-gtk/TODO 2004-07-06 23:14:59 UTC (rev 307)
@@ -1,6 +1,5 @@
TODO:
* Validation in server editing dialog
-* Framework for confirmation dialogs?
* Password prompt dialog
* Compositing command parser
* Hilight active tabs
Added: trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ButtonDialog.pm
===================================================================
--- trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ButtonDialog.pm 2004-07-06
22:42:37 UTC (rev 306)
+++ trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ButtonDialog.pm 2004-07-06
23:14:59 UTC (rev 307)
@@ -0,0 +1,102 @@
+# vim: set ft=perl ts=4 sw=4:
+# Haver::UI::Gtk::ButtonDialog - generic message dialog with buttons
+#
+# Copyright (C) 2004 Bryan Donlan, Dylan William Hardison.
+#
+# This module is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This module is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this module; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+package Haver::UI::Gtk::ButtonDialog;
+
+use strict;
+use warnings;
+
+use constant {
+ TRUE => 1,
+ FALSE => 0,
+};
+
+use Gtk;
+use Carp;
+
+sub new {
+ my ($class, %options) = @_;
+ carp "Required Text parameter missing" unless defined $options{Text};
+
+ my $dialog;
+
+ my @buttons;
+
+ if (!defined $options{Buttons}) {
+ @buttons = ['OK', sub { $dialog->destroy; }];
+ } else {
+ my ($btntext, $btnsub);
+ my @btnlist = @{$options{Buttons}};
+ carp 'Odd number of buttons' if @btnlist % 2;
+ while (@btnlist) {
+ my ($btntext, $btnsub) = splice @btnlist, 0, 2;
+ if (!defined $btnsub) {
+ $btnsub = sub { $dialog->destroy; };
+ } else {
+ my $oldsub = $btnsub;
+ $btnsub = sub { $oldsub->($dialog); };
+ }
+ push @buttons, [$btntext, $btnsub];
+ }
+ }
+
+ $dialog = new Gtk::Dialog();
+ $dialog->set_title($options{Title}) if defined $options{Title};
+ $dialog->set_modal(TRUE);
+ $dialog->set_position('center');
+
+ my $message = new Gtk::Label($options{Text});
+ $dialog->vbox->pack_start(fixpad($message, $options{TextPad} || 0),
TRUE, TRUE, 0);
+ $message->show;
+
+ my $bb = new Gtk::HButtonBox();
+
+ $bb->set_layout_default($options{Layout} || 'end');
+
+ if (!defined $options{ButtonSpacing}) {
+ $options{ButtonSpacing} = 10;
+ }
+ $bb->set_spacing_default($options{ButtonSpacing});
+
+ for (@buttons) {
+ my $button = new Gtk::Button($_->[0]);
+ $button->signal_connect('clicked', $_->[1]);
+ $bb->add($button);
+ $button->show;
+ }
+
+ $bb->show;
+ $dialog->action_area->pack_start($bb, TRUE, TRUE, 0);
+ $dialog->show;
+
+ return $dialog;
+}
+
+sub fixpad {
+ my ($object, $pad) = @_;
+ my $vbox = new Gtk::VBox(FALSE, 0);
+ my $hbox = new Gtk::HBox(FALSE, 0);
+ $hbox->pack_start($object, TRUE, TRUE, $pad);
+ $vbox->pack_start($hbox, TRUE, TRUE, $pad);
+ $hbox->show;
+ $vbox->show;
+ return $vbox;
+}
+
+1;
Property changes on: trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ButtonDialog.pm
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ServerSelectDialog.pm
===================================================================
--- trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ServerSelectDialog.pm
2004-07-06 22:42:37 UTC (rev 306)
+++ trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ServerSelectDialog.pm
2004-07-06 23:14:59 UTC (rev 307)
@@ -28,6 +28,7 @@
use Gtk;
use Haver::UI::Gtk::ServerEditDialog;
+use Haver::UI::Gtk::ButtonDialog;
#use POE;
sub new {
@@ -196,52 +197,31 @@
sub server_save {
my ($self, $config) = @_;
- return if ($config->{Name} eq '');
+ if ($config->{Name} eq '') {
+ Haver::UI::Gtk::ButtonDialog->new(
+ Title => 'Error',
+ Text => 'You must specify a name for the server.',
+ TextPad => 20,
+ );
+ return;
+ }
if (!exists($config->{Oldname}) or $config->{Name} ne
$config->{Oldname}) {
if (exists $self->{servers}{$config->{Name}}) {
- my $confirm = new Gtk::Dialog();
-
- $confirm->set_title('Confirm replace');
- $confirm->set_modal(TRUE);
-
- my $message = new Gtk::Label('Are you sure you want to
replace server "' . $config->{Name} . '"?');
-
- my $yes = new Gtk::Button('Yes');
- my $no = new Gtk::Button('No');
-
- my $bb = new Gtk::HButtonBox();
- $bb->set_layout_default('end');
- $bb->set_spacing_default(10);
-
- $confirm->vbox->pack_start(fixpad($message, 20), TRUE,
FALSE, 0);
- # $confirm->action_area->pack_end($yes, FALSE,
FALSE, 0);
- # $confirm->action_area->pack_end($no, FALSE,
FALSE, 0);
- $bb->add($yes);
- $bb->add($no);
- $confirm->action_area->pack_start($bb, TRUE, TRUE, 0);
-
- $yes->signal_connect('clicked',
- sub {
- delete
$self->{servers}{$config->{Name}};
- $self->server_save($config);
- $confirm->destroy;
- undef $confirm; # Break possible
circular ref
- }
+ Haver::UI::Gtk::ButtonDialog->new(
+ Title => 'Confirm replace',
+ Text => 'Are you sure you want to replace
server "' . $config->{Name} . '"?',
+ TextPad => 20,
+ Buttons => [
+ Yes => sub {
+ my $confirm = shift;
+ delete
$self->{servers}{$config->{Name}};
+ $self->server_save($config);
+ $confirm->destroy;
+ },
+ No => undef, # Use default dialog close
behavior
+ ],
);
- $no->signal_connect('clicked',
- sub {
- $confirm->destroy;
- undef $confirm;
- }
- );
-
- $message->show;
- $yes->show;
- $no->show;
- $bb->show;
- $confirm->show;
-
return;
}
delete $self->{servers}{$config->{Oldname}} if defined
$config->{Oldname};