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