graphmanager: can remove property

Add public remove_property to PropertyExt
This commit is contained in:
Stéphane Cerveau 2022-02-03 16:09:26 +01:00
parent 8059f73f51
commit a21350b4a0
3 changed files with 28 additions and 4 deletions

View file

@ -344,6 +344,14 @@ impl PropertyExt for Node {
self.update_description();
}
/// Remove a port property with a name.
///
fn remove_property(&self, name: &str) {
let private = imp::Node::from_instance(self);
trace!("property name={} removed", name);
private.properties.borrow_mut().remove(name);
}
/// Retrieves node properties.
///
fn properties(&self) -> Ref<HashMap<String, String>> {

View file

@ -22,7 +22,7 @@ use gtk::{
prelude::*,
subclass::prelude::*,
};
use log::info;
use log::trace;
use std::cell::RefCell;
use std::cell::{Cell, Ref};
use std::collections::HashMap;
@ -223,17 +223,25 @@ impl SelectionExt for Port {
}
impl PropertyExt for Port {
/// Add a node property with a name and a value.
/// Add a port property with a name and a value.
///
fn add_property(&self, name: &str, value: &str) {
let private = imp::Port::from_instance(self);
info!("property name={} updated with value={}", name, value);
trace!("property name={} updated with value={}", name, value);
private
.properties
.borrow_mut()
.insert(name.to_string(), value.to_string());
}
/// Remove a port property with a name.
///
fn remove_property(&self, name: &str) {
let private = imp::Port::from_instance(self);
trace!("property name={} removed", name);
private.properties.borrow_mut().remove(name);
}
/// Retrieves node properties.
///
fn properties(&self) -> Ref<HashMap<String, String>> {

View file

@ -28,13 +28,21 @@ pub trait PropertyExt {
///
fn add_property(&self, name: &str, value: &str);
/// Add a node property with a name and a value.
///
fn remove_property(&self, name: &str);
/// Update the properties.
///
/// Update the PropertyExt properties.
///
fn update_properties(&self, new_properties: &HashMap<String, String>) {
for (key, value) in new_properties {
self.add_property(key, value);
if value.is_empty() {
self.remove_property(key);
} else {
self.add_property(key, value);
}
}
}