Problem description
I am working on GTK UI in Cambalache, and I have this minimal minimal Vala code to kickstart it with no functionality yet:
public class Application : Gtk.Application {
public Application () {
Object (application_id: "gps.correlate");
}
protected override void activate () {
var builder = new Gtk.Builder ();
try {
builder.add_from_file ("gps correlate.ui");
} catch (Error e) {
print ("Error: %s\n", e.message);
return;
}
var window = builder.get_object ("main_window") as Gtk.Window;
if (window != null) {
window.set_application (this);
window.present ();
}
}
public static int main (string[] args) {
var app = new Application ();
return app.run (args);
}
}
As it can be clearly seen, I only explicitly retrieve the "main_window" from Builder. However, running the program fails with message:
$ ./simple
Error: gps correlate.ui:33:1 Object with ID not found
The problematic line is <menu id="hamburger_menu"> in my popover menu defintion:
<object class="GtkMenuButton">
<property name="icon-name">open-menu-symbolic</property>
<property name="popover">
<object class="GtkPopoverMenu">
<property name="menu-model">
<menu id="hamburger_menu">
<item>
<attribute name="label">Settings</attribute>
</item>
<item>
<attribute name="label">Strip GPS Tags</attribute>
</item>
<item>
<attribute name="label">Help</attribute>
</item>
<item>
<attribute name="label">About</attribute>
</item>
</menu>
</property>
</object>
</property>
</object>
Indeed, the error got only introduced after I attempted to add the menu model for GtkPopoverMenu. Nonetheless, I don't see how this line would be responsible, nor what could I do to fix it. As I stated earlier, the only element I explicitly retrieve is the main window, and that process doesn't fail. Moreover, this line defines the id, but the error message contains a blank spot in its place.
Additional information
I compiled the program with: valac --pkg gtk4 --pkg libadwaita-1 --pkg gio-2.0 simple.vala, my OS is Fedora 39, and the whole UI file is listed for completeness down below:
<?xml version='1.0' encoding='UTF-8'?>
<!-- Created with Cambalache 0.16.0 -->
<interface>
<!-- interface-name gps correlate.ui -->
<requires lib="gio" version="2.0"/>
<requires lib="gtk" version="4.12"/>
<requires lib="libadwaita" version="1.3"/>
<object class="GtkWindow" id="main_window">
<property name="title">GPS Correlate</property>
<property name="titlebar">
<object class="GtkHeaderBar">
<child>
<object class="GtkButton" id="add_images">
<property name="icon-name">list-add-symbolic</property>
</object>
</child>
<child>
<object class="GtkButton" id="remove_images">
<property name="icon-name">edit-delete-symbolic</property>
</object>
</child>
<child>
<object class="GtkButton" id="add_gpx">
<property name="icon-name">mark-location-symbolic</property>
</object>
</child>
<child type="end">
<object class="GtkMenuButton">
<property name="icon-name">open-menu-symbolic</property>
<property name="popover">
<object class="GtkPopoverMenu">
<property name="menu-model">
<menu id="hamburger_menu">
<item>
<attribute name="label">Settings</attribute>
</item>
<item>
<attribute name="label">Strip GPS Tags</attribute>
</item>
<item>
<attribute name="label">Help</attribute>
</item>
<item>
<attribute name="label">About</attribute>
</item>
</menu>
</property>
</object>
</property>
</object>
</child>
<child type="end">
<object class="GtkStack" id="run_abort_stack">
<child>
<object class="GtkButton" id="run_correlation">
<property name="label">Run</property>
<child>
<object class="GtkBox">
<property name="spacing">6</property>
<child>
<object class="GtkImage">
<property name="icon-name">media-playback-start-symbolic</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Run</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkButton" id="abort_correlation">
<property name="label">Run</property>
<child>
<object class="GtkBox">
<property name="spacing">6</property>
<child>
<object class="GtkImage">
<property name="icon-name">media-playback-stop-symbolic</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label">Abort</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</property>
<child>
<object class="AdwBanner" id="gpx_set">
<property name="button-label">Remove</property>
<property name="valign">start</property>
</object>
</child>
</object>
</interface>