╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Patches.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
990 .selector = "to", 991 .text = target_branch, 992 .label = if (status_kind == .merged) " target branch this patch was merged into " else " target branch this patch will go to ", 993 }, 994 }; 995 var copyable_text = try ui.widget.CopyableText.init(allocator, session, fields[@intFromBool(entry.revision_oid.len == 0)..], 0); 996 errdefer copyable_text.deinit(allocator); 997 try box.children.put(allocator, copyable_text.getFocus().id, .{ .widget = .{ .copyable_text = copyable_text }, .rect = null, .min_size = null }); 998 } 999 1000 // tabs switching between the patches page's views 1001 pub fn initHeader(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 1002 var header = try Header.init(allocator, session, data.search); 1003 errdefer header.deinit(allocator); 1004 const selected_index = View.viewIndex(data.view); 1005 const page_selected = std.meta.activeTag(session.data.current_page) == .repo_patches; 1006 1007 // a list tab per status, labeled with its listing's patch count 1008 const status_labels = [_][]const u8{ open_tab_label, closed_tab_label, merged_tab_label }; 1009 for ([_]Status{ .open, .closed, .merged }, status_labels, 0..) |status, status_label, index| { 1010 const route = try thread.searchRoute(ui.RoutablePage.repoPatchesRoute(data.identity, status, data.label, ""), data.search); 1011 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == index); 1012 var label_buf: [64]u8 = undefined; 1013 const label = try thread.countLabel(&label_buf, status_label, data.window(status).*); 1014 try header.addTab(allocator, label, link, index); 1015 } 1016 1017 // labels tab 1018 { 1019 const labels_route = try thread.searchRoute(ui.RoutablePage.repoThreadLabelsRoute(.patch, data.identity, data.label), data.search); 1020 const labels_link = try ui.inPageTabLink(session, labels_route, page_selected and selected_index == View.viewIndex(.labels)); 1021 try header.addTab(allocator, labels_tab_label, labels_link, View.viewIndex(.labels)); 1022 } 1023 1024 // new-patch tab; an edit or resolve url shows its tab in this place 1025 { 1026 const route = switch (data.view) { 1027 .edit => ui.RoutablePage.repoThreadEditRoute(.patch, data.identity, data.selected_id) orelse return error.RouteTooLong, 1028 .publish => ui.RoutablePage.repoPatchPublishRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 1029 .merge => ui.RoutablePage.repoPatchMergeRoute(data.identity, data.selected_id) orelse return error.RouteTooLong, 1030 .new_comment => ui.RoutablePage.repoThreadCommentNewRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1031 .edit_comment => ui.RoutablePage.repoThreadCommentEditRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1032 .remove => ui.RoutablePage.repoThreadRemoveRoute(.patch, data.identity, data.selected_id, data.comment_id) orelse return error.RouteTooLong, 1033 .resolve => ui.RoutablePage.repoPatchesResolveRoute(data.identity, data.selected_id, data.theirs_picks) orelse return error.RouteTooLong, 1034 else => ui.RoutablePage.repoThreadNewRoute(.patch, data.identity) orelse return error.RouteTooLong, 1035 }; 1036 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.new)); 1037 const label: []const u8 = switch (data.view) { 1038 .edit => edit_tab_label, 1039 .publish => publish_tab_label, 1040 .merge => merge_tab_label, 1041 .new_comment => reply_tab_label, 1042 .edit_comment => edit_tab_label, 1043 .remove => remove_tab_label, 1044 .resolve => resolve_tab_label, 1045 else => new_tab_label, 1046 }; 1047 try header.addTab(allocator, label, link, View.viewIndex(.new)); 1048 } 1049 1050 // drafts belong to the logged-in user and are not available locally 1051 if (session.data.host_kind != .local) { 1052 const route = ui.RoutablePage.repoPatchesDraftsRoute(data.identity) orelse return error.RouteTooLong; 1053 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.drafts)); 1054 var label_buf: [64]u8 = undefined; 1055 const label = try std.fmt.bufPrint(&label_buf, drafts_tab_label ++ " ({d})", .{data.drafts.count}); 1056 try header.addTab(allocator, label, link, View.viewIndex(.drafts)); 1057 } 1058 1059 // conflicts tab, labeled with the conflict count 1060 if (data.conflicts.count > 0) { 1061 const route = ui.RoutablePage.repoPatchesConflictsRoute(data.identity, "") orelse return error.RouteTooLong; 1062 const link = try ui.inPageTabLink(session, route, page_selected and selected_index == View.viewIndex(.conflicts)); 1063 var label_buf: [64]u8 = undefined; 1064 const label = try std.fmt.bufPrint(&label_buf, conflicts_tab_label ++ " ({d})", .{data.conflicts.count}); 1065 try header.addTab(allocator, label, link, View.viewIndex(.conflicts)); 1066 } 1067 1068 header.select(View.viewIndex(data.view)); 1069 return header; 1070 } 1071