╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1980 1981 const route = ui.RoutablePage.repoIssuesRoute(self.data.identity, .open, "", &event_id_hex) orelse return; 1982 try self.session.navigate(route); 1983 } 1984 1985 // re-emit the selected issue's event with the form's content (status 1986 // preserved), then reload the issue's page. this is the terminal path; 1987 // the web posts the form to the edit route. 1988 fn submitEditedIssue(self: *View, allocator: std.mem.Allocator) !void { 1989 if (comptime wasm) return; 1990 const io = self.session.io orelse return; 1991 const src = self.data.repo_source orelse return; 1992 const entry = self.data.selectedIssue() orelse return; 1993 const author_email = (try self.session.eventAuthorEmail()) orelse return; 1994 1995 const form = self.issueForm() orelse return; 1996 const title_input = &form.children.values()[title_field_index].widget.text_input; 1997 const tags_input = &form.children.values()[tags_field_index].widget.text_input; 1998 const description_input = &form.children.values()[description_field_index].widget.text_input; 1999 2000 const title = try title_input.text(allocator); 2001 defer allocator.free(title); 2002 const tags = try tags_input.text(allocator); 2003 defer allocator.free(tags); 2004 const description = try description_input.text(allocator); 2005 defer allocator.free(description); 2006 2007 if (!evt.Issue.fieldsValid(title, tags)) return; 2008 2009 var id_bytes: [evt.event_id_size]u8 = undefined; 2010 _ = try std.fmt.hexToBytes(&id_bytes, entry.id[0 .. evt.event_id_size * 2]); 2011 2012 switch (src.repo_kind) { 2013 inline else => |repo_kind| { 2014 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, .{ .path = src.path }); 2015 defer any_repo.deinit(io, allocator); 2016 switch (any_repo) { 2017 inline else => |*repo| try evt.Issue.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 2018 .title = title, 2019 .tags = tags, 2020 .description = description, 2021 } }, author_email), 2022 } 2023 }, 2024 } 2025 2026 const route = ui.RoutablePage.repoIssuesRoute(self.data.identity, entry.issue.event.status, "", entry.id) orelse return; 2027 try self.session.navigate(route); 2028 } 2029 2030 // flip the shown issue's status by re-emitting its event, then reload the 2031 // page rooted at the issue so the view reflects the change. this is the 2032 // terminal path; the web posts the button's form to the status route. 2033 fn toggleIssueStatus(self: *View, allocator: std.mem.Allocator, index: usize) !void { 2034 if (comptime wasm) return; 2035 const io = self.session.io orelse return; 2036 const src = self.data.repo_source orelse return; 2037 const sel = self.detailed_index[index] orelse return; 2038 const entry = self.window(index).issues[sel]; 2039 const author_email = (try self.session.eventAuthorEmail()) orelse return; 2040 2041 const status: evt.Issue.Status = switch (entry.issue.event.status) { 2042 .open => .closed, 2043 .closed => .open, 2044 }; 2045 2046 var id_bytes: [evt.event_id_size]u8 = undefined; 2047 _ = try std.fmt.hexToBytes(&id_bytes, entry.id[0 .. evt.event_id_size * 2]); 2048 2049 switch (src.repo_kind) { 2050 inline else => |repo_kind| { 2051 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, .{ .path = src.path }); 2052 defer any_repo.deinit(io, allocator); 2053 switch (any_repo) { 2054 inline else => |*repo| try evt.Issue.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .status = status }, author_email), 2055 } 2056 }, 2057 } 2058 2059 const route = ui.RoutablePage.repoIssuesRoute(self.data.identity, status, "", entry.id) orelse return; 2060 try self.session.navigate(route); 2061 } 2062 2063 // arrow keys move the tag selection; at the flow's edges focus crosses to 2064 // the neighboring widgets. 2065 fn tagsInput(self: *View, index: usize, key: Key, root_focus: *Focus) !void { 2066 const tf = self.tagFlow(index) orelse return; 2067 const cid = tf.focus.child_id orelse return; 2068 const cur = tf.indexOfFocusId(cid) orelse return; 2069 const count = tf.text_boxes.items.len; 2070 switch (key) { 2071 .arrow_left => if (cur > 0) self.focusTag(index, tf, root_focus, cur - 1) else try self.focusList(index, root_focus), 2072 .arrow_right => if (cur + 1 < count) self.focusTag(index, tf, root_focus, cur + 1), 2073 .arrow_up => if (tf.rowStep(cur, false)) |i| self.focusTag(index, tf, root_focus, i) else self.focusAuthor(index, root_focus), 2074 .arrow_down => if (tf.rowStep(cur, true)) |i| self.focusTag(index, tf, root_focus, i) else try self.focusDescription(index, root_focus), 2075 .home => self.focusTag(index, tf, root_focus, 0), 2076 .end => self.focusTag(index, tf, root_focus, count - 1), 2077 else => {}, 2078 } 2079 } 2080 2081 const button_in_row_index: usize = 1; 2082 const title_child_index: usize = 0; 2083 const tags_child_index: usize = 2; 2084 2085 fn tagFlow(self: *View, index: usize) ?*ui.TagFlow { 2086 const inner = self.detailInner(index); 2087 if (inner.children.count() <= tags_child_index) return null; 2088 return switch (inner.children.values()[tags_child_index].widget) { 2089 .tag_flow => |*tf| tf, 2090 else => null, 2091 }; 2092 } 2093 2094 fn tagsFocused(self: *View, index: usize) bool { 2095 const inner = self.detailInner(index); 2096 const cid = inner.getFocus().child_id orelse return false; 2097 return inner.children.getIndex(cid) == tags_child_index and self.tagFlow(index) != null; 2098 } 2099 2100 // the open/close button inside the detail frame's tool row, identified 2101 // by its posting kind; a logged-out session's or conflicted issue's row 2102 // has none. 2103 fn statusButton(self: *View, index: usize) ?*wgt.TextBox(ui.Widget) { 2104 const row = self.toolRow(index); 2105 if (row.children.count() <= button_in_row_index) return null; 2106 switch (row.children.values()[button_in_row_index].widget) { 2107 .text_box => |*tb| switch (tb.box.focus.kind) { 2108 .custom => |custom| if (std.mem.eql(u8, custom, "submit")) return tb, 2109 else => {}, 2110 }, 2111 else => {}, 2112 } 2113 return null; 2114 } 2115 2116 fn toolRowFocused(self: *View, index: usize) bool { 2117 const outer = self.detailOuter(index); 2118 const cid = outer.getFocus().child_id orelse return false; 2119 return outer.children.getIndex(cid) == tool_row_index; 2120 } 2121 2122 fn focusTag(self: *View, index: usize, tf: *ui.TagFlow, root_focus: *Focus, item: usize) void { 2123 root_focus.setFocus(tf.text_boxes.items[item].getFocus().id); 2124 // keep the tag visible on the terminal: its rect offset by the flow's 2125 // position in the pane. 2126 if (self.session.is_terminal and item < tf.rects.items.len) { 2127 if (self.detailInner(index).children.values()[tags_child_index].rect) |flow_rect| { 2128 var rect = tf.rects.items[item]; 2129 rect.x += flow_rect.x; 2130 rect.y += flow_rect.y; 2131 self.detailScroll(index).scrollToRect(rect); 2132 } 2133 } 2134 } 2135 2136 fn titleFocused(self: *View, index: usize) bool { 2137 const inner = self.detailInner(index); 2138 const cid = inner.getFocus().child_id orelse return false; 2139 return inner.children.getIndex(cid) == title_child_index; 2140 } 2141 2142 fn authorPresent(self: *View, index: usize) bool { 2143 return self.author_id[index] != null; 2144 } 2145 2146 fn authorFocused(self: *View, index: usize) bool { 2147 const inner = self.detailInner(index); 2148 const cid = inner.getFocus().child_id orelse return false; 2149 return cid == self.author_id[index]; 2150 } 2151 2152 fn descriptionFocused(self: *View, index: usize) bool { 2153 const cid = self.detailInner(index).getFocus().child_id orelse return false; 2154 return cid == self.description_id[index]; 2155 } 2156 2157 // the author sits right under the title at the top of the pane, so 2158 // focusing it scrolls there. 2159 fn focusAuthor(self: *View, index: usize, root_focus: *Focus) void { 2160 const id = self.author_id[index] orelse return; 2161 root_focus.setFocus(id); 2162 self.detailScroll(index).y = 0; 2163 } 2164 2165 // the title sits at the top of the pane, so focusing it scrolls there. 2166 fn focusTitle(self: *View, index: usize, root_focus: *Focus) void { 2167 const inner = self.detailInner(index); 2168 if (inner.children.count() == 0) return; 2169 root_focus.setFocus(inner.children.keys()[title_child_index]); 2170 self.detailScroll(index).y = 0; 2171 } 2172 2173 fn focusTags(self: *View, index: usize, root_focus: *Focus) !void { 2174 const tf = self.tagFlow(index) orelse return; 2175 if (tf.text_boxes.items.len == 0) return; 2176 const cid = tf.focus.child_id orelse tf.text_boxes.items[0].getFocus().id; 2177 const item = tf.indexOfFocusId(cid) orelse 0; 2178 self.focusTag(index, tf, root_focus, item); 2179 } 2180 2181 fn focusDescription(self: *View, index: usize, root_focus: *Focus) !void { 2182 if (self.description_id[index]) |id| root_focus.setFocus(id); 2183 } 2184 2185 // return to the tool row's last-focused button (the header when the 2186 // description page shows no row). 2187 fn focusToolRow(self: *View, index: usize, root_focus: *Focus) void { 2188 const cid = self.toolRow(index).getFocus().child_id orelse return self.focusHeader(root_focus); 2189 root_focus.setFocus(cid); 2190 } 2191 2192 // enter the detail pane. an empty pane (no issues) can't be entered. 2193 fn focusDetail(self: *View, index: usize, root_focus: *Focus) !void { 2194 if (self.detailInner(index).children.count() == 0) return; 2195 root_focus.setFocus(self.detailOuter(index).getFocus().id); 2196 } 2197 2198 // return to the list. 2199 fn focusList(self: *View, index: usize, root_focus: *Focus) !void { 2200 root_focus.setFocus(self.listScroll(index).getFocus().id); 2201 } 2202 2203 // cross to the header tabs above the stack. 2204 fn focusHeader(self: *View, root_focus: *Focus) void { 2205 root_focus.setFocus(self.box.children.keys()[header_index]); 2206 } 2207 2208 pub fn clearGrid(self: *View) void { 2209 self.box.clearGrid(); 2210 } 2211 2212 pub fn getGrid(self: View) ?Grid { 2213 return self.box.getGrid(); 2214 } 2215 2216 pub fn getFocus(self: *View) *Focus { 2217 return self.box.getFocus(); 2218 } 2219 2220 // for the parent's "scroll up at the top jumps to the header" check: at the 2221 // top only while the header tabs hold focus, so up from the split 2222 // crosses into the tabs first. 2223 pub fn getSelectedIndex(self: *View) ?usize { 2224 return if (self.headerActive()) 0 else 1; 2225 } 2226 }; 2227 2228 // the "a:" navigation link for `status`'s issues page filtered to the 2229 // url-encoded `tag` and rooted at issue `id` within `identity` ("owner/name"). 2230 // a rooted url ignores `status` (it derives its view from the issue's own); 2231 // with an empty `id` this is the bare list link. 2232 fn issuesLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, status: evt.Issue.Status, tag: []const u8, id: []const u8) ![]const u8 { 2233 const route = ui.RoutablePage.repoIssuesRoute(identity, status, tag, id) orelse return error.RouteTooLong; 2234 const url = try route.toUrl(page_arena); 2235 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 2236 } 2237 2238 // the in-page "ai:" anchor for selecting issue `id` in `identity`'s list; the 2239 // href is only followed with js off. 2240 fn issueRowLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, id: []const u8) ![]const u8 { 2241 const route = ui.RoutablePage.repoIssuesRoute(identity, .open, "", id) orelse return error.RouteTooLong; 2242 const url = try route.toUrl(page_arena); 2243 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 2244 } 2245 2246 // the "a:" link to the window `status_maybe` names, keeping the tag filter, 2247 // or the conflicts window when null, rooted at issue `id`. 2248 fn windowLink(page_arena: *std.heap.ArenaAllocator, data: *const Self, status_maybe: ?evt.Issue.Status, id: []const u8) ![]const u8 { 2249 if (status_maybe) |status| return issuesLink(page_arena, data.identity, status, data.tag, id); 2250 return conflictsLink(page_arena, data.identity, id); 2251 } 2252 2253 // the "a:" link to the conflicts list rooted at issue `start` ("" = the 2254 // first window). 2255 fn conflictsLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, start: []const u8) ![]const u8 { 2256 const route = ui.RoutablePage.repoIssuesConflictsRoute(identity, start) orelse return error.RouteTooLong; 2257 const url = try route.toUrl(page_arena); 2258 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 2259 } 2260 2261 // the "a:" link to the whole-description page of issue `id` within `identity`. 2262 fn descriptionLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, id: []const u8) ![]const u8 { 2263 const route = ui.RoutablePage.repoIssuesDescriptionRoute(identity, id) orelse return error.RouteTooLong; 2264 const url = try route.toUrl(page_arena); 2265 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 2266 } 2267 2268 // the "a:" link to `status`'s issues list filtered to `tag` (raw; encoded here). 2269 fn tagLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, status: evt.Issue.Status, tag: []const u8) ![]const u8 { 2270 const encoded = try ui.urlEncodeRef(page_arena.allocator(), tag); 2271 const route = ui.RoutablePage.repoIssuesRoute(identity, status, encoded, "") orelse return error.RouteTooLong; 2272 const url = try route.toUrl(page_arena); 2273 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 2274 } 2275 2276 // tabs switching between the issues page's views. 2277 pub const Header = struct { 2278 box: wgt.Box(ui.Widget), 2279 tab_ids: std.AutoArrayHashMapUnmanaged(usize, void), 2280 2281 pub fn init(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 2282 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 2283 errdefer box.deinit(allocator); 2284 2285 var tab_ids: std.AutoArrayHashMapUnmanaged(usize, void) = .empty; 2286 errdefer tab_ids.deinit(allocator); 2287 2288 const aa = session.page_arena.allocator(); 2289 2290 // a list tab per status, labeled with its listing's issue count 2291 for ([_]evt.Issue.Status{ .open, .closed }) |status| { 2292 const route = ui.RoutablePage.repoIssuesRoute(data.identity, status, data.tag, "") orelse return error.RouteTooLong; 2293 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 2294 const label = try std.fmt.allocPrint(aa, "{s} ({d})", .{ @tagName(status), data.window(status).count }); 2295 try addTab(allocator, &box, &tab_ids, label, link); 2296 } 2297 2298 // tags tab, labeled with the active tag filter 2299 { 2300 const tags_route = ui.RoutablePage.repoIssuesTagsRoute(data.identity, data.tag) orelse return error.RouteTooLong; 2301 const tags_link = try std.fmt.allocPrint(aa, "ai:{s}", .{try tags_route.toUrl(session.page_arena)}); 2302 const label = if (data.tag.len == 0) "tags" else blk: { 2303 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.tag)); 2304 break :blk try std.fmt.allocPrint(aa, "tags ({s})", .{decoded}); 2305 }; 2306 try addTab(allocator, &box, &tab_ids, label, tags_link); 2307 } 2308 2309 // new-issue tab; an edit or resolve url shows its tab in this place 2310 { 2311 const route = switch (data.view) { 2312 .edit => ui.RoutablePage.repoIssuesEditRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 2313 .resolve => ui.RoutablePage.repoIssuesResolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong, 2314 else => ui.RoutablePage.repoIssuesNewRoute(data.identity) orelse return error.RouteTooLong, 2315 }; 2316 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 2317 const label: []const u8 = switch (data.view) { 2318 .edit => "edit", 2319 .resolve => "resolve", 2320 else => "new", 2321 }; 2322 try addTab(allocator, &box, &tab_ids, label, link); 2323 } 2324 2325 // conflicts tab, labeled with the conflict count 2326 if (data.conflicts.count > 0) { 2327 const route = ui.RoutablePage.repoIssuesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 2328 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 2329 const label = try std.fmt.allocPrint(aa, "conflicts ({d})", .{data.conflicts.count}); 2330 try addTab(allocator, &box, &tab_ids, label, link); 2331 } 2332 2333 var self = Header{ .box = box, .tab_ids = tab_ids }; 2334 // the tab matching the page's view is selected initially. 2335 self.getFocus().child_id = self.tab_ids.keys()[View.viewIndex(data.view)]; 2336 return self; 2337 } 2338 2339 fn addTab(allocator: std.mem.Allocator, box: *wgt.Box(ui.Widget), tab_ids: *std.AutoArrayHashMapUnmanaged(usize, void), label: []const u8, link: []const u8) !void { 2340 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 2341 errdefer text_box.deinit(allocator); 2342 text_box.getFocus().focusable = true; 2343 text_box.getFocus().kind = .{ .custom = link }; 2344 try tab_ids.put(allocator, text_box.getFocus().id, {}); 2345 try box.children.put(allocator, text_box.getFocus().id, .{ 2346 .widget = .{ .text_box = text_box }, 2347 .rect = null, 2348 .min_size = .{ .width = label.len + 2, .height = null }, 2349 }); 2350 } 2351 2352 pub fn deinit(self: *Header, allocator: std.mem.Allocator) void { 2353 self.box.deinit(allocator); 2354 self.tab_ids.deinit(allocator); 2355 } 2356 2357 pub fn build(self: *Header, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 2358 self.clearGrid(); 2359 // only the selected tab shows its border 2360 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 2361 switch (child.widget) { 2362 .text_box => |*tb| tb.options.border_style = if (self.getFocus().child_id == id) .single else .hidden, 2363 else => {}, 2364 } 2365 } 2366 try self.box.build(allocator, constraint, root_focus); 2367 } 2368 2369 pub fn input(self: *Header, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 2370 _ = allocator; 2371 const current_tab = self.currentTabIndex() orelse return; 2372 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 2373 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 2374 } 2375 } 2376 2377 pub fn clearGrid(self: *Header) void { 2378 self.box.clearGrid(); 2379 } 2380 2381 pub fn getGrid(self: Header) ?Grid { 2382 return self.box.getGrid(); 2383 } 2384 2385 pub fn getFocus(self: *Header) *Focus { 2386 return self.box.getFocus(); 2387 } 2388 2389 pub fn getSelectedIndex(self: Header) ?usize { 2390 return self.currentTabIndex(); 2391 } 2392 2393 fn currentTabIndex(self: Header) ?usize { 2394 const child_id = self.box.focus.child_id orelse return null; 2395 return self.tab_ids.getIndex(child_id); 2396 } 2397 }; 2398