╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Patches.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
766 field_count += 1; 767 } 768 769 if (field_count > 0) { 770 var copyable_text = try ui.widget.CopyableText.init(allocator, session, fields[0..field_count]); 771 errdefer copyable_text.deinit(allocator); 772 try box.children.put(allocator, copyable_text.getFocus().id, .{ .widget = .{ .copyable_text = copyable_text }, .rect = null, .min_size = null }); 773 } 774 } 775 776 fn cloneDirectoryName(allocator: std.mem.Allocator, title: []const u8) ![]const u8 { 777 var name: [64]u8 = undefined; 778 var len: usize = 0; 779 var pending: ?u8 = null; 780 781 for (title) |char| { 782 if (std.ascii.isAlphanumeric(char)) { 783 const needed: usize = if (pending == null) 1 else 2; 784 if (len + needed > name.len) break; 785 if (pending) |value| { 786 name[len] = value; 787 len += 1; 788 } 789 name[len] = std.ascii.toLower(char); 790 len += 1; 791 pending = null; 792 } else if (char == ' ') { 793 if (len != 0) pending = '-'; 794 } else if (char == '.') { 795 if (len != 0 and pending != '-') pending = '.'; 796 } 797 } 798 if (len == 0) return ""; 799 return allocator.dupe(u8, name[0..len]); 800 } 801 802 // tabs switching between the patches page's views 803 pub fn initHeader(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 804 var header = try Header.init(allocator); 805 errdefer header.deinit(allocator); 806 const aa = session.page_arena.allocator(); 807 const selected_index = View.viewIndex(data.view); 808 const page_selected = std.meta.activeTag(session.data.current_page) == .repo_patches; 809 810 // a list tab per status, labeled with its listing's patch count 811 for ([_]Status{ .open, .closed, .merged }, 0..) |status, index| { 812 const route = ui.RoutablePage.repoPatchesRoute(data.identity, status, data.tag, "") orelse return error.RouteTooLong; 813 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == index); 814 var label_buf: [64]u8 = undefined; 815 const label = try std.fmt.bufPrint(&label_buf, "{s} ({d})", .{ @tagName(status), data.window(status).count }); 816 try header.addTab(allocator, label, link, index); 817 } 818 819 // tags tab, labeled with the active tag filter 820 { 821 const tags_route = ui.RoutablePage.repoThreadTagsRoute(.patch, data.identity, data.tag) orelse return error.RouteTooLong; 822 const tags_link = try ui.inPageTabLink(session, tags_route, page_selected and selected_index == View.viewIndex(.tags)); 823 const label = if (data.tag.len == 0) "tags" else blk: { 824 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.tag)); 825 break :blk try std.fmt.allocPrint(aa, "tags ({s})", .{decoded}); 826 }; 827 try header.addTab(allocator, label, tags_link, View.viewIndex(.tags)); 828 } 829 830 // new-patch tab; an edit or resolve url shows its tab in this place 831 if (session.local == null) { 832 const route = switch (data.view) { 833 .edit => ui.RoutablePage.repoThreadEditRoute(.patch, data.identity, data.selected_id) orelse return error.RouteTooLong, 834 .publish => ui.RoutablePage.repoPatchPublishRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 835 .merge => ui.RoutablePage.repoPatchMergeRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 836 .new_comment => ui.RoutablePage.repoThreadCommentNewRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 837 .edit_comment => ui.RoutablePage.repoThreadCommentEditRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 838 .remove => ui.RoutablePage.repoThreadRemoveRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 839 .resolve => ui.RoutablePage.repoPatchesResolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong, 840 else => ui.RoutablePage.repoThreadNewRoute(.patch, data.identity) orelse return error.RouteTooLong, 841 }; 842 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.new)); 843 const label: []const u8 = switch (data.view) { 844 .edit => "edit", 845 .publish => "publish", 846 .merge => "merge", 847 .new_comment => "reply", 848 .edit_comment => "edit", 849 .remove => "remove", 850 .resolve => "resolve", 851 else => "new", 852 }; 853 try header.addTab(allocator, label, link, View.viewIndex(.new)); 854 } 855 856 // drafts belong to the logged-in user and are not available locally 857 if (session.local == null) { 858 const route = ui.RoutablePage.repoPatchesDraftsRoute(data.identity) orelse return error.RouteTooLong; 859 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.drafts)); 860 var label_buf: [64]u8 = undefined; 861 const label = try std.fmt.bufPrint(&label_buf, "drafts ({d})", .{data.drafts.count}); 862 try header.addTab(allocator, label, link, View.viewIndex(.drafts)); 863 } 864 865 // conflicts tab, labeled with the conflict count 866 if (data.conflicts.count > 0) { 867 const route = ui.RoutablePage.repoPatchesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 868 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.conflicts)); 869 var label_buf: [64]u8 = undefined; 870 const label = try std.fmt.bufPrint(&label_buf, "conflicts ({d})", .{data.conflicts.count}); 871 try header.addTab(allocator, label, link, View.viewIndex(.conflicts)); 872 } 873 874 header.select(View.viewIndex(data.view)); 875 return header; 876 } 877