╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
542 } 543 544 // refs — the repo's branches and tags. 545 { 546 var refs_view = try Refs.View.init(allocator, &data.refs, session); 547 errdefer refs_view.deinit(allocator); 548 try stack.children.put(allocator, refs_view.getFocus().id, .{ .repo_refs = refs_view }); 549 } 550 551 // discussions and their comment permalinks. 552 if (data.repo.event.discuss_role != null) { 553 var discussions_view = try Discussions.View.init(allocator, &data.discussions, session); 554 errdefer discussions_view.deinit(allocator); 555 try stack.children.put(allocator, discussions_view.getFocus().id, .{ .repo_discussions = discussions_view }); 556 } 557 558 // issues — the repo's issue tracker and comment permalinks. 559 if (data.repo.event.issue_role != null) { 560 var issues_view = try Issues.View.init(allocator, &data.issues, session); 561 errdefer issues_view.deinit(allocator); 562 try stack.children.put(allocator, issues_view.getFocus().id, .{ .repo_issues = issues_view }); 563 } 564 565 // patches and their comment permalinks. 566 if (data.repo.event.patch_role != null) { 567 var patches_view = try Patches.View.init(allocator, &data.patches, session); 568 errdefer patches_view.deinit(allocator); 569 try stack.children.put(allocator, patches_view.getFocus().id, .{ .repo_patches = patches_view }); 570 } 571 572 if (data.handle.canWrite()) { 573 var events_view = try Events.View.init(allocator, &data.events, session); 574 errdefer events_view.deinit(allocator); 575 try stack.children.put(allocator, events_view.getFocus().id, .{ .repo_events = events_view }); 576 } 577 578 if (data.undo) |*undo| { 579 var undo_view = try Undo.View.init(allocator, undo, session); 580 errdefer undo_view.deinit(allocator); 581 try stack.children.put(allocator, undo_view.getFocus().id, .{ .repo_undo = undo_view }); 582 } 583 584 if (data.settings) |*settings| { 585 var settings_view = try Settings.View.init(allocator, settings, session); 586 errdefer settings_view.deinit(allocator); 587 try stack.children.put(allocator, settings_view.getFocus().id, .{ .repo_settings = settings_view }); 588 } 589 590 // the header shows new repo with a login, and new user without one 591 // and user only outside local mode, so keep the stack's children 592 // 1:1 with the tabs by skipping the same views. 593 const identity = try session.page_arena.allocator().print("{s}:{s}", .{ data.header.owner_name, data.header.name }); 594 if (session.data.user_id != null) { 595 const route = ui.RoutablePage{ .repo_repo_new = ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len).from(identity) orelse return error.RouteTooLong }; 596 var new_repo_view = try ui.NewRepo.View.init(allocator, session, route); 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