From 877ecbc8642b3a8bb8f433a0f22f130843071448 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 26 Jun 2011 23:28:21 -0400 Subject: [PATCH] Commands - done - The 'done' command now functional. - Localized CmdDone.cpp. --- src/Task.cpp | 12 ++++--- src/commands/CmdDone.cpp | 66 +++++++++++++++++-------------------- src/commands/CmdHistory.cpp | 8 ++--- src/commands/CmdUrgency.cpp | 2 +- src/commands/Command.cpp | 4 ++- src/en-US.h | 10 ++++-- 6 files changed, 54 insertions(+), 48 deletions(-) diff --git a/src/Task.cpp b/src/Task.cpp index 4fcb5439a..15ee2fc3f 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -881,10 +881,14 @@ void Task::substitute ( void Task::validate () const { // Every task needs an ID, entry and description attribute. - if (!has ("uuid") || - !has ("entry") || - !has ("description")) - throw std::string ("A task must have a description in order to be valid."); + if (!has ("uuid")) + throw std::string ("A task must have a UUID."); + + if (!has ("entry")) + throw std::string ("A task must have an entry timestamp."); + + if (!has ("description")) + throw std::string ("A task must have a description."); if (get ("description") == "") // No i18n throw std::string ("Cannot add a task that is blank, or contains or characters."); diff --git a/src/commands/CmdDone.cpp b/src/commands/CmdDone.cpp index 765753388..175f4a057 100644 --- a/src/commands/CmdDone.cpp +++ b/src/commands/CmdDone.cpp @@ -25,10 +25,14 @@ // //////////////////////////////////////////////////////////////////////////////// +#define L10N // Localization complete. + #include #include #include #include +#include +#include #include 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 tasks; context.tdb.lock (context.config.getBoolean ("locking")); - Filter filter; - context.tdb.loadPending (tasks, filter); + context.tdb.loadPending (tasks); - // Filter sequence. - std::vector all = tasks; - context.filter.applySequence (tasks, context.sequence); - if (tasks.size () == 0) + // Apply filter. + std::vector 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 ::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; } diff --git a/src/commands/CmdHistory.cpp b/src/commands/CmdHistory.cpp index 42e7967ad..3f17e4c51 100644 --- a/src/commands/CmdHistory.cpp +++ b/src/commands/CmdHistory.cpp @@ -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; } diff --git a/src/commands/CmdUrgency.cpp b/src/commands/CmdUrgency.cpp index 01bb242e0..cb0e44f05 100644 --- a/src/commands/CmdUrgency.cpp +++ b/src/commands/CmdUrgency.cpp @@ -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; } diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index 1b341586d..2cbd13559 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -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); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/en-US.h b/src/en-US.h index ec37e777a..ab268dd14 100644 --- a/src/en-US.h +++ b/src/en-US.h @@ -169,7 +169,6 @@ #define STRING_CMD_LOGO_COLOR_REQ "The logo command requires that color support is enabled." #define STRING_CMD_EXEC_USAGE "Executes external commands and scripts" #define STRING_CMD_URGENCY_USAGE "Displays the urgency measure of a task." -#define STRING_CMD_URGENCY_NO_TASKS "No tasks specified." #define STRING_CMD_URGENCY_RESULT "task {1} urgency {2}" #define STRING_CMD_ADD_USAGE "Adds a new task." #define STRING_CMD_ADD_FEEDBACK "Created task {1}." @@ -222,7 +221,6 @@ #define STRING_CMD_HISTORY_DEL "Deleted" #define STRING_CMD_HISTORY_NET "Net" #define STRING_CMD_HISTORY_USAGE_A "Shows a report of task history, by year." -#define STRING_CMD_HISTORY_NO_TASKS "No tasks." #define STRING_CMD_HISTORY_AVERAGE "Average" #define STRING_CMD_HISTORY_LEGEND "Legend: {1}, {2}, {3}" #define STRING_CMD_HISTORY_LEGEND_A "Legend: + added, X completed, - deleted" @@ -231,6 +229,12 @@ #define STRING_CMD_GHISTORY_YEAR "Year" #define STRING_CMD_GHISTORY_MONTH "Month" #define STRING_CMD_GHISTORY_NUMBER "Number Added/Completed/Deleted" +#define STRING_CMD_DONE_USAGE "Marks the specified task as completed." +#define STRING_CMD_DONE_PROCEED "Proceed with change?" +#define STRING_CMD_DONE_COMPLETED "Completed {1} '{2}'." +#define STRING_CMD_DONE_NOT_PENDING "Task {1} '{2}' is neither pending nor waiting." +#define STRING_CMD_DONE_MARKED "Marked {1} task as done" +#define STRING_CMD_DONE_MARKED_N "Marked {1} tasks as done" // Config #define STRING_CONFIG_OVERNEST "Configuration file nested to more than 10 levels deep - this has to be a mistake." @@ -272,6 +276,8 @@ #define STRING_INFINITE_LOOP "Terminated substitution because more than {1} changes were made - infinite loop protection." // Feedback +#define STRING_FEEDBACK_NO_TASKS "No tasks." +#define STRING_FEEDBACK_NO_TASKS_SP "No tasks specified." #define STRING_FEEDBACK_NO_MATCH "No matches." #define STRING_FEEDBACK_TASKS_SINGLE "(1 task)" #define STRING_FEEDBACK_TASKS_PLURAL "({1} tasks)"