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