From e5334b1d5e463e38b84af73762c87c648c7c3b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Tue, 18 Jan 2022 11:26:03 +0100 Subject: [PATCH] graphview: Remove the link in remove_port Remove the link when removing a port from a node. Update documentation --- src/graphmanager/graphview.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/graphmanager/graphview.rs b/src/graphmanager/graphview.rs index a938ccb..7587569 100644 --- a/src/graphmanager/graphview.rs +++ b/src/graphmanager/graphview.rs @@ -516,6 +516,8 @@ impl GraphView { } // Port related methods + /// Add the port with id from node with id. + /// pub fn add_port( &self, node_id: u32, @@ -538,19 +540,26 @@ impl GraphView { } } - pub fn remove_port(&self, id: u32, node_id: u32) { + /// Remove the port with id from node with id. + /// + pub fn remove_port(&self, port_id: u32, node_id: u32) { let private = imp::GraphView::from_instance(self); let nodes = private.nodes.borrow(); if let Some(node) = nodes.get(&node_id) { - node.remove_port(id); + if let Some(link_id) = self.port_is_linked(port_id) { + self.remove_link(link_id); + } + node.remove_port(port_id); } } - - pub fn port_is_linked(&self, port_id: u32) -> Option<(u32, u32, u32)> { + /// Check if the port is linked + /// + /// Returns Some(link id) or `None` if the port is not linked. + pub fn port_is_linked(&self, port_id: u32) -> Option { let private = imp::GraphView::from_instance(self); for (key, link) in private.links.borrow().iter() { if link.port_from == port_id || link.port_to == port_id { - return Some((*key, link.node_from, link.port_from)); + return Some(*key); } } None