╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Repo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
521 522 if (session.data.host_kind == .server) { 523 var user_view = try ui.UserSettings.initView(allocator, session); 524 errdefer user_view.deinit(allocator); 525 try stack.children.put(allocator, user_view.getFocus().id, user_view); 526 } 527 528 if (session.is_terminal) { 529 var quit_view = try Quit.View.init(allocator, session); 530 errdefer quit_view.deinit(allocator); 531 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 532 } 533 534 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 535 } 536 537 var self = View{ .box = box }; 538 // a page opens on its tabs, except that search results open in the 539 // tab's own search box. 540 const results = data.files.find != null or 541 (data.changes == .commits and data.changes.commits.search != null) or 542 data.discussions.search != null or data.issues.search != null or data.patches.search != null; 543 self.getFocus().child_id = box.children.keys()[if (results) stack_index else header_index]; 544 return self; 545 } 546 547 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 548 self.box.deinit(allocator); 549 } 550 551 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 552 self.clearGrid(); 553 const header = &self.box.children.values()[header_index].widget.repo_header; 554 const stack = &self.box.children.values()[stack_index].widget.stack; 555 556 // each header tab maps 1:1 to a stack child by position 557 if (header.getSelectedIndex()) |index| 558 stack.getFocus().child_id = stack.children.keys()[index]; 559 try self.box.build(allocator, constraint, root_focus); 560 } 561 562 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 563 const stack = &self.box.children.values()[stack_index].widget.stack; 564 if (self.getFocus().child_id) |child_id| { 565 if (self.box.children.getIndex(child_id)) |current_index| { 566 const child = &self.box.children.values()[current_index].widget; 567 var index = current_index; 568 569 const direction = inp.vertDirection(key); 570 571 switch (direction) { 572 .up => { 573 switch (child.*) { 574 .repo_header => { 575 try child.input(allocator, key, root_focus); 576 }, 577 .stack => { 578 if (child.stack.getSelected()) |selected_widget| { 579 if (selected_widget.atTop(root_focus)) { 580 index = header_index; 581 } else { 582 try child.input(allocator, key, root_focus); 583 } 584 } 585 }, 586 else => {}, 587 } 588 }, 589 .down => { 590 switch (child.*) { 591 .repo_header => { 592 if (stack.getSelected()) |selected_widget| switch (selected_widget.*) { 593 .repo_files => |*v| if (v.focusHeader(root_focus)) return, 594 .repo_commits => |*v| if (v.focusHeader(root_focus)) return, 595 .repo_refs => |*v| if (v.focusHeader(root_focus)) return, 596 .repo_events => |*v| if (v.focusHeader(root_focus)) return, 597 .repo_undo => |*v| if (v.focusHeader(root_focus)) return, 598 .repo_settings => |*v| if (v.focusHeader(root_focus)) return, 599 else => {}, 600 }; 601 index = stack_index; 602 }, 603 .stack => { 604 try child.input(allocator, key, root_focus); 605 }, 606 else => {}, 607 } 608 }, 609 .none => { 610 try child.input(allocator, key, root_focus); 611 }, 612 } 613 614 if (index != current_index) { 615 root_focus.setFocus(self.box.children.keys()[index]); 616 } 617 } 618 } 619 } 620 621 pub fn clearGrid(self: *View) void { 622 self.box.clearGrid(); 623 } 624 625 pub fn getGrid(self: View) ?Grid { 626 return self.box.getGrid(); 627 } 628 629 pub fn getFocus(self: *View) *Focus { 630 return self.box.getFocus(); 631 } 632 }; 633