╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
607 var self = View{ .box = box }; 608 // a page opens on its tabs, except that search results open in the 609 // tab's own search box. 610 const results = data.files.find != null or 611 (data.changes == .commits and data.changes.commits.search != null) or 612 data.discussions.search != null or data.issues.search != null or data.patches.search != null; 613 self.getFocus().child_id = box.children.keys()[if (results) stack_index else header_index]; 614 return self; 615 } 616 617 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 618 self.box.deinit(allocator); 619 } 620 621 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 622 self.clearGrid(); 623 const header = &self.box.children.values()[header_index].widget.repo_header; 624 const stack = &self.box.children.values()[stack_index].widget.stack; 625 626 // each header tab maps 1:1 to a stack child by position 627 if (header.getSelectedIndex()) |index| 628 stack.getFocus().child_id = stack.children.keys()[index]; 629 try self.box.build(allocator, constraint, root_focus); 630 } 631 632 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 633 const stack = &self.box.children.values()[stack_index].widget.stack; 634 if (self.getFocus().child_id) |child_id| { 635 if (self.box.children.getIndex(child_id)) |current_index| { 636 const child = &self.box.children.values()[current_index].widget; 637 var index = current_index; 638 639 const direction = inp.vertDirection(key); 640 641 switch (direction) { 642 .up => { 643 switch (child.*) { 644 .repo_header => { 645 try child.input(allocator, key, root_focus); 646 }, 647 .stack => { 648 if (child.stack.getSelected()) |selected_widget| { 649 if (selected_widget.atTop(root_focus)) { 650 index = header_index; 651 } else { 652 try child.input(allocator, key, root_focus); 653 } 654 } 655 }, 656 else => {}, 657 } 658 }, 659 .down => { 660 switch (child.*) { 661 .repo_header => { 662 if (stack.getSelected()) |selected_widget| switch (selected_widget.*) { 663 .repo_files => |*v| if (v.focusHeader(root_focus)) return, 664 .repo_commits => |*v| if (v.focusHeader(root_focus)) return, 665 .repo_refs => |*v| if (v.focusHeader(root_focus)) return, 666 .repo_events => |*v| if (v.focusHeader(root_focus)) return, 667 .repo_undo => |*v| if (v.focusHeader(root_focus)) return, 668 .repo_settings => |*v| if (v.focusHeader(root_focus)) return, 669 .user_notifications => |*v| if (v.focusHeader(root_focus)) return, 670 else => {}, 671 }; 672 index = stack_index; 673 }, 674 .stack => { 675 try child.input(allocator, key, root_focus); 676 }, 677 else => {}, 678 } 679 }, 680 .none => { 681 try child.input(allocator, key, root_focus); 682 }, 683 } 684 685 if (index != current_index) { 686 root_focus.setFocus(self.box.children.keys()[index]); 687 } 688 } 689 } 690 } 691 692 pub fn clearGrid(self: *View) void { 693 self.box.clearGrid(); 694 } 695 696 pub fn getGrid(self: View) ?Grid { 697 return self.box.getGrid(); 698 } 699 700 pub fn getFocus(self: *View) *Focus { 701 return self.box.getFocus(); 702 } 703 }; 704