╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Fork.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
191 } 192 { 193 var stack = try wgt.Stack(ui.Widget).init(allocator); 194 errdefer stack.deinit(allocator); 195 const selected = data.patch.selectedThread() orelse return error.NotFound; 196 var patch_detail = try Patches.Detail.init(allocator, &data.patch, session, selected.*, .{ .actions = data.patch.repo_source != null }); 197 errdefer patch_detail.deinit(allocator); 198 try stack.children.put(allocator, patch_detail.getFocus().id, .{ .repo_patch_detail = patch_detail }); 199 { 200 var diff = try Diff.View.init(allocator, &data.diff, session); 201 errdefer diff.deinit(allocator); 202 try stack.children.put(allocator, diff.getFocus().id, .{ .diff_view = diff }); 203 } 204 { 205 var files = try Files.View.init(allocator, &data.files, session); 206 errdefer files.deinit(allocator); 207 try stack.children.put(allocator, files.getFocus().id, .{ .repo_files = files }); 208 } 209 { 210 var commits = try Commits.View.init(allocator, &data.commits, session); 211 errdefer commits.deinit(allocator); 212 try stack.children.put(allocator, commits.getFocus().id, .{ .repo_commits = commits }); 213 } 214 const identity = try std.fmt.allocPrint(session.page_arena.allocator(), "{s}:{s}", .{ data.header.forker_name, data.header.name }); 215 if (session.data.user_id != null) { 216 const route = ui.RoutablePage.forkRepoNewRoute(identity, data.header.id) orelse return error.RouteTooLong; 217 var new_repo = try ui.NewRepo.View.init(allocator, session, route); 218 errdefer new_repo.deinit(allocator); 219 try stack.children.put(allocator, new_repo.getFocus().id, .{ .new_repo = new_repo }); 220 } else if (session.data.host_kind == .server) { 221 const route = ui.RoutablePage.forkUserNewRoute(identity, data.header.id) orelse return error.RouteTooLong; 222 var new_user = try ui.NewUser.View.init(allocator, session, route); 223 errdefer new_user.deinit(allocator); 224 try stack.children.put(allocator, new_user.getFocus().id, .{ .new_user = new_user }); 225 } 226 if (session.data.host_kind == .server) { 227 var user_view = try ui.UserLogout.initView(allocator, session); 228 errdefer user_view.deinit(allocator); 229 try stack.children.put(allocator, user_view.getFocus().id, user_view); 230 } 231 if (session.is_terminal) { 232 var quit = try Quit.View.init(allocator, session); 233 errdefer quit.deinit(allocator); 234 try stack.children.put(allocator, quit.getFocus().id, .{ .quit = quit }); 235 } 236 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 237 } 238 // a page opens on its tabs, except that search results open in the 239 // files tab's search box. 240 box.getFocus().child_id = box.children.keys()[if (data.files.find != null) stack_index else header_index]; 241 return .{ .box = box }; 242 } 243 244 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 245 self.box.deinit(allocator); 246 } 247 248 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 249 self.clearGrid(); 250 const header = &self.box.children.values()[header_index].widget.fork_header; 251 const stack = &self.box.children.values()[stack_index].widget.stack; 252 if (header.getSelectedIndex()) |index| stack.getFocus().child_id = stack.children.keys()[index]; 253 try self.box.build(allocator, constraint, root_focus); 254 } 255 256 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 257 const stack = &self.box.children.values()[stack_index].widget.stack; 258 const current_id = self.box.getFocus().child_id orelse return; 259 const current_index = self.box.children.getIndex(current_id) orelse return; 260 const child = &self.box.children.values()[current_index].widget; 261 var next_index = current_index; 262 switch (inp.vertDirection(key)) { 263 .up => switch (child.*) { 264 .fork_header => try child.input(allocator, key, root_focus), 265 .stack => if (stack.getSelected()) |selected| { 266 if (selected.atTop(root_focus)) next_index = header_index else try child.input(allocator, key, root_focus); 267 }, 268 else => {}, 269 }, 270 .down => switch (child.*) { 271 .fork_header => { 272 if (stack.getSelected()) |selected| switch (selected.*) { 273 .repo_patch_detail => |*view| if (view.focusFirst(root_focus)) return, 274 .repo_files => |*view| if (view.focusHeader(root_focus)) return, 275 .repo_commits => |*view| if (view.focusHeader(root_focus)) return, 276 else => {}, 277 }; 278 next_index = stack_index; 279 }, 280 .stack => try child.input(allocator, key, root_focus), 281 else => {}, 282 }, 283 .none => try child.input(allocator, key, root_focus), 284 } 285 if (next_index != current_index) root_focus.setFocus(self.box.children.keys()[next_index]); 286 } 287 288 pub fn clearGrid(self: *View) void { 289 self.box.clearGrid(); 290 } 291 292 pub fn getGrid(self: View) ?Grid { 293 return self.box.getGrid(); 294 } 295 296 pub fn getFocus(self: *View) *Focus { 297 return self.box.getFocus(); 298 } 299 }; 300