apprt/gtk: support last_tab

This commit is contained in:
Mitchell Hashimoto
2024-08-26 20:09:45 -07:00
parent 3d1ee3daa8
commit d7e7f55956
2 changed files with 14 additions and 26 deletions

View File

@ -795,31 +795,7 @@ pub fn hasTabs(self: *const Surface) bool {
return window.hasTabs();
}
pub fn gotoPreviousTab(self: *Surface) void {
const window = self.container.window() orelse {
log.info(
"gotoPreviousTab invalid for container={s}",
.{@tagName(self.container)},
);
return;
};
window.gotoPreviousTab(self);
}
pub fn gotoNextTab(self: *Surface) void {
const window = self.container.window() orelse {
log.info(
"gotoNextTab invalid for container={s}",
.{@tagName(self.container)},
);
return;
};
window.gotoNextTab(self);
}
pub fn gotoTab(self: *Surface, n: usize) void {
pub fn gotoTab(self: *Surface, tab: apprt.GotoTab) void {
const window = self.container.window() orelse {
log.info(
"gotoTab invalid for container={s}",
@ -828,7 +804,12 @@ pub fn gotoTab(self: *Surface, n: usize) void {
return;
};
window.gotoTab(n);
switch (tab) {
.previous => window.gotoPreviousTab(self),
.next => window.gotoNextTab(self),
.last => window.gotoLastTab(),
else => window.gotoTab(@intFromEnum(tab)),
}
}
pub fn setShouldClose(self: *Surface) void {

View File

@ -288,6 +288,13 @@ pub fn gotoNextTab(self: *Window, surface: *Surface) void {
self.focusCurrentTab();
}
/// Go to the next tab for a surface.
pub fn gotoLastTab(self: *Window) void {
const max = c.gtk_notebook_get_n_pages(self.notebook) -| 1;
c.gtk_notebook_set_current_page(self.notebook, max);
self.focusCurrentTab();
}
/// Go to the specific tab index.
pub fn gotoTab(self: *Window, n: usize) void {
if (n == 0) return;