mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
apprt/gtk: add reload config
This commit is contained in:
@ -197,7 +197,10 @@ fn updateConfigErrors(self: *App) !void {
|
|||||||
|
|
||||||
fn syncActionAccelerators(self: *App) !void {
|
fn syncActionAccelerators(self: *App) !void {
|
||||||
try self.syncActionAccelerator("app.quit", .{ .quit = {} });
|
try self.syncActionAccelerator("app.quit", .{ .quit = {} });
|
||||||
|
try self.syncActionAccelerator("app.reload_config", .{ .reload_config = {} });
|
||||||
try self.syncActionAccelerator("win.close", .{ .close_surface = {} });
|
try self.syncActionAccelerator("win.close", .{ .close_surface = {} });
|
||||||
|
try self.syncActionAccelerator("win.new_window", .{ .new_window = {} });
|
||||||
|
try self.syncActionAccelerator("win.new_tab", .{ .new_tab = {} });
|
||||||
}
|
}
|
||||||
|
|
||||||
fn syncActionAccelerator(
|
fn syncActionAccelerator(
|
||||||
@ -371,6 +374,17 @@ fn gtkActivate(app: *c.GtkApplication, ud: ?*anyopaque) callconv(.C) void {
|
|||||||
}, .{ .forever = {} });
|
}, .{ .forever = {} });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn gtkActionReloadConfig(
|
||||||
|
_: *c.GSimpleAction,
|
||||||
|
_: *c.GVariant,
|
||||||
|
ud: ?*anyopaque,
|
||||||
|
) callconv(.C) void {
|
||||||
|
const self: *App = @ptrCast(@alignCast(ud orelse return));
|
||||||
|
_ = self.core_app.mailbox.push(.{
|
||||||
|
.reload_config = {},
|
||||||
|
}, .{ .forever = {} });
|
||||||
|
}
|
||||||
|
|
||||||
fn gtkActionQuit(
|
fn gtkActionQuit(
|
||||||
_: *c.GSimpleAction,
|
_: *c.GSimpleAction,
|
||||||
_: *c.GVariant,
|
_: *c.GVariant,
|
||||||
@ -386,11 +400,24 @@ fn gtkActionQuit(
|
|||||||
/// This is called to setup the action map that this application supports.
|
/// This is called to setup the action map that this application supports.
|
||||||
/// This should be called only once on startup.
|
/// This should be called only once on startup.
|
||||||
fn initActions(self: *App) void {
|
fn initActions(self: *App) void {
|
||||||
const action_quit = c.g_simple_action_new("quit", null);
|
const actions = .{
|
||||||
defer c.g_object_unref(action_quit);
|
.{ "quit", >kActionQuit },
|
||||||
_ = c.g_signal_connect_data(action_quit, "activate", c.G_CALLBACK(>kActionQuit), self, null, c.G_CONNECT_DEFAULT);
|
.{ "reload_config", >kActionReloadConfig },
|
||||||
|
};
|
||||||
|
|
||||||
c.g_action_map_add_action(@ptrCast(self.app), @ptrCast(action_quit));
|
inline for (actions) |entry| {
|
||||||
|
const action = c.g_simple_action_new(entry[0], null);
|
||||||
|
defer c.g_object_unref(action);
|
||||||
|
_ = c.g_signal_connect_data(
|
||||||
|
action,
|
||||||
|
"activate",
|
||||||
|
c.G_CALLBACK(entry[1]),
|
||||||
|
self,
|
||||||
|
null,
|
||||||
|
c.G_CONNECT_DEFAULT,
|
||||||
|
);
|
||||||
|
c.g_action_map_add_action(@ptrCast(self.app), @ptrCast(action));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This sets the self.menu property to the application menu that can be
|
/// This sets the self.menu property to the application menu that can be
|
||||||
@ -407,6 +434,13 @@ fn initMenu(self: *App) void {
|
|||||||
c.g_menu_append(section, "New Tab", "win.new_tab");
|
c.g_menu_append(section, "New Tab", "win.new_tab");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const section = c.g_menu_new();
|
||||||
|
defer c.g_object_unref(section);
|
||||||
|
c.g_menu_append_section(menu, null, @ptrCast(@alignCast(section)));
|
||||||
|
c.g_menu_append(section, "Reload Configuration", "app.reload_config");
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const section = c.g_menu_new();
|
const section = c.g_menu_new();
|
||||||
defer c.g_object_unref(section);
|
defer c.g_object_unref(section);
|
||||||
|
@ -94,12 +94,14 @@ pub fn init(self: *Window, app: *App) !void {
|
|||||||
c.gtk_window_set_titlebar(gtk_window, header);
|
c.gtk_window_set_titlebar(gtk_window, header);
|
||||||
{
|
{
|
||||||
const btn = c.gtk_menu_button_new();
|
const btn = c.gtk_menu_button_new();
|
||||||
|
c.gtk_widget_set_tooltip_text(btn, "Main Menu");
|
||||||
c.gtk_menu_button_set_icon_name(@ptrCast(btn), "open-menu-symbolic");
|
c.gtk_menu_button_set_icon_name(@ptrCast(btn), "open-menu-symbolic");
|
||||||
c.gtk_menu_button_set_menu_model(@ptrCast(btn), @ptrCast(@alignCast(app.menu)));
|
c.gtk_menu_button_set_menu_model(@ptrCast(btn), @ptrCast(@alignCast(app.menu)));
|
||||||
c.gtk_header_bar_pack_end(@ptrCast(header), btn);
|
c.gtk_header_bar_pack_end(@ptrCast(header), btn);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const btn = c.gtk_button_new_from_icon_name("tab-new-symbolic");
|
const btn = c.gtk_button_new_from_icon_name("tab-new-symbolic");
|
||||||
|
c.gtk_widget_set_tooltip_text(btn, "New Tab");
|
||||||
c.gtk_header_bar_pack_end(@ptrCast(header), btn);
|
c.gtk_header_bar_pack_end(@ptrCast(header), btn);
|
||||||
_ = c.g_signal_connect_data(btn, "clicked", c.G_CALLBACK(>kActionNewTab), self, null, c.G_CONNECT_DEFAULT);
|
_ = c.g_signal_connect_data(btn, "clicked", c.G_CALLBACK(>kActionNewTab), self, null, c.G_CONNECT_DEFAULT);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user