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