╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Fork.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
138 } 139 140 pub const View = struct { 141 box: wgt.Box(ui.Widget), 142 143 const header_index: usize = 0; 144 const stack_index: usize = 1; 145 146 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 147 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .vert }); 148 errdefer box.deinit(allocator); 149 { 150 var header = try Header.View.init(allocator, &data.header, session); 151 errdefer header.deinit(allocator); 152 try box.children.put(allocator, header.getFocus().id, .{ .widget = .{ .fork_header = header }, .rect = null, .min_size = null }); 153 } 154 { 155 var stack = try wgt.Stack(ui.Widget).init(allocator); 156 errdefer stack.deinit(allocator); 157 const selected = data.patch.selectedThread() orelse return error.NotFound; 158 var patch_detail = try Patches.Detail.init(allocator, &data.patch, session, selected.*, .{ .actions = data.patch.repo_source != null }); 159 errdefer patch_detail.deinit(allocator); 160 try stack.children.put(allocator, patch_detail.getFocus().id, .{ .repo_patch_detail = patch_detail }); 161 { 162 var files = try Files.View.init(allocator, &data.files, session); 163 errdefer files.deinit(allocator); 164 try stack.children.put(allocator, files.getFocus().id, .{ .repo_files = files }); 165 } 166 { 167 var commits = try Commits.View.init(allocator, &data.commits, session); 168 errdefer commits.deinit(allocator); 169 try stack.children.put(allocator, commits.getFocus().id, .{ .repo_commits = commits }); 170 } 171 if (session.data.user_id != null) { 172 var settings = try Settings.View.init(allocator, session); 173 errdefer settings.deinit(allocator); 174 try stack.children.put(allocator, settings.getFocus().id, .{ .home_settings = settings }); 175 } 176 if (!session.data.is_local) { 177 var auth = try Auth.View.init(allocator, &data.auth, session); 178 errdefer auth.deinit(allocator); 179 try stack.children.put(allocator, auth.getFocus().id, .{ .home_auth = auth }); 180 } 181 if (session.is_terminal) { 182 var quit = try Quit.View.init(allocator, session); 183 errdefer quit.deinit(allocator); 184 try stack.children.put(allocator, quit.getFocus().id, .{ .quit = quit }); 185 } 186 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 187 } 188 box.getFocus().child_id = box.children.keys()[header_index]; 189 return .{ .box = box }; 190 } 191 192 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 193 self.box.deinit(allocator); 194 } 195 196 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 197 self.clearGrid(); 198 const header = &self.box.children.values()[header_index].widget.fork_header; 199 const stack = &self.box.children.values()[stack_index].widget.stack; 200 if (header.getSelectedIndex()) |index| stack.getFocus().child_id = stack.children.keys()[index]; 201 try self.box.build(allocator, constraint, root_focus); 202 } 203 204 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 205 const stack = &self.box.children.values()[stack_index].widget.stack; 206 const current_id = self.box.getFocus().child_id orelse return; 207 const current_index = self.box.children.getIndex(current_id) orelse return; 208 const child = &self.box.children.values()[current_index].widget; 209 var next_index = current_index; 210 switch (inp.vertDirection(key)) { 211 .up => switch (child.*) { 212 .fork_header => try child.input(allocator, key, root_focus), 213 .stack => if (stack.getSelected()) |selected| { 214 const at_top = switch (selected.*) { 215 .repo_patch_detail => |*view| view.atTop(root_focus), 216 .repo_files => |*view| view.getSelectedIndex() == 0, 217 .repo_commits => |*view| view.getSelectedIndex() == 0, 218 .home_settings => |*view| view.getSelectedIndex() == 0, 219 .home_auth => |*view| view.getSelectedIndex() == 0, 220 .quit => |*view| view.getSelectedIndex() == 0, 221 else => false, 222 }; 223 if (at_top) next_index = header_index else try child.input(allocator, key, root_focus); 224 }, 225 else => {}, 226 }, 227 .down => switch (child.*) { 228 .fork_header => { 229 if (stack.getSelected()) |selected| switch (selected.*) { 230 .repo_patch_detail => |*view| if (view.focusFirst(root_focus)) return, 231 .repo_files => |*view| if (view.focusCloneUrl(root_focus)) return, 232 .repo_commits => |*view| if (view.focusCloneUrl(root_focus)) return, 233 else => {}, 234 }; 235 next_index = stack_index; 236 }, 237 .stack => try child.input(allocator, key, root_focus), 238 else => {}, 239 }, 240 .none => try child.input(allocator, key, root_focus), 241 } 242 if (next_index != current_index) root_focus.setFocus(self.box.children.keys()[next_index]); 243 } 244 245 pub fn clearGrid(self: *View) void { 246 self.box.clearGrid(); 247 } 248 249 pub fn getGrid(self: View) ?Grid { 250 return self.box.getGrid(); 251 } 252 253 pub fn getFocus(self: *View) *Focus { 254 return self.box.getFocus(); 255 } 256 }; 257