╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Branches.zig ─────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
202 } 203 204 // label the inputs for this frame and register them for the web form 205 // handling. a failure labels the input it came from. 206 fn labelInputs(self: *View, root_focus: *Focus) !void { 207 const saved = self.session.formFeedback(.repo_branches); 208 for ([_]usize{ default_index, add_index }) |index| { 209 const name = self.formInput(index); 210 const default = index == default_index; 211 const failure = if (saved) |value| (if (value.default == default) value.failure else null) else null; 212 name.options.top_label.text = if (failure) |value| switch (value) { 213 .not_found => if (default) " default branch (not found) " else " add a protected branch (not found) ", 214 .already_added => " add a protected branch (already added) ", 215 .too_many => " add a protected branch (too many branches) ", 216 .too_long => if (default) " default branch (name too long) " else " add a protected branch (name too long) ", 217 } else if (default) " default branch " else " add a protected branch "; 218 name.options.bottom_label.text = if (root_focus.grandchild_id == name.getFocus().id) " press enter " else ""; 219 try self.session.text_inputs.put(self.session.arena.allocator(), name.getFocus().id, name); 220 } 221 } 222 223 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 224 // a form row keeps every key but the vertical ones, which move between rows 225 if (self.activeForm()) |index| if (inp.vertDirection(key) == .none) { 226 if (key == .enter) { 227 const name = try self.formInput(index).text(allocator); 228 defer allocator.free(name); 229 try self.act(allocator, if (index == default_index) .default else .protect, name); 230 } else try self.formInput(index).input(allocator, key, root_focus); 231 return; 232 }; 233 234 const rows = self.contentBox(); 235 const current = rows.children.getIndex(rows.getFocus().child_id orelse return) orelse return; 236 if (inp.rowDelta(key, @intCast(rows.children.count()))) |delta| { 237 ui.widget.moveRowFocus(rows, &self.scroll, root_focus, delta); 238 return; 239 } 240 switch (key) { 241 .arrow_left, .arrow_right => _ = ui.widget.moveInSelectedRow(rows, root_focus, key == .arrow_right), 242 else => { 243 // the text and the form rows sit above the rows, and a row's name is a link the host follows 244 if (current <= add_index) return; 245 const row_box = &rows.children.values()[current].widget.box; 246 const button_id = row_box.getFocus().child_id orelse return; 247 if (row_box.children.getIndex(button_id) != 1 or !inp.activated(root_focus, button_id, key)) return; 248 try self.act(allocator, .unprotect, self.data.names[current - add_index - 1]); 249 }, 250 } 251 } 252 253 // the terminal performs the action itself; the web posts the form instead 254 fn act(self: *View, allocator: std.mem.Allocator, action: Action, branch: []const u8) !void { 255 if (comptime wasm) return; 256 const io = self.session.io orelse return; 257 const users_dir = self.session.users_dir orelse return; 258 const actor = (try self.session.authorize(self.data.identity, .owner, null)) orelse return; 259 if (try perform(io, allocator, users_dir, actor, self.data.identity, action, branch)) |failure| { 260 self.session.data.form_feedback = .{ .repo_branches = .{ .failure = failure, .name = try self.session.arena.allocator().dupe(u8, branch), .default = action == .default } }; 261 return; 262 } 263 try self.session.navigate(ui.RoutablePage.repoBranchesRoute(self.data.identity) orelse return error.RouteTooLong); 264 } 265 266 pub fn clearGrid(self: *View) void { 267 self.scroll.clearGrid(); 268 } 269 270 pub fn getGrid(self: View) ?Grid { 271 return self.scroll.getGrid(); 272 } 273 274 pub fn getFocus(self: *View) *Focus { 275 return self.scroll.getFocus(); 276 } 277 278 // up leaves the view from the explanatory text 279 pub fn atTop(self: *View) bool { 280 return self.contentBox().getFocus().child_id == self.aboutBox().getFocus().id; 281 } 282 }; 283