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