Implement revert all changes, fixes #128

This commit is contained in:
Jeremy Soller 2025-01-17 09:43:46 -07:00
parent 03de470425
commit 686185b0f1
No known key found for this signature in database
GPG key ID: D02FD439211AF56F
3 changed files with 14 additions and 1 deletions

View file

@ -199,6 +199,7 @@ pub enum Action {
Paste,
Quit,
Redo,
RevertAllChanges,
Save,
SaveAsDialog,
SelectAll,
@ -245,6 +246,7 @@ impl Action {
Self::Paste => Message::Paste,
Self::Quit => Message::Quit,
Self::Redo => Message::Redo,
Self::RevertAllChanges => Message::RevertAllChanges,
Self::Save => Message::Save(entity_opt),
Self::SaveAsDialog => Message::SaveAsDialog(entity_opt),
Self::SelectAll => Message::SelectAll,
@ -367,6 +369,7 @@ pub enum Message {
Quit,
QuitForce,
Redo,
RevertAllChanges,
Save(Option<segmented_button::Entity>),
SaveAll,
SaveAsDialog(Option<segmented_button::Entity>),
@ -2227,6 +2230,13 @@ impl Application for App {
return self.update(Message::TabChanged(self.tab_model.active()));
}
}
Message::RevertAllChanges => {
if let Some(Tab::Editor(tab)) = self.active_tab_mut() {
tab.reload();
return self.update(Message::TabChanged(self.tab_model.active()));
}
}
Message::Save(entity_opt) => {
let mut title_opt = None;

View file

@ -139,7 +139,7 @@ pub fn menu_bar<'a>(
MenuItem::Button(fl!("save"), None, Action::Save),
MenuItem::Button(fl!("save-as"), None, Action::SaveAsDialog),
MenuItem::Divider,
MenuItem::Button(fl!("revert-all-changes"), None, Action::Todo),
MenuItem::Button(fl!("revert-all-changes"), None, Action::RevertAllChanges),
MenuItem::Divider,
MenuItem::Button(
fl!("menu-document-statistics"),

View file

@ -127,6 +127,9 @@ impl EditorTab {
match editor.load_text(path, self.attrs) {
Ok(()) => {
log::info!("reloaded {:?}", path);
// Clear changed state
editor.set_changed(false);
}
Err(err) => {
log::error!("failed to reload {:?}: {}", path, err);