From 897649a3afd192f8e7552e16b815d4c11602ba2c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 16 Jul 2025 13:44:59 -0700 Subject: [PATCH] apprt/gtk-ng: GhosttyConfigErrors --- src/apprt/gtk-ng/build/gresource.zig | 1 + src/apprt/gtk-ng/class/config_errors.zig | 70 +++++++++++++++++++ .../gtk-ng/ui/1.5/config-errors-dialog.blp | 26 +++++++ 3 files changed, 97 insertions(+) create mode 100644 src/apprt/gtk-ng/class/config_errors.zig create mode 100644 src/apprt/gtk-ng/ui/1.5/config-errors-dialog.blp diff --git a/src/apprt/gtk-ng/build/gresource.zig b/src/apprt/gtk-ng/build/gresource.zig index db5c2cf6e..433c504da 100644 --- a/src/apprt/gtk-ng/build/gresource.zig +++ b/src/apprt/gtk-ng/build/gresource.zig @@ -30,6 +30,7 @@ pub const icon_sizes: []const comptime_int = &.{ 16, 32, 128, 256, 512, 1024 }; /// /// These will be asserted to exist at runtime. pub const blueprints: []const Blueprint = &.{ + .{ .major = 1, .minor = 5, .name = "config-errors-dialog" }, .{ .major = 1, .minor = 5, .name = "window" }, }; diff --git a/src/apprt/gtk-ng/class/config_errors.zig b/src/apprt/gtk-ng/class/config_errors.zig new file mode 100644 index 000000000..fdf16602b --- /dev/null +++ b/src/apprt/gtk-ng/class/config_errors.zig @@ -0,0 +1,70 @@ +const std = @import("std"); +const adw = @import("adw"); +const gobject = @import("gobject"); +const gtk = @import("gtk"); + +const gresource = @import("../build/gresource.zig"); +const adw_version = @import("../adw_version.zig"); +const GhosttyConfig = @import("config.zig").GhosttyConfig; + +const log = std.log.scoped(.gtk_ghostty_window); + +pub const GhosttyConfigErrors = extern struct { + const Self = @This(); + parent_instance: Parent, + + pub const Parent = if (adw_version.supportsDialogs()) + adw.AlertDialog + else + adw.MessageDialog; + + pub const getGObjectType = gobject.ext.defineClass(Self, .{ + .instanceInit = &init, + .classInit = &Class.init, + .parent_class = &Class.parent, + .private = .{ .Type = Private, .offset = &Private.offset }, + }); + + const Private = struct { + _todo: u8 = 0, + var offset: c_int = 0; + }; + + pub fn new(config: *GhosttyConfig) *Self { + return gobject.ext.newInstance(Self, .{ + .config = config, + }); + } + + fn init(self: *Self, _: *Class) callconv(.C) void { + gtk.Widget.initTemplate(self.as(gtk.Widget)); + } + + pub fn as(win: *Self, comptime T: type) *T { + return gobject.ext.as(T, win); + } + + pub const Class = extern struct { + parent_class: Parent.Class, + var parent: *Parent.Class = undefined; + pub const Instance = Self; + + fn init(class: *Class) callconv(.C) void { + gtk.Widget.Class.setTemplateFromResource( + class.as(gtk.Widget.Class), + switch (Parent) { + adw.AlertDialog => comptime gresource.blueprint(.{ + .major = 1, + .minor = 5, + .name = "config-errors-dialog", + }), + else => unreachable, + }, + ); + } + + pub fn as(class: *Class, comptime T: type) *T { + return gobject.ext.as(T, class); + } + }; +}; diff --git a/src/apprt/gtk-ng/ui/1.5/config-errors-dialog.blp b/src/apprt/gtk-ng/ui/1.5/config-errors-dialog.blp new file mode 100644 index 000000000..2669ef390 --- /dev/null +++ b/src/apprt/gtk-ng/ui/1.5/config-errors-dialog.blp @@ -0,0 +1,26 @@ +using Gtk 4.0; +using Adw 1; + +Adw.AlertDialog config_errors_dialog { + heading: _("Configuration Errors"); + body: _("One or more configuration errors were found. Please review the errors below, and either reload your configuration or ignore these errors."); + + responses [ + ignore: _("Ignore"), + reload: _("Reload Configuration") suggested, + ] + + extra-child: ScrolledWindow { + min-content-width: 500; + min-content-height: 100; + + TextView { + editable: false; + cursor-visible: false; + top-margin: 8; + bottom-margin: 8; + left-margin: 8; + right-margin: 8; + } + }; +}