╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
449 var diff_view = try Diff.View.init(allocator, diff, session); 450 errdefer diff_view.deinit(allocator); 451 try stack.children.put(allocator, diff_view.getFocus().id, .{ .diff_view = diff_view }); 452 }, 453 .commits => |*commits| { 454 var commits_view = try Commits.View.init(allocator, commits, session); 455 errdefer commits_view.deinit(allocator); 456 try stack.children.put(allocator, commits_view.getFocus().id, .{ .repo_commits = commits_view }); 457 }, 458 } 459 460 // refs — the repo's branches and tags. 461 { 462 var refs_view = try Refs.View.init(allocator, &data.refs, session); 463 errdefer refs_view.deinit(allocator); 464 try stack.children.put(allocator, refs_view.getFocus().id, .{ .repo_refs = refs_view }); 465 } 466 467 // discussions and their comment permalinks. 468 if (data.repo.event.discuss_role != null) { 469 var discussions_view = try Discussions.View.init(allocator, &data.discussions, session); 470 errdefer discussions_view.deinit(allocator); 471 try stack.children.put(allocator, discussions_view.getFocus().id, .{ .repo_discussions = discussions_view }); 472 } 473 474 // issues — the repo's issue tracker and comment permalinks. 475 if (data.repo.event.issue_role != null) { 476 var issues_view = try Issues.View.init(allocator, &data.issues, session); 477 errdefer issues_view.deinit(allocator); 478 try stack.children.put(allocator, issues_view.getFocus().id, .{ .repo_issues = issues_view }); 479 } 480 481 // patches and their comment permalinks. 482 if (data.repo.event.patch_role != null) { 483 var patches_view = try Patches.View.init(allocator, &data.patches, session); 484 errdefer patches_view.deinit(allocator); 485 try stack.children.put(allocator, patches_view.getFocus().id, .{ .repo_patches = patches_view }); 486 } 487 488 if (data.handle.canWrite()) { 489 var events_view = try Events.View.init(allocator, &data.events, session); 490 errdefer events_view.deinit(allocator); 491 try stack.children.put(allocator, events_view.getFocus().id, .{ .repo_events = events_view }); 492 } 493 494 if (data.undo) |*undo| { 495 var undo_view = try Undo.View.init(allocator, undo, session); 496 errdefer undo_view.deinit(allocator); 497 try stack.children.put(allocator, undo_view.getFocus().id, .{ .repo_undo = undo_view }); 498 } 499 500 if (data.settings) |*settings| { 501 var settings_view = try Settings.View.init(allocator, settings, session); 502 errdefer settings_view.deinit(allocator); 503 try stack.children.put(allocator, settings_view.getFocus().id, .{ .repo_settings = settings_view }); 504 } 505 506 // the header shows new repo with a login, and new user without one 507 // and user only outside local mode, so keep the stack's children 508 // 1:1 with the tabs by skipping the same views. 509 const identity = try session.page_arena.allocator().print("{s}:{s}", .{ data.header.owner_name, data.header.name }); 510 if (session.data.user_id != null) { 511 const route = ui.RoutablePage{ .repo_repo_new = ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len).from(identity) orelse return error.RouteTooLong }; 512 var new_repo_view = try ui.NewRepo.View.init(allocator, session, route); 513 errdefer new_repo_view.deinit(allocator); 514 try stack.children.put(allocator, new_repo_view.getFocus().id, .{ .new_repo = new_repo_view }); 515 } else if (session.data.host_kind == .server) { 516 const route = ui.RoutablePage{ .repo_user_new = ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len).from(identity) orelse return error.RouteTooLong }; 517 var new_user_view = try ui.NewUser.View.init(allocator, session, route); 518 errdefer new_user_view.deinit(allocator); 519 try stack.children.put(allocator, new_user_view.getFocus().id, .{ .new_user = new_user_view }); 520 } 521 522 if (session.data.host_kind == .server) { 523 var user_view = try ui.UserSettings.initView(allocator, session); 524 errdefer user_view.deinit(allocator); 525 try stack.children.put(allocator, user_view.getFocus().id, user_view); 526 } 527 528 if (session.is_terminal) { 529 var quit_view = try Quit.View.init(allocator, session); 530 errdefer quit_view.deinit(allocator); 531 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 532 } 533 534 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 535 } 536 537 var self = View{ .box = box }; 538 // a page opens on its tabs, except that search results open in the 539 // tab's own search box. 540 const results = data.files.find != null or 541 (data.changes == .commits and data.changes.commits.search != null) or 542 data.discussions.search != null or data.issues.search != null or data.patches.search != null; 543 self.getFocus().child_id = box.children.keys()[if (results) stack_index else header_index]; 544 return self; 545 } 546 547 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 548 self.box.deinit(allocator); 549 } 550 551 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 552 self.clearGrid(); 553 const header = &self.box.children.values()[header_index].widget.repo_header; 554 const stack = &self.box.children.values()[stack_index].widget.stack; 555 556 // each header tab maps 1:1 to a stack child by position 557 if (header.getSelectedIndex()) |index| 558 stack.getFocus().child_id = stack.children.keys()[index]; 559 try self.box.build(allocator, constraint, root_focus); 560 } 561 562 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 563 const stack = &self.box.children.values()[stack_index].widget.stack; 564 if (self.getFocus().child_id) |child_id| { 565 if (self.box.children.getIndex(child_id)) |current_index| { 566 const child = &self.box.children.values()[current_index].widget; 567 var index = current_index; 568 569 const direction = inp.vertDirection(key); 570 571 switch (direction) { 572 .up => { 573 switch (child.*) { 574 .repo_header => { 575 try child.input(allocator, key, root_focus); 576 }, 577 .stack => { 578 if (child.stack.getSelected()) |selected_widget| { 579 if (selected_widget.atTop(root_focus)) { 580 index = header_index; 581 } else { 582 try child.input(allocator, key, root_focus); 583 } 584 } 585 }, 586 else => {}, 587 } 588 }, 589 .down => { 590 switch (child.*) { 591 .repo_header => { 592 if (stack.getSelected()) |selected_widget| switch (selected_widget.*) { 593 .repo_files => |*v| if (v.focusHeader(root_focus)) return, 594 .repo_commits => |*v| if (v.focusHeader(root_focus)) return, 595 .repo_refs => |*v| if (v.focusHeader(root_focus)) return, 596 .repo_events => |*v| if (v.focusHeader(root_focus)) return, 597 .repo_undo => |*v| if (v.focusHeader(root_focus)) return, 598 .repo_settings => |*v| if (v.focusHeader(root_focus)) return, 599 else => {}, 600 }; 601 index = stack_index; 602 }, 603 .stack => { 604 try child.input(allocator, key, root_focus); 605 }, 606 else => {}, 607 } 608 }, 609 .none => { 610 try child.input(allocator, key, root_focus); 611 }, 612 } 613 614 if (index != current_index) { 615 root_focus.setFocus(self.box.children.keys()[index]); 616 } 617 } 618 } 619 } 620 621 pub fn clearGrid(self: *View) void { 622 self.box.clearGrid(); 623 } 624 625 pub fn getGrid(self: View) ?Grid { 626 return self.box.getGrid(); 627 } 628 629 pub fn getFocus(self: *View) *Focus { 630 return self.box.getFocus(); 631 } 632 }; 633