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