Skip to content

Commit

Permalink
Fixed undo manager to properly handle the undo stack (SuperTux#1504)
Browse files Browse the repository at this point in the history
* Fixed undo manager to properly handle the undo stack (will no longer ask to save a freshly opened, unmodified level)

* Fixed issue with the preceeding correction of the Undo manager

Co-authored-by: Semphris <invalid@example.com>
  • Loading branch information
2 people authored and mbernard2 committed Aug 18, 2020
1 parent 43dd596 commit 6ce825e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ Editor::Editor() :
m_enabled(false),
m_bgr_surface(Surface::from_file("images/background/antarctic/arctis2.png")),
m_undo_manager(new UndoManager),
m_ignore_sector_change(false)
m_ignore_sector_change(false),
m_level_first_loaded(false)
{
auto toolbox_widget = std::make_unique<EditorToolboxWidget>(*this);
auto layers_widget = std::make_unique<EditorLayersWidget>(*this);
Expand Down Expand Up @@ -395,7 +396,6 @@ Editor::delete_current_sector()
void
Editor::set_level(std::unique_ptr<Level> level, bool reset)
{
m_undo_manager->reset_index();
std::string sector_name = "main";
Vector translation;

Expand Down Expand Up @@ -436,6 +436,13 @@ Editor::set_level(std::unique_ptr<Level> level, bool reset)
m_layers_widget->refresh_sector_text();
m_toolbox_widget->update_mouse_icon();
m_overlay_widget->on_level_change();

if (!m_level_first_loaded)
{
m_undo_manager->try_snapshot(*m_level);
m_undo_manager->reset_index();
m_level_first_loaded = true;
}
}

void
Expand Down
2 changes: 2 additions & 0 deletions src/editor/editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ class Editor final : public Screen,

std::unique_ptr<UndoManager> m_undo_manager;
bool m_ignore_sector_change;

bool m_level_first_loaded;

private:
Editor(const Editor&) = delete;
Expand Down

0 comments on commit 6ce825e

Please sign in to comment.