Skip to content

Commit

Permalink
Implement revert all changes, fixes #128
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Jan 17, 2025
1 parent 03de470 commit 686185b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ pub enum Action {
Paste,
Quit,
Redo,
RevertAllChanges,
Save,
SaveAsDialog,
SelectAll,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -367,6 +369,7 @@ pub enum Message {
Quit,
QuitForce,
Redo,
RevertAllChanges,
Save(Option<segmented_button::Entity>),
SaveAll,
SaveAsDialog(Option<segmented_button::Entity>),
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
3 changes: 3 additions & 0 deletions src/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 686185b

Please sign in to comment.