╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Threads.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
2384 2385 fn removeEvent(self: *This, allocator: std.mem.Allocator, event_kind: evt.EventKind, id: [evt.event_id_size]u8) !void { 2386 if (comptime wasm) return; 2387 const io = self.session.io orelse return; 2388 const src = self.data.repo_source orelse return; 2389 const author = (try self.session.eventAuthor()) orelse return; 2390 2391 switch (src.repo_kind) { 2392 inline else => |repo_kind| { 2393 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2394 defer any_repo.deinit(io, allocator); 2395 switch (any_repo) { 2396 inline else => |*repo| try evt.remove(.repo, repo_kind, repo.self_repo_opts, io, allocator, repo, &id, event_kind, author), 2397 } 2398 }, 2399 } 2400 2401 const id_hex = std.fmt.bytesToHex(id, .lower); 2402 const route = ui.RoutablePage.repoEventsRoute(self.data.identity, .removed, event_kind, &id_hex) orelse return; 2403 try self.session.navigate(route); 2404 } 2405 2406 // flip the shown thread's status by re-emitting its event, then reload the 2407 // page rooted at the thread so the view reflects the change. this is the 2408 // terminal path; the web posts the button's form to the status route. 2409 fn toggleStatus(self: *This, allocator: std.mem.Allocator, index: usize) !void { 2410 if (comptime !has_status) return; 2411 if (comptime wasm) return; 2412 const io = self.session.io orelse return; 2413 const src = self.data.repo_source orelse return; 2414 const sel = self.detailed_index[index] orelse return; 2415 const entry = self.window(index).items[sel]; 2416 const author = (try self.session.eventAuthor()) orelse return; 2417 2418 const status = (statusChange(entryStatus(entry)) orelse return).status; 2419 2420 const id_bytes = try evt.parseEventId(entry.id); 2421 2422 switch (src.repo_kind) { 2423 inline else => |repo_kind| { 2424 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, src.localInitOpts()); 2425 defer any_repo.deinit(io, allocator); 2426 switch (any_repo) { 2427 inline else => |*repo| try Event.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .status = status }, author), 2428 } 2429 }, 2430 } 2431 2432 const route = listRoute(self.data.identity, status, "", entry.id) orelse return; 2433 try self.session.navigate(route); 2434 } 2435 2436 // arrow keys move the tag selection; at the flow's edges focus crosses to 2437 // the neighboring widgets. 2438 fn tagsInput(self: *This, index: usize, child_index: usize, tf: *ui.TagFlow, key: Key, root_focus: *Focus) void { 2439 const cid = tf.focus.child_id orelse return; 2440 const cur = tf.indexOfFocusId(cid) orelse return; 2441 const count = tf.text_boxes.items.len; 2442 switch (key) { 2443 .arrow_left => if (cur > 0) self.focusTag(index, child_index, tf, root_focus, cur - 1) else self.focusList(index, root_focus), 2444 .arrow_right => if (cur + 1 < count) self.focusTag(index, child_index, tf, root_focus, cur + 1), 2445 .arrow_up => if (tf.rowStep(cur, false)) |i| { 2446 self.focusTag(index, child_index, tf, root_focus, i); 2447 } else { 2448 _ = self.moveDetailVertical(index, root_focus, false); 2449 }, 2450 .arrow_down => if (tf.rowStep(cur, true)) |i| { 2451 self.focusTag(index, child_index, tf, root_focus, i); 2452 } else { 2453 _ = self.moveDetailVertical(index, root_focus, true); 2454 }, 2455 .home => self.focusTag(index, child_index, tf, root_focus, 0), 2456 .end => self.focusTag(index, child_index, tf, root_focus, count - 1), 2457 else => {}, 2458 } 2459 } 2460 2461 // the tool row's first child after the spacer that pushes it right 2462 const first_in_row_index: usize = 1; 2463 2464 fn toolRowFocused(self: *This, index: usize) bool { 2465 const outer = self.detailOuter(index); 2466 const cid = outer.getFocus().child_id orelse return false; 2467 return outer.children.getIndex(cid) == tool_row_index; 2468 } 2469 2470 fn focusTag(self: *This, index: usize, child_index: usize, tf: *ui.TagFlow, root_focus: *Focus, item: usize) void { 2471 root_focus.setFocus(tf.text_boxes.items[item].getFocus().id); 2472 // keep the tag visible on the terminal: its rect offset by the flow's 2473 // position in the pane. 2474 if (self.session.is_terminal and item < tf.rects.items.len) { 2475 if (self.detailInner(index).children.values()[child_index].rect) |flow_rect| { 2476 var rect = tf.rects.items[item]; 2477 rect.x += flow_rect.x; 2478 rect.y += flow_rect.y; 2479 self.detailScroll(index).scrollToRect(rect); 2480 } 2481 } 2482 } 2483 2484 // return to the tool row's last-focused button (the header when the 2485 // description page shows no row). 2486 fn focusToolRow(self: *This, index: usize, root_focus: *Focus) void { 2487 const cid = self.toolRow(index).getFocus().child_id orelse return self.focusHeader(root_focus); 2488 root_focus.setFocus(cid); 2489 } 2490 2491 // enter the detail pane. an empty pane can't be entered. 2492 fn focusDetail(self: *This, index: usize, root_focus: *Focus) void { 2493 if (self.detailInner(index).children.count() == 0) return; 2494 root_focus.setFocus(self.detailOuter(index).getFocus().id); 2495 } 2496 2497 // return to the list. 2498 fn focusList(self: *This, index: usize, root_focus: *Focus) void { 2499 root_focus.setFocus(self.listScroll(index).getFocus().id); 2500 } 2501 2502 // cross to the header tabs above the stack. 2503 fn focusHeader(self: *This, root_focus: *Focus) void { 2504 root_focus.setFocus(self.box.children.keys()[header_index]); 2505 } 2506 2507 pub fn clearGrid(self: *This) void { 2508 self.box.clearGrid(); 2509 } 2510 2511 pub fn getGrid(self: This) ?Grid { 2512 return self.box.getGrid(); 2513 } 2514 2515 pub fn getFocus(self: *This) *Focus { 2516 return self.box.getFocus(); 2517 } 2518 2519 // for the parent's "scroll up at the top jumps to the header" check: at the 2520 // top only while the header tabs hold focus, so up from the split 2521 // crosses into the tabs first. 2522 pub fn getSelectedIndex(self: *This) ?usize { 2523 return if (self.headerActive()) 0 else 1; 2524 } 2525 }; 2526 } 2527