From d291c933520f983e430dbe18e3dbac5ca52b5c3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Mon, 3 Jan 2022 17:01:56 +0100 Subject: [PATCH] app: add graph pop menu Add a pop menu to add new plugin to the graph --- src/app.rs | 44 +++++++++++++++++++++++++++++++++-- src/gps.ui | 8 +++++++ src/graphmanager/graphview.rs | 9 +++++++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/app.rs b/src/app.rs index 8a08e9b..3b0819b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -292,6 +292,10 @@ impl GPSApp { } } } + pub fn display_plugin_list(app: &GPSApp) { + let elements = Pipeline::elements_list().expect("Unable to obtain element's list"); + plugindialogs::display_plugin_list(app, &elements); + } pub fn build_ui(&self, application: &Application) { let drawing_area_window: Viewport = self @@ -395,8 +399,7 @@ impl GPSApp { let app_weak = self.downgrade(); add_button.connect_clicked(glib::clone!(@weak window => move |_| { let app = upgrade_weak!(app_weak); - let elements = Pipeline::elements_list().expect("Unable to obtain element's list"); - plugindialogs::display_plugin_list(&app, &elements); + GPSApp::display_plugin_list(&app); })); let add_button: Button = self @@ -467,7 +470,44 @@ impl GPSApp { let app = upgrade_weak!(app_weak); app.load_graph("graphs/video.xml").expect("Unable to open file"); })); + let app_weak = self.downgrade(); + // When user clicks on port with right button + self.graphview + .borrow() + .connect_local( + "graph-right-clicked", + false, + glib::clone!(@weak application => @default-return None, move |values: &[Value]| { + let app = upgrade_weak!(app_weak, None); + let point = values[1].get::().expect("point in args[2]"); + + let port_menu: gio::MenuModel = app + .builder + .object("graph_menu") + .expect("Couldn't get menu model for graph"); + + let pop_menu: PopoverMenu = PopoverMenu::from_model(Some(&port_menu)); + pop_menu.set_parent(&*app.graphview.borrow_mut()); + pop_menu.set_pointing_to(&Rectangle { + x: point.to_vec2().x() as i32, + y: point.to_vec2().y() as i32, + width: 0, + height: 0, + }); + // add an action to delete link + let action = gio::SimpleAction::new("graph.add-plugin", None); + action.connect_activate(glib::clone!(@weak pop_menu => move |_,_| { + GPSApp::display_plugin_list(&app); + pop_menu.unparent(); + })); + application.add_action(&action); + + pop_menu.show(); + None + }), + ) + .expect("Failed to register graph-right-clicked signal of graphview"); let app_weak = self.downgrade(); // When user clicks on port with right button self.graphview diff --git a/src/gps.ui b/src/gps.ui index 711a9fa..f4eded6 100644 --- a/src/gps.ui +++ b/src/gps.ui @@ -34,6 +34,14 @@ _Delete link app.port.delete-link + + + +
+ + _Add plugin + app.graph.add-plugin +
diff --git a/src/graphmanager/graphview.rs b/src/graphmanager/graphview.rs index 27ebb68..e0af894 100644 --- a/src/graphmanager/graphview.rs +++ b/src/graphmanager/graphview.rs @@ -146,6 +146,9 @@ mod imp { widget.unselect_all(); node.set_selected(true); obj.emit_by_name("node-right-clicked", &[&node.id(), &graphene::Point::new(x as f32,y as f32)]).expect("unable to send signal"); + } else { + widget.unselect_all(); + obj.emit_by_name("graph-right-clicked", &[&graphene::Point::new(x as f32,y as f32)]).expect("unable to send signal"); } } else if gesture.current_button() == BUTTON_PRIMARY { let widget = drag_controller.widget().expect("click event has no widget") @@ -243,6 +246,12 @@ mod imp { <()>::static_type().into(), ) .build(), + Signal::builder( + "graph-right-clicked", + &[graphene::Point::static_type().into()], + <()>::static_type().into(), + ) + .build(), ] }); SIGNALS.as_ref()