[perl-Gtk3] Add overrides for Gtk3::ListStore's and Gtk3::TreeStore's insert_with_values()
- From: Torsten SchÃnfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Gtk3] Add overrides for Gtk3::ListStore's and Gtk3::TreeStore's insert_with_values()
- Date: Mon, 28 Jan 2013 16:56:23 +0000 (UTC)
commit 59d020563f5ec69af4c4a0b3bb7148ae518d05dc
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date: Mon Jan 28 17:54:14 2013 +0100
Add overrides for Gtk3::ListStore's and Gtk3::TreeStore's insert_with_values()
NEWS | 4 +++-
lib/Gtk3.pm | 38 ++++++++++++++++++++++++++++++++++++++
t/overrides.t | 44 +++++++++++++++++++++++++++++++++++---------
3 files changed, 76 insertions(+), 10 deletions(-)
---
diff --git a/NEWS b/NEWS
index 254977b..1427cd5 100644
--- a/NEWS
+++ b/NEWS
@@ -7,8 +7,10 @@
* Add overrides for Gtk3::FileChooserDialog.
* Add overrides for Gtk3::RecentChooserDialog.
* Add overrides for Gtk3::TextBuffer.
-* Add an override for Gtk3::main_level.
+* Add overrides for Gtk3::ListStore's and Gtk3::TreeStore's
+ insert_with_values().
* Add overrides for various button constructors.
+* Add an override for Gtk3::main_level.
* Add overrides for Gtk3::Gdk::RGBA.
* Add Gtk3::EVENT_PROPAGATE and Gtk3::EVENT_STOP.
* In Gtk3::TreeModel::get, if no columns are specified, use all columns.
diff --git a/lib/Gtk3.pm b/lib/Gtk3.pm
index 6da9281..36f5e0b 100644
--- a/lib/Gtk3.pm
+++ b/lib/Gtk3.pm
@@ -822,6 +822,25 @@ sub Gtk3::ListStore::get {
return Gtk3::TreeModel::get (@_);
}
+sub Gtk3::ListStore::insert_with_values {
+ my ($model, $position, @columns_and_values) = @_;
+ my ($columns, $values) = _unpack_keys_and_values (\ columns_and_values);
+ if (not defined $columns) {
+ croak ("Usage: Gtk3::ListStore::insert_with_values (\$model, \$position, \\\ columns, \\\ values)\n",
+ " -or-: Gtk3::ListStore::insert_with_values (\$model, \$position, \$column1 => \$value1, ...)");
+ }
+ my @wrapped_values = ();
+ foreach my $i (0..$#{$columns}) {
+ my $column_type = $model->get_column_type ($columns->[$i]);
+ push @wrapped_values,
+ Glib::Object::Introspection::GValueWrapper->new (
+ $column_type, $values->[$i]);
+ }
+ return Glib::Object::Introspection->invoke (
+ $_GTK_BASENAME, 'ListStore', 'insert_with_valuesv', # FIXME: missing rename-to annotation?
+ $model, $position, $columns, \ wrapped_values);
+}
+
sub Gtk3::ListStore::set {
return _common_tree_model_set ('ListStore', @_);
}
@@ -1058,6 +1077,25 @@ sub Gtk3::TreeStore::get {
return Gtk3::TreeModel::get (@_);
}
+sub Gtk3::TreeStore::insert_with_values {
+ my ($model, $parent, $position, @columns_and_values) = @_;
+ my ($columns, $values) = _unpack_keys_and_values (\ columns_and_values);
+ if (not defined $columns) {
+ croak ("Usage: Gtk3::TreeStore::insert_with_values (\$model, \$parent, \$position, \\\ columns, \\\ values)\n",
+ " -or-: Gtk3::TreeStore::insert_with_values (\$model, \$parent, \$position, \$column1 => \$value1, ...)");
+ }
+ my @wrapped_values = ();
+ foreach my $i (0..$#{$columns}) {
+ my $column_type = $model->get_column_type ($columns->[$i]);
+ push @wrapped_values,
+ Glib::Object::Introspection::GValueWrapper->new (
+ $column_type, $values->[$i]);
+ }
+ return Glib::Object::Introspection->invoke (
+ $_GTK_BASENAME, 'TreeStore', 'insert_with_values',
+ $model, $parent, $position, $columns, \ wrapped_values);
+}
+
sub Gtk3::TreeStore::set {
return _common_tree_model_set ('TreeStore', @_);
}
diff --git a/t/overrides.t b/t/overrides.t
index 6aa4a4f..06d26d1 100644
--- a/t/overrides.t
+++ b/t/overrides.t
@@ -7,7 +7,7 @@ use warnings;
use utf8;
use Encode;
-plan tests => 125;
+plan tests => 131;
# Gtk3::CHECK_VERSION and check_version
{
@@ -173,7 +173,7 @@ SKIP: {
is ($button->get_label, $label);
}
-# Gtk3::ListStore::new, set and get
+# Gtk3::ListStore::new, set and get, insert_with_values
SKIP: {
skip 'tree model ctors not properly supported', 5
unless check_gi_version(1, 29, 17);
@@ -191,9 +191,22 @@ SKIP: {
is_deeply ([$model->get ($iter, 0,1)], ['Bar', 42]);
is (scalar $model->get ($iter, 0,1), 42);
- local $@;
- eval { $model->set ($iter, 0) };
- like ($@, qr/Usage/);
+ {
+ local $@;
+ eval { $model->set ($iter, 0) };
+ like ($@, qr/Usage/);
+ }
+
+ $iter = $model->insert_with_values (-1, [0, 1], ['FooFoo', 2323]);
+ is_deeply ([$model->get ($iter)], ['FooFoo', 2323]);
+ $iter = $model->insert_with_values (-1, 0 => 'BarBar', 1 => 4242);
+ is_deeply ([$model->get ($iter)], ['BarBar', 4242]);
+
+ {
+ local $@;
+ eval { $model->insert_with_values (-1, 0); };
+ like ($@, qr/Usage/);
+ }
}
# Gtk3::Menu::popup and popup_for_device
@@ -256,7 +269,7 @@ SKIP: {
is ($button->get_label, '_Test');
}
-# Gtk3::TreeStore::new, set and get
+# Gtk3::TreeStore::new, set and get, insert_with_values
SKIP: {
skip 'tree model ctors not properly supported', 5
unless check_gi_version(1, 29, 17);
@@ -274,9 +287,22 @@ SKIP: {
is_deeply ([$model->get ($iter, 0,1)], ['Bar', 42]);
is (scalar $model->get ($iter, 0,1), 42);
- local $@;
- eval { $model->set ($iter, 0) };
- like ($@, qr/Usage/);
+ {
+ local $@;
+ eval { $model->set ($iter, 0) };
+ like ($@, qr/Usage/);
+ }
+
+ $iter = $model->insert_with_values (undef, -1, [0, 1], ['FooFoo', 2323]);
+ is_deeply ([$model->get ($iter)], ['FooFoo', 2323]);
+ $iter = $model->insert_with_values (undef, -1, 0 => 'BarBar', 1 => 4242);
+ is_deeply ([$model->get ($iter)], ['BarBar', 4242]);
+
+ {
+ local $@;
+ eval { $model->insert_with_values (undef, -1, 0); };
+ like ($@, qr/Usage/);
+ }
}
# Gtk3::TreePath::new, new_from_string, new_from_indices, get_indices
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]