╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
551 { 552 var refs_view = try Refs.View.init(allocator, &data.refs, session); 553 errdefer refs_view.deinit(allocator); 554 try stack.children.put(allocator, refs_view.getFocus().id, .{ .repo_refs = refs_view }); 555 } 556 557 // discussions and their comment permalinks. 558 if (data.repo.event.discuss_role != null) { 559 var discussions_view = try Discussions.View.init(allocator, &data.discussions, session); 560 errdefer discussions_view.deinit(allocator); 561 try stack.children.put(allocator, discussions_view.getFocus().id, .{ .repo_discussions = discussions_view }); 562 } 563 564 // issues — the repo's issue tracker and comment permalinks. 565 if (data.repo.event.issue_role != null) { 566 var issues_view = try Issues.View.init(allocator, &data.issues, session); 567 errdefer issues_view.deinit(allocator); 568 try stack.children.put(allocator, issues_view.getFocus().id, .{ .repo_issues = issues_view }); 569 } 570 571 // patches and their comment permalinks. 572 if (data.repo.event.patch_role != null) { 573 var patches_view = try Patches.View.init(allocator, &data.patches, session); 574 errdefer patches_view.deinit(allocator); 575 try stack.children.put(allocator, patches_view.getFocus().id, .{ .repo_patches = patches_view }); 576 } 577 578 if (data.handle.canWrite()) { 579 var events_view = try Events.View.init(allocator, &data.events, session); 580 errdefer events_view.deinit(allocator); 581 try stack.children.put(allocator, events_view.getFocus().id, .{ .repo_events = events_view }); 582 } 583 584 if (data.undo) |*undo| { 585 var undo_view = try Undo.View.init(allocator, undo, session); 586 errdefer undo_view.deinit(allocator); 587 try stack.children.put(allocator, undo_view.getFocus().id, .{ .repo_undo = undo_view }); 588 } 589 590 if (data.settings) |*settings| { 591 var settings_view = try Settings.View.init(allocator, settings, session); 592 errdefer settings_view.deinit(allocator); 593 try stack.children.put(allocator, settings_view.getFocus().id, .{ .repo_settings = settings_view }); 594 } 595 596 // the header shows new repo with a login, and new user without one 597 // and user only outside local mode, so keep the stack's children 598 // 1:1 with the tabs by skipping the same views. 599 const identity = try session.page_arena.allocator().print("{s}:{s}", .{ data.header.owner_name, data.header.name }); 600 if (session.data.user_id != null) { 601 const route = ui.RoutablePage{ .repo_repo_new = ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len).from(identity) orelse return error.RouteTooLong }; 602 var new_repo_view = try ui.NewRepo.View.init(allocator, session, route); 603 errdefer new_repo_view.deinit(allocator); 604 try stack.children.put(allocator, new_repo_view.getFocus().id, .{ .new_repo = new_repo_view }); 605 } else if (session.data.host_kind == .server) { 606 const route = ui.RoutablePage{ .repo_user_new = ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len).from(identity) orelse return error.RouteTooLong }; 607 var new_user_view = try ui.NewUser.View.init(allocator, session, route); 608 errdefer new_user_view.deinit(allocator); 609 try stack.children.put(allocator, new_user_view.getFocus().id, .{ .new_user = new_user_view }); 610 } 611 612 if (session.data.host_kind == .server) { 613 const route = ui.RoutablePage{ .repo_user = .{ .name = ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len).from(identity) orelse return error.RouteTooLong } }; 614 var user_view = try ui.UserSettings.initView(allocator, session, &data.user_notifications, route); 615 errdefer user_view.deinit(allocator); 616 try stack.children.put(allocator, user_view.getFocus().id, user_view); 617 } 618 619 if (session.is_terminal) { 620 var quit_view = try Quit.View.init(allocator, session); 621 errdefer quit_view.deinit(allocator); 622 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 623 } 624 625 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 626 } 627 628 var self = View{ .box = box }; 629 // a page opens on its tabs, except that search results open in the 630 // tab's own search box. 631 const results = data.files.find != null or 632 (data.changes == .commits and data.changes.commits.search != null) or 633 data.discussions.search != null or data.issues.search != null or data.patches.search != null; 634 self.getFocus().child_id = box.children.keys()[if (results) stack_index else header_index]; 635 return self; 636 } 637 638 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 639 self.box.deinit(allocator); 640 } 641 642 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 643 self.clearGrid(); 644 const header = &self.box.children.values()[header_index].widget.repo_header; 645 const stack = &self.box.children.values()[stack_index].widget.stack; 646 647 // each header tab maps 1:1 to a stack child by position 648 if (header.getSelectedIndex()) |index| 649 stack.getFocus().child_id = stack.children.keys()[index]; 650 try self.box.build(allocator, constraint, root_focus); 651 } 652 653 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 654 const stack = &self.box.children.values()[stack_index].widget.stack; 655 if (self.getFocus().child_id) |child_id| { 656 if (self.box.children.getIndex(child_id)) |current_index| { 657 const child = &self.box.children.values()[current_index].widget; 658 var index = current_index; 659 660 const direction = inp.vertDirection(key); 661 662 switch (direction) { 663 .up => { 664 switch (child.*) { 665 .repo_header => { 666 try child.input(allocator, key, root_focus); 667 }, 668 .stack => { 669 if (child.stack.getSelected()) |selected_widget| { 670 if (selected_widget.atTop(root_focus)) { 671 index = header_index; 672 } else { 673 try child.input(allocator, key, root_focus); 674 } 675 } 676 }, 677 else => {}, 678 } 679 }, 680 .down => { 681 switch (child.*) { 682 .repo_header => { 683 if (stack.getSelected()) |selected_widget| switch (selected_widget.*) { 684 .repo_files => |*v| if (v.focusHeader(root_focus)) return, 685 .repo_commits => |*v| if (v.focusHeader(root_focus)) return, 686 .repo_refs => |*v| if (v.focusHeader(root_focus)) return, 687 .repo_events => |*v| if (v.focusHeader(root_focus)) return, 688 .repo_undo => |*v| if (v.focusHeader(root_focus)) return, 689 .repo_settings => |*v| if (v.focusHeader(root_focus)) return, 690 .user_notifications => |*v| if (v.focusHeader(root_focus)) return, 691 else => {}, 692 }; 693 index = stack_index; 694 }, 695 .stack => { 696 try child.input(allocator, key, root_focus); 697 }, 698 else => {}, 699 } 700 }, 701 .none => { 702 try child.input(allocator, key, root_focus); 703 }, 704 } 705 706 if (index != current_index) { 707 root_focus.setFocus(self.box.children.keys()[index]); 708 } 709 } 710 } 711 } 712 713 pub fn clearGrid(self: *View) void { 714 self.box.clearGrid(); 715 } 716 717 pub fn getGrid(self: View) ?Grid { 718 return self.box.getGrid(); 719 } 720 721 pub fn getFocus(self: *View) *Focus { 722 return self.box.getFocus(); 723 } 724 }; 725