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