diff --git a/ChangeLog b/ChangeLog index f182c10ef..fc8bff940 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,7 @@ ------ current release --------------------------- -1.8.0 (6/30/2009) +1.8.0 (7/7/2009) + Added zsh tab completion script (thanks to P.C. Shyamshankar). + Fixed bug that cause the _forcecolor configuration variable to be considered obsolete (thank to Bruce Dillahunty). @@ -59,6 +59,7 @@ Add: and diagnostics will be generated that will help pinpoint a problem. + The new "undo" command replaces the old "undo" and "undelete" command with a complete undo stack that can rollback all changes. + + While waiting for a file lock, task states the reason for the delay. ------ old releases ------------------------------ diff --git a/src/TDB.cpp b/src/TDB.cpp index 06977aa1c..cdc6334e7 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -35,7 +35,9 @@ #include "text.h" #include "util.h" #include "TDB.h" +#include "Table.h" #include "Timer.h" +#include "color.h" #include "main.h" extern Context context; @@ -534,17 +536,91 @@ void TDB::undo () << lastChange.toString () << std::endl; - // confirm + // Attributes are all there is, so figure the different attribute names + // between before and after. + Table table; + table.setTableWidth (context.getWidth ()); + table.setTableIntraPadding (2); + table.addColumn (" "); + table.addColumn ("Prior Values"); + table.addColumn ("Current Values"); + table.setColumnUnderline (1); + table.setColumnUnderline (2); + table.setColumnWidth (0, Table::minimum); + table.setColumnWidth (1, Table::flexible); + table.setColumnWidth (2, Table::flexible); + + Task after (current); + if (prior != "") { - Task priorTask (prior); - Task currentTask (current); - std::cout << taskDifferences (prior, current) - << std::endl; + Task before (prior); + + std::vector beforeAtts; + foreach (att, before) + beforeAtts.push_back (att->first); + + std::vector afterAtts; + foreach (att, after) + afterAtts.push_back (att->first); + + std::vector beforeOnly; + std::vector afterOnly; + listDiff (beforeAtts, afterAtts, beforeOnly, afterOnly); + + int row; + foreach (name, beforeOnly) + { + row = table.addRow (); + table.addCell (row, 0, *name); + table.addCell (row, 1, renderAttribute (*name, before.get (*name))); + table.setCellFg (row, 1, Text::red); + } + + foreach (name, before) + { + std::string priorValue = before.get (name->first); + std::string currentValue = after.get (name->first); + + if (currentValue != "") + { + row = table.addRow (); + table.addCell (row, 0, name->first); + table.addCell (row, 1, renderAttribute (name->first, priorValue)); + table.addCell (row, 2, renderAttribute (name->first, currentValue)); + + if (priorValue != currentValue) + { + table.setCellFg (row, 1, Text::red); + table.setCellFg (row, 2, Text::green); + } + } + } + + foreach (name, afterOnly) + { + row = table.addRow (); + table.addCell (row, 0, *name); + table.addCell (row, 2, renderAttribute (*name, after.get (*name))); + table.setCellFg (row, 2, Text::green); + } } else - std::cout << " - This was a new task" - << std::endl; + { + int row; + foreach (name, after) + { + row = table.addRow (); + table.addCell (row, 0, name->first); + table.addCell (row, 2, renderAttribute (name->first, after.get (name->first))); + table.setCellFg (row, 2, Text::green); + } + } + + // Confirm. + std::cout << std::endl + << table.render () + << std::endl; if (!confirm ("The undo command is not reversible. Are you sure you want to undo the last update?")) throw std::string ("No changes made."); diff --git a/src/util.cpp b/src/util.cpp index 073bdf16b..7ab42aa4c 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -529,3 +529,16 @@ std::string taskDifferences (const Task& before, const Task& after) } //////////////////////////////////////////////////////////////////////////////// +std::string renderAttribute (const std::string& name, const std::string& value) +{ + Att a; + if (a.type (name) == "date") + { + Date d ((time_t)::atoi (value.c_str ())); + return d.toString (context.config.get ("dateformat", "m/d/Y")); + } + + return value; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/util.h b/src/util.h index 22a917a98..2b0b69b01 100644 --- a/src/util.h +++ b/src/util.h @@ -76,6 +76,7 @@ void spit (const std::string&, const std::string&); void spit (const std::string&, const std::vector &, bool addNewlines = true); bool taskDiff (const Task&, const Task&); std::string taskDifferences (const Task&, const Task&); +std::string renderAttribute (const std::string&, const std::string&); #endif ////////////////////////////////////////////////////////////////////////////////