[perl-Gtk3] Add overrides for Gtk3::FileChooserDialog



commit f4d9d19fc4fbc45983528df1bbacc9b711a52f16
Author: Dave M <dave nerd gmail com>
Date:   Tue Jan 8 23:08:50 2013 +0100

    Add overrides for Gtk3::FileChooserDialog

 NEWS          |    1 +
 lib/Gtk3.pm   |   26 ++++++++++++++++++++++++++
 t/overrides.t |   13 ++++++++++++-
 3 files changed, 39 insertions(+), 1 deletions(-)
---
diff --git a/NEWS b/NEWS
index 9ab70c5..d993ca4 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@
 * Add overrides for Gtk3::Dialog, including the conversion of predefined
   response IDs to nick names.  This is an API change.
 * Add overrides for Gtk3::Editable.
+* Add overrides for Gtk3::FileChooserDialog.
 * Add Gtk3::EVENT_PROPAGATE and Gtk3::EVENT_STOP.
 * Test that no double-frees occur for custom Gtk3::Widget subclasses.
 
diff --git a/lib/Gtk3.pm b/lib/Gtk3.pm
index 79cb120..dbf2abb 100644
--- a/lib/Gtk3.pm
+++ b/lib/Gtk3.pm
@@ -725,6 +725,32 @@ sub Gtk3::Editable::insert_text {
     @_ == 4 ? @_ : (@_[0,1], length $_[1], $_[2]));
 }
 
+sub Gtk3::FileChooserDialog::new {
+  my ($class, $title, $parent, $action, @varargs) = @_;
+
+  if (@varargs % 2) {
+    croak 'Usage: Gtk2::FileChooserDialog->new' .
+          ' (title, parent, action, backend, button-text =>' .
+          " response-id, ...)\n";
+  }
+
+  my $result = Glib::Object::new (
+    $class,
+    title => $title,
+    action => $action,
+  );
+
+  if ($parent) {
+    $result->set_transient_for ($parent);
+  }
+
+  for (my $i = 0; $i < @varargs; $i += 2) {
+    $result->add_button ($varargs[$i], $_GTK_RESPONSE_NICK_TO_ID->($varargs[$i+1]));
+  }
+
+  return $result;
+}
+
 sub Gtk3::HBox::new {
   my ($class, $homogeneous, $spacing) = @_;
   $homogeneous = 5 unless defined $homogeneous;
diff --git a/t/overrides.t b/t/overrides.t
index 876dc8e..84e2ceb 100644
--- a/t/overrides.t
+++ b/t/overrides.t
@@ -5,7 +5,7 @@ BEGIN { require './t/inc/setup.pl' };
 use strict;
 use warnings;
 
-plan tests => 95;
+plan tests => 98;
 
 # Gtk3::CHECK_VERSION and check_version
 {
@@ -102,6 +102,17 @@ plan tests => 95;
   is ($entry->get_text, $orig_text . $my_text);
 }
 
+# Gtk3::FileChooserDialog
+{
+  my $parent = Gtk3::Window->new;
+  my $dialog = Gtk3::FileChooserDialog->new ('some title', $parent, 'save',
+                                             'gtk-cancel' => 'cancel',
+                                             'gtk-ok' => 23);
+  is ($dialog->get_title, 'some title');
+  is ($dialog->get_transient_for, $parent);
+  is ($dialog->get_action, 'save');
+}
+
 # Gtk3::ListStore::new, set and get
 SKIP: {
   skip 'tree model ctors not properly supported', 5



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]