╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
451 var events_view = try Events.View.init(allocator, &data.events, session); 452 errdefer events_view.deinit(allocator); 453 try stack.children.put(allocator, events_view.getFocus().id, .{ .repo_events = events_view }); 454 } 455 456 if (data.undo) |*undo| { 457 var undo_view = try Undo.View.init(allocator, undo, session); 458 errdefer undo_view.deinit(allocator); 459 try stack.children.put(allocator, undo_view.getFocus().id, .{ .repo_undo = undo_view }); 460 } 461 462 if (data.settings) |*settings| { 463 var settings_view = try Settings.View.init(allocator, settings, session); 464 errdefer settings_view.deinit(allocator); 465 try stack.children.put(allocator, settings_view.getFocus().id, .{ .repo_settings = settings_view }); 466 } 467 468 // the header shows new repo with a login, and new user without one 469 // and user only outside local mode, so keep the stack's children 470 // 1:1 with the tabs by skipping the same views. 471 const identity = try std.fmt.allocPrint(session.page_arena.allocator(), "{s}:{s}", .{ data.header.owner_name, data.header.name }); 472 if (session.data.user_id != null) { 473 const route = ui.RoutablePage{ .repo_repo_new = ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len).from(identity) orelse return error.RouteTooLong }; 474 var new_repo_view = try ui.NewRepo.View.init(allocator, session, route); 475 errdefer new_repo_view.deinit(allocator); 476 try stack.children.put(allocator, new_repo_view.getFocus().id, .{ .new_repo = new_repo_view }); 477 } else if (session.data.host_kind == .server) { 478 const route = ui.RoutablePage{ .repo_user_new = ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len).from(identity) orelse return error.RouteTooLong }; 479 var new_user_view = try ui.NewUser.View.init(allocator, session, route); 480 errdefer new_user_view.deinit(allocator); 481 try stack.children.put(allocator, new_user_view.getFocus().id, .{ .new_user = new_user_view }); 482 } 483 484 if (session.data.host_kind == .server) { 485 var user_view = try ui.UserLogout.initView(allocator, session); 486 errdefer user_view.deinit(allocator); 487 try stack.children.put(allocator, user_view.getFocus().id, user_view); 488 } 489 490 if (session.is_terminal) { 491 var quit_view = try Quit.View.init(allocator, session); 492 errdefer quit_view.deinit(allocator); 493 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 494 } 495 496 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 497 } 498 499 var self = View{ .box = box }; 500 // a page opens on its tabs, except that search results open in the 501 // tab's own search box. 502 const results = data.files.find != null or 503 (data.changes == .commits and data.changes.commits.search != null) or 504 data.issues.search != null or data.patches.search != null or data.discussions.search != null; 505 self.getFocus().child_id = box.children.keys()[if (results) stack_index else header_index]; 506 return self; 507 } 508 509 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 510 self.box.deinit(allocator); 511 } 512 513 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 514 self.clearGrid(); 515 const header = &self.box.children.values()[header_index].widget.repo_header; 516 const stack = &self.box.children.values()[stack_index].widget.stack; 517 518 // each header tab maps 1:1 to a stack child by position 519 if (header.getSelectedIndex()) |index| 520 stack.getFocus().child_id = stack.children.keys()[index]; 521 try self.box.build(allocator, constraint, root_focus); 522 } 523 524 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 525 const stack = &self.box.children.values()[stack_index].widget.stack; 526 if (self.getFocus().child_id) |child_id| { 527 if (self.box.children.getIndex(child_id)) |current_index| { 528 const child = &self.box.children.values()[current_index].widget; 529 var index = current_index; 530 531 const direction = inp.vertDirection(key); 532 533 switch (direction) { 534 .up => { 535 switch (child.*) { 536 .repo_header => { 537 try child.input(allocator, key, root_focus); 538 }, 539 .stack => { 540 if (child.stack.getSelected()) |selected_widget| { 541 if (selected_widget.atTop(root_focus)) { 542 index = header_index; 543 } else { 544 try child.input(allocator, key, root_focus); 545 } 546 } 547 }, 548 else => {}, 549 } 550 }, 551 .down => { 552 switch (child.*) { 553 .repo_header => { 554 if (stack.getSelected()) |selected_widget| switch (selected_widget.*) { 555 .repo_files => |*v| if (v.focusHeader(root_focus)) return, 556 .repo_commits => |*v| if (v.focusHeader(root_focus)) return, 557 .repo_refs => |*v| if (v.focusHeader(root_focus)) return, 558 .repo_events => |*v| if (v.focusHeader(root_focus)) return, 559 .repo_undo => |*v| if (v.focusHeader(root_focus)) return, 560 else => {}, 561 }; 562 index = stack_index; 563 }, 564 .stack => { 565 try child.input(allocator, key, root_focus); 566 }, 567 else => {}, 568 } 569 }, 570 .none => { 571 try child.input(allocator, key, root_focus); 572 }, 573 } 574 575 if (index != current_index) { 576 root_focus.setFocus(self.box.children.keys()[index]); 577 } 578 } 579 } 580 } 581 582 pub fn clearGrid(self: *View) void { 583 self.box.clearGrid(); 584 } 585 586 pub fn getGrid(self: View) ?Grid { 587 return self.box.getGrid(); 588 } 589 590 pub fn getFocus(self: *View) *Focus { 591 return self.box.getFocus(); 592 } 593 }; 594