diff --git a/src/app/gui/source.rs b/src/app/gui/source.rs index 40573ec..b3979c1 100644 --- a/src/app/gui/source.rs +++ b/src/app/gui/source.rs @@ -14,6 +14,7 @@ use crate::app::{ use super::metric::{metric_display_ui, metric_edit_ui}; pub fn source_panel(app: &mut App, ui: &mut Ui) { + let mut source_to_put_metric_on : Option = None; let mut to_swap: Option = None; let mut to_insert: Vec = Vec::new(); // let mut to_delete: Option = None; @@ -103,12 +104,7 @@ pub fn source_panel(app: &mut App, ui: &mut Ui) { ); ui.add_space(2.0); if ui.small_button(" + ").clicked() { - // TODO find a better - if let Err(e) = - app.data.add_metric(&app.input_metric, source) - { - error!(target: "ui", "Error adding metric : {:?}", e); - } + source_to_put_metric_on = Some(source.id); } ui.add_space(1.0); // DAMN! if ui.small_button("o").clicked() { @@ -208,6 +204,17 @@ pub fn source_panel(app: &mut App, ui: &mut Ui) { metrics.push(m); } } + if let Some(s) = source_to_put_metric_on { + for source in app.data.sources.read().expect("Sources RwLock poisoned").iter() { + if source.id == s { + if let Err(e) = + app.data.add_metric(&app.input_metric, &source) + { + error!(target: "ui", "Error adding metric : {:?}", e); + } + } + } + } } pub fn source_display_ui(ui: &mut Ui, source: &mut Source, _width: f32) {