Save file to recents on save

This commit is contained in:
Nathan Rowe 2026-06-29 12:08:06 -04:00 committed by Ashley Wulber
parent 495f52cd5b
commit dfcef22632

View file

@ -691,13 +691,7 @@ impl App {
return Some(NewTab::Exists(entity)); return Some(NewTab::Exists(entity));
} }
// Add to recent files, ensuring only one entry self.add_to_recents(&canonical);
self.config_state.recent_files.retain(|x| x != &canonical);
self.config_state
.recent_files
.push_front(canonical.to_path_buf());
self.config_state.recent_files.truncate(10);
self.save_config_state();
let mut tab = EditorTab::new(&self.config); let mut tab = EditorTab::new(&self.config);
tab.open(canonical); tab.open(canonical);
@ -707,6 +701,15 @@ impl App {
} }
} }
fn add_to_recents(&mut self, canonical: &PathBuf) {
self.config_state.recent_files.retain(|x| x != canonical);
self.config_state
.recent_files
.push_front(canonical.to_path_buf());
self.config_state.recent_files.truncate(10);
self.save_config_state();
}
fn update_config(&mut self) -> Task<Message> { fn update_config(&mut self) -> Task<Message> {
//TODO: provide iterator over data //TODO: provide iterator over data
let entities: Vec<_> = self.tab_model.iter().collect(); let entities: Vec<_> = self.tab_model.iter().collect();
@ -2586,11 +2589,18 @@ impl Application for App {
let entity = entity_opt.unwrap_or_else(|| self.tab_model.active()); let entity = entity_opt.unwrap_or_else(|| self.tab_model.active());
if let Some(Tab::Editor(tab)) = self.tab_model.data_mut::<Tab>(entity) { if let Some(Tab::Editor(tab)) = self.tab_model.data_mut::<Tab>(entity) {
if tab.path_opt.is_none() { match tab.path_opt.clone() {
return self.update(Message::SaveAsDialog(Some(entity))); Some(path) => {
title_opt = Some(tab.title());
tab.save();
if let Ok(canonical) = fs::canonicalize(&path) {
self.add_to_recents(&canonical);
}
}
None => {
return self.update(Message::SaveAsDialog(Some(entity)));
}
} }
title_opt = Some(tab.title());
tab.save();
} }
if let Some(title) = title_opt { if let Some(title) = title_opt {
self.tab_model.text_set(self.tab_model.active(), title); self.tab_model.text_set(self.tab_model.active(), title);
@ -2601,10 +2611,17 @@ impl Application for App {
let entities: Vec<_> = self.tab_model.iter().collect(); let entities: Vec<_> = self.tab_model.iter().collect();
for entity in entities { for entity in entities {
if let Some(Tab::Editor(tab)) = self.tab_model.data_mut::<Tab>(entity) { if let Some(Tab::Editor(tab)) = self.tab_model.data_mut::<Tab>(entity) {
if tab.path_opt.is_none() { match tab.path_opt.clone() {
log::warn!("{} has no path when doing save all", tab.title()); Some(path) => {
tab.save();
if let Ok(canonical) = fs::canonicalize(&path) {
self.add_to_recents(&canonical);
}
}
None => {
log::warn!("{} has no path when doing save all", tab.title());
}
} }
tab.save();
} }
} }
return self.update_dialogs(); return self.update_dialogs();
@ -2648,6 +2665,11 @@ impl Application for App {
tab.path_opt = Some(paths.remove(0)); tab.path_opt = Some(paths.remove(0));
title_opt = Some(tab.title()); title_opt = Some(tab.title());
tab.save(); tab.save();
if let Some(path) = tab.path_opt.clone() {
if let Ok(canonical) = fs::canonicalize(&path) {
self.add_to_recents(&canonical);
}
}
} }
if let Some(title) = title_opt { if let Some(title) = title_opt {
self.tab_model.text_set(entity, title); self.tab_model.text_set(entity, title);