╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
597 errdefer new_repo_view.deinit(allocator); 598 try stack.children.put(allocator, new_repo_view.getFocus().id, .{ .new_repo = new_repo_view }); 599 } else if (session.data.host_kind == .server) { 600 const route = ui.RoutablePage{ .repo_user_new = ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len).from(identity) orelse return error.RouteTooLong }; 601 var new_user_view = try ui.NewUser.View.init(allocator, session, route); 602 errdefer new_user_view.deinit(allocator); 603 try stack.children.put(allocator, new_user_view.getFocus().id, .{ .new_user = new_user_view }); 604 } 605 606 if (session.data.host_kind == .server) { 607 const route = ui.RoutablePage{ .repo_user = .{ .name = ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len).from(identity) orelse return error.RouteTooLong } }; 608 var user_view = try ui.UserSettings.initView(allocator, session, &data.user_notifications, route); 609 errdefer user_view.deinit(allocator); 610 try stack.children.put(allocator, user_view.getFocus().id, user_view); 611 } 612 613 if (session.is_terminal) { 614 var quit_view = try Quit.View.init(allocator, session); 615 errdefer quit_view.deinit(allocator); 616 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 617 } 618 619 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 620 } 621 622 var self = View{ .box = box }; 623 // a page opens on its tabs, except that search results open in the 624 // tab's own search box. 625 const results = data.files.find != null or 626 (data.changes == .commits and data.changes.commits.search != null) or 627 data.discussions.search != null or data.issues.search != null or data.patches.search != null; 628 self.getFocus().child_id = box.children.keys()[if (results) stack_index else header_index]; 629 return self; 630 } 631 632 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 633 self.box.deinit(allocator); 634 } 635 636 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 637 self.clearGrid(); 638 const header = &self.box.children.values()[header_index].widget.repo_header; 639 const stack = &self.box.children.values()[stack_index].widget.stack; 640 641 // each header tab maps 1:1 to a stack child by position 642 if (header.getSelectedIndex()) |index| 643 stack.getFocus().child_id = stack.children.keys()[index]; 644 try self.box.build(allocator, constraint, root_focus); 645 } 646 647 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 648 const stack = &self.box.children.values()[stack_index].widget.stack; 649 if (self.getFocus().child_id) |child_id| { 650 if (self.box.children.getIndex(child_id)) |current_index| { 651 const child = &self.box.children.values()[current_index].widget; 652 var index = current_index; 653 654 const direction = inp.vertDirection(key); 655 656 switch (direction) { 657 .up => { 658 switch (child.*) { 659 .repo_header => { 660 try child.input(allocator, key, root_focus); 661 }, 662 .stack => { 663 if (child.stack.getSelected()) |selected_widget| { 664 if (selected_widget.atTop(root_focus)) { 665 index = header_index; 666 } else { 667 try child.input(allocator, key, root_focus); 668 } 669 } 670 }, 671 else => {}, 672 } 673 }, 674 .down => { 675 switch (child.*) { 676 .repo_header => { 677 if (stack.getSelected()) |selected_widget| switch (selected_widget.*) { 678 .repo_files => |*v| if (v.focusHeader(root_focus)) return, 679 .repo_commits => |*v| if (v.focusHeader(root_focus)) return, 680 .repo_refs => |*v| if (v.focusHeader(root_focus)) return, 681 .repo_events => |*v| if (v.focusHeader(root_focus)) return, 682 .repo_undo => |*v| if (v.focusHeader(root_focus)) return, 683 .repo_settings => |*v| if (v.focusHeader(root_focus)) return, 684 .user_notifications => |*v| if (v.focusHeader(root_focus)) return, 685 else => {}, 686 }; 687 index = stack_index; 688 }, 689 .stack => { 690 try child.input(allocator, key, root_focus); 691 }, 692 else => {}, 693 } 694 }, 695 .none => { 696 try child.input(allocator, key, root_focus); 697 }, 698 } 699 700 if (index != current_index) { 701 root_focus.setFocus(self.box.children.keys()[index]); 702 } 703 } 704 } 705 } 706 707 pub fn clearGrid(self: *View) void { 708 self.box.clearGrid(); 709 } 710 711 pub fn getGrid(self: View) ?Grid { 712 return self.box.getGrid(); 713 } 714 715 pub fn getFocus(self: *View) *Focus { 716 return self.box.getFocus(); 717 } 718 }; 719