╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
565 errdefer undo_view.deinit(allocator); 566 try stack.children.put(allocator, undo_view.getFocus().id, .{ .repo_undo = undo_view }); 567 } 568 569 if (data.settings) |*settings| { 570 var settings_view = try Settings.View.init(allocator, settings, session); 571 errdefer settings_view.deinit(allocator); 572 try stack.children.put(allocator, settings_view.getFocus().id, .{ .repo_settings = settings_view }); 573 } 574 575 // the header shows new repo with a login, and new user without one 576 // and user only outside local mode, so keep the stack's children 577 // 1:1 with the tabs by skipping the same views. 578 const identity = try session.page_arena.allocator().print("{s}:{s}", .{ data.header.owner_name, data.header.name }); 579 if (session.data.user_id != null) { 580 const route = ui.RoutablePage{ .repo_repo_new = ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len).from(identity) orelse return error.RouteTooLong }; 581 var new_repo_view = try ui.NewRepo.View.init(allocator, session, route); 582 errdefer new_repo_view.deinit(allocator); 583 try stack.children.put(allocator, new_repo_view.getFocus().id, .{ .new_repo = new_repo_view }); 584 } else if (session.data.host_kind == .server) { 585 const route = ui.RoutablePage{ .repo_user_new = ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len).from(identity) orelse return error.RouteTooLong }; 586 var new_user_view = try ui.NewUser.View.init(allocator, session, route); 587 errdefer new_user_view.deinit(allocator); 588 try stack.children.put(allocator, new_user_view.getFocus().id, .{ .new_user = new_user_view }); 589 } 590 591 if (session.data.host_kind == .server) { 592 const route = ui.RoutablePage{ .repo_user = .{ .name = ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len).from(identity) orelse return error.RouteTooLong } }; 593 var user_view = try ui.UserSettings.initView(allocator, session, &data.user_notifications, route); 594 errdefer user_view.deinit(allocator); 595 try stack.children.put(allocator, user_view.getFocus().id, user_view); 596 } 597 598 if (session.is_terminal) { 599 var quit_view = try Quit.View.init(allocator, session); 600 errdefer quit_view.deinit(allocator); 601 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 602 } 603 604 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 605 } 606 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