mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Enhancement - duplicate
- Implemented duplicate command. - Now allows duplication (and demotion) of recurring tasks.
This commit is contained in:
parent
8a22ac7cf2
commit
23f0a9658e
2 changed files with 61 additions and 43 deletions
|
@ -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 () ?
|
||||||
|
|
||||||
|
|
|
@ -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");
|
||||||
|
|
||||||
// Apply deltas.
|
out << "Note: task "
|
||||||
deltaDescription (dup, task);
|
<< task->id
|
||||||
deltaTags (dup, task);
|
<< " was a recurring task. The new task is not."
|
||||||
deltaAttributes (dup, task);
|
|
||||||
deltaSubstitutions (dup, task);
|
|
||||||
|
|
||||||
// A New task needs a new entry time.
|
|
||||||
char entryTime[16];
|
|
||||||
sprintf (entryTime, "%u", (unsigned int) time (NULL));
|
|
||||||
dup.setAttribute ("entry", entryTime);
|
|
||||||
|
|
||||||
if (!tdb.addT (dup))
|
|
||||||
throw std::string ("Could not create new task.");
|
|
||||||
|
|
||||||
if (context.config.get ("echo.command", true))
|
|
||||||
out << "Duplicated "
|
|
||||||
<< seq->getId ()
|
|
||||||
<< " '"
|
|
||||||
<< seq->getDescription ()
|
|
||||||
<< "'"
|
|
||||||
<< std::endl;
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
out << "Task "
|
|
||||||
<< seq->getId ()
|
|
||||||
<< " '"
|
|
||||||
<< seq->getDescription ()
|
|
||||||
<< "' is a recurring task, and cannot be duplicated."
|
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply deltas.
|
||||||
|
deltaDescription (dup);
|
||||||
|
context.task.remove ("description");
|
||||||
|
|
||||||
|
deltaTags (dup);
|
||||||
|
context.task.remove ("tags");
|
||||||
|
|
||||||
|
deltaAttributes (dup);
|
||||||
|
deltaSubstitutions (dup);
|
||||||
|
|
||||||
|
// A New task needs a new entry time.
|
||||||
|
char entryTime[16];
|
||||||
|
sprintf (entryTime, "%u", (unsigned int) time (NULL));
|
||||||
|
dup.set ("entry", entryTime);
|
||||||
|
|
||||||
|
context.tdb.add (dup);
|
||||||
|
|
||||||
|
if (context.config.get ("echo.command", true))
|
||||||
|
out << "Duplicated "
|
||||||
|
<< task->id
|
||||||
|
<< " '"
|
||||||
|
<< task->get ("description")
|
||||||
|
<< "'"
|
||||||
|
<< std::endl;
|
||||||
|
++count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.tdb.commit ();
|
||||||
|
context.tdb.unlock ();
|
||||||
|
|
||||||
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 ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue