mirror of
https://gitlab.freedesktop.org/dabrain34/GstPipelineStudio.git
synced 2024-11-25 02:21:00 +00:00
pluginlist: avoid mulitple init
Allow only one initialization of the plugin list.
This commit is contained in:
parent
914fc1f077
commit
c16102928b
2 changed files with 53 additions and 45 deletions
|
@ -24,6 +24,7 @@ use gtk::{
|
||||||
AboutDialog, Application, ApplicationWindow, Builder, Button, FileChooserAction,
|
AboutDialog, Application, ApplicationWindow, Builder, Button, FileChooserAction,
|
||||||
FileChooserDialog, PopoverMenu, ResponseType, Statusbar, Viewport,
|
FileChooserDialog, PopoverMenu, ResponseType, Statusbar, Viewport,
|
||||||
};
|
};
|
||||||
|
use once_cell::unsync::OnceCell;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::rc::{Rc, Weak};
|
use std::rc::{Rc, Weak};
|
||||||
|
@ -40,6 +41,7 @@ pub struct GPSAppInner {
|
||||||
pub graphview: RefCell<GraphView>,
|
pub graphview: RefCell<GraphView>,
|
||||||
pub builder: Builder,
|
pub builder: Builder,
|
||||||
pub pipeline: RefCell<Pipeline>,
|
pub pipeline: RefCell<Pipeline>,
|
||||||
|
pub plugin_list_initialized: OnceCell<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// This represents our main application window.
|
// This represents our main application window.
|
||||||
|
@ -82,6 +84,7 @@ impl GPSApp {
|
||||||
graphview: RefCell::new(GraphView::new()),
|
graphview: RefCell::new(GraphView::new()),
|
||||||
builder,
|
builder,
|
||||||
pipeline: RefCell::new(pipeline),
|
pipeline: RefCell::new(pipeline),
|
||||||
|
plugin_list_initialized: OnceCell::new(),
|
||||||
}));
|
}));
|
||||||
Ok(app)
|
Ok(app)
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,62 +62,67 @@ pub fn display_plugin_list(app: &GPSApp, elements: &[ElementInfo]) {
|
||||||
.object("dialog-plugin-list")
|
.object("dialog-plugin-list")
|
||||||
.expect("Couldn't get window");
|
.expect("Couldn't get window");
|
||||||
|
|
||||||
dialog.set_title(Some("Plugin list"));
|
if app.plugin_list_initialized.get().is_none() {
|
||||||
dialog.set_default_size(640, 480);
|
dialog.set_title(Some("Plugin list"));
|
||||||
|
dialog.set_default_size(640, 480);
|
||||||
|
|
||||||
let text_view: TextView = app
|
let text_view: TextView = app
|
||||||
.builder
|
.builder
|
||||||
.object("textview-plugin-list")
|
.object("textview-plugin-list")
|
||||||
.expect("Couldn't get window");
|
.expect("Couldn't get window");
|
||||||
let text_buffer: TextBuffer = text_view.buffer();
|
let text_buffer: TextBuffer = text_view.buffer();
|
||||||
|
|
||||||
let tree: TreeView = app
|
let tree: TreeView = app
|
||||||
.builder
|
.builder
|
||||||
.object("treeview-plugin-list")
|
.object("treeview-plugin-list")
|
||||||
.expect("Couldn't get window");
|
.expect("Couldn't get window");
|
||||||
if tree.n_columns() < 2 {
|
if tree.n_columns() < 2 {
|
||||||
append_column(&tree, 0);
|
append_column(&tree, 0);
|
||||||
append_column(&tree, 1);
|
append_column(&tree, 1);
|
||||||
}
|
|
||||||
tree.set_search_column(1);
|
|
||||||
let model = create_and_fill_model(elements);
|
|
||||||
// Setting the model into the view.
|
|
||||||
tree.set_model(Some(&model));
|
|
||||||
|
|
||||||
// The closure responds to selection changes by connection to "::cursor-changed" signal,
|
|
||||||
// that gets emitted when the cursor moves (focus changes).
|
|
||||||
tree.connect_cursor_changed(glib::clone!(@weak dialog, @weak text_buffer => move |tree_view| {
|
|
||||||
let selection = tree_view.selection();
|
|
||||||
if let Some((model, iter)) = selection.selected() {
|
|
||||||
let element_name = model
|
|
||||||
.get(&iter, 1)
|
|
||||||
.get::<String>()
|
|
||||||
.expect("Treeview selection, column 1");
|
|
||||||
let description = Pipeline::element_description(&element_name).expect("Unable to get element list from GStreamer");
|
|
||||||
text_buffer.set_text("");
|
|
||||||
text_buffer.insert_markup(&mut text_buffer.end_iter(), &description);
|
|
||||||
}
|
}
|
||||||
|
tree.set_search_column(1);
|
||||||
|
let model = create_and_fill_model(elements);
|
||||||
|
// Setting the model into the view.
|
||||||
|
tree.set_model(Some(&model));
|
||||||
|
|
||||||
}));
|
// The closure responds to selection changes by connection to "::cursor-changed" signal,
|
||||||
let app_weak = app.downgrade();
|
// that gets emitted when the cursor moves (focus changes).
|
||||||
tree.connect_row_activated(
|
tree.connect_cursor_changed(glib::clone!(@weak dialog, @weak text_buffer => move |tree_view| {
|
||||||
glib::clone!(@weak dialog => move |tree_view, _tree_path, _tree_column| {
|
|
||||||
let app = upgrade_weak!(app_weak);
|
|
||||||
let selection = tree_view.selection();
|
let selection = tree_view.selection();
|
||||||
if let Some((model, iter)) = selection.selected() {
|
if let Some((model, iter)) = selection.selected() {
|
||||||
// Now getting back the values from the row corresponding to the
|
|
||||||
// iterator `iter`.
|
|
||||||
//
|
|
||||||
|
|
||||||
let element_name = model
|
let element_name = model
|
||||||
.get(&iter, 1)
|
.get(&iter, 1)
|
||||||
.get::<String>()
|
.get::<String>()
|
||||||
.expect("Treeview selection, column 1");
|
.expect("Treeview selection, column 1");
|
||||||
println!("{}", element_name);
|
let description = Pipeline::element_description(&element_name).expect("Unable to get element list from GStreamer");
|
||||||
app.add_new_element(element_name);
|
text_buffer.set_text("");
|
||||||
|
text_buffer.insert_markup(&mut text_buffer.end_iter(), &description);
|
||||||
}
|
}
|
||||||
}),
|
|
||||||
);
|
}));
|
||||||
|
let app_weak = app.downgrade();
|
||||||
|
tree.connect_row_activated(
|
||||||
|
glib::clone!(@weak dialog => move |tree_view, _tree_path, _tree_column| {
|
||||||
|
let app = upgrade_weak!(app_weak);
|
||||||
|
let selection = tree_view.selection();
|
||||||
|
if let Some((model, iter)) = selection.selected() {
|
||||||
|
// Now getting back the values from the row corresponding to the
|
||||||
|
// iterator `iter`.
|
||||||
|
//
|
||||||
|
|
||||||
|
let element_name = model
|
||||||
|
.get(&iter, 1)
|
||||||
|
.get::<String>()
|
||||||
|
.expect("Treeview selection, column 1");
|
||||||
|
println!("{}", element_name);
|
||||||
|
app.add_new_element(element_name);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
app.plugin_list_initialized
|
||||||
|
.set(true)
|
||||||
|
.expect("Should never happen");
|
||||||
|
}
|
||||||
|
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue