diff --git a/src/apprt/gtk-ng/class/command_palette.zig b/src/apprt/gtk-ng/class/command_palette.zig index 5d00cf446..8b7bb328c 100644 --- a/src/apprt/gtk-ng/class/command_palette.zig +++ b/src/apprt/gtk-ng/class/command_palette.zig @@ -174,14 +174,18 @@ pub const CommandPalette = extern struct { } } - fn dialogClosed(_: adw.Dialog, self: *CommandPalette) callconv(.c) void { + fn close(self: *CommandPalette) void { + const priv = self.private(); + _ = priv.dialog.close(); + } + + fn dialogClosed(_: *adw.Dialog, self: *CommandPalette) callconv(.c) void { self.unref(); } fn searchStopped(_: *gtk.SearchEntry, self: *CommandPalette) callconv(.c) void { // ESC was pressed - close the palette - const priv = self.private(); - _ = priv.dialog.close(); + self.close(); } fn searchActivated(_: *gtk.SearchEntry, self: *CommandPalette) callconv(.c) void { @@ -203,7 +207,7 @@ pub const CommandPalette = extern struct { // If the dialog has been shown, close it. if (priv.dialog.as(gtk.Widget).getRealized() != 0) { - _ = priv.dialog.close(); + self.close(); return; } @@ -227,7 +231,7 @@ pub const CommandPalette = extern struct { // another dialog (such as the change title dialog). If that occurs then // the command palette dialog won't be counted as having closed properly // and cannot receive focus when reopened. - _ = priv.dialog.close(); + self.close(); const cmd = gobject.ext.cast(Command, object_ orelse return) orelse return; const action = cmd.getAction() orelse return; diff --git a/src/apprt/gtk-ng/class/window.zig b/src/apprt/gtk-ng/class/window.zig index fe9a2d7b6..ae953eee0 100644 --- a/src/apprt/gtk-ng/class/window.zig +++ b/src/apprt/gtk-ng/class/window.zig @@ -1064,10 +1064,18 @@ pub const Window = extern struct { fn dispose(self: *Self) callconv(.c) void { const priv = self.private(); + + command_palette: { + // TODO: this can be simplified once WeakRef.get() can return a null. + const command_palette = gobject.ext.cast(CommandPalette, priv.command_palette.get()) orelse break :command_palette; + command_palette.unref(); + } + if (priv.config) |v| { v.unref(); priv.config = null; } + priv.tab_bindings.setSource(null); gtk.Widget.disposeTemplate( @@ -1708,9 +1716,12 @@ pub const Window = extern struct { /// TODO: accept the surface that toggled the command palette as a parameter fn toggleCommandPalette(self: *Window) void { const priv = self.private(); + // Get a reference to a command palette. First check the weak reference // that we save to see if we already have one stored. If we don't then // create a new one. + // + // TODO: once WeakRef.get() can return a null this will need to be fixed up. const command_palette = gobject.ext.cast(CommandPalette, priv.command_palette.get()) orelse command_palette: { // Create a fresh command palette. const command_palette = CommandPalette.new();