Delete items from graph when they are removed by the pipewire server.

This commit is contained in:
Tom A. Wagner
2021-01-08 12:34:22 +01:00
parent 9784b9bae0
commit 181661a2db
5 changed files with 233 additions and 104 deletions

View File

@@ -205,6 +205,14 @@ impl GraphView {
private.nodes.borrow_mut().insert(id, node);
}
pub fn remove_node(&self, id: u32) {
let private = imp::GraphView::from_instance(self);
let mut nodes = private.nodes.borrow_mut();
if let Some(node) = nodes.remove(&id) {
node.unparent();
}
}
pub fn add_port_to_node(&self, node_id: u32, port_id: u32, port: crate::view::port::Port) {
let private = imp::GraphView::from_instance(self);
@@ -229,6 +237,14 @@ impl GraphView {
self.queue_draw();
}
pub fn remove_link(&self, id: u32) {
let private = imp::GraphView::from_instance(self);
let mut links = private.links.borrow_mut();
links.remove(&id);
self.queue_draw();
}
pub fn set_dragged(&self, widget: Option<gtk::Widget>) {
*imp::GraphView::from_instance(self).dragged.borrow_mut() = widget;
}

View File

@@ -142,4 +142,16 @@ impl Node {
.get(&id)
.map(|port_rc| port_rc.clone())
}
pub fn remove_port(&self, id: u32) {
let private = imp::Node::from_instance(self);
if let Some(port) = private.ports.borrow_mut().remove(&id) {
match port.direction {
Direction::Input => private.num_ports_in.set(private.num_ports_in.get() - 1),
Direction::Output => private.num_ports_in.set(private.num_ports_out.get() - 1),
}
port.widget.unparent();
}
}
}