╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ thread.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
3241 .title = try aa.dupe(u8, title), 3242 .labels = try aa.dupe(u8, labels), 3243 .description = try aa.dupe(u8, description), 3244 .target_branch = try aa.dupe(u8, target_branch), 3245 .source_branch = if (source) |value| try value.field().text(aa) else "", 3246 .source_kind = if (source) |value| value.selectedKind() else .fork, 3247 } else .{ 3248 .title = try aa.dupe(u8, title), 3249 .labels = try aa.dupe(u8, labels), 3250 .description = try aa.dupe(u8, description), 3251 }, 3252 }); 3253 } 3254 3255 fn submitConfirmation(self: *This, allocator: std.mem.Allocator, button_index: usize) !void { 3256 switch (confirmation(self.data.view) orelse return) { 3257 .publish => if (comptime supports_drafts) { 3258 if (comptime wasm) return; 3259 const entry = self.data.selectedThread() orelse return; 3260 if (!entryDraft(entry.*)) return; 3261 const author = ((try self.session.authorize(self.data.identity, .read, kind)) orelse return).author; 3262 try self.data.publishDraft(self.session, allocator, author, entry.id); 3263 const route = listRoute(self.data.identity, @fromBackingInt(@intCast(0)), entry.id) orelse return; 3264 try self.session.navigate(route); 3265 } else unreachable, 3266 .merge => if (comptime supports_merge) { 3267 if (comptime wasm) return; 3268 const entry = self.data.selectedThread() orelse return; 3269 const revision: evt.Patch.MergeRevision = if (button_index > 1) .squash else .source; 3270 if (!Data.canMerge(entry.*, self.session) or entry.mergeability.get(revision) != .clean) return; 3271 const author = ((try self.session.authorize(self.data.identity, .write, kind)) orelse return).author; 3272 self.data.mergePatch(self.session, allocator, author, entry.id, revision) catch |err| switch (err) { 3273 error.MergeConflict, error.MergeCheckUnavailable, error.PatchOutOfDate, error.PatchDataUnavailable => { 3274 const route = listRoute(self.data.identity, entryStatus(entry.*), entry.id) orelse return; 3275 try self.session.navigate(route); 3276 return; 3277 }, 3278 else => return err, 3279 }; 3280 const merged = std.meta.stringToEnum(Status, "merged") orelse return; 3281 const route = listRoute(self.data.identity, merged, entry.id) orelse return; 3282 try self.session.navigate(route); 3283 } else unreachable, 3284 .remove => try self.submitRemove(allocator), 3285 } 3286 } 3287 3288 fn submitRemove(self: *This, allocator: std.mem.Allocator) !void { 3289 const comment = self.data.comment_id.len != 0; 3290 const event_id = if (comment) self.data.comment_id else self.data.selected_id; 3291 const id = evt.parseEventId(event_id) catch return; 3292 try self.removeEvent(allocator, if (comment) .comment else kind, id); 3293 } 3294 3295 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 3296 if (comptime wasm) return; 3297 const actor = (try self.session.authorize(self.data.identity, .read, kind)) orelse return; 3298 const author = actor.author; 3299 3300 if (comptime supports_drafts) { 3301 const selected = self.data.selectedThread() orelse return; 3302 if (event_kind == kind and entryDraft(selected.*)) { 3303 try Data.removeDraft(self.session, allocator, author, &id); 3304 const route = draftsRoute(self.data.identity) orelse return; 3305 try self.session.navigate(route); 3306 return; 3307 } 3308 } 3309 3310 const io = self.session.io orelse return; 3311 const src = self.data.repo_source orelse return; 3312 if (!try src.canModify(io, allocator, actor, event_kind, &id)) return; 3313 const thread_id = evt.parseEventId(self.data.selected_id) catch return; 3314 3315 switch (src.repo_kind) { 3316 inline else => |repo_kind| { 3317 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 3318 defer any_repo.deinit(io, allocator); 3319 switch (any_repo) { 3320 inline else => |*repo| try evt.removeInThread(self.session.eventHost(), repo_kind, repo.self_repo_opts, io, allocator, repo, kind, &thread_id, event_kind, &id, author), 3321 } 3322 }, 3323 } 3324 3325 // back to the thread, or to its list when the thread itself was removed 3326 const selected = self.data.selectedThread() orelse return; 3327 const route = listRoute(self.data.identity, entryStatus(selected.*), if (event_kind == kind) "" else self.data.selected_id) orelse return; 3328 try self.session.navigate(route); 3329 } 3330 3331 // enter the detail pane, landing on the way back to the list when it shows 3332 fn focusDetail(self: *This, index: usize, root_focus: *Focus) void { 3333 if (widget.listBackId(self.detailFrame(index)) != null) return widget.focusListBack(self.detailFrame(index), root_focus); 3334 _ = self.detail(index).focusFirst(root_focus); 3335 } 3336 3337 // return to the list. 3338 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 3339 root_focus.setFocus(self.listScroll(index).getFocus().id); 3340 } 3341 3342 // cross to the header tabs above the stack. 3343 fn focusHeader(self: *This, root_focus: *Focus) void { 3344 root_focus.setFocus(self.box.children.keys()[header_index]); 3345 } 3346 3347 pub fn clearGrid(self: *This) void { 3348 self.box.clearGrid(); 3349 } 3350 3351 pub fn getGrid(self: This) ?Grid { 3352 return self.box.getGrid(); 3353 } 3354 3355 pub fn getFocus(self: *This) *Focus { 3356 return self.box.getFocus(); 3357 } 3358 3359 // for the parent's "scroll up at the top jumps to the header" check: at the 3360 // top only while the header tabs hold focus, so up from the split 3361 // crosses into the tabs first. 3362 pub fn atTop(self: *This) bool { 3363 return self.headerActive(); 3364 } 3365 }; 3366 } 3367