From 1c04294b3a2d16d336b0ae9bf3aaecc5d148bfaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Thu, 10 Feb 2022 13:00:16 +0100 Subject: [PATCH] WIP: app: allow to load recent open files Keep a list of 4 files and be able to load it again --- TODO.md | 1 + src/app.rs | 1 + src/settings.rs | 20 ++++++++++++++++++++ src/ui/gps.ui | 4 ++++ 4 files changed, 26 insertions(+) diff --git a/TODO.md b/TODO.md index 6857c1f..7dc76d4 100644 --- a/TODO.md +++ b/TODO.md @@ -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 diff --git a/src/app.rs b/src/app.rs index 1327dd7..c4e89a3 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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); }); }); diff --git a/src/settings.rs b/src/settings.rs index d617a0d..2e50bbd 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -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, + pub recent_open_files: Vec, pub paned_positions: HashMap, pub preferences: HashMap, } @@ -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 { + 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(); diff --git a/src/ui/gps.ui b/src/ui/gps.ui index c151f19..5fcc4d9 100644 --- a/src/ui/gps.ui +++ b/src/ui/gps.ui @@ -18,6 +18,10 @@ app.save_as <primary>n + + _Open recent ... + app.open_recent + _Preferences app.preferences