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