WIP: app: allow to load recent open files

Keep a list of 4 files and be able to load it
again
This commit is contained in:
Stéphane Cerveau 2022-02-10 13:00:16 +01:00
parent 9e4e915b1d
commit 1c04294b3a
4 changed files with 26 additions and 0 deletions

View file

@ -112,6 +112,7 @@
- [ ] reopen the last log on prematured exit (crash)
- [ ] Play/pause should be prevented until the pipeline is ready
- [ ] Filter the elements by class/rank etc.
- [ ] Add a list of recent open files to the burger menu
### CI/Infra

View file

@ -483,6 +483,7 @@ impl GPSApp {
GPSApp::get_file_from_dialog(&app, false, move |app, filename| {
app.load_graph(&filename)
.unwrap_or_else(|_| GPS_ERROR!("Unable to open file {}", filename));
Settings::add_recent_open_file(&filename);
});
});

View file

@ -17,6 +17,7 @@ use crate::config;
use crate::logger;
#[derive(Debug, Serialize, Deserialize, Default)]
#[serde(default)]
pub struct Settings {
pub app_maximized: bool,
pub app_width: i32,
@ -24,6 +25,7 @@ pub struct Settings {
// values must be emitted before tables
pub favorites: Vec<String>,
pub recent_open_files: Vec<String>,
pub paned_positions: HashMap<String, i32>,
pub preferences: HashMap<String, String>,
}
@ -89,6 +91,24 @@ impl Settings {
favorites
}
pub fn add_recent_open_file(filename: &str) {
let mut settings = Settings::load_settings();
if settings.recent_open_files.len() >= 4 {
settings.recent_open_files.pop();
}
settings.recent_open_files.insert(0, String::from(filename));
Settings::save_settings(&settings);
}
pub fn get_recent_open_files() -> Vec<String> {
let mut recent_open_files = Vec::new();
let settings = Settings::load_settings();
for recent in settings.recent_open_files {
recent_open_files.push(recent);
}
recent_open_files
}
// Save the provided settings to the settings path
pub fn save_settings(settings: &Settings) {
Settings::settings_file_exist();

View file

@ -18,6 +18,10 @@
<attribute name="action">app.save_as</attribute>
<attribute name="accel">&lt;primary&gt;n</attribute>
</item>
<submenu>
<attribute name="label" translatable="yes" comments="Primary menu entry that open recent files">_Open recent ...</attribute>
<attribute name="action">app.open_recent</attribute>
</submenu>
<item>
<attribute name="label" translatable="yes" comments="Primary menu entry that open the preferences">_Preferences</attribute>
<attribute name="action">app.preferences</attribute>