Skip to content

Commit

Permalink
Stop usage of deprecated gtk.types.Types class
Browse files Browse the repository at this point in the history
  • Loading branch information
jwharm committed Oct 30, 2024
1 parent 43c86c2 commit 0cb6e45
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 16 deletions.
4 changes: 2 additions & 2 deletions docs/getting-started/getting_started_06.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ To handle these two cases, we override the `activate()` method, which gets calle
To learn more about `GApplication` entry points, consult the GIO [documentation](https://docs.gtk.org/gio/class.Application.html).

```java
import io.github.jwharm.javagi.gtk.types.Types;
import io.github.jwharm.javagi.gobject.types.Types;
import org.gnome.gio.ApplicationFlags;
import org.gnome.gio.File;
import org.gnome.glib.List;
Expand Down Expand Up @@ -95,7 +95,7 @@ public class ExampleApp extends Application {
Another important class that is part of the application support in GTK is {{ javadoc('Gtk.ApplicationWindow') }}. It is typically subclassed as well. Our subclass does not do anything yet, so we will just get an empty window.

```java
import io.github.jwharm.javagi.gtk.types.Types;
import io.github.jwharm.javagi.gobject.types.Types;
import org.gnome.gio.File;
import org.gnome.glib.Type;
import org.gnome.gobject.GObject;
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/getting_started_07.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Our simple ui file gives the window a title, and puts a `GtkStack` widget as the
</interface>
```

To make use of this file in our application, we revisit our `GtkApplicationWindow` subclass, and add a `GtkTemplate` annotation. The annotation is processed by the `io.github.jwharm.javagi.gtk.types.Types.register()` method. It will call {{ doc('[email protected]_template_from_resource') }} from the class init function to set the ui file as template for this class, and call {{ doc('[email protected]_template') }} in the instance init function to instantiate the template for each instance of our class.
To make use of this file in our application, we revisit our `GtkApplicationWindow` subclass, and add a `GtkTemplate` annotation. The annotation is processed by the `TemplateTypes.register()` method. It will call {{ doc('[email protected]_template_from_resource') }} from the class init function to set the ui file as template for this class, and call {{ doc('[email protected]_template') }} in the instance init function to instantiate the template for each instance of our class.

```java
...
Expand Down
9 changes: 2 additions & 7 deletions docs/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ A class with a `@GtkTemplate` annotation will be registered as a Gtk composite t
=== "Java"

```java
import io.github.jwharm.javagi.gtk.types.Types;

@GtkTemplate(name="HelloWindow", ui="/my/example/hello-window.ui")
public class HelloWindow extends ApplicationWindow {

private static final Type gtype = Types.register(HelloWindow.class);
private static final Type gtype = TemplateTypes.register(HelloWindow.class);

@GtkChild
public HeaderBar header_bar;
Expand All @@ -31,12 +29,10 @@ A class with a `@GtkTemplate` annotation will be registered as a Gtk composite t
=== "Kotlin"

```kotlin
import io.github.jwharm.javagi.gtk.types.Types

@GtkTemplate(name="HelloWindow", ui="/my/example/hello-window.ui")
class HelloWindow : ApplicationWindow {
companion object {
val gtype: Type = Types.register<HelloWindow, Widget>(HelloWindow::class.java)
val gtype: Type = TemplateTypes.register<HelloWindow, Widget>(HelloWindow::class.java)
}

@GtkChild
Expand All @@ -53,7 +49,6 @@ A class with a `@GtkTemplate` annotation will be registered as a Gtk composite t
...
```


In the above class, the `header_bar` and `label` fields and the `buttonClicked` callback function are all declared the UI file. During class initialization, the fields are set to the associated widget.

Because the registration of composite template classes uses reflection, you must add the following `exports` statement to your `module-info.java` file:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import io.github.jwharm.javagi.base.GErrorException;
import io.github.jwharm.javagi.gtk.annotations.GtkCallback;
import io.github.jwharm.javagi.gobject.JavaClosure;
import io.github.jwharm.javagi.gtk.types.TemplateTypes;
import org.gnome.glib.GLib;
import org.gnome.glib.LogLevelFlags;
import org.gnome.glib.Type;
import org.gnome.gobject.*;
import org.gnome.gtk.*;
import io.github.jwharm.javagi.gtk.types.Types;

import java.lang.foreign.MemorySegment;
import java.lang.reflect.Method;
Expand All @@ -50,7 +50,7 @@
public final class BuilderJavaScope extends BuilderCScope
implements BuilderScope {

private static final Type gtype = Types.register(BuilderJavaScope.class);
private static final Type gtype = TemplateTypes.register(BuilderJavaScope.class);

static {
Gtk.javagi$ensureInitialized();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import io.github.jwharm.javagi.base.GErrorException;
import io.github.jwharm.javagi.gtk.annotations.GtkChild;
import io.github.jwharm.javagi.gtk.annotations.GtkTemplate;
import io.github.jwharm.javagi.gtk.types.Types;
import io.github.jwharm.javagi.gtk.types.TemplateTypes;
import org.gnome.gio.ApplicationFlags;
import org.gnome.gio.Resource;
import org.gnome.glib.Type;
Expand Down Expand Up @@ -76,7 +76,7 @@ public void testGtkChild() {

@GtkTemplate(name="ChildTestWindow", ui="/io/github/jwharm/javagi/gtk/TemplateChildTest.ui")
public static class TestWindow extends ApplicationWindow {
public static Type gtype = Types.register(TestWindow.class);
public static Type gtype = TemplateTypes.register(TestWindow.class);
public TestWindow(MemorySegment address ){
super(address);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import io.github.jwharm.javagi.base.GErrorException;
import io.github.jwharm.javagi.gtk.annotations.GtkChild;
import io.github.jwharm.javagi.gtk.annotations.GtkTemplate;
import io.github.jwharm.javagi.gtk.types.Types;
import io.github.jwharm.javagi.gtk.types.TemplateTypes;
import org.gnome.gio.ApplicationFlags;
import org.gnome.gio.Resource;
import org.gnome.glib.Type;
Expand Down Expand Up @@ -71,7 +71,7 @@ public void testSignalConnection() {

@GtkTemplate(name="SignalTestWindow", ui="/io/github/jwharm/javagi/gtk/TemplateSignalTest.ui")
public static class TestWindow extends ApplicationWindow {
public static Type gtype = Types.register(TestWindow.class);
public static Type gtype = TemplateTypes.register(TestWindow.class);
public TestWindow(MemorySegment address ){
super(address);
}
Expand Down

0 comments on commit 0cb6e45

Please sign in to comment.