Detect when local changes occured to file
This commit is contained in:
parent
8f03080b87
commit
1955de9e3e
5 changed files with 47 additions and 4 deletions
|
|
@ -485,7 +485,7 @@ void Toolbar::top_toolbar() {
|
||||||
}
|
}
|
||||||
std::vector<std::pair<std::string, std::string>> tabNames;
|
std::vector<std::pair<std::string, std::string>> tabNames;
|
||||||
for(size_t i = 0; i < main.worlds.size(); i++)
|
for(size_t i = 0; i < main.worlds.size(); i++)
|
||||||
tabNames.emplace_back(main.worlds[i]->netObjMan.is_connected() ? "data/icons/network.svg" : "", main.worlds[i]->name);
|
tabNames.emplace_back(main.worlds[i]->netObjMan.is_connected() ? "data/icons/network.svg" : "", main.worlds[i]->name + (main.worlds[i]->hasUnsavedLocalChanges ? "*" : ""));
|
||||||
std::optional<size_t> closedTab;
|
std::optional<size_t> closedTab;
|
||||||
gui.tab_list("file tab list", tabNames, main.worldIndex, closedTab);
|
gui.tab_list("file tab list", tabNames, main.worldIndex, closedTab);
|
||||||
if(!main.world->clientStillConnecting) {
|
if(!main.world->clientStillConnecting) {
|
||||||
|
|
|
||||||
|
|
@ -404,6 +404,7 @@ void World::save_to_file(const std::filesystem::path& filePathToSaveAt) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Logger::get().log("USERINFO", "File saved");
|
Logger::get().log("USERINFO", "File saved");
|
||||||
|
undo.set_save_action();
|
||||||
}
|
}
|
||||||
catch(const std::exception& e) {
|
catch(const std::exception& e) {
|
||||||
Logger::get().log("WORLDFATAL", std::string("Save error: ") + e.what());
|
Logger::get().log("WORLDFATAL", std::string("Save error: ") + e.what());
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ class World {
|
||||||
void scale_up(const WorldScalar& scaleUpAmount);
|
void scale_up(const WorldScalar& scaleUpAmount);
|
||||||
void scale_up_step();
|
void scale_up_step();
|
||||||
|
|
||||||
|
bool hasUnsavedLocalChanges = false;
|
||||||
bool setToDestroy = false;
|
bool setToDestroy = false;
|
||||||
NetworkingObjects::DelayUpdateSerializedClassManager delayedUpdateObjectManager;
|
NetworkingObjects::DelayUpdateSerializedClassManager delayedUpdateObjectManager;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#include "WorldUndoManager.hpp"
|
#include "WorldUndoManager.hpp"
|
||||||
|
#include "World.hpp"
|
||||||
|
|
||||||
void WorldUndoAction::scale_up(const WorldScalar& scaleAmount) {}
|
void WorldUndoAction::scale_up(const WorldScalar& scaleAmount) {}
|
||||||
WorldUndoAction::~WorldUndoAction() {}
|
WorldUndoAction::~WorldUndoAction() {}
|
||||||
|
|
@ -18,17 +19,23 @@ bool WorldUndoManager::can_redo() {
|
||||||
void WorldUndoManager::push(std::unique_ptr<WorldUndoAction> undoAction) {
|
void WorldUndoManager::push(std::unique_ptr<WorldUndoAction> undoAction) {
|
||||||
push_undo(std::move(undoAction));
|
push_undo(std::move(undoAction));
|
||||||
redoQueue.clear();
|
redoQueue.clear();
|
||||||
|
world.hasUnsavedLocalChanges = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldUndoManager::push_undo(std::unique_ptr<WorldUndoAction> undoAction) {
|
void WorldUndoManager::push_undo(std::unique_ptr<WorldUndoAction> undoAction) {
|
||||||
if(undoQueue.size() == UNDO_QUEUE_LIMIT)
|
if(undoQueue.size() == UNDO_QUEUE_LIMIT) {
|
||||||
|
if(undoActionSavedAt.has_value()) {
|
||||||
|
if(undoQueue.front().get() == undoActionSavedAt.value())
|
||||||
|
undoActionSavedAt = nullptr;
|
||||||
|
else if(undoActionSavedAt.value() == nullptr)
|
||||||
|
undoActionSavedAt = std::nullopt;
|
||||||
|
}
|
||||||
undoQueue.pop_front();
|
undoQueue.pop_front();
|
||||||
|
}
|
||||||
undoQueue.emplace_back(std::move(undoAction));
|
undoQueue.emplace_back(std::move(undoAction));
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldUndoManager::push_redo(std::unique_ptr<WorldUndoAction> undoAction) {
|
void WorldUndoManager::push_redo(std::unique_ptr<WorldUndoAction> undoAction) {
|
||||||
if(redoQueue.size() == UNDO_QUEUE_LIMIT)
|
|
||||||
redoQueue.pop_front();
|
|
||||||
redoQueue.emplace_back(std::move(undoAction));
|
redoQueue.emplace_back(std::move(undoAction));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,6 +48,8 @@ void WorldUndoManager::undo() {
|
||||||
push_redo(std::move(undoQueue.back()));
|
push_redo(std::move(undoQueue.back()));
|
||||||
undoQueue.pop_back();
|
undoQueue.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_world_has_unsaved_local_changes();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldUndoManager::redo() {
|
void WorldUndoManager::redo() {
|
||||||
|
|
@ -52,11 +61,14 @@ void WorldUndoManager::redo() {
|
||||||
push_undo(std::move(redoQueue.back()));
|
push_undo(std::move(redoQueue.back()));
|
||||||
redoQueue.pop_back();
|
redoQueue.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_world_has_unsaved_local_changes();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldUndoManager::clear() {
|
void WorldUndoManager::clear() {
|
||||||
redoQueue.clear();
|
redoQueue.clear();
|
||||||
undoQueue.clear();
|
undoQueue.clear();
|
||||||
|
undoActionSavedAt = std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldUndoManager::scale_up(const WorldScalar& scaleAmount) {
|
void WorldUndoManager::scale_up(const WorldScalar& scaleAmount) {
|
||||||
|
|
@ -142,3 +154,26 @@ std::vector<std::string> WorldUndoManager::get_front_undo_queue_names(unsigned c
|
||||||
}
|
}
|
||||||
return toRet;
|
return toRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WorldUndoManager::set_save_action() {
|
||||||
|
if(undoQueue.empty())
|
||||||
|
undoActionSavedAt = nullptr;
|
||||||
|
else
|
||||||
|
undoActionSavedAt = undoQueue.back().get();
|
||||||
|
world.hasUnsavedLocalChanges = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldUndoManager::set_world_has_unsaved_local_changes() {
|
||||||
|
// Saved action value meanings:
|
||||||
|
// - a pointer to an action: The file was saved when that undo action was the last one in place
|
||||||
|
// - nullptr: The file was saved when undoQueue was empty
|
||||||
|
// - nullopt: The undo action the file was saved at was lost
|
||||||
|
if(!undoActionSavedAt.has_value())
|
||||||
|
world.hasUnsavedLocalChanges = true;
|
||||||
|
else {
|
||||||
|
if(undoQueue.empty())
|
||||||
|
world.hasUnsavedLocalChanges = undoActionSavedAt.value() != nullptr;
|
||||||
|
else
|
||||||
|
world.hasUnsavedLocalChanges = undoActionSavedAt.value() != undoQueue.back().get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,8 @@ class WorldUndoManager {
|
||||||
bool fill_netid_list_from_undoid_list(std::vector<NetworkingObjects::NetObjID>& netIDList, const std::vector<UndoObjectID>& undoIDList);
|
bool fill_netid_list_from_undoid_list(std::vector<NetworkingObjects::NetObjID>& netIDList, const std::vector<UndoObjectID>& undoIDList);
|
||||||
std::vector<std::string> get_front_undo_queue_names(unsigned count);
|
std::vector<std::string> get_front_undo_queue_names(unsigned count);
|
||||||
|
|
||||||
|
void set_save_action();
|
||||||
|
|
||||||
World& world;
|
World& world;
|
||||||
private:
|
private:
|
||||||
void push_undo(std::unique_ptr<WorldUndoAction> undoAction);
|
void push_undo(std::unique_ptr<WorldUndoAction> undoAction);
|
||||||
|
|
@ -49,5 +51,9 @@ class WorldUndoManager {
|
||||||
std::deque<std::unique_ptr<WorldUndoAction>> undoQueue;
|
std::deque<std::unique_ptr<WorldUndoAction>> undoQueue;
|
||||||
std::deque<std::unique_ptr<WorldUndoAction>> redoQueue;
|
std::deque<std::unique_ptr<WorldUndoAction>> redoQueue;
|
||||||
|
|
||||||
|
std::optional<WorldUndoAction*> undoActionSavedAt = nullptr;
|
||||||
|
|
||||||
|
void set_world_has_unsaved_local_changes();
|
||||||
|
|
||||||
UndoObjectID lastUndoObjectID = 0;
|
UndoObjectID lastUndoObjectID = 0;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue