diff --git a/src/Database.cpp b/src/Database.cpp index e6245149..5f47acd7 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -96,7 +96,7 @@ std::vector Database::allLines () //////////////////////////////////////////////////////////////////////////////// void Database::addInterval (const Interval& interval) { - undoTxnStart (); + startTransaction (); if (interval.range.is_open ()) { @@ -104,7 +104,7 @@ void Database::addInterval (const Interval& interval) // created on demand. auto df = getDatafile (interval.range.start.year (), interval.range.start.month ()); _files[df].addInterval (interval); - undoTxn ("interval", "", interval.json ()); + recordUndoAction ("interval", "", interval.json ()); } else { @@ -123,17 +123,17 @@ void Database::addInterval (const Interval& interval) _files[df].addInterval (segmentedInterval); - undoTxn ("interval", "", segmentedInterval.json ()); + recordUndoAction ("interval", "", segmentedInterval.json ()); } } - undoTxnEnd (); + endTransaction (); } //////////////////////////////////////////////////////////////////////////////// void Database::deleteInterval (const Interval& interval) { - undoTxnStart (); + startTransaction (); auto intervalRange = interval.range; for (auto& segment : segmentRange (intervalRange)) @@ -150,10 +150,10 @@ void Database::deleteInterval (const Interval& interval) _files[df].deleteInterval (segmentedInterval); - undoTxn ("interval", segmentedInterval.json (), ""); + recordUndoAction ("interval", segmentedInterval.json (), ""); } - undoTxnEnd (); + endTransaction (); } //////////////////////////////////////////////////////////////////////////////// @@ -163,17 +163,17 @@ void Database::deleteInterval (const Interval& interval) // Interval belongs in a different file. void Database::modifyInterval (const Interval& from, const Interval& to) { - undoTxnStart (); + startTransaction (); deleteInterval (from); addInterval (to); - undoTxnEnd (); + endTransaction (); } //////////////////////////////////////////////////////////////////////////////// // The _txn member is a reference count, allowing multiple nested transactions. // This accommodates the Database::modifyInterval call, that in turn calls // ::addInterval and ::deleteInterval. -void Database::undoTxnStart () +void Database::startTransaction () { if (_txn == 0) { @@ -185,9 +185,9 @@ void Database::undoTxnStart () //////////////////////////////////////////////////////////////////////////////// // The _txn member is a reference count. The undo data is only written when -// ::undoTxnEnd decrements the counter to zero, therefore the undo command can +// ::endTransaction decrements the counter to zero, therefore the undo command can // perform multiple atomic steps. -void Database::undoTxnEnd () +void Database::endTransaction () { --_txn; if (_txn == 0) @@ -212,10 +212,10 @@ void Database::undoTxnEnd () // Record undoable transactions. There are several types: // interval changes to stored intervals // config changes to configuration -void Database::undoTxn ( - const std::string& type, - const std::string& before, - const std::string& after) +void Database::recordUndoAction ( + const std::string &type, + const std::string &before, + const std::string &after) { _currentTransaction->addUndoAction (type, before, after); } diff --git a/src/Database.h b/src/Database.h index 01e0779e..4009f802 100644 --- a/src/Database.h +++ b/src/Database.h @@ -49,9 +49,9 @@ public: void deleteInterval (const Interval&); void modifyInterval (const Interval&, const Interval&); - void undoTxnStart (); - void undoTxnEnd (); - void undoTxn (const std::string&, const std::string&, const std::string&); + void startTransaction (); + void endTransaction (); + void recordUndoAction (const std::string &, const std::string &, const std::string &); std::string dump () const; diff --git a/src/commands/CmdConfig.cpp b/src/commands/CmdConfig.cpp index 36aeabea..98fe5fca 100644 --- a/src/commands/CmdConfig.cpp +++ b/src/commands/CmdConfig.cpp @@ -72,9 +72,9 @@ static bool setConfigVariable (Database& database, const Rules& rules, std::stri auto before = line; line = line.substr (0, pos) + name + " = " + value; - database.undoTxnStart (); - database.undoTxn ("config", before, line); - database.undoTxnEnd (); + database.startTransaction (); + database.recordUndoAction ("config", before, line); + database.endTransaction (); change = true; } @@ -107,9 +107,9 @@ static bool setConfigVariable (Database& database, const Rules& rules, std::stri auto before = line; line = line.substr (0, pos) + leaf + " " + value; - database.undoTxnStart (); - database.undoTxn ("config", before, line); - database.undoTxnEnd (); + database.startTransaction (); + database.recordUndoAction ("config", before, line); + database.endTransaction (); change = true; } @@ -132,9 +132,9 @@ static bool setConfigVariable (Database& database, const Rules& rules, std::stri // Add new line. lines.push_back (name + " = " + json::encode (value)); - database.undoTxnStart (); - database.undoTxn ("config", "", lines.back()); - database.undoTxnEnd (); + database.startTransaction (); + database.recordUndoAction ("config", "", lines.back ()); + database.endTransaction (); change = true; } @@ -155,9 +155,9 @@ static bool setConfigVariable (Database& database, const Rules& rules, std::stri // Add new line. lines.push_back (name + " = " + json::encode (value)); - database.undoTxnStart (); - database.undoTxn ("config", "", lines.back ()); - database.undoTxnEnd (); + database.startTransaction (); + database.recordUndoAction ("config", "", lines.back ()); + database.endTransaction (); change = true; } @@ -203,9 +203,9 @@ static int unsetConfigVariable (Database& database, const Rules& rules, std::str if (! confirmation || confirm (format ("Are you sure you want to remove '{1}'?", name))) { - database.undoTxnStart (); - database.undoTxn ("config", line, ""); - database.undoTxnEnd (); + database.startTransaction (); + database.recordUndoAction ("config", line, ""); + database.endTransaction (); line = ""; change = true;