[gjs: 1/2] overrides/Gtk: Make GTK4 widgets iteratable
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 1/2] overrides/Gtk: Make GTK4 widgets iteratable
- Date: Sat, 23 May 2020 15:19:17 +0000 (UTC)
commit 995dde5ffee371da1daf6b62926e072dc1983924
Author: Florian Müllner <fmuellner gnome org>
Date: Tue May 19 21:56:08 2020 +0200
overrides/Gtk: Make GTK4 widgets iteratable
GTK4 removed the Gtk.Container interface, and added API on Gtk.Widget
to iterate over children instead. While that API is perfectly fine
to use from javascript, implementing the iterable protocol allows
for a more idiomatic use like
for (let child of widget)
doStuff(child);
and also provides a convenient replacement for the removed get_children()
method:
const children = [...widget];
modules/core/overrides/Gtk.js | 7 +++++++
1 file changed, 7 insertions(+)
---
diff --git a/modules/core/overrides/Gtk.js b/modules/core/overrides/Gtk.js
index 9839c0ba..a1e85314 100644
--- a/modules/core/overrides/Gtk.js
+++ b/modules/core/overrides/Gtk.js
@@ -125,6 +125,13 @@ function _init() {
return klass;
};
+ if (Gtk.Widget.prototype.get_first_child) {
+ Gtk.Widget.prototype[Symbol.iterator] = function* () {
+ for (let c = this.get_first_child(); c; c = c.get_next_sibling())
+ yield c;
+ };
+ }
+
if (Gtk.BuilderScope) {
BuilderScope = GObject.registerClass({
Implements: [Gtk.BuilderScope],
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]