refactor: re-work how projects are opened
Prep for opening directories on the command line.
This commit is contained in:
parent
23fcf64b62
commit
692e04b6a8
4 changed files with 30 additions and 11 deletions
|
@ -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)
|
||||
|
|
|
@ -29,7 +29,7 @@ column: usize,
|
|||
file_exists: bool,
|
||||
file_dirty: bool = false,
|
||||
detailed: bool = false,
|
||||
project: bool = false,
|
||||
file: bool = false,
|
||||
|
||||
const project_icon = "";
|
||||
const Self = @This();
|
||||
|
@ -53,7 +53,6 @@ pub fn create(a: Allocator, parent: Plane) !Widget {
|
|||
.on_render = render,
|
||||
.on_receive = receive,
|
||||
});
|
||||
btn.opts.ctx.show_project();
|
||||
return Widget.to(btn);
|
||||
}
|
||||
|
||||
|
@ -131,7 +130,7 @@ fn render_detailed(self: *Self, plane: *Plane, theme: *const Widget.Theme) void
|
|||
self.render_file_icon(plane, theme);
|
||||
_ = plane.print(" ", .{}) catch {};
|
||||
}
|
||||
if (self.project) {
|
||||
if (!self.file) {
|
||||
const project_name = tp.env.get().str("project");
|
||||
_ = plane.print("{s} ({s})", .{ self.name, project_name }) catch {};
|
||||
} else {
|
||||
|
@ -184,14 +183,18 @@ pub fn receive(self: *Self, _: *Button.State(Self), _: tp.pid_ref, m: tp.message
|
|||
self.file_icon = self.file_icon_buf[0..file_icon.len :0];
|
||||
self.file_dirty = false;
|
||||
self.abbrv_home();
|
||||
self.project = false;
|
||||
self.file = true;
|
||||
} else if (try m.match(.{ "E", "close" })) {
|
||||
self.name = "";
|
||||
self.lines = 0;
|
||||
self.line = 0;
|
||||
self.column = 0;
|
||||
self.file_exists = true;
|
||||
self.file = false;
|
||||
self.show_project();
|
||||
} else if (try m.match(.{ "PRJ", "open" })) {
|
||||
if (!self.file)
|
||||
self.show_project();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -214,7 +217,6 @@ fn show_project(self: *Self) void {
|
|||
@memcpy(self.name_buf[0..project_name.len], project_name);
|
||||
self.name = self.name_buf[0..project_name.len];
|
||||
self.abbrv_home();
|
||||
self.project = true;
|
||||
}
|
||||
|
||||
fn abbrv_home(self: *Self) void {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue