╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Files.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
846 .content = try std.fmt.allocPrint(aa, "{s} {s}", .{ @tagName(ref_or_oid), decoded }), 847 }; 848 } 849 850 pub const View = struct { 851 box: wgt.Box(ui.Widget), 852 data: *const Header, 853 854 pub fn init(allocator: std.mem.Allocator, data: *const Header, session: *ui.Session, identity: []const u8) !Header.View { 855 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 856 errdefer box.deinit(allocator); 857 858 if (!session.data.is_local and (session.data.git_http_port != null or session.data.git_ssh_port != null)) { 859 var clone_url = try ui.widget.CopyableText.initClone(allocator, session, identity); 860 errdefer clone_url.deinit(allocator); 861 const min_width = clone_url.minWidth(); 862 box.getFocus().child_id = clone_url.getFocus().id; 863 try box.children.put(allocator, clone_url.getFocus().id, .{ .widget = .{ .copyable_text = clone_url }, .rect = null, .min_size = .{ .width = min_width, .height = 3 }, .max_size = .{ .width = min_width, .height = 3 } }); 864 } 865 866 var spacer = try ui.widget.Spacer.init(allocator); 867 errdefer spacer.deinit(allocator); 868 try box.children.put(allocator, spacer.getFocus().id, .{ .widget = .{ .spacer = spacer }, .rect = null, .min_size = null }); 869 870 var text_box = try wgt.TextBox.init(allocator, data.content, .{ .border_style = .hidden, .wrap_kind = .none }); 871 errdefer text_box.deinit(allocator); 872 try box.children.put(allocator, text_box.getFocus().id, .{ .widget = .{ .text_box = text_box }, .rect = null, .min_size = null, .flex = .shrink }); 873 874 return .{ .box = box, .data = data }; 875 } 876 877 pub fn deinit(self: *Header.View, allocator: std.mem.Allocator) void { 878 self.box.deinit(allocator); 879 } 880 881 pub fn build(self: *Header.View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 882 self.clearGrid(); 883 try self.box.build(allocator, constraint, root_focus); 884 } 885 886 pub fn input(self: *Header.View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 887 const clone_url = self.cloneUrl() orelse return; 888 try clone_url.input(allocator, key, root_focus); 889 } 890 891 pub fn focusCloneUrl(self: *Header.View, root_focus: *Focus) bool { 892 const clone_url = self.cloneUrl() orelse return false; 893 root_focus.setFocus(clone_url.getFocus().id); 894 return true; 895 } 896 897 pub fn hasCloneUrl(self: *Header.View) bool { 898 return self.cloneUrl() != null; 899 } 900 901 fn cloneUrl(self: *Header.View) ?*ui.widget.CopyableText { 902 for (self.box.children.values()) |*child| switch (child.widget) { 903 .copyable_text => |*copyable_text| return copyable_text, 904 else => {}, 905 }; 906 return null; 907 } 908 909 pub fn clearGrid(self: *Header.View) void { 910 self.box.clearGrid(); 911 } 912 913 pub fn getGrid(self: Header.View) ?Grid { 914 return self.box.getGrid(); 915 } 916 917 pub fn getFocus(self: *Header.View) *Focus { 918 return self.box.getFocus(); 919 } 920 }; 921 }; 922