Enhancement - append

- Implemented append command.
This commit is contained in:
Paul Beckingham 2009-06-15 01:44:42 -04:00
parent 3d9ec60153
commit 98316f7ab1
3 changed files with 59 additions and 57 deletions

View file

@ -162,7 +162,7 @@ std::string Context::dispatch ()
int gcMod = 0; // Change occurred by way of gc. int gcMod = 0; // Change occurred by way of gc.
std::string out; std::string out;
// TODO Just look at this thing. It just cries out for a dispatch table. // TODO Just look at this thing. It cries out for a dispatch table.
if (cmd.command == "projects") { out = handleProjects (); } if (cmd.command == "projects") { out = handleProjects (); }
else if (cmd.command == "tags") { out = handleTags (); } else if (cmd.command == "tags") { out = handleTags (); }
else if (cmd.command == "colors") { out = handleColor (); } else if (cmd.command == "colors") { out = handleColor (); }
@ -178,7 +178,9 @@ std::string Context::dispatch ()
else if (cmd.command == "add") { out = handleAdd (); } else if (cmd.command == "add") { out = handleAdd (); }
/* /*
else if (cmd.command == "" && task.getId ()) { out = handleModify (); } else if (cmd.command == "" && task.getId ()) { out = handleModify (); }
*/
else if (cmd.command == "append") { out = handleAppend (); } else if (cmd.command == "append") { out = handleAppend (); }
/*
else if (cmd.command == "annotate") { out = handleAnnotate (); } else if (cmd.command == "annotate") { out = handleAnnotate (); }
else if (cmd.command == "done") { out = handleDone (); } else if (cmd.command == "done") { out = handleDone (); }
else if (cmd.command == "undelete") { out = handleUndelete (); } else if (cmd.command == "undelete") { out = handleUndelete (); }

View file

@ -745,42 +745,48 @@ std::string handleModify ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string handleAppend () std::string handleAppend ()
{ {
/*
int count = 0; int count = 0;
*/
std::stringstream out; std::stringstream out;
/*
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);
handleRecurrence (tasks);
// Filter sequence.
std::vector <Task> all = tasks;
context.filter.applySequence (tasks, context.sequence);
foreach (task, tasks)
{ {
foreach (other, all) foreach (other, all)
{ {
if (other->getId () == seq->getId () || // Self if (other->id == task->id || // Self
(seq->has ("parent") && (task->has ("parent") &&
seq->getAttribute ("parent") == other->getAttribute ("parent")) || // Sibling task->get ("parent") == other->get ("parent")) || // Sibling
other->getUUID () == seq->getAttribute ("parent")) // Parent other->get ("uuid") == task->get ("parent")) // Parent
{ {
// A non-zero value forces a file write. // A non-zero value forces a file write.
int changes = 0; int changes = 0;
// Apply other deltas. // Apply other deltas.
changes += deltaAppend (*other, task); changes += deltaAppend (*other);
changes += deltaTags (*other, task); context.task.remove ("description");
changes += deltaAttributes (*other, task);
changes += deltaTags (*other);
context.task.remove ("tags");
changes += deltaAttributes (*other);
if (changes) if (changes)
{ {
tdb.modifyT (*other); context.tdb.update (*other);
if (context.config.get ("echo.command", true)) if (context.config.get ("echo.command", true))
out << "Appended '" out << "Appended '"
<< task.getDescription () << context.task.get ("description")
<< "' to task " << "' to task "
<< other->getId () << other->id
<< std::endl; << std::endl;
} }
@ -789,9 +795,12 @@ std::string handleAppend ()
} }
} }
context.tdb.commit ();
context.tdb.unlock ();
if (context.config.get ("echo.command", true)) if (context.config.get ("echo.command", true))
out << "Appended " << count << " task" << (count == 1 ? "" : "s") << std::endl; out << "Appended " << count << " task" << (count == 1 ? "" : "s") << std::endl;
*/
return out.str (); return out.str ();
} }
@ -974,12 +983,12 @@ std::string handleAnnotate ()
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int deltaAppend (Task& task, Task& delta) int deltaAppend (Task& task)
{ {
if (delta.has ("description")) if (context.task.has ("description"))
{ {
task.set ("description", task.set ("description",
task.get ("description") + " " + delta.get ("description")); task.get ("description") + " " + context.task.get ("description"));
return 1; return 1;
} }
@ -987,11 +996,11 @@ int deltaAppend (Task& task, Task& delta)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int deltaDescription (Task& task, Task& delta) int deltaDescription (Task& task)
{ {
if (delta.has ("description")) if (context.task.has ("description"))
{ {
task.set ("description", delta.get ("description")); task.set ("description", context.task.get ("description"));
return 1; return 1;
} }
@ -999,60 +1008,51 @@ int deltaDescription (Task& task, Task& delta)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int deltaTags (Task& task, Task& delta) int deltaTags (Task& task)
{ {
int changes = 0; int changes = 0;
// Apply or remove tags, if any. // Apply or remove tags, if any.
std::vector <std::string> tags; std::vector <std::string> tags;
delta.getTags (tags); context.task.getTags (tags);
for (unsigned int i = 0; i < tags.size (); ++i) foreach (tag, tags)
{ {
if (tags[i][0] == '+') task.addTag (*tag);
task.addTag (tags[i].substr (1, std::string::npos));
else
task.addTag (tags[i]);
++changes; ++changes;
} }
/* foreach (tag, context.tagRemovals)
// TODO Needs Task::getRemoveTags
delta.getRemoveTags (tags);
for (unsigned int i = 0; i < tags.size (); ++i)
{ {
if (tags[i][0] == '-') task.removeTag (*tag);
task.removeTag (tags[i].substr (1, std::string::npos));
else
task.removeTag (tags[i]);
++changes; ++changes;
} }
*/
return changes; return changes;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int deltaAttributes (Task& task, Task& delta) int deltaAttributes (Task& task)
{ {
int changes = 0; int changes = 0;
foreach (att, delta) foreach (att, context.task)
{ {
if (att->second.value () == "") if (att->first != "uuid")
task.remove (att->first); {
else if (att->second.value () == "")
task.set (att->first, att->second.value ()); task.remove (att->first);
else
task.set (att->first, att->second.value ());
++changes; ++changes;
}
} }
return changes; return changes;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int deltaSubstitutions (Task& task, Task& delta) int deltaSubstitutions (Task& task)
{ {
std::string description = task.get ("description"); std::string description = task.get ("description");
std::vector <Att> annotations; std::vector <Att> annotations;

View file

@ -69,11 +69,11 @@ std::string handleUndo ();
std::string handleColor (); std::string handleColor ();
std::string handleAnnotate (); std::string handleAnnotate ();
std::string handleDuplicate (); std::string handleDuplicate ();
int deltaAppend (Task&, Task&); int deltaAppend (Task&);
int deltaDescription (Task&, Task&); int deltaDescription (Task&);
int deltaTags (Task&, Task&); int deltaTags (Task&);
int deltaAttributes (Task&, Task&); int deltaAttributes (Task&);
int deltaSubstitutions (Task&, Task&); int deltaSubstitutions (Task&);
// edit.cpp // edit.cpp
std::string handleEdit (); std::string handleEdit ();