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