Skip to content

Commit

Permalink
Add missing generic parameter in Gtk.Widget[Symbol.iterator] and add …
Browse files Browse the repository at this point in the history
…documentations
  • Loading branch information
JumpLink committed Nov 8, 2024
1 parent 922819c commit 9bace34
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
20 changes: 16 additions & 4 deletions packages/lib/src/injections/gio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,23 @@ export default {
const FileEnumerator = namespace.assertClass("FileEnumerator");

FileEnumerator.fields.push(
// Implementation of the override [Gio.FileEnumerator[Symbol.iterator](https://gjs-docs.gnome.org/gjs/overrides.md#gio-fileenumerator-symbol-iterator)
new JSField({
name: "Symbol.iterator",
parent: FileEnumerator,
computed: true,
doc: 'Gio.FileEnumerator are sync iterators.\nEach iteration returns a Gio.FileInfo:\n\n```js\nimport Gio from "gi://Gio";\n\nconst dir = Gio.File.new_for_path("/");\nconst enumerator = dir.enumerate_children(\n "standard::name",\n Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,\n null\n);\n\nfor (const file_info of enumerator) {\n console.log(file_info.get_name());\n}\n```\n',
type: new FunctionType(
{},
new GenerifiedType(new NativeType("IterableIterator"), new GenericType("FileInfo"))
)
}),
// Implementation of the override [Gio.FileEnumerator[Symbol.asyncIterator]](https://gjs-docs.gnome.org/gjs/overrides.md#gio-fileenumerator-symbol-asynciterator)
new JSField({
name: "Symbol.asyncIterator",
parent: FileEnumerator,
computed: true,
doc: 'Gio.FileEnumerator are async iterators.\nEach iteration returns a Gio.FileInfo:\n\n```js\nimport Gio from "gi://Gio";\n\nconst dir = Gio.File.new_for_path("/");\nconst enumerator = dir.enumerate_children(\n "standard::name",\n Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,\n null\n);\n\nfor await (const file_info of enumerator) {\n console.log(file_info.get_name());\n}\n```\n',
type: new FunctionType(
{},
new GenerifiedType(new NativeType("AsyncIterableIterator"), new GenericType("FileInfo"))
Expand Down Expand Up @@ -572,43 +576,51 @@ export default {
const Bytes = namespace.assertInstalledImport("GLib").assertClass("Bytes");

InputStream.members.push(
// Implementation of the override [Gio.InputStream.prototype.createAsyncIterator](https://gjs-docs.gnome.org/gjs/overrides.md#gio-inputstream-createasynciterator)
new IntrospectedClassFunction({
name: "createAsyncIterator",
parent: InputStream,
doc: 'Creates an asynchronous iterator for a Gio.InputStream that reads the stream in chunks.\n\nEach iteration will return a GLib.Bytes object containing at most `count` bytes (default 4096). The iterator will end when the stream is exhausted.\n\nExample:\n```js\nimport Gio from "gi://Gio";\n\nconst textDecoder = new TextDecoder("utf-8");\n\nconst file = Gio.File.new_for_path("/etc/os-release");\nconst inputStream = file.read(null);\n\nfor await (const bytes of inputStream.createAsyncIterator(4)) {\n log(textDecoder.decode(bytes.toArray()));\n}\n```\n\n@returns An async iterator yielding GLib.Bytes objects',
parameters: [
new IntrospectedFunctionParameter({
name: "count",
type: new NativeType("number"),
isOptional: true,
direction: GirDirection.In
direction: GirDirection.In,
doc: "Maximum number of bytes to read per chunk (default: 4096)"
}),
new IntrospectedFunctionParameter({
name: "priority",
type: new NativeType("number"),
isOptional: true,
direction: GirDirection.In
direction: GirDirection.In,
doc: "I/O priority of the request (default: GLib.PRIORITY_DEFAULT)"
})
],
return_type: new GenerifiedType(
new NativeType("AsyncIterableIterator"),
new GenericType(`${Bytes.namespace.namespace}.${Bytes.name}`)
)
}),
// Implementation of the override [Gio.InputStream.prototype.createSyncIterator](https://gjs-docs.gnome.org/gjs/overrides.md#gio-inputstream-createsynciterator)
new IntrospectedClassFunction({
name: "createSyncIterator",
parent: InputStream,
doc: 'Creates a synchronous iterator for a Gio.InputStream that reads the stream in chunks.\n\nEach iteration will return a GLib.Bytes object containing at most `count` bytes (default 4096). The iterator will end when the stream is exhausted.\n\nExample:\n```js\nimport Gio from "gi://Gio";\n\nconst textDecoder = new TextDecoder("utf-8");\n\nconst file = Gio.File.new_for_path("/etc/os-release");\nconst inputStream = file.read(null);\n\nfor (const bytes of inputStream.createSyncIterator(4)) {\n log(textDecoder.decode(bytes.toArray()));\n}\n```\n\n@returns An iterable yielding GLib.Bytes objects',
parameters: [
new IntrospectedFunctionParameter({
name: "count",
type: new NativeType("number"),
isOptional: true,
direction: GirDirection.In
direction: GirDirection.In,
doc: "Maximum number of bytes to read per chunk (default: 4096)"
}),
new IntrospectedFunctionParameter({
name: "priority",
type: new NativeType("number"),
isOptional: true,
direction: GirDirection.In
direction: GirDirection.In,
doc: "I/O priority of the request (default: GLib.PRIORITY_DEFAULT)"
})
],
return_type: new GenerifiedType(
Expand Down
25 changes: 8 additions & 17 deletions packages/lib/src/injections/gtk4.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IntrospectedNamespace } from "../gir/namespace.js";
import { NativeType, FunctionType } from "../gir.js";
import { IntrospectedField, JSField } from "../gir/property.js";
import { NativeType, FunctionType, GenericType, GenerifiedType } from "../gir.js";
import { JSField } from "../gir/property.js";

export default {
namespace: "Gtk",
Expand All @@ -10,24 +10,15 @@ export default {
const Widget = namespace.assertClass("Widget");

Widget.fields.push(
new IntrospectedField({
name: "Symbol.iterator",
parent: Widget,
computed: true,
type: new FunctionType({}, new NativeType("IterableIterator"))
})
);
}

{
const ListBox = namespace.assertClass("ListBox");

ListBox.fields.push(
new JSField({
name: "Symbol.iterator",
parent: ListBox,
parent: Widget,
computed: true,
type: new FunctionType({}, new NativeType("IterableIterator"))
doc: "Gtk.Widget is an iterable of its children.",
type: new FunctionType(
{},
new GenerifiedType(new NativeType("IterableIterator"), new GenericType("Widget"))
)
})
);
}
Expand Down

0 comments on commit 9bace34

Please sign in to comment.