CmdConfig: Added recording of undoable transactions

This commit is contained in:
Paul Beckingham 2016-05-14 13:59:33 -04:00
parent 7d5befb607
commit 8870ba6bd0

View file

@ -72,7 +72,13 @@ static bool setConfigVariable (Database& database, const Rules& rules, std::stri
rules.get (name), rules.get (name),
value))) value)))
{ {
auto before = line;
line = line.substr (0, pos) + name + " = " + value; line = line.substr (0, pos) + name + " = " + value;
database.undoTxnStart ();
database.undoTxn ("config", before, line);
database.undoTxnEnd ();
change = true; change = true;
} }
} }
@ -101,7 +107,13 @@ static bool setConfigVariable (Database& database, const Rules& rules, std::stri
rules.get (name), rules.get (name),
value))) value)))
{ {
auto before = line;
line = line.substr (0, pos) + leaf + " " + value; line = line.substr (0, pos) + leaf + " " + value;
database.undoTxnStart ();
database.undoTxn ("config", before, line);
database.undoTxnEnd ();
change = true; change = true;
} }
} }
@ -123,6 +135,11 @@ static bool setConfigVariable (Database& database, const Rules& rules, std::stri
// Add new line. // Add new line.
lines.push_back (name + " = " + JSON2::encode (value)); lines.push_back (name + " = " + JSON2::encode (value));
database.undoTxnStart ();
database.undoTxn ("config", "", lines.back ());
database.undoTxnEnd ();
change = true; change = true;
} }
} }
@ -167,6 +184,10 @@ static int unsetConfigVariable (Database& database, const Rules& rules, std::str
if (! confirmation || if (! confirmation ||
confirm (format ("Are you sure you want to remove '{1}'?", name))) confirm (format ("Are you sure you want to remove '{1}'?", name)))
{ {
database.undoTxnStart ();
database.undoTxn ("config", line, "");
database.undoTxnEnd ();
line = ""; line = "";
change = true; change = true;
} }