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