╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Fork.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
184 }; 185 }, 186 } 187 } 188 189 pub const View = struct { 190 box: wgt.Box(ui.Widget), 191 192 const header_index: usize = 0; 193 const stack_index: usize = 1; 194 195 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 196 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border = null, .direction = .vert }); 197 errdefer box.deinit(allocator); 198 { 199 var header = try Header.View.init(allocator, &data.header, data.commits.commit_count, data.delete != null, session); 200 errdefer header.deinit(allocator); 201 try box.children.put(allocator, header.getFocus().id, .{ .widget = .{ .fork_header = header }, .rect = null, .min_size = null }); 202 } 203 { 204 var stack = try wgt.Stack(ui.Widget).init(allocator); 205 errdefer stack.deinit(allocator); 206 const selected = data.patch.selectedThread() orelse return error.NotFound; 207 var patch_detail = try Patches.Detail.init(allocator, &data.patch, session, selected.*, .{ .actions = data.patch.repo_source != null }); 208 errdefer patch_detail.deinit(allocator); 209 try stack.children.put(allocator, patch_detail.getFocus().id, .{ .repo_patch_detail = patch_detail }); 210 { 211 var diff = try Diff.View.init(allocator, &data.diff, session); 212 errdefer diff.deinit(allocator); 213 try stack.children.put(allocator, diff.getFocus().id, .{ .diff_view = diff }); 214 } 215 { 216 var files = try Files.View.init(allocator, &data.files, session); 217 errdefer files.deinit(allocator); 218 try stack.children.put(allocator, files.getFocus().id, .{ .repo_files = files }); 219 } 220 { 221 var commits = try Commits.View.init(allocator, &data.commits, session); 222 errdefer commits.deinit(allocator); 223 try stack.children.put(allocator, commits.getFocus().id, .{ .repo_commits = commits }); 224 } 225 const identity = try session.page_arena.allocator().print("{s}:{s}", .{ data.header.forker_name, data.header.name }); 226 // right after commits, as in the header 227 if (data.delete) |delete| { 228 var view = try ui.Delete.View.init(allocator, delete, session, ui.RoutablePage.forkDeleteRoute(identity, data.header.id) orelse return error.RouteTooLong); 229 errdefer view.deinit(allocator); 230 try stack.children.put(allocator, view.getFocus().id, .{ .delete_form = view }); 231 } 232 if (session.data.user_id != null) { 233 const route = ui.RoutablePage.forkRepoNewRoute(identity, data.header.id) orelse return error.RouteTooLong; 234 var new_repo = try ui.NewRepo.View.init(allocator, session, route); 235 errdefer new_repo.deinit(allocator); 236 try stack.children.put(allocator, new_repo.getFocus().id, .{ .new_repo = new_repo }); 237 } else if (session.data.host_kind == .server) { 238 const route = ui.RoutablePage.forkUserNewRoute(identity, data.header.id) orelse return error.RouteTooLong; 239 var new_user = try ui.NewUser.View.init(allocator, session, route); 240 errdefer new_user.deinit(allocator); 241 try stack.children.put(allocator, new_user.getFocus().id, .{ .new_user = new_user }); 242 } 243 if (session.data.host_kind == .server) { 244 const route = ui.RoutablePage.forkUserRoute(identity, data.header.id) orelse return error.RouteTooLong; 245 var user_view = try ui.UserSettings.initView(allocator, session, &data.user_notifications, route); 246 errdefer user_view.deinit(allocator); 247 try stack.children.put(allocator, user_view.getFocus().id, user_view); 248 } 249 if (session.is_terminal) { 250 var quit = try Quit.View.init(allocator, session); 251 errdefer quit.deinit(allocator); 252 try stack.children.put(allocator, quit.getFocus().id, .{ .quit = quit }); 253 } 254 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 255 } 256 // a page opens on its tabs, except that search results open in the 257 // files tab's search box. 258 box.getFocus().child_id = box.children.keys()[if (data.files.find != null) stack_index else header_index]; 259 return .{ .box = box }; 260 } 261 262 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 263 self.box.deinit(allocator); 264 } 265 266 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 267 self.clearGrid(); 268 const header = &self.box.children.values()[header_index].widget.fork_header; 269 const stack = &self.box.children.values()[stack_index].widget.stack; 270 if (header.getSelectedIndex()) |index| stack.getFocus().child_id = stack.children.keys()[index]; 271 try self.box.build(allocator, constraint, root_focus); 272 } 273 274 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 275 const stack = &self.box.children.values()[stack_index].widget.stack; 276 const current_id = self.box.getFocus().child_id orelse return; 277 const current_index = self.box.children.getIndex(current_id) orelse return; 278 const child = &self.box.children.values()[current_index].widget; 279 var next_index = current_index; 280 switch (inp.vertDirection(key)) { 281 .up => switch (child.*) { 282 .fork_header => try child.input(allocator, key, root_focus), 283 .stack => if (stack.getSelected()) |selected| { 284 if (selected.atTop(root_focus)) next_index = header_index else try child.input(allocator, key, root_focus); 285 }, 286 else => {}, 287 }, 288 .down => switch (child.*) { 289 .fork_header => { 290 if (stack.getSelected()) |selected| switch (selected.*) { 291 .repo_patch_detail => |*view| if (view.focusFirst(root_focus)) return, 292 .repo_files => |*view| if (view.focusHeader(root_focus)) return, 293 .repo_commits => |*view| if (view.focusHeader(root_focus)) return, 294 .user_notifications => |*view| if (view.focusHeader(root_focus)) return, 295 else => {}, 296 }; 297 next_index = stack_index; 298 }, 299 .stack => try child.input(allocator, key, root_focus), 300 else => {}, 301 }, 302 .none => try child.input(allocator, key, root_focus), 303 } 304 if (next_index != current_index) root_focus.setFocus(self.box.children.keys()[next_index]); 305 } 306 307 pub fn clearGrid(self: *View) void { 308 self.box.clearGrid(); 309 } 310 311 pub fn getGrid(self: View) ?Grid { 312 return self.box.getGrid(); 313 } 314 315 pub fn getFocus(self: *View) *Focus { 316 return self.box.getFocus(); 317 } 318 }; 319