add deletion of views

This commit is contained in:
Rokas Puzonas 2025-05-24 22:25:26 +03:00
parent 7de55bde54
commit 1428d3d9bf
2 changed files with 50 additions and 0 deletions

View File

@ -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| {

View File

@ -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 {