From d7e7f559562f681747792fb4c58ab070a9345127 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 26 Aug 2024 20:09:45 -0700 Subject: [PATCH] apprt/gtk: support last_tab --- src/apprt/gtk/Surface.zig | 33 +++++++-------------------------- src/apprt/gtk/Window.zig | 7 +++++++ 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/src/apprt/gtk/Surface.zig b/src/apprt/gtk/Surface.zig index 7ae690ce5..8e393a2bc 100644 --- a/src/apprt/gtk/Surface.zig +++ b/src/apprt/gtk/Surface.zig @@ -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 { diff --git a/src/apprt/gtk/Window.zig b/src/apprt/gtk/Window.zig index 1615b986f..9df7a04ed 100644 --- a/src/apprt/gtk/Window.zig +++ b/src/apprt/gtk/Window.zig @@ -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;