╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Fork.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
113 }, 114 }; 115 patch_data.repo_id = target_id; 116 117 const requested_ref: ?ui.RoutablePage.RefOrOid = switch (route) { 118 .fork_files => |f| if (f.oid.len == 0) null else .object, 119 .fork_commits => |c| if (c.oid.len == 0) null else .object, 120 else => null, 121 }; 122 const requested_value: []const u8 = switch (route) { 123 .fork_files => |*f| f.oid.slice(), 124 .fork_commits => |*c| c.oid.slice(), 125 else => "", 126 }; 127 const files_path: []const u8 = switch (route) { 128 .fork_files => |*f| f.path.slice(), 129 else => "", 130 }; 131 const files_line: usize = switch (route) { 132 .fork_files => |f| f.line, 133 else => 0, 134 }; 135 const files_find: []const u8 = switch (route) { 136 .fork_files => |*f| f.find.slice(), 137 else => "", 138 }; 139 const commits_content: ui.RoutablePage.RepoCommitsRoute.Content = switch (route) { 140 .fork_commits => |c| c.content, 141 else => .{ .diff = .{} }, 142 }; 143 const files = try Files.init(.xit, repo_opts, arena, fork_repo, io, arena.child_allocator, handle, requested_ref, requested_value, files_path, files_line, files_find); 144 var commits = try Commits.init(.xit, repo_opts, arena, fork_repo, io, arena.child_allocator, haxy_moment, handle, requested_ref, requested_value, commits_content, &commits_base_oid, "", ""); 145 commits.commit_count = if (newest_revision) |revision| revision.record.commit_count else 0; 146 const diff_start: usize = switch (route) { 147 .fork_diff => |d| d.start, 148 else => 0, 149 }; 150 const diff_path = switch (route) { 151 .fork_diff => |*d| try aa.dupe(u8, d.path.slice()), 152 else => "", 153 }; 154 155 return .{ 156 .header = try Header.init(arena, target_record.event.name, identity.owner, &id_hex, requested_value), 157 .files = files, 158 .commits = commits, 159 .patch = patch_data, 160 .diff = .{ 161 .route = .{ .fork = .{ .identity = try aa.dupe(u8, identity.identity), .id = try aa.dupe(u8, &id_hex) } }, 162 .path = diff_path, 163 .window = try Diff.render(.xit, repo_opts, io, arena.child_allocator, aa, fork_repo, &commits_base_oid, fork_oid, diff_start, diff_path), 164 }, 165 .auth = Auth.init(), 166 .quit = Quit.init(), 167 }; 168 }, 169 } 170 } 171 172 pub const View = struct { 173 box: wgt.Box(ui.Widget), 174 175 const header_index: usize = 0; 176 const stack_index: usize = 1; 177 178 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 179 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 180 errdefer box.deinit(allocator); 181 { 182 var header = try Header.View.init(allocator, &data.header, data.commits.commit_count, session); 183 errdefer header.deinit(allocator); 184 try box.children.put(allocator, header.getFocus().id, .{ .widget = .{ .fork_header = header }, .rect = null, .min_size = null }); 185 } 186 { 187 var stack = try wgt.Stack(ui.Widget).init(allocator); 188 errdefer stack.deinit(allocator); 189 const selected = data.patch.selectedThread() orelse return error.NotFound; 190 var patch_detail = try Patches.Detail.init(allocator, &data.patch, session, selected.*, .{ .actions = data.patch.repo_source != null }); 191 errdefer patch_detail.deinit(allocator); 192 try stack.children.put(allocator, patch_detail.getFocus().id, .{ .repo_patch_detail = patch_detail }); 193 { 194 var diff = try Diff.View.init(allocator, &data.diff, session); 195 errdefer diff.deinit(allocator); 196 try stack.children.put(allocator, diff.getFocus().id, .{ .diff_view = diff }); 197 } 198 { 199 var files = try Files.View.init(allocator, &data.files, session); 200 errdefer files.deinit(allocator); 201 try stack.children.put(allocator, files.getFocus().id, .{ .repo_files = files }); 202 } 203 { 204 var commits = try Commits.View.init(allocator, &data.commits, session); 205 errdefer commits.deinit(allocator); 206 try stack.children.put(allocator, commits.getFocus().id, .{ .repo_commits = commits }); 207 } 208 if (session.data.user_id != null) { 209 const identity = try std.fmt.allocPrint(session.page_arena.allocator(), "{s}/{s}", .{ data.header.forker_name, data.header.name }); 210 const route = ui.RoutablePage.forkNewRepoRoute(identity, data.header.id) orelse return error.RouteTooLong; 211 var new_repo = try ui.NewRepo.View.init(allocator, session, route); 212 errdefer new_repo.deinit(allocator); 213 try stack.children.put(allocator, new_repo.getFocus().id, .{ .new_repo = new_repo }); 214 } 215 if (session.data.host_kind == .server) { 216 var auth = try Auth.View.init(allocator, &data.auth, session); 217 errdefer auth.deinit(allocator); 218 try stack.children.put(allocator, auth.getFocus().id, .{ .home_auth = auth }); 219 } 220 if (session.is_terminal) { 221 var quit = try Quit.View.init(allocator, session); 222 errdefer quit.deinit(allocator); 223 try stack.children.put(allocator, quit.getFocus().id, .{ .quit = quit }); 224 } 225 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 226 } 227 // a page opens on its tabs, except that search results open in the 228 // files tab's search box. 229 box.getFocus().child_id = box.children.keys()[if (data.files.find != null) stack_index else header_index]; 230 return .{ .box = box }; 231 } 232 233 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 234 self.box.deinit(allocator); 235 } 236 237 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 238 self.clearGrid(); 239 const header = &self.box.children.values()[header_index].widget.fork_header; 240 const stack = &self.box.children.values()[stack_index].widget.stack; 241 if (header.getSelectedIndex()) |index| stack.getFocus().child_id = stack.children.keys()[index]; 242 try self.box.build(allocator, constraint, root_focus); 243 } 244 245 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 246 const stack = &self.box.children.values()[stack_index].widget.stack; 247 const current_id = self.box.getFocus().child_id orelse return; 248 const current_index = self.box.children.getIndex(current_id) orelse return; 249 const child = &self.box.children.values()[current_index].widget; 250 var next_index = current_index; 251 switch (inp.vertDirection(key)) { 252 .up => switch (child.*) { 253 .fork_header => try child.input(allocator, key, root_focus), 254 .stack => if (stack.getSelected()) |selected| { 255 if (selected.atTop(root_focus)) next_index = header_index else try child.input(allocator, key, root_focus); 256 }, 257 else => {}, 258 }, 259 .down => switch (child.*) { 260 .fork_header => { 261 if (stack.getSelected()) |selected| switch (selected.*) { 262 .repo_patch_detail => |*view| if (view.focusFirst(root_focus)) return, 263 .repo_files => |*view| if (view.focusHeader(root_focus)) return, 264 .repo_commits => |*view| if (view.focusHeader(root_focus)) return, 265 else => {}, 266 }; 267 next_index = stack_index; 268 }, 269 .stack => try child.input(allocator, key, root_focus), 270 else => {}, 271 }, 272 .none => try child.input(allocator, key, root_focus), 273 } 274 if (next_index != current_index) root_focus.setFocus(self.box.children.keys()[next_index]); 275 } 276 277 pub fn clearGrid(self: *View) void { 278 self.box.clearGrid(); 279 } 280 281 pub fn getGrid(self: View) ?Grid { 282 return self.box.getGrid(); 283 } 284 285 pub fn getFocus(self: *View) *Focus { 286 return self.box.getFocus(); 287 } 288 }; 289