diff --git a/ChangeLog b/ChangeLog index d6aa75d7d..5b21ebc1b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 2.5.1 () - +- TW-1704 Use Task::identifier to reference the Task in the output - The default configuration is now 256-color only. - The 'columns' report now shows whether a column is modifiable or read only. diff --git a/src/Task.cpp b/src/Task.cpp index 55f7c099d..c0f51293f 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -202,6 +202,20 @@ std::string Task::statusToText (Task::status s) return "pending"; } +//////////////////////////////////////////////////////////////////////////////// +// Returns a proper handle to the task. Tasks should not be referenced by UUIDs +// as long as they have non-zero ID. +// +const std::string Task::identifier (bool shortened /* = false */) const +{ + if (this->id != 0) + return format (this->id); + else if (shortened) + return this->get ("uuid").substr (0, 8); + else + return this->get ("uuid"); +} + //////////////////////////////////////////////////////////////////////////////// void Task::setAsNow (const std::string& att) { diff --git a/src/Task.h b/src/Task.h index 7776f7ad0..9173981dd 100644 --- a/src/Task.h +++ b/src/Task.h @@ -92,6 +92,7 @@ public: void setAsNow (const std::string&); bool has (const std::string&) const; std::vector all (); + const std::string identifier (bool shortened = false) const; const std::string get (const std::string&) const; const std::string& get_ref (const std::string&) const; int get_int (const std::string&) const; diff --git a/src/commands/CmdAnnotate.cpp b/src/commands/CmdAnnotate.cpp index b916c58b5..d83fdbf46 100644 --- a/src/commands/CmdAnnotate.cpp +++ b/src/commands/CmdAnnotate.cpp @@ -79,7 +79,7 @@ int CmdAnnotate::execute (std::string&) // Annotate the specified task. std::string question = format (STRING_CMD_ANNO_CONFIRM, - task.id, + task.identifier (true), task.get ("description")); task.modify (Task::modAnnotate, true); diff --git a/src/commands/CmdAppend.cpp b/src/commands/CmdAppend.cpp index 15221d6f9..0465b7936 100644 --- a/src/commands/CmdAppend.cpp +++ b/src/commands/CmdAppend.cpp @@ -79,7 +79,7 @@ int CmdAppend::execute (std::string&) // Append to the specified task. std::string question = format (STRING_CMD_APPEND_CONFIRM, - task.id, + task.identifier (true), task.get ("description")); task.modify (Task::modAppend, true); diff --git a/src/commands/CmdDelete.cpp b/src/commands/CmdDelete.cpp index 1523f0fe1..431c29d87 100644 --- a/src/commands/CmdDelete.cpp +++ b/src/commands/CmdDelete.cpp @@ -80,14 +80,9 @@ int CmdDelete::execute (std::string&) { // Delete the specified task. std::string question; - if (task.id) - question = format (STRING_CMD_DELETE_CONFIRM, - task.id, - task.get ("description")); - else - question = format (STRING_CMD_DELETE_CONFIRM, - task.get ("uuid"), - task.get ("description")); + question = format (STRING_CMD_DELETE_CONFIRM, + task.identifier (true), + task.get ("description")); task.modify (Task::modAnnotate); task.setStatus (Task::deleted); @@ -173,7 +168,7 @@ int CmdDelete::execute (std::string&) else { std::cout << format (STRING_CMD_DELETE_NOT_DEL, - task.id, + task.identifier (true), task.get ("description")) << "\n"; rc = 1; diff --git a/src/commands/CmdDenotate.cpp b/src/commands/CmdDenotate.cpp index b4e0706f2..d5affca24 100644 --- a/src/commands/CmdDenotate.cpp +++ b/src/commands/CmdDenotate.cpp @@ -127,7 +127,7 @@ int CmdDenotate::execute (std::string&) if (before != task) { std::string question = format (STRING_CMD_DENO_CONFIRM, - task.id, + task.identifier (true), task.get ("description")); if (permission (taskDifferences (before, task) + question, filtered.size ())) diff --git a/src/commands/CmdDone.cpp b/src/commands/CmdDone.cpp index 8556216e6..830d8a45f 100644 --- a/src/commands/CmdDone.cpp +++ b/src/commands/CmdDone.cpp @@ -81,7 +81,7 @@ int CmdDone::execute (std::string&) { // Complete the specified task. std::string question = format (STRING_CMD_DONE_CONFIRM, - task.id, + task.identifier (true), task.get ("description")); task.modify (Task::modAnnotate); @@ -121,7 +121,7 @@ int CmdDone::execute (std::string&) else { std::cout << format (STRING_CMD_DONE_NOTPEND, - task.id, + task.identifier (true), task.get ("description")) << "\n"; rc = 1; diff --git a/src/commands/CmdDuplicate.cpp b/src/commands/CmdDuplicate.cpp index 2eb555724..beb454aa6 100644 --- a/src/commands/CmdDuplicate.cpp +++ b/src/commands/CmdDuplicate.cpp @@ -88,7 +88,7 @@ int CmdDuplicate::execute (std::string&) dup.remove ("recur"); dup.remove ("until"); dup.remove ("imask"); - std::cout << format (STRING_CMD_DUPLICATE_NON_REC, task.id) + std::cout << format (STRING_CMD_DUPLICATE_NON_REC, task.identifier ()) << "\n"; } @@ -96,7 +96,7 @@ int CmdDuplicate::execute (std::string&) else if (dup.getStatus () == Task::recurring) { dup.remove ("mask"); - std::cout << format (STRING_CMD_DUPLICATE_REC, task.id) + std::cout << format (STRING_CMD_DUPLICATE_REC, task.identifier ()) << "\n"; } @@ -106,7 +106,7 @@ int CmdDuplicate::execute (std::string&) dup.modify (Task::modAnnotate); if (permission (format (STRING_CMD_DUPLICATE_CONFIRM, - task.id, + task.identifier (true), task.get ("description")), filtered.size ())) { diff --git a/src/commands/CmdModify.cpp b/src/commands/CmdModify.cpp index 7fea872b1..655fe3c17 100644 --- a/src/commands/CmdModify.cpp +++ b/src/commands/CmdModify.cpp @@ -82,14 +82,9 @@ int CmdModify::execute (std::string&) checkConsistency(before, task); std::string question; - if (task.id != 0) - question = format (STRING_CMD_MODIFY_CONFIRM, - task.id, - task.get ("description")); - else - question = format (STRING_CMD_MODIFY_CONFIRM, - task.get ("uuid"), - task.get ("description")); + question = format (STRING_CMD_MODIFY_CONFIRM, + task.identifier (true), + task.get ("description")); if (permission (taskDifferences (before, task) + question, filtered.size ())) { diff --git a/src/commands/CmdPrepend.cpp b/src/commands/CmdPrepend.cpp index d3a8cba14..e655aad0a 100644 --- a/src/commands/CmdPrepend.cpp +++ b/src/commands/CmdPrepend.cpp @@ -79,7 +79,7 @@ int CmdPrepend::execute (std::string&) // Prepend to the specified task. std::string question = format (STRING_CMD_PREPEND_CONFIRM, - task.id, + task.identifier (true), task.get ("description")); task.modify (Task::modPrepend, true); diff --git a/src/commands/CmdStart.cpp b/src/commands/CmdStart.cpp index da1690b52..2cb861999 100644 --- a/src/commands/CmdStart.cpp +++ b/src/commands/CmdStart.cpp @@ -80,7 +80,7 @@ int CmdStart::execute (std::string&) // Start the specified task. std::string question = format (STRING_CMD_START_CONFIRM, - task.id, + task.identifier (true), task.get ("description")); task.modify (Task::modAnnotate); task.setAsNow ("start"); diff --git a/src/commands/CmdStop.cpp b/src/commands/CmdStop.cpp index 7ca2638e0..b0a3fcef5 100644 --- a/src/commands/CmdStop.cpp +++ b/src/commands/CmdStop.cpp @@ -78,7 +78,7 @@ int CmdStop::execute (std::string&) // Stop the specified task. std::string question = format (STRING_CMD_STOP_CONFIRM, - task.id, + task.identifier (true), task.get ("description")); task.modify (Task::modAnnotate); @@ -108,7 +108,7 @@ int CmdStop::execute (std::string&) else { std::cout << format (STRING_CMD_STOP_ALREADY, - task.id, + task.identifier (true), task.get ("description")) << "\n"; rc = 1; diff --git a/src/commands/CmdUrgency.cpp b/src/commands/CmdUrgency.cpp index cb853ce14..c47a18c49 100644 --- a/src/commands/CmdUrgency.cpp +++ b/src/commands/CmdUrgency.cpp @@ -70,19 +70,10 @@ int CmdUrgency::execute (std::string& output) std::stringstream out; for (auto& task : filtered) { - if (task.id) - { - out << format (STRING_CMD_URGENCY_RESULT, - task.id, trim (format (task.urgency (), 6, 3))) - << "\n"; - } - else - { - out << format (STRING_CMD_URGENCY_RESULT, - task.get ("uuid"), - trim (format (task.urgency (), 6, 3))) - << "\n"; - } + out << format (STRING_CMD_URGENCY_RESULT, + task.identifier (), + trim (format (task.urgency (), 6, 3))) + << "\n"; } output = out.str (); diff --git a/src/dependency.cpp b/src/dependency.cpp index cfb90717e..599b83cfc 100644 --- a/src/dependency.cpp +++ b/src/dependency.cpp @@ -145,7 +145,7 @@ void dependencyChainOnComplete (Task& task) // Nag about broken chain. if (context.config.getBoolean ("dependency.reminder")) { - std::cout << format (STRING_DEPEND_BLOCKED, task.id) + std::cout << format (STRING_DEPEND_BLOCKED, task.identifier ()) << "\n"; for (auto& b : blocking) @@ -200,7 +200,7 @@ void dependencyChainOnStart (Task& task) // broken chain. if (blocking.size ()) { - std::cout << format (STRING_DEPEND_BLOCKED, task.id) + std::cout << format (STRING_DEPEND_BLOCKED, task.identifier ()) << "\n"; for (auto& b : blocking) diff --git a/src/feedback.cpp b/src/feedback.cpp index 27c1d56dc..45ff910c8 100644 --- a/src/feedback.cpp +++ b/src/feedback.cpp @@ -309,12 +309,10 @@ void feedback_affected (const std::string& effect, const Task& task) { if (context.verbose ("affected")) { - if (task.id) - std::cout << format (effect, task.id, task.get ("description")) - << "\n"; - else - std::cout << format (effect, task.get ("uuid"), task.get ("description")) - << "\n"; + std::cout << format (effect, + task.identifier (true), + task.get ("description")) + << "\n"; } } @@ -373,12 +371,8 @@ void feedback_special_tags (const Task& task, const std::string& tag) if (msg.length ()) { - if (task.id) - std::cout << format (msg, task.id) - << "\n"; - else - std::cout << format (msg, task.get ("uuid")) - << "\n"; + std::cout << format (msg, task.identifier ()) + << "\n"; } } } @@ -506,7 +500,9 @@ std::string onExpiration (Task& task) std::stringstream msg; if (context.verbose ("affected")) - msg << format (STRING_FEEDBACK_EXPIRED, task.id, task.get ("description")); + msg << format (STRING_FEEDBACK_EXPIRED, + task.identifier (true), + task.get ("description")); return msg.str (); }