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