mirror of
https://gitlab.freedesktop.org/dabrain34/GstPipelineStudio.git
synced 2024-12-24 08:50:29 +00:00
settings: use HashMap to save paned positions
Save the hashmap in the settings.toml file
This commit is contained in:
parent
bdec43655d
commit
247cf2c844
3 changed files with 70 additions and 53 deletions
91
src/app.rs
91
src/app.rs
|
@ -106,28 +106,6 @@ impl GPSApp {
|
||||||
window.set_application(Some(application));
|
window.set_application(Some(application));
|
||||||
window.set_title(Some("GStreamer Pipeline Studio"));
|
window.set_title(Some("GStreamer Pipeline Studio"));
|
||||||
|
|
||||||
let settings = Settings::load_settings();
|
|
||||||
window.set_size_request(settings.app_width, settings.app_height);
|
|
||||||
let paned: Paned = builder
|
|
||||||
.object("graph_dashboard-paned")
|
|
||||||
.expect("Couldn't get graph_dashboard-paned");
|
|
||||||
paned.set_position(settings.app_graph_dashboard_paned_pos);
|
|
||||||
let paned: Paned = builder
|
|
||||||
.object("graph_logs-paned")
|
|
||||||
.expect("Couldn't get graph_logs-paned");
|
|
||||||
paned.set_position(settings.app_graph_logs_paned_pos);
|
|
||||||
let paned: Paned = builder
|
|
||||||
.object("elements_preview-paned")
|
|
||||||
.expect("Couldn't get elements_preview-paned");
|
|
||||||
paned.set_position(settings.app_elements_preview_paned_pos);
|
|
||||||
let paned: Paned = builder
|
|
||||||
.object("elements_properties-paned")
|
|
||||||
.expect("Couldn't get elements_properties-paned");
|
|
||||||
paned.set_position(settings.app_elements_properties_paned_pos);
|
|
||||||
|
|
||||||
if settings.app_maximized {
|
|
||||||
window.maximize();
|
|
||||||
}
|
|
||||||
let pipeline = GPS::Pipeline::new().expect("Unable to initialize GStreamer subsystem");
|
let pipeline = GPS::Pipeline::new().expect("Unable to initialize GStreamer subsystem");
|
||||||
let app = GPSApp(Rc::new(GPSAppInner {
|
let app = GPSApp(Rc::new(GPSAppInner {
|
||||||
window,
|
window,
|
||||||
|
@ -140,9 +118,52 @@ impl GPSApp {
|
||||||
let app_weak = app.downgrade();
|
let app_weak = app.downgrade();
|
||||||
app.pipeline.borrow().set_app(app_weak);
|
app.pipeline.borrow().set_app(app_weak);
|
||||||
app.graphview.borrow_mut().set_id(0);
|
app.graphview.borrow_mut().set_id(0);
|
||||||
|
|
||||||
|
let settings = Settings::load_settings();
|
||||||
|
|
||||||
|
if settings.app_maximized {
|
||||||
|
app.window.maximize();
|
||||||
|
} else {
|
||||||
|
app.window
|
||||||
|
.set_size_request(settings.app_width, settings.app_height);
|
||||||
|
}
|
||||||
|
app.set_paned_position(&settings, "graph_dashboard-paned", 100);
|
||||||
|
app.set_paned_position(&settings, "graph_logs-paned", 100);
|
||||||
|
app.set_paned_position(&settings, "elements_preview-paned", 100);
|
||||||
|
app.set_paned_position(&settings, "elements_properties-paned", 100);
|
||||||
|
app.set_paned_position(&settings, "playcontrols_position-paned", 100);
|
||||||
|
|
||||||
Ok(app)
|
Ok(app)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_paned_position(
|
||||||
|
&self,
|
||||||
|
settings: &Settings,
|
||||||
|
paned_name: &str,
|
||||||
|
paned_default_position: i32,
|
||||||
|
) {
|
||||||
|
let paned: Paned = self
|
||||||
|
.builder
|
||||||
|
.object(paned_name)
|
||||||
|
.unwrap_or_else(|| panic!("Couldn't get {}", paned_name));
|
||||||
|
paned.set_position(
|
||||||
|
*settings
|
||||||
|
.paned_positions
|
||||||
|
.get(paned_name)
|
||||||
|
.unwrap_or(&paned_default_position),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn save_paned_position(&self, settings: &mut Settings, paned_name: &str) {
|
||||||
|
let paned: Paned = self
|
||||||
|
.builder
|
||||||
|
.object(paned_name)
|
||||||
|
.unwrap_or_else(|| panic!("Couldn't get {}", paned_name));
|
||||||
|
settings
|
||||||
|
.paned_positions
|
||||||
|
.insert(paned_name.to_string(), paned.position());
|
||||||
|
}
|
||||||
|
|
||||||
pub fn on_startup(application: >k::Application) {
|
pub fn on_startup(application: >k::Application) {
|
||||||
// Create application and error out if that fails for whatever reason
|
// Create application and error out if that fails for whatever reason
|
||||||
let app = match GPSApp::new(application) {
|
let app = match GPSApp::new(application) {
|
||||||
|
@ -220,26 +241,12 @@ impl GPSApp {
|
||||||
settings.app_maximized = window.is_maximized();
|
settings.app_maximized = window.is_maximized();
|
||||||
settings.app_width = window.width();
|
settings.app_width = window.width();
|
||||||
settings.app_height = window.height();
|
settings.app_height = window.height();
|
||||||
let paned: Paned = app
|
app.save_paned_position(&mut settings, "graph_dashboard-paned");
|
||||||
.builder
|
app.save_paned_position(&mut settings, "graph_logs-paned");
|
||||||
.object("graph_dashboard-paned")
|
app.save_paned_position(&mut settings, "elements_preview-paned");
|
||||||
.expect("Couldn't get graph_dashboard-paned");
|
app.save_paned_position(&mut settings, "elements_properties-paned");
|
||||||
settings.app_graph_dashboard_paned_pos = paned.position();
|
app.save_paned_position(&mut settings, "playcontrols_position-paned");
|
||||||
let paned: Paned = app
|
|
||||||
.builder
|
|
||||||
.object("graph_logs-paned")
|
|
||||||
.expect("Couldn't get graph_logs-paned");
|
|
||||||
settings.app_graph_logs_paned_pos = paned.position();
|
|
||||||
let paned: Paned = app
|
|
||||||
.builder
|
|
||||||
.object("elements_preview-paned")
|
|
||||||
.expect("Couldn't get elements_preview-paned");
|
|
||||||
settings.app_elements_preview_paned_pos = paned.position();
|
|
||||||
let paned: Paned = app
|
|
||||||
.builder
|
|
||||||
.object("elements_properties-paned")
|
|
||||||
.expect("Couldn't get elements_properties-paned");
|
|
||||||
settings.app_elements_properties_paned_pos = paned.position();
|
|
||||||
Settings::save_settings(&settings);
|
Settings::save_settings(&settings);
|
||||||
|
|
||||||
let pop_menu: PopoverMenu = app
|
let pop_menu: PopoverMenu = app
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use gtk::glib;
|
use gtk::glib;
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::fs::create_dir_all;
|
use std::fs::create_dir_all;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
@ -13,10 +14,7 @@ pub struct Settings {
|
||||||
pub app_maximized: bool,
|
pub app_maximized: bool,
|
||||||
pub app_width: i32,
|
pub app_width: i32,
|
||||||
pub app_height: i32,
|
pub app_height: i32,
|
||||||
pub app_graph_dashboard_paned_pos: i32,
|
pub paned_positions: HashMap<String, i32>,
|
||||||
pub app_graph_logs_paned_pos: i32,
|
|
||||||
pub app_elements_preview_paned_pos: i32,
|
|
||||||
pub app_elements_properties_paned_pos: i32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
|
@ -101,15 +99,27 @@ impl Settings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Settings {
|
let mut settings = Settings {
|
||||||
app_width: 800,
|
app_width: 800,
|
||||||
app_height: 600,
|
app_height: 600,
|
||||||
app_graph_dashboard_paned_pos: 600,
|
|
||||||
app_graph_logs_paned_pos: 400,
|
|
||||||
app_elements_preview_paned_pos: 300,
|
|
||||||
app_elements_properties_paned_pos: 150,
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
};
|
||||||
|
settings
|
||||||
|
.paned_positions
|
||||||
|
.insert(String::from("graph_dashboard-paned"), 600);
|
||||||
|
settings
|
||||||
|
.paned_positions
|
||||||
|
.insert(String::from("graph_logs-paned"), 400);
|
||||||
|
settings
|
||||||
|
.paned_positions
|
||||||
|
.insert(String::from("elements_preview-paned"), 300);
|
||||||
|
settings
|
||||||
|
.paned_positions
|
||||||
|
.insert(String::from("elements_properties-paned"), 150);
|
||||||
|
settings
|
||||||
|
.paned_positions
|
||||||
|
.insert(String::from("playcontrols_position-paned"), 400);
|
||||||
|
settings
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,7 +145,7 @@
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<property name="spacing">1</property>
|
<property name="spacing">1</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkPaned">
|
<object class="GtkPaned" id="playcontrols_position-paned">
|
||||||
<property name="vexpand">0</property>
|
<property name="vexpand">0</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox">
|
<object class="GtkBox">
|
||||||
|
|
Loading…
Reference in a new issue