Enhancement - duplicate

- Implemented duplicate command.
- Now allows duplication (and demotion) of recurring tasks.
This commit is contained in:
Paul Beckingham 2009-06-16 22:40:59 -04:00
parent 8a22ac7cf2
commit 23f0a9658e
2 changed files with 61 additions and 43 deletions

View file

@ -204,7 +204,9 @@ std::string Context::dispatch ()
else if (cmd.command == "export") { out = handleExport (); } else if (cmd.command == "export") { out = handleExport (); }
/* /*
else if (cmd.command == "import") { out = handleImport (); } else if (cmd.command == "import") { out = handleImport (); }
*/
else if (cmd.command == "duplicate") { out = handleDuplicate (); } else if (cmd.command == "duplicate") { out = handleDuplicate (); }
/*
else if (cmd.command == "edit") { out = handleEdit (); } else if (cmd.command == "edit") { out = handleEdit (); }
*/ */
@ -449,7 +451,6 @@ void Context::parse ()
// Anything else is just considered description. // Anything else is just considered description.
else else
{ {
header ("parse description '" + *arg + "'");
if (foundSequence) if (foundSequence)
foundSomethingAfterSequence = true; foundSomethingAfterSequence = true;
@ -473,7 +474,10 @@ void Context::parse ()
} }
if (descCandidate != "" && noVerticalSpace (descCandidate)) if (descCandidate != "" && noVerticalSpace (descCandidate))
{
header ("parse description '" + descCandidate + "'");
task.set ("description", descCandidate); task.set ("description", descCandidate);
}
// TODO task.validate () ? // TODO task.validate () ?

View file

@ -880,58 +880,72 @@ std::string handleAppend ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string handleDuplicate () std::string handleDuplicate ()
{ {
/*
int count = 0;
*/
std::stringstream out; std::stringstream out;
/* int count = 0;
std::vector <T> all;
tdb.allPendingT (all);
std::vector <T> filtered = all; std::vector <Task> tasks;
filterSequence (filtered, task); context.tdb.lock (context.config.get ("locking", true));
foreach (seq, filtered) context.tdb.loadPending (tasks, context.filter);
// Filter sequence.
context.filter.applySequence (tasks, context.sequence);
foreach (task, tasks)
{ {
if (seq->getStatus () != T::recurring && seq->getAttribute ("parent") == "") Task dup (*task);
dup.set ("uuid", uuid ()); // Needs a new UUID.
dup.setStatus (Task::pending);
dup.remove ("start"); // Does not inherit start date.
dup.remove ("end"); // Does not inherit end date.
// Recurring tasks are duplicated and downgraded to regular tasks.
if (task->getStatus () == Task::recurring)
{ {
T dup (*seq); dup.remove ("parent");
dup.setUUID (uuid ()); // Needs a new UUID. dup.remove ("recur");
dup.remove ("until");
dup.remove ("imak");
dup.remove ("imask");
out << "Note: task "
<< task->id
<< " was a recurring task. The new task is not."
<< std::endl;
}
// Apply deltas. // Apply deltas.
deltaDescription (dup, task); deltaDescription (dup);
deltaTags (dup, task); context.task.remove ("description");
deltaAttributes (dup, task);
deltaSubstitutions (dup, task); deltaTags (dup);
context.task.remove ("tags");
deltaAttributes (dup);
deltaSubstitutions (dup);
// A New task needs a new entry time. // A New task needs a new entry time.
char entryTime[16]; char entryTime[16];
sprintf (entryTime, "%u", (unsigned int) time (NULL)); sprintf (entryTime, "%u", (unsigned int) time (NULL));
dup.setAttribute ("entry", entryTime); dup.set ("entry", entryTime);
if (!tdb.addT (dup)) context.tdb.add (dup);
throw std::string ("Could not create new task.");
if (context.config.get ("echo.command", true)) if (context.config.get ("echo.command", true))
out << "Duplicated " out << "Duplicated "
<< seq->getId () << task->id
<< " '" << " '"
<< seq->getDescription () << task->get ("description")
<< "'" << "'"
<< std::endl; << std::endl;
++count; ++count;
} }
else
out << "Task " context.tdb.commit ();
<< seq->getId () context.tdb.unlock ();
<< " '"
<< seq->getDescription ()
<< "' is a recurring task, and cannot be duplicated."
<< std::endl;
}
if (context.config.get ("echo.command", true)) if (context.config.get ("echo.command", true))
out << "Duplicated " << count << " task" << (count == 1 ? "" : "s") << std::endl; out << "Duplicated " << count << " task" << (count == 1 ? "" : "s") << std::endl;
*/
return out.str (); return out.str ();
} }