feat(core): appstate
This commit is contained in:
@@ -1,21 +1,10 @@
|
||||
const std = @import("std");
|
||||
const vaxis = @import("vaxis");
|
||||
const vxfw = vaxis.vxfw;
|
||||
|
||||
const models = @import("../core/models.zig");
|
||||
const provider = @import("../core/provider/provider.zig");
|
||||
const local_provider = @import("../core/provider/local.zig");
|
||||
const Tab = @import("../core/tab/tab.zig").Tab;
|
||||
const locked = @import("../core/sync.zig").locked;
|
||||
const CoreModel = @import("../app_common/Model.zig");
|
||||
const core = @import("../app_common/root.zig");
|
||||
|
||||
/// Our main application state
|
||||
const Model = struct {
|
||||
crash: bool = false,
|
||||
allocator: std.mem.Allocator,
|
||||
current_items_view: *vxfw.ListView,
|
||||
core_model: CoreModel,
|
||||
root_provider: *RootProvider,
|
||||
|
||||
/// Helper function to return a vxfw.Widget struct
|
||||
pub fn widget(self: *Model) vxfw.Widget {
|
||||
@@ -36,11 +25,17 @@ const Model = struct {
|
||||
ctx.quit = true;
|
||||
return;
|
||||
}
|
||||
if (key.matches('r', .{ .ctrl = true })) {
|
||||
vm.crash = true;
|
||||
if (key.matches('r', .{})) {
|
||||
// vm.crash = true;
|
||||
ctx.redraw = true;
|
||||
return ctx.requestFocus(vm.current_items_view.widget());
|
||||
}
|
||||
// if (key.matches(vaxis.Key.left, .{})) {
|
||||
// ctx.redraw = true;
|
||||
// return ctx.requestFocus(vm.current_items_view.widget());
|
||||
// }
|
||||
|
||||
handle_key(key, &vm.core_model.appState) catch {};
|
||||
},
|
||||
.focus_in => return ctx.requestFocus(vm.current_items_view.widget()),
|
||||
else => {},
|
||||
@@ -93,7 +88,7 @@ const Model = struct {
|
||||
};
|
||||
try rootWidgets.append(list_surface);
|
||||
|
||||
const current_location_text = if (vm.core_model.tab.currentLocation) |loc| loc.item.fullName.path else "";
|
||||
const current_location_text = if (vm.core_model.appState.currentTab.currentLocation) |loc| loc.item.fullName.path else "";
|
||||
const current_location_text_element = try ctx.arena.create(vxfw.Text);
|
||||
current_location_text_element.* = vxfw.Text{
|
||||
.text = current_location_text,
|
||||
@@ -218,24 +213,26 @@ pub fn main() !void {
|
||||
defer pool.deinit();
|
||||
|
||||
var localContentProvider = local_provider.LocalContentProvider{ .threadPool = &pool };
|
||||
var localContentProv = localContentProvider.provider();
|
||||
|
||||
const homeFullName: models.FullName = .{ .path = "/home/adam" };
|
||||
const homeItem = try localContentProvider.getItemByFullName(homeFullName, &.{}, allocator);
|
||||
const c = switch (homeItem.item) {
|
||||
.container => |c| c,
|
||||
.element => unreachable,
|
||||
};
|
||||
var rootProvider = RootProvider.init(allocator);
|
||||
defer rootProvider.deinit();
|
||||
|
||||
try rootProvider.providers.append(&localContentProv);
|
||||
|
||||
const current_path = try std.fs.cwd().realpathAlloc(allocator, ".");
|
||||
defer allocator.free(current_path);
|
||||
|
||||
const start_full_name = try local_provider.getFullNameByNativePath(allocator, models.NativePath{ .path = current_path });
|
||||
defer allocator.free(start_full_name.path);
|
||||
|
||||
var tab1 = try allocator.create(Tab);
|
||||
defer allocator.destroy(tab1);
|
||||
|
||||
tab1.init(&pool, allocator);
|
||||
tab1.init(&pool, &rootProvider, allocator);
|
||||
defer tab1.deinit();
|
||||
|
||||
tab1.setCurrentLocation(c);
|
||||
|
||||
const model = try allocator.create(Model);
|
||||
defer allocator.destroy(model);
|
||||
try tab1.setCurrentLocation(start_full_name);
|
||||
|
||||
// TODO: remove
|
||||
std.Thread.sleep(1 * std.time.ns_per_s);
|
||||
@@ -260,13 +257,21 @@ pub fn main() !void {
|
||||
.draw_cursor = false,
|
||||
.children = .{ .slice = items },
|
||||
};
|
||||
|
||||
var appState: AppState = AppState.init(allocator);
|
||||
appState.currentTab = tab1;
|
||||
|
||||
const model = try allocator.create(Model);
|
||||
defer allocator.destroy(model);
|
||||
|
||||
var core_model: CoreModel = undefined;
|
||||
try CoreModel.init(&core_model, std.heap.ArenaAllocator.init(allocator), appState);
|
||||
|
||||
model.* = .{
|
||||
.allocator = allocator,
|
||||
.core_model = .{
|
||||
.current_items_allocator = std.heap.ArenaAllocator.init(allocator),
|
||||
.tab = tab1,
|
||||
},
|
||||
.core_model = core_model,
|
||||
.current_items_view = &list,
|
||||
.root_provider = &rootProvider,
|
||||
};
|
||||
defer model.core_model.deinit();
|
||||
|
||||
@@ -288,4 +293,17 @@ pub fn main() !void {
|
||||
}
|
||||
}
|
||||
|
||||
const asd1 = @import("../core/allocator.zig");
|
||||
const std = @import("std");
|
||||
const vaxis = @import("vaxis");
|
||||
const vxfw = vaxis.vxfw;
|
||||
|
||||
const models = @import("../core/models.zig");
|
||||
const provider = @import("../core/provider/provider.zig");
|
||||
const RootProvider = @import("../core/provider/root.zig").RootProvider;
|
||||
const local_provider = @import("../core/provider/local.zig");
|
||||
const Tab = @import("../core/tab/tab.zig").Tab;
|
||||
const locked = @import("../core/sync.zig").locked;
|
||||
const CoreModel = @import("../app_common/Model.zig");
|
||||
const core = @import("../app_common/root.zig");
|
||||
const AppState = @import("../core/app_state.zig").AppState;
|
||||
const handle_key = @import("./action_map.zig").handle_key;
|
||||
|
||||
Reference in New Issue
Block a user