mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
apprt/gtk: update config error contents on reload
This commit is contained in:
@ -14,6 +14,7 @@ const log = std.log.scoped(.gtk);
|
|||||||
|
|
||||||
app: *App,
|
app: *App,
|
||||||
window: *c.GtkWindow,
|
window: *c.GtkWindow,
|
||||||
|
view: PrimaryView,
|
||||||
|
|
||||||
pub fn create(app: *App) !void {
|
pub fn create(app: *App) !void {
|
||||||
if (app.config_errors_window != null) return error.InvalidOperation;
|
if (app.config_errors_window != null) return error.InvalidOperation;
|
||||||
@ -27,6 +28,7 @@ pub fn create(app: *App) !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(self: *ConfigErrors) void {
|
pub fn update(self: *ConfigErrors) void {
|
||||||
|
self.view.update(&self.app.config);
|
||||||
_ = c.gtk_window_present(self.window);
|
_ = c.gtk_window_present(self.window);
|
||||||
_ = c.gtk_widget_grab_focus(@ptrCast(self.window));
|
_ = c.gtk_widget_grab_focus(@ptrCast(self.window));
|
||||||
}
|
}
|
||||||
@ -52,10 +54,12 @@ fn init(self: *ConfigErrors, app: *App) !void {
|
|||||||
self.* = .{
|
self.* = .{
|
||||||
.app = app,
|
.app = app,
|
||||||
.window = gtk_window,
|
.window = gtk_window,
|
||||||
|
.view = undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Show the window
|
// Show the window
|
||||||
const view = try PrimaryView.init(self);
|
const view = try PrimaryView.init(self);
|
||||||
|
self.view = view;
|
||||||
c.gtk_window_set_child(@ptrCast(window), view.root);
|
c.gtk_window_set_child(@ptrCast(window), view.root);
|
||||||
c.gtk_widget_show(window);
|
c.gtk_widget_show(window);
|
||||||
}
|
}
|
||||||
@ -71,6 +75,7 @@ fn userdataSelf(ud: *anyopaque) *ConfigErrors {
|
|||||||
|
|
||||||
const PrimaryView = struct {
|
const PrimaryView = struct {
|
||||||
root: *c.GtkWidget,
|
root: *c.GtkWidget,
|
||||||
|
text: *c.GtkTextView,
|
||||||
|
|
||||||
pub fn init(root: *ConfigErrors) !PrimaryView {
|
pub fn init(root: *ConfigErrors) !PrimaryView {
|
||||||
// All our widgets
|
// All our widgets
|
||||||
@ -79,7 +84,7 @@ const PrimaryView = struct {
|
|||||||
"the configuration. Please review the errors below and reload " ++
|
"the configuration. Please review the errors below and reload " ++
|
||||||
"your configuration or ignore the erroneous lines.",
|
"your configuration or ignore the erroneous lines.",
|
||||||
);
|
);
|
||||||
const buf = try contentsBuffer(&root.app.config);
|
const buf = contentsBuffer(&root.app.config);
|
||||||
defer c.g_object_unref(buf);
|
defer c.g_object_unref(buf);
|
||||||
const buttons = try ButtonsView.init(root);
|
const buttons = try ButtonsView.init(root);
|
||||||
const text_scroll = c.gtk_scrolled_window_new();
|
const text_scroll = c.gtk_scrolled_window_new();
|
||||||
@ -105,11 +110,17 @@ const PrimaryView = struct {
|
|||||||
c.gtk_text_view_set_left_margin(@ptrCast(text), 8);
|
c.gtk_text_view_set_left_margin(@ptrCast(text), 8);
|
||||||
c.gtk_text_view_set_right_margin(@ptrCast(text), 8);
|
c.gtk_text_view_set_right_margin(@ptrCast(text), 8);
|
||||||
|
|
||||||
return .{ .root = view.root };
|
return .{ .root = view.root, .text = @ptrCast(text) };
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update(self: *PrimaryView, config: *const Config) void {
|
||||||
|
const buf = contentsBuffer(config);
|
||||||
|
defer c.g_object_unref(buf);
|
||||||
|
c.gtk_text_view_set_buffer(@ptrCast(self.text), buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the GtkTextBuffer for the config errors that we want to show.
|
/// Returns the GtkTextBuffer for the config errors that we want to show.
|
||||||
fn contentsBuffer(config: *const Config) !*c.GtkTextBuffer {
|
fn contentsBuffer(config: *const Config) *c.GtkTextBuffer {
|
||||||
const buf = c.gtk_text_buffer_new(null);
|
const buf = c.gtk_text_buffer_new(null);
|
||||||
errdefer c.g_object_unref(buf);
|
errdefer c.g_object_unref(buf);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user