-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
2 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { IntrospectedNamespace } from "../gir/namespace.js"; | ||
import { Generic, GenericType, GenerifiedTypeIdentifier } from "../gir.js"; | ||
import { IntrospectedBaseClass } from "../gir/class.js"; | ||
|
||
export default { | ||
namespace: "Gtk", | ||
version: "4.0", | ||
modifier: (namespace: IntrospectedNamespace) => { | ||
const FlowBox = namespace.getClass("FlowBox"); | ||
const ListBox = namespace.getClass("ListBox"); | ||
const StringList = namespace.getClass("StringList"); | ||
const StringObject = namespace.getClass("StringObject"); | ||
const GObject = namespace.assertInstalledImport("GObject").assertClass("Object"); | ||
|
||
if (!FlowBox) { | ||
throw new Error("Gtk.FlowBox not found."); | ||
} | ||
|
||
if (!ListBox) { | ||
throw new Error("Gtk.ListBox not found."); | ||
} | ||
|
||
if (!StringList) { | ||
throw new Error("Gtk.StringList not found."); | ||
} | ||
|
||
if (!StringObject) { | ||
throw new Error("Gtk.StringObject not found."); | ||
} | ||
|
||
// Add generic support for StringList | ||
StringList.addGeneric({ | ||
default: StringObject.getType(), | ||
constraint: GObject.getType() | ||
}); | ||
|
||
// Add generic support for FlowBox | ||
FlowBox.addGeneric({ | ||
default: GObject.getType(), | ||
constraint: GObject.getType() | ||
}); | ||
|
||
// Add generic support for ListBox | ||
ListBox.addGeneric({ | ||
default: GObject.getType(), | ||
constraint: GObject.getType() | ||
}); | ||
|
||
// Update bind_model methods to use generics | ||
const updateBindModel = (cls: IntrospectedBaseClass, widgetFuncName: string) => { | ||
cls.members = cls.members.map(m => { | ||
if (m.name === "bind_model") { | ||
m.generics.push(new Generic(new GenericType("A"), GObject.getType(), undefined, GObject.getType())); | ||
return m.copy({ | ||
parameters: m.parameters.map(p => { | ||
if (p.name === "model") { | ||
return p.copy({ | ||
type: new GenerifiedTypeIdentifier("ListModel", "Gio", [new GenericType("A")]) | ||
}); | ||
} | ||
if (p.name === "create_widget_func") { | ||
return p.copy({ | ||
type: new GenerifiedTypeIdentifier(widgetFuncName, "Gtk", [new GenericType("A")]) | ||
}); | ||
} | ||
return p; | ||
}) | ||
}); | ||
} | ||
return m; | ||
}); | ||
}; | ||
|
||
updateBindModel(FlowBox, "FlowBoxCreateWidgetFunc"); | ||
updateBindModel(ListBox, "ListBoxCreateWidgetFunc"); | ||
} | ||
}; |