feat: things
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
pub fn handle(action: Action, appState: *AppState) !void {
|
||||
pub fn handle(action: Action, appState: *AppState, arena: std.mem.Allocator) !void {
|
||||
switch (action) {
|
||||
.GoUp => {
|
||||
if (appState.currentTab.currentLocation) |currentLocation| {
|
||||
const parent = currentLocation.item.parent;
|
||||
if (parent) |p| {
|
||||
try appState.currentTab.setCurrentLocation(.{ .path = p.path.path });
|
||||
const path = try arena.dupe(u8, p.path.path);
|
||||
try appState.currentTab.setCurrentLocation(.{ .path = path });
|
||||
} else return error.NoParent;
|
||||
} else return error.NoCurrentLocation;
|
||||
},
|
||||
@@ -12,6 +13,7 @@ pub fn handle(action: Action, appState: *AppState) !void {
|
||||
}
|
||||
}
|
||||
|
||||
const std = @import("std");
|
||||
const Action = @import("action.zig").Action;
|
||||
const AppState = @import("../app_state.zig").AppState;
|
||||
const RootProvider = @import("../provider/root.zig").RootProvider;
|
||||
|
||||
@@ -35,7 +35,11 @@ pub const AppState = struct {
|
||||
}
|
||||
|
||||
pub fn deinit(self: *AppState) void {
|
||||
self.tabPreCurrentItemsUnload.deinit();
|
||||
self.currentTabChanged.deinit();
|
||||
for (self.tabs.items) |*tab| {
|
||||
tab.deinit();
|
||||
}
|
||||
self.tabs.deinit();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,11 @@ pub const Item = struct {
|
||||
self.allocator.free(self.displayName);
|
||||
self.allocator.free(self.fullName.path);
|
||||
self.allocator.free(self.nativePath.path);
|
||||
|
||||
if (self.parent) |p| {
|
||||
self.allocator.free(p.path.path);
|
||||
}
|
||||
|
||||
for (self.errors.items) |e| {
|
||||
self.allocator.free(e.content);
|
||||
}
|
||||
@@ -54,6 +59,7 @@ pub const Container = struct {
|
||||
self.item.allocator.free(itemFullName.path);
|
||||
}
|
||||
self.children.deinit();
|
||||
self.item.allocator.destroy(self);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ pub fn Observable(T: type) type {
|
||||
}
|
||||
|
||||
pub fn detach(self: *Self, obs: *const Observer(T)) void {
|
||||
if (std.mem.indexOfScalar(*const Observer, self.observers.items, obs)) |index| {
|
||||
if (std.mem.indexOfScalar(*const Observer(T), self.observers.items, obs)) |index| {
|
||||
_ = self.observers.swapRemove(index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ pub const Tab = struct {
|
||||
pub fn setCurrentLocation(self: *Tab, newLocationFullName: models.FullName) !void {
|
||||
if (self.currentLocation) |c| {
|
||||
c.item.deinit();
|
||||
self.allocator.destroy(c);
|
||||
}
|
||||
|
||||
errdefer {
|
||||
@@ -45,6 +44,9 @@ pub const Tab = struct {
|
||||
}
|
||||
|
||||
const newLocation = try self.rootProvider.getItemByFullName(newLocationFullName, &.{}, self.allocator);
|
||||
errdefer {
|
||||
newLocation.deinit();
|
||||
}
|
||||
|
||||
const newLocationContainer = switch (newLocation.item) {
|
||||
.container => |c| c,
|
||||
@@ -53,6 +55,7 @@ pub const Tab = struct {
|
||||
|
||||
self.currentLocation = newLocationContainer;
|
||||
self.currentLocationChanged.notify(newLocationContainer);
|
||||
std.debug.print("\nASD1\n", .{});
|
||||
|
||||
//TODO: Proper error handling
|
||||
std.Thread.Pool.spawn(self.threadPool, loadItemsWrapper, .{ self, newLocationContainer }) catch unreachable;
|
||||
@@ -68,17 +71,12 @@ pub const Tab = struct {
|
||||
|
||||
self.preCurrentItemsUnload.notify(self);
|
||||
|
||||
if (self.currentItems.data) |items| {
|
||||
items.deinit();
|
||||
}
|
||||
|
||||
self.currentItems.data = null;
|
||||
}
|
||||
|
||||
//TODO: half the capacity to prevent "leaking" after a huuuge container has been opened once
|
||||
_ = self._private.currentItemsAllocator.reset(.retain_capacity);
|
||||
|
||||
const arenaAllocator = &self._private.currentItemsAllocator;
|
||||
const arena = arenaAllocator.allocator();
|
||||
const arena = self._private.currentItemsAllocator.allocator();
|
||||
|
||||
var threadSafeAllocator = std.heap.ThreadSafeAllocator{ .child_allocator = arena };
|
||||
const allocator = threadSafeAllocator.allocator();
|
||||
@@ -121,6 +119,7 @@ pub const Tab = struct {
|
||||
defer self.currentItems.mutex.unlock();
|
||||
self.currentItemsChanged = true;
|
||||
}
|
||||
std.debug.print("\nASDX\n", .{});
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Tab) void {
|
||||
|
||||
Reference in New Issue
Block a user