Compare commits

...

4 commits

3 changed files with 51 additions and 11 deletions

View file

@ -249,6 +249,14 @@
"inherit": "project",
"on_match_failure": "ignore",
"press": [
["f", "find_file"],
["e", "find_file"],
["n", "create_new_file"],
["o", "open_file"],
["r", "open_recent_project"],
["p", "open_command_palette"],
["t", "change_theme"],
["a", "add_task"],
["c", "open_config"],
["g", "open_gui_config"],
["k", "open_keybind_config"],
@ -256,6 +264,9 @@
["ctrl+f ctrl+f ctrl+f ctrl+f ctrl+f", "home_sheeran"],
["ctrl+shift+r", "restart"],
["f6", "open_config"],
["v", "open_version_info"],
["ctrl+q", "quit"],
["q", "quit"],
["up", "home_menu_up"],
["down", "home_menu_down"],
["enter", "home_menu_activate"]

View file

@ -44,6 +44,7 @@ pub fn create(
.on_click = on_click,
.on_layout = layout,
.on_render = render,
.on_receive = receive,
.on_event = event_handler,
});
}
@ -60,11 +61,32 @@ pub fn ctx_deinit(self: *Self) void {
if (self.behind) |p| self.allocator.free(p);
}
fn on_click(_: *Self, _: *Button.State(Self)) void {
git.status(0) catch {};
fn on_click(self: *Self, _: *Button.State(Self)) void {
self.refresh_git_status();
command.executeName("show_git_status", .{}) catch {};
}
fn refresh_git_status(_: *Self) void {
git.status(0) catch {};
}
pub fn receive(self: *Self, _: *Button.State(Self), _: tp.pid_ref, m: tp.message) error{Exit}!bool {
if (try m.match(.{ "E", tp.more }))
return self.process_event(m);
if (try m.match(.{ "PRJ", "open" }))
self.refresh_git_status();
return false;
}
fn process_event(self: *Self, m: tp.message) error{Exit}!bool {
if (try m.match(.{ tp.any, "dirty", tp.more }) or
try m.match(.{ tp.any, "save", tp.more }) or
try m.match(.{ tp.any, "open", tp.more }) or
try m.match(.{ tp.any, "close" }))
self.refresh_git_status();
return false;
}
fn receive_git(self: *Self, _: tp.pid_ref, m: tp.message) MessageFilter.Error!bool {
return if (try match(m.buf, .{ "git", more }))
self.process_git(m)

View file

@ -200,24 +200,34 @@ fn render_terminal_title(self: *Self) void {
}
pub fn receive(self: *Self, _: *Button.State(Self), _: tp.pid_ref, m: tp.message) error{Exit}!bool {
if (try m.match(.{ "E", tp.more }))
return self.process_event(m);
if (try m.match(.{ "PRJ", "open" })) {
if (!self.file)
self.show_project();
}
return false;
}
fn process_event(self: *Self, m: tp.message) error{Exit}!bool {
var file_path: []const u8 = undefined;
var file_type: []const u8 = undefined;
var file_icon: []const u8 = undefined;
var file_dirty: bool = undefined;
var eol_mode: Buffer.EolModeTag = @intFromEnum(Buffer.EolMode.lf);
if (try m.match(.{ "E", "pos", tp.extract(&self.lines), tp.extract(&self.line), tp.extract(&self.column) }))
if (try m.match(.{ tp.any, "pos", tp.extract(&self.lines), tp.extract(&self.line), tp.extract(&self.column) }))
return false;
if (try m.match(.{ "E", "dirty", tp.extract(&file_dirty) })) {
if (try m.match(.{ tp.any, "dirty", tp.extract(&file_dirty) })) {
self.file_dirty = file_dirty;
} else if (try m.match(.{ "E", "eol_mode", tp.extract(&eol_mode), tp.extract(&self.utf8_sanitized) })) {
} else if (try m.match(.{ tp.any, "eol_mode", tp.extract(&eol_mode), tp.extract(&self.utf8_sanitized) })) {
self.eol_mode = @enumFromInt(eol_mode);
} else if (try m.match(.{ "E", "save", tp.extract(&file_path) })) {
} else if (try m.match(.{ tp.any, "save", tp.extract(&file_path) })) {
@memcpy(self.name_buf[0..file_path.len], file_path);
self.name = self.name_buf[0..file_path.len];
self.file_exists = true;
self.file_dirty = false;
self.name = project_manager.abbreviate_home(&self.name_buf, self.name);
} else if (try m.match(.{ "E", "open", tp.extract(&file_path), tp.extract(&self.file_exists), tp.extract(&file_type), tp.extract(&file_icon), tp.extract(&self.file_color) })) {
} else if (try m.match(.{ tp.any, "open", tp.extract(&file_path), tp.extract(&self.file_exists), tp.extract(&file_type), tp.extract(&file_icon), tp.extract(&self.file_color) })) {
self.eol_mode = .lf;
@memcpy(self.name_buf[0..file_path.len], file_path);
self.name = self.name_buf[0..file_path.len];
@ -229,7 +239,7 @@ pub fn receive(self: *Self, _: *Button.State(Self), _: tp.pid_ref, m: tp.message
self.file_dirty = false;
self.name = project_manager.abbreviate_home(&self.name_buf, self.name);
self.file = true;
} else if (try m.match(.{ "E", "close" })) {
} else if (try m.match(.{ tp.any, "close" })) {
self.name = "";
self.lines = 0;
self.line = 0;
@ -238,9 +248,6 @@ pub fn receive(self: *Self, _: *Button.State(Self), _: tp.pid_ref, m: tp.message
self.file = false;
self.eol_mode = .lf;
self.show_project();
} else if (try m.match(.{ "PRJ", "open" })) {
if (!self.file)
self.show_project();
}
return false;
}