diff --git a/src/app.zig b/src/app.zig index a670e1d..8cb1183 100644 --- a/src/app.zig +++ b/src/app.zig @@ -1085,6 +1085,46 @@ pub const Project = struct { }); } + pub fn removeFile(self: *Project, allocator: std.mem.Allocator, file_id: Id) void { + const file = self.files.get(file_id) orelse return; + + self.removeSampleList(file.samples_id); + file.deinit(allocator); + + self.files.remove(file_id); + file.* = undefined; + } + + pub fn removeChannel(self: *Project, allocator: std.mem.Allocator, channel_id: Id) void { + const channel = self.channels.get(channel_id) orelse return; + + self.removeSampleList(channel.collected_samples_id); + + channel.deinit(allocator); + self.channels.remove(channel_id); + channel.* = undefined; + } + + pub fn removeView(self: *Project, allocator: std.mem.Allocator, view_id: Id) void { + const view = self.views.get(view_id) orelse return; + + if (view.transformed_samples) |sample_list_id| { + self.removeSampleList(sample_list_id); + } + + switch (view.reference) { + .file => |file_id| { + self.removeFile(allocator, file_id); + }, + .channel => |channel_id| { + self.removeChannel(allocator, channel_id); + } + } + + self.views.remove(view_id); + view.* = undefined; + } + pub fn deinit(self: *Project, allocator: Allocator) void { var file_iter = self.files.iterator(); while (file_iter.next()) |file| { diff --git a/src/screens/main_screen.zig b/src/screens/main_screen.zig index c2e8cc1..a47430d 100644 --- a/src/screens/main_screen.zig +++ b/src/screens/main_screen.zig @@ -723,6 +723,16 @@ fn showViewSettings(self: *MainScreen, view_id: Id) !void { view.transforms.appendAssumeCapacity(.{ .addition = 0 }); } } + + _ = ui.createBox(.{ .size_y = UI.Sizing.initGrowFull() }); + + { + const btn = ui.textButton("Delete"); + btn.borders = UI.Borders.all(.{ .color = srcery.red, .size = 4 }); + if (ui.signal(btn).clicked()) { + project.removeView(self.app.allocator, view_id); + } + } } fn showMarkedRange(self: *MainScreen, view_id: Id, index: usize) void {