╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
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