Commands - done

- The 'done' command now functional.
- Localized CmdDone.cpp.
This commit is contained in:
Paul Beckingham 2011-06-26 23:28:21 -04:00
parent 1b90adc1aa
commit 877ecbc864
6 changed files with 54 additions and 48 deletions

View file

@ -25,10 +25,14 @@
//
////////////////////////////////////////////////////////////////////////////////
#define L10N // Localization complete.
#include <sstream>
#include <Context.h>
#include <Permission.h>
#include <main.h>
#include <text.h>
#include <i18n.h>
#include <CmdDone.h>
extern Context context;
@ -38,7 +42,7 @@ CmdDone::CmdDone ()
{
_keyword = "done";
_usage = "task done ID [tags] [attrs] [desc...]";
_description = "Marks the specified task as completed.";
_description = STRING_CMD_DONE_USAGE;
_read_only = false;
_displays_id = false;
}
@ -47,44 +51,40 @@ CmdDone::CmdDone ()
int CmdDone::execute (std::string& output)
{
int rc = 0;
/*
int count = 0;
std::stringstream out;
std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter;
context.tdb.loadPending (tasks, filter);
context.tdb.loadPending (tasks);
// Filter sequence.
std::vector <Task> all = tasks;
context.filter.applySequence (tasks, context.sequence);
if (tasks.size () == 0)
// Apply filter.
std::vector <Task> filtered;
filter (tasks, filtered);
if (filtered.size () == 0)
{
context.footnote ("No tasks specified.");
context.footnote (STRING_FEEDBACK_NO_TASKS_SP);
return 1;
}
Permission permission;
if (context.sequence.size () > (size_t) context.config.getInteger ("bulk"))
if (filtered.size () > (size_t) context.config.getInteger ("bulk"))
permission.bigSequence ();
bool nagged = false;
std::vector <Task>::iterator task;
for (task = tasks.begin (); task != tasks.end (); ++task)
for (task = filtered.begin (); task != filtered.end (); ++task)
{
if (task->getStatus () == Task::pending ||
task->getStatus () == Task::waiting)
{
Task before (*task);
// Apply other deltas.
if (deltaDescription (*task))
permission.bigChange ();
deltaTags (*task);
deltaAttributes (*task);
deltaSubstitutions (*task);
// Apply the command line modifications to the new task.
Arguments modifications = context.args.extract_modifications ();
modify_task (*task, modifications);
apply_defaults (*task);
// Add an end date.
char entryTime[16];
@ -104,16 +104,13 @@ int CmdDone::execute (std::string& output)
if (taskDiff (before, *task))
{
if (permission.confirmed (before, taskDifferences (before, *task) + "Proceed with change?"))
if (permission.confirmed (before, taskDifferences (before, *task) + STRING_CMD_DONE_PROCEED))
{
context.tdb.update (*task);
if (context.config.getBoolean ("echo.command"))
out << "Completed "
<< task->id
<< " '"
<< task->get ("description")
<< "'.\n";
out << format (STRING_CMD_DONE_COMPLETED, task->id, task->get ("description"))
<< "\n";
dependencyChainOnComplete (*task);
context.footnote (onProjectChange (*task, false));
@ -122,17 +119,14 @@ int CmdDone::execute (std::string& output)
}
}
updateRecurrenceMask (all, *task);
updateRecurrenceMask (filtered, *task);
if (!nagged)
nagged = nag (*task);
}
else
{
out << "Task "
<< task->id
<< " '"
<< task->get ("description")
<< "' is neither pending nor waiting.\n";
out << format (STRING_CMD_DONE_NOT_PENDING, task->id, task->get ("description"))
<< "\n";
rc = 1;
}
}
@ -143,14 +137,14 @@ int CmdDone::execute (std::string& output)
context.tdb.unlock ();
if (context.config.getBoolean ("echo.command"))
out << "Marked "
<< count
<< " task"
<< (count == 1 ? "" : "s")
<< " as done.\n";
if (count == 1)
out << format (STRING_CMD_DONE_MARKED, count)
<< "\n";
else
out << format (STRING_CMD_DONE_MARKED_N, count)
<< "\n";
output = out.str ();
*/
return rc;
}

View file

@ -190,7 +190,7 @@ int CmdHistoryMonthly::execute (std::string& output)
<< "\n";
else
{
out << STRING_CMD_HISTORY_NO_TASKS << "\n";
out << STRING_FEEDBACK_NO_TASKS << "\n";
rc = 1;
}
@ -347,7 +347,7 @@ int CmdHistoryAnnual::execute (std::string& output)
<< "\n";
else
{
out << STRING_CMD_HISTORY_NO_TASKS << "\n";
out << STRING_FEEDBACK_NO_TASKS << "\n";
rc = 1;
}
@ -546,7 +546,7 @@ int CmdGHistoryMonthly::execute (std::string& output)
}
else
{
out << STRING_CMD_HISTORY_NO_TASKS << "\n";
out << STRING_FEEDBACK_NO_TASKS << "\n";
rc = 1;
}
@ -742,7 +742,7 @@ int CmdGHistoryAnnual::execute (std::string& output)
}
else
{
out << STRING_CMD_HISTORY_NO_TASKS << "\n";
out << STRING_FEEDBACK_NO_TASKS << "\n";
rc = 1;
}

View file

@ -64,7 +64,7 @@ int CmdUrgency::execute (std::string& output)
if (filtered.size () == 0)
{
context.footnote (STRING_CMD_URGENCY_NO_TASKS);
context.footnote (STRING_FEEDBACK_NO_TASKS_SP);
return 1;
}

View file

@ -360,7 +360,9 @@ void Command::modify_task (Task& task, Arguments& arguments)
throw format (STRING_CMD_MOD_UNEXPECTED, arg->first);
}
task.set ("description", description);
// Only update description if one was specified.
if (description.length ())
task.set ("description", description);
}
////////////////////////////////////////////////////////////////////////////////