╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Fork.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
183 const header_index: usize = 0; 184 const stack_index: usize = 1; 185 186 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 187 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border = null, .direction = .vert }); 188 errdefer box.deinit(allocator); 189 { 190 var header = try Header.View.init(allocator, &data.header, data.commits.commit_count, session); 191 errdefer header.deinit(allocator); 192 try box.children.put(allocator, header.getFocus().id, .{ .widget = .{ .fork_header = header }, .rect = null, .min_size = null }); 193 } 194 { 195 var stack = try wgt.Stack(ui.Widget).init(allocator); 196 errdefer stack.deinit(allocator); 197 const selected = data.patch.selectedThread() orelse return error.NotFound; 198 var patch_detail = try Patches.Detail.init(allocator, &data.patch, session, selected.*, .{ .actions = data.patch.repo_source != null }); 199 errdefer patch_detail.deinit(allocator); 200 try stack.children.put(allocator, patch_detail.getFocus().id, .{ .repo_patch_detail = patch_detail }); 201 { 202 var diff = try Diff.View.init(allocator, &data.diff, session); 203 errdefer diff.deinit(allocator); 204 try stack.children.put(allocator, diff.getFocus().id, .{ .diff_view = diff }); 205 } 206 { 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 var user_view = try ui.UserSettings.initView(allocator, session); 230 errdefer user_view.deinit(allocator); 231 try stack.children.put(allocator, user_view.getFocus().id, user_view); 232 } 233 if (session.is_terminal) { 234 var quit = try Quit.View.init(allocator, session); 235 errdefer quit.deinit(allocator); 236 try stack.children.put(allocator, quit.getFocus().id, .{ .quit = quit }); 237 } 238 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 239 } 240 // a page opens on its tabs, except that search results open in the 241 // files tab's search box. 242 box.getFocus().child_id = box.children.keys()[if (data.files.find != null) stack_index else header_index]; 243 return .{ .box = box }; 244 } 245 246 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 247 self.box.deinit(allocator); 248 } 249 250 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 251 self.clearGrid(); 252 const header = &self.box.children.values()[header_index].widget.fork_header; 253 const stack = &self.box.children.values()[stack_index].widget.stack; 254 if (header.getSelectedIndex()) |index| stack.getFocus().child_id = stack.children.keys()[index]; 255 try self.box.build(allocator, constraint, root_focus); 256 } 257 258 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 259 const stack = &self.box.children.values()[stack_index].widget.stack; 260 const current_id = self.box.getFocus().child_id orelse return; 261 const current_index = self.box.children.getIndex(current_id) orelse return; 262 const child = &self.box.children.values()[current_index].widget; 263 var next_index = current_index; 264 switch (inp.vertDirection(key)) { 265 .up => switch (child.*) { 266 .fork_header => try child.input(allocator, key, root_focus), 267 .stack => if (stack.getSelected()) |selected| { 268 if (selected.atTop(root_focus)) next_index = header_index else try child.input(allocator, key, root_focus); 269 }, 270 else => {}, 271 }, 272 .down => switch (child.*) { 273 .fork_header => { 274 if (stack.getSelected()) |selected| switch (selected.*) { 275 .repo_patch_detail => |*view| if (view.focusFirst(root_focus)) return, 276 .repo_files => |*view| if (view.focusHeader(root_focus)) return, 277 .repo_commits => |*view| if (view.focusHeader(root_focus)) return, 278 else => {}, 279 }; 280 next_index = stack_index; 281 }, 282 .stack => try child.input(allocator, key, root_focus), 283 else => {}, 284 }, 285 .none => try child.input(allocator, key, root_focus), 286 } 287 if (next_index != current_index) root_focus.setFocus(self.box.children.keys()[next_index]); 288 } 289 290 pub fn clearGrid(self: *View) void { 291 self.box.clearGrid(); 292 } 293 294 pub fn getGrid(self: View) ?Grid { 295 return self.box.getGrid(); 296 } 297 298 pub fn getFocus(self: *View) *Focus { 299 return self.box.getFocus(); 300 } 301 }; 302