Compare commits
3 commits
06a31ea5fd
...
d53a24a1d2
| Author | SHA1 | Date | |
|---|---|---|---|
| d53a24a1d2 | |||
| 7d7a45f539 | |||
| cdd1e09069 |
4 changed files with 45 additions and 14 deletions
|
|
@ -98,9 +98,9 @@ pub fn request_recent_files(max: usize) (ProjectManagerError || ProjectError)!vo
|
|||
return send(.{ "request_recent_files", project, max });
|
||||
}
|
||||
|
||||
pub fn request_recent_projects(allocator: std.mem.Allocator) (ProjectError || CallError)!tp.message {
|
||||
pub fn request_recent_projects() (ProjectManagerError || ProjectError)!void {
|
||||
const project = tp.env.get().str("project");
|
||||
return (try get()).pid.call(allocator, request_timeout, .{ "request_recent_projects", project });
|
||||
return send(.{ "request_recent_projects", project });
|
||||
}
|
||||
|
||||
pub fn query_recent_files(max: usize, query: []const u8) (ProjectManagerError || ProjectError)!void {
|
||||
|
|
@ -462,6 +462,9 @@ const Process = struct {
|
|||
self.sort_projects_by_last_used(&recent_projects);
|
||||
var message = std.ArrayList(u8).init(self.allocator);
|
||||
const writer = message.writer();
|
||||
try cbor.writeArrayHeader(writer, 3);
|
||||
try cbor.writeValue(writer, "PRJ");
|
||||
try cbor.writeValue(writer, "recent_projects");
|
||||
try cbor.writeArrayHeader(writer, recent_projects.items.len);
|
||||
for (recent_projects.items) |project| {
|
||||
try cbor.writeArrayHeader(writer, 2);
|
||||
|
|
@ -469,6 +472,7 @@ const Process = struct {
|
|||
try cbor.writeValue(writer, if (self.projects.get(project.name)) |_| true else false);
|
||||
}
|
||||
from.send_raw(.{ .buf = message.items }) catch return error.ClientFailed;
|
||||
self.logger.print("{d} projects found", .{recent_projects.items.len});
|
||||
}
|
||||
|
||||
fn query_recent_files(self: *Process, from: tp.pid_ref, project_directory: []const u8, max: usize, query: []const u8) (ProjectError || Project.ClientError)!void {
|
||||
|
|
|
|||
|
|
@ -27,10 +27,12 @@ pub fn deinit(palette: *Type) void {
|
|||
palette.allocator.free(entry.label);
|
||||
}
|
||||
|
||||
pub fn load_entries(palette: *Type) !usize {
|
||||
const rsp = try project_manager.request_recent_projects(palette.allocator);
|
||||
defer palette.allocator.free(rsp.buf);
|
||||
var iter: []const u8 = rsp.buf;
|
||||
pub fn load_entries_with_args(palette: *Type, ctx: command.Context) !usize {
|
||||
var items_cbor: []const u8 = undefined;
|
||||
if (!(cbor.match(ctx.args.buf, .{ "PRJ", "recent_projects", tp.extract_cbor(&items_cbor) }) catch false))
|
||||
return error.InvalidRecentProjects;
|
||||
|
||||
var iter: []const u8 = items_cbor;
|
||||
var len = try cbor.decodeArrayHeader(&iter);
|
||||
while (len > 0) : (len -= 1) {
|
||||
var name_: []const u8 = undefined;
|
||||
|
|
|
|||
|
|
@ -47,6 +47,10 @@ pub fn Create(options: type) type {
|
|||
pub const ButtonState = Button.State(*Menu.State(*Self));
|
||||
|
||||
pub fn create(allocator: std.mem.Allocator) !tui.Mode {
|
||||
return create_with_args(allocator, .{});
|
||||
}
|
||||
|
||||
pub fn create_with_args(allocator: std.mem.Allocator, ctx: command.Context) !tui.Mode {
|
||||
const mv = tui.mainview() orelse return error.NotFound;
|
||||
const self = try allocator.create(Self);
|
||||
errdefer allocator.destroy(self);
|
||||
|
|
@ -77,7 +81,10 @@ pub fn Create(options: type) type {
|
|||
.entries = std.ArrayList(Entry).init(allocator),
|
||||
};
|
||||
if (self.menu.scrollbar) |scrollbar| scrollbar.style_factory = scrollbar_style;
|
||||
self.longest_hint = try options.load_entries(self);
|
||||
self.longest_hint = if (@hasDecl(options, "load_entries_with_args"))
|
||||
try options.load_entries_with_args(self, ctx)
|
||||
else
|
||||
try options.load_entries(self);
|
||||
if (@hasDecl(options, "restore_state"))
|
||||
options.restore_state(self) catch {};
|
||||
try self.commands.init(self);
|
||||
|
|
@ -467,11 +474,15 @@ pub fn Create(options: type) type {
|
|||
const button = self.menu.get_selected() orelse return;
|
||||
const refresh = options.delete_item(self.menu, button);
|
||||
if (refresh) {
|
||||
options.clear_entries(self);
|
||||
self.longest_hint = try options.load_entries(self);
|
||||
if (self.entries.items.len > 0)
|
||||
self.initial_selected = self.menu.selected;
|
||||
try self.start_query(0);
|
||||
if (@hasDecl(options, "load_entries")) {
|
||||
options.clear_entries(self);
|
||||
self.longest_hint = try options.load_entries(self);
|
||||
if (self.entries.items.len > 0)
|
||||
self.initial_selected = self.menu.selected;
|
||||
try self.start_query(0);
|
||||
} else {
|
||||
return palette_menu_cancel(self, .{});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -413,6 +413,9 @@ fn receive_safe(self: *Self, from: tp.pid_ref, m: tp.message) !void {
|
|||
return;
|
||||
}
|
||||
|
||||
if (try m.match(.{ "PRJ", "recent_projects", tp.more })) // async recent projects request
|
||||
return self.enter_overlay_mode_with_args(@import("mode/overlay/open_recent_project.zig").Type, .{ .args = m });
|
||||
|
||||
if (try m.match(.{ "PRJ", tp.more })) // drop late project manager query responses
|
||||
return;
|
||||
|
||||
|
|
@ -684,6 +687,17 @@ fn enter_overlay_mode(self: *Self, mode: type) command.Result {
|
|||
refresh_hover();
|
||||
}
|
||||
|
||||
fn enter_overlay_mode_with_args(self: *Self, mode: type, ctx: command.Context) command.Result {
|
||||
command.executeName("disable_fast_scroll", .{}) catch {};
|
||||
command.executeName("disable_jump_mode", .{}) catch {};
|
||||
if (self.mini_mode_) |_| try cmds.exit_mini_mode(self, .{});
|
||||
if (self.input_mode_outer_) |_| try cmds.exit_overlay_mode(self, .{});
|
||||
self.input_mode_outer_ = self.input_mode_;
|
||||
self.input_mode_ = try mode.create_with_args(self.allocator, ctx);
|
||||
if (self.input_mode_) |*m| m.run_init();
|
||||
refresh_hover();
|
||||
}
|
||||
|
||||
fn get_input_mode(self: *Self, mode_name: []const u8) !Mode {
|
||||
return keybind.mode(mode_name, self.allocator, .{});
|
||||
}
|
||||
|
|
@ -914,8 +928,8 @@ const cmds = struct {
|
|||
}
|
||||
pub const open_recent_meta: Meta = .{ .description = "Open recent" };
|
||||
|
||||
pub fn open_recent_project(self: *Self, _: Ctx) Result {
|
||||
return self.enter_overlay_mode(@import("mode/overlay/open_recent_project.zig").Type);
|
||||
pub fn open_recent_project(_: *Self, _: Ctx) Result {
|
||||
try project_manager.request_recent_projects();
|
||||
}
|
||||
pub const open_recent_project_meta: Meta = .{ .description = "Open project" };
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue