refactor: re-work how projects are opened

Prep for opening directories on the command line.
This commit is contained in:
CJ van den Berg 2024-06-23 20:53:35 +02:00
parent 23fcf64b62
commit 692e04b6a8
4 changed files with 30 additions and 11 deletions

View file

@ -45,7 +45,6 @@ const NavState = struct {
};
pub fn create(a: std.mem.Allocator, n: Plane) !Widget {
try project_manager.open_cwd();
const self = try a.create(Self);
self.* = .{
.a = a,
@ -165,6 +164,19 @@ const cmds = struct {
try tp.self_pid().send("quit");
}
pub fn open_project_cwd(self: *Self, _: Ctx) tp.result {
try project_manager.open_cwd();
_ = try self.statusbar.msg(.{ "PRJ", "open" });
}
pub fn open_project_dir(self: *Self, ctx: Ctx) tp.result {
var project_dir: []const u8 = undefined;
if (!try ctx.args.match(.{tp.extract(&project_dir)}))
return;
try project_manager.open(project_dir);
_ = try self.statusbar.msg(.{ "PRJ", "open" });
}
pub fn navigate(self: *Self, ctx: Ctx) tp.result {
tui.reset_drag_context();
const frame = tracy.initZone(@src(), .{ .name = "navigate" });
@ -202,6 +214,10 @@ const cmds = struct {
file = file_name;
} else return tp.exit_error(error.InvalidArgument);
if (tp.env.get().str("project").len == 0) {
try open_project_cwd(self, .{});
}
const f = project_manager.normalize_file_path(file orelse return);
const same_file = if (self.editor) |editor| if (editor.file_path) |fp|
std.mem.eql(u8, fp, f)