apprt/gtk: refactor action callbacks to reduce code duplication
It was getting very monotonous reading the code. Signed-off-by: Tristan Partin <tristan@partin.io>pull/7126/head
parent
2bcd76c3d9
commit
793c727986
|
|
@ -811,16 +811,19 @@ fn gtkWindowUpdateScaleFactor(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: we MUST NOT use the GtkButton parameter because gtkActionNewTab
|
/// Perform a binding action on the window's action surface.
|
||||||
// sends an undefined value.
|
fn performBindingAction(self: *Window, action: input.Binding.Action) void {
|
||||||
fn gtkTabNewClick(_: *gtk.Button, self: *Window) callconv(.c) void {
|
|
||||||
const surface = self.actionSurface() orelse return;
|
const surface = self.actionSurface() orelse return;
|
||||||
_ = surface.performBindingAction(.{ .new_tab = {} }) catch |err| {
|
_ = surface.performBindingAction(action) catch |err| {
|
||||||
log.warn("error performing binding action error={}", .{err});
|
log.warn("error performing binding action error={}", .{err});
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn gtkTabNewClick(_: *gtk.Button, self: *Window) callconv(.c) void {
|
||||||
|
self.performBindingAction(.{ .new_tab = {} });
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a new tab from the AdwTabOverview. We can't copy gtkTabNewClick
|
/// Create a new tab from the AdwTabOverview. We can't copy gtkTabNewClick
|
||||||
/// because we need to return an AdwTabPage from this function.
|
/// because we need to return an AdwTabPage from this function.
|
||||||
fn gtkNewTabFromOverview(_: *adw.TabOverview, self: *Window) callconv(.c) *adw.TabPage {
|
fn gtkNewTabFromOverview(_: *adw.TabOverview, self: *Window) callconv(.c) *adw.TabPage {
|
||||||
|
|
@ -1007,11 +1010,7 @@ fn gtkActionNewWindow(
|
||||||
_: ?*glib.Variant,
|
_: ?*glib.Variant,
|
||||||
self: *Window,
|
self: *Window,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const surface = self.actionSurface() orelse return;
|
self.performBindingAction(.{ .new_window = {} });
|
||||||
_ = surface.performBindingAction(.{ .new_window = {} }) catch |err| {
|
|
||||||
log.warn("error performing binding action error={}", .{err});
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gtkActionNewTab(
|
fn gtkActionNewTab(
|
||||||
|
|
@ -1019,8 +1018,7 @@ fn gtkActionNewTab(
|
||||||
_: ?*glib.Variant,
|
_: ?*glib.Variant,
|
||||||
self: *Window,
|
self: *Window,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
// We can use undefined because the button is not used.
|
self.performBindingAction(.{ .new_tab = {} });
|
||||||
gtkTabNewClick(undefined, self);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gtkActionCloseTab(
|
fn gtkActionCloseTab(
|
||||||
|
|
@ -1028,11 +1026,7 @@ fn gtkActionCloseTab(
|
||||||
_: ?*glib.Variant,
|
_: ?*glib.Variant,
|
||||||
self: *Window,
|
self: *Window,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const surface = self.actionSurface() orelse return;
|
self.performBindingAction(.{ .close_tab = {} });
|
||||||
_ = surface.performBindingAction(.{ .close_tab = {} }) catch |err| {
|
|
||||||
log.warn("error performing binding action error={}", .{err});
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gtkActionSplitRight(
|
fn gtkActionSplitRight(
|
||||||
|
|
@ -1040,11 +1034,7 @@ fn gtkActionSplitRight(
|
||||||
_: ?*glib.Variant,
|
_: ?*glib.Variant,
|
||||||
self: *Window,
|
self: *Window,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const surface = self.actionSurface() orelse return;
|
self.performBindingAction(.{ .new_split = .right });
|
||||||
_ = surface.performBindingAction(.{ .new_split = .right }) catch |err| {
|
|
||||||
log.warn("error performing binding action error={}", .{err});
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gtkActionSplitDown(
|
fn gtkActionSplitDown(
|
||||||
|
|
@ -1052,11 +1042,7 @@ fn gtkActionSplitDown(
|
||||||
_: ?*glib.Variant,
|
_: ?*glib.Variant,
|
||||||
self: *Window,
|
self: *Window,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const surface = self.actionSurface() orelse return;
|
self.performBindingAction(.{ .new_split = .down });
|
||||||
_ = surface.performBindingAction(.{ .new_split = .down }) catch |err| {
|
|
||||||
log.warn("error performing binding action error={}", .{err});
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gtkActionSplitLeft(
|
fn gtkActionSplitLeft(
|
||||||
|
|
@ -1064,11 +1050,7 @@ fn gtkActionSplitLeft(
|
||||||
_: ?*glib.Variant,
|
_: ?*glib.Variant,
|
||||||
self: *Window,
|
self: *Window,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const surface = self.actionSurface() orelse return;
|
self.performBindingAction(.{ .new_split = .left });
|
||||||
_ = surface.performBindingAction(.{ .new_split = .left }) catch |err| {
|
|
||||||
log.warn("error performing binding action error={}", .{err});
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gtkActionSplitUp(
|
fn gtkActionSplitUp(
|
||||||
|
|
@ -1076,11 +1058,7 @@ fn gtkActionSplitUp(
|
||||||
_: ?*glib.Variant,
|
_: ?*glib.Variant,
|
||||||
self: *Window,
|
self: *Window,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const surface = self.actionSurface() orelse return;
|
self.performBindingAction(.{ .new_split = .right });
|
||||||
_ = surface.performBindingAction(.{ .new_split = .up }) catch |err| {
|
|
||||||
log.warn("error performing binding action error={}", .{err});
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gtkActionToggleInspector(
|
fn gtkActionToggleInspector(
|
||||||
|
|
@ -1088,11 +1066,7 @@ fn gtkActionToggleInspector(
|
||||||
_: ?*glib.Variant,
|
_: ?*glib.Variant,
|
||||||
self: *Window,
|
self: *Window,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const surface = self.actionSurface() orelse return;
|
self.performBindingAction(.{ .inspector = .toggle });
|
||||||
_ = surface.performBindingAction(.{ .inspector = .toggle }) catch |err| {
|
|
||||||
log.warn("error performing binding action error={}", .{err});
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gtkActionCopy(
|
fn gtkActionCopy(
|
||||||
|
|
@ -1100,11 +1074,7 @@ fn gtkActionCopy(
|
||||||
_: ?*glib.Variant,
|
_: ?*glib.Variant,
|
||||||
self: *Window,
|
self: *Window,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const surface = self.actionSurface() orelse return;
|
self.performBindingAction(.{ .copy_to_clipboard = {} });
|
||||||
_ = surface.performBindingAction(.{ .copy_to_clipboard = {} }) catch |err| {
|
|
||||||
log.warn("error performing binding action error={}", .{err});
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gtkActionPaste(
|
fn gtkActionPaste(
|
||||||
|
|
@ -1112,11 +1082,7 @@ fn gtkActionPaste(
|
||||||
_: ?*glib.Variant,
|
_: ?*glib.Variant,
|
||||||
self: *Window,
|
self: *Window,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const surface = self.actionSurface() orelse return;
|
self.performBindingAction(.{ .paste_from_clipboard = {} });
|
||||||
_ = surface.performBindingAction(.{ .paste_from_clipboard = {} }) catch |err| {
|
|
||||||
log.warn("error performing binding action error={}", .{err});
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gtkActionReset(
|
fn gtkActionReset(
|
||||||
|
|
@ -1124,11 +1090,7 @@ fn gtkActionReset(
|
||||||
_: ?*glib.Variant,
|
_: ?*glib.Variant,
|
||||||
self: *Window,
|
self: *Window,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const surface = self.actionSurface() orelse return;
|
self.performBindingAction(.{ .reset = {} });
|
||||||
_ = surface.performBindingAction(.{ .reset = {} }) catch |err| {
|
|
||||||
log.warn("error performing binding action error={}", .{err});
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gtkActionClear(
|
fn gtkActionClear(
|
||||||
|
|
@ -1136,11 +1098,7 @@ fn gtkActionClear(
|
||||||
_: ?*glib.Variant,
|
_: ?*glib.Variant,
|
||||||
self: *Window,
|
self: *Window,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const surface = self.actionSurface() orelse return;
|
self.performBindingAction(.{ .clear_screen = {} });
|
||||||
_ = surface.performBindingAction(.{ .clear_screen = {} }) catch |err| {
|
|
||||||
log.warn("error performing binding action error={}", .{err});
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gtkActionPromptTitle(
|
fn gtkActionPromptTitle(
|
||||||
|
|
@ -1148,11 +1106,7 @@ fn gtkActionPromptTitle(
|
||||||
_: ?*glib.Variant,
|
_: ?*glib.Variant,
|
||||||
self: *Window,
|
self: *Window,
|
||||||
) callconv(.C) void {
|
) callconv(.C) void {
|
||||||
const surface = self.actionSurface() orelse return;
|
self.performBindingAction(.{ .prompt_surface_title = {} });
|
||||||
_ = surface.performBindingAction(.{ .prompt_surface_title = {} }) catch |err| {
|
|
||||||
log.warn("error performing binding action error={}", .{err});
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the surface to use for an action.
|
/// Returns the surface to use for an action.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue