Permalink
Browse files

#9 TI-1: Add wrapper methods for config and interval undo-actions

- make recordUndoAction private
  • Loading branch information...
lauft committed Jul 18, 2018
1 parent b8b0bbf commit 881d9590da97f7834cd66f44d0ef2e5e4770f06f
Showing with 28 additions and 9 deletions.
  1. +19 −3 src/Database.cpp
  2. +4 −1 src/Database.h
  3. +5 −5 src/commands/CmdConfig.cpp
@@ -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);
recordUndoAction ("interval", "", interval.json ());
recordIntervalAction ("", interval.json ());
}
else
{
@@ -123,7 +123,7 @@ void Database::addInterval (const Interval& interval)

_files[df].addInterval (segmentedInterval);

recordUndoAction ("interval", "", segmentedInterval.json ());
recordIntervalAction ("", segmentedInterval.json ());
}
}

@@ -150,7 +150,7 @@ void Database::deleteInterval (const Interval& interval)

_files[df].deleteInterval (segmentedInterval);

recordUndoAction ("interval", segmentedInterval.json (), "");
recordIntervalAction (segmentedInterval.json (), "");
}

endTransaction ();
@@ -220,6 +220,22 @@ void Database::recordUndoAction (
_currentTransaction->addUndoAction (type, before, after);
}

////////////////////////////////////////////////////////////////////////////////
void Database::recordConfigAction (
const std::string& before,
const std::string& after)
{
recordUndoAction ("config", before, after);
}

////////////////////////////////////////////////////////////////////////////////
void Database::recordIntervalAction (
const std::string& before,
const std::string& after)
{
recordUndoAction ("interval", before, after);
}

////////////////////////////////////////////////////////////////////////////////
std::string Database::dump () const
{
@@ -51,7 +51,8 @@ class Database

void startTransaction ();
void endTransaction ();
void recordUndoAction (const std::string &, const std::string &, const std::string &);
void recordConfigAction(const std::string&, const std::string&);
void recordIntervalAction(const std::string&, const std::string&);

std::string dump () const;

@@ -60,6 +61,8 @@ class Database
std::vector <Range> segmentRange (const Range&);
void initializeDatafiles ();

void recordUndoAction (const std::string &, const std::string &, const std::string &);

private:
std::string _location {"~/.timewarrior/data"};
std::vector <Datafile> _files {};
@@ -73,7 +73,7 @@ static bool setConfigVariable (Database& database, const Rules& rules, std::stri
line = line.substr (0, pos) + name + " = " + value;

database.startTransaction ();
database.recordUndoAction ("config", before, line);
database.recordConfigAction (before, line);
database.endTransaction ();

change = true;
@@ -108,7 +108,7 @@ static bool setConfigVariable (Database& database, const Rules& rules, std::stri
line = line.substr (0, pos) + leaf + " " + value;

database.startTransaction ();
database.recordUndoAction ("config", before, line);
database.recordConfigAction (before, line);
database.endTransaction ();

change = true;
@@ -133,7 +133,7 @@ static bool setConfigVariable (Database& database, const Rules& rules, std::stri
lines.push_back (name + " = " + json::encode (value));

database.startTransaction ();
database.recordUndoAction ("config", "", lines.back ());
database.recordConfigAction ("", lines.back ());
database.endTransaction ();

change = true;
@@ -156,7 +156,7 @@ static bool setConfigVariable (Database& database, const Rules& rules, std::stri
lines.push_back (name + " = " + json::encode (value));

database.startTransaction ();
database.recordUndoAction ("config", "", lines.back ());
database.recordConfigAction ("", lines.back ());
database.endTransaction ();

change = true;
@@ -204,7 +204,7 @@ static int unsetConfigVariable (Database& database, const Rules& rules, std::str
confirm (format ("Are you sure you want to remove '{1}'?", name)))
{
database.startTransaction ();
database.recordUndoAction ("config", line, "");
database.recordConfigAction (line, "");
database.endTransaction ();

line = "";

0 comments on commit 881d959

Please sign in to comment.