Make unapplied changes counter private

This commit is contained in:
Oliver Hamlet
2016-01-12 10:58:53 +00:00
parent 6307a3c194
commit e2ee8f838c
4 changed files with 26 additions and 10 deletions
+6 -6
View File
@@ -160,12 +160,12 @@ namespace loot {
return true;
}
else if (request == "cancelSort") {
--_lootState.numUnappliedChanges;
_lootState.decrementUnappliedChangeCounter();
callback->Success("");
return true;
}
else if (request == "editorOpened") {
++_lootState.numUnappliedChanges;
_lootState.incrementUnappliedChangeCounter();
callback->Success("");
return true;
}
@@ -173,7 +173,7 @@ namespace loot {
// This version of the editorClosed query has no arguments as it is
// sent when editing is cancelled. Just update the unapplied changes
// counter.
--_lootState.numUnappliedChanges;
_lootState.decrementUnappliedChangeCounter();
callback->Success("");
return true;
}
@@ -253,7 +253,7 @@ namespace loot {
// One argument, which is the plugin metadata that has changed (+ its name).
try {
callback->Success(ApplyUserEdits(request["args"][0]));
--_lootState.numUnappliedChanges;
_lootState.decrementUnappliedChangeCounter();
}
catch (loot::error &e) {
BOOST_LOG_TRIVIAL(error) << "Failed to apply plugin metadata. Details: " << e.what();
@@ -297,7 +297,7 @@ namespace loot {
return true;
}
else if (requestName == "applySort") {
--_lootState.numUnappliedChanges;
_lootState.decrementUnappliedChangeCounter();
BOOST_LOG_TRIVIAL(trace) << "User has accepted sorted load order, applying it.";
try {
_lootState.CurrentGame().SetLoadOrder(request["args"][0].as<list<string>>());
@@ -983,7 +983,7 @@ namespace loot {
node.push_back(pluginNode);
}
++_lootState.numUnappliedChanges;
_lootState.incrementUnappliedChangeCounter();
if (node.size() > 0)
callback->Success(JSON::stringify(node));
+1 -1
View File
@@ -152,7 +152,7 @@ namespace loot {
assert(CefCurrentlyOn(TID_UI));
// Check if unapplied changes exist.
if (_lootState.numUnappliedChanges > 0) {
if (_lootState.hasUnappliedChanges()) {
browser->GetMainFrame()->ExecuteJavaScript("onQuit();", browser->GetMainFrame()->GetURL(), 0);
return true;
}
+13 -1
View File
@@ -46,7 +46,7 @@ using boost::format;
namespace fs = boost::filesystem;
namespace loot {
LootState::LootState() : numUnappliedChanges(0), _currentGame(_games.end()) {}
LootState::LootState() : unappliedChangeCounter(0), _currentGame(_games.end()) {}
void LootState::Init(const std::string& cmdLineGame) {
// Do some preliminary locale / UTF-8 support setup here, in case the settings file reading requires it.
@@ -229,6 +229,18 @@ namespace loot {
return installedGames;
}
bool LootState::hasUnappliedChanges() const {
return unappliedChangeCounter > 0;
}
void LootState::incrementUnappliedChangeCounter() {
++unappliedChangeCounter;
}
void LootState::decrementUnappliedChangeCounter() {
--unappliedChangeCounter;
}
void LootState::SelectGame(std::string preferredGame) {
if (preferredGame.empty()) {
// Get preferred game from settings.
+6 -2
View File
@@ -48,13 +48,17 @@ namespace loot {
// Get the folder names of the installed games.
std::vector<std::string> InstalledGames();
// Used to check if LOOT has unaccepted sorting or metadata changes on quit.
int numUnappliedChanges;
bool hasUnappliedChanges() const;
void incrementUnappliedChangeCounter();
void decrementUnappliedChangeCounter();
private:
std::list<Game> _games;
std::list<Game>::iterator _currentGame;
std::vector<std::string> _initErrors;
// Used to check if LOOT has unaccepted sorting or metadata changes on quit.
size_t unappliedChangeCounter;
// Select initial game.
void SelectGame(std::string cmdLineGame);