diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 852b59f8e..8b6892f23 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,13 +40,12 @@ set (task_SRCS API.cpp API.h Variant.cpp Variant.h ViewTask.cpp ViewTask.h ViewText.cpp ViewText.h - command.cpp + helpers.cpp dependency.cpp feedback.cpp i18n.h interactive.cpp recur.cpp - report.cpp rules.cpp rx.cpp rx.h sort.cpp diff --git a/src/command.cpp b/src/command.cpp deleted file mode 100644 index 4b739487b..000000000 --- a/src/command.cpp +++ /dev/null @@ -1,176 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// taskwarrior - a command line task list manager. -// -// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez. -// All rights reserved. -// -// This program is free software; you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free Software -// Foundation; either version 2 of the License, or (at your option) any later -// version. -// -// This program is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -// details. -// -// You should have received a copy of the GNU General Public License along with -// this program; if not, write to the -// -// Free Software Foundation, Inc., -// 51 Franklin Street, Fifth Floor, -// Boston, MA -// 02110-1301 -// USA -// -//////////////////////////////////////////////////////////////////////////////// - -#include -#include - -extern Context context; - -//////////////////////////////////////////////////////////////////////////////// -int deltaAppend (Task& task) -{ - if (context.task.has ("description")) - { - task.set ("description", - task.get ("description") + " " + context.task.get ("description")); - return 1; - } - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -int deltaPrepend (Task& task) -{ - if (context.task.has ("description")) - { - task.set ("description", - context.task.get ("description") + " " + task.get ("description")); - return 1; - } - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -int deltaDescription (Task& task) -{ - if (context.task.has ("description")) - { - task.set ("description", context.task.get ("description")); - return 1; - } - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// -int deltaTags (Task& task) -{ - int changes = 0; - - // Apply or remove tags, if any. - std::vector tags; - context.task.getTags (tags); - std::vector ::iterator tag; - for (tag = tags.begin (); tag != tags.end (); ++tag) - { - task.addTag (*tag); - ++changes; - } - - for (tag = context.tagRemovals.begin (); tag != context.tagRemovals.end (); ++tag) - { - task.removeTag (*tag); - ++changes; - } - - return changes; -} - -//////////////////////////////////////////////////////////////////////////////// -int deltaAttributes (Task& task) -{ - int changes = 0; - - std::map ::iterator att; - for (att = context.task.begin (); att != context.task.end (); ++att) - { - if (att->second.name () != "uuid" && - att->second.name () != "description" && - att->second.name () != "tags") - { - // Some things don't propagate to the parent task. - if (att->second.name () == "wait" && - task.getStatus () == Task::recurring) - { - // NOP - } - - // Modifying "wait" changes status, but not for recurring parent tasks. - else if (att->second.name () == "wait") - { - if (att->second.value () == "") - { - task.remove (att->first); - task.setStatus (Task::pending); - } - else - { - task.set (att->first, att->second.value ()); - task.setStatus (Task::waiting); - } - } - - // Modifying dependencies requires adding/removing uuids. - else if (att->second.name () == "depends") - { - std::vector deps; - split (deps, att->second.value (), ','); - - std::vector ::iterator i; - for (i = deps.begin (); i != deps.end (); i++) - { - int id = atoi (i->c_str ()); - if (id < 0) - task.removeDependency (-id); - else - task.addDependency (id); - } - } - - // Now the generalized handling. - else if (att->second.value () == "") - task.remove (att->second.name ()); - else - // One of the few places where the compound attribute name is used. - task.set (att->first, att->second.value ()); - - ++changes; - } - } - - return changes; -} - -//////////////////////////////////////////////////////////////////////////////// -int deltaSubstitutions (Task& task) -{ - std::string description = task.get ("description"); - std::vector annotations; - task.getAnnotations (annotations); - - context.subst.apply (description, annotations); - - task.set ("description", description); - task.setAnnotations (annotations); - - return 1; -} - -//////////////////////////////////////////////////////////////////////////////// -// vim: ts=2 sw=2 et diff --git a/src/report.cpp b/src/helpers.cpp similarity index 63% rename from src/report.cpp rename to src/helpers.cpp index ac47afa0e..57f06db7b 100644 --- a/src/report.cpp +++ b/src/helpers.cpp @@ -218,4 +218,146 @@ static void countTasks ( } } -/////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +int deltaAppend (Task& task) +{ + if (context.task.has ("description")) + { + task.set ("description", + task.get ("description") + " " + context.task.get ("description")); + return 1; + } + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +int deltaPrepend (Task& task) +{ + if (context.task.has ("description")) + { + task.set ("description", + context.task.get ("description") + " " + task.get ("description")); + return 1; + } + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +int deltaDescription (Task& task) +{ + if (context.task.has ("description")) + { + task.set ("description", context.task.get ("description")); + return 1; + } + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// +int deltaTags (Task& task) +{ + int changes = 0; + + // Apply or remove tags, if any. + std::vector tags; + context.task.getTags (tags); + std::vector ::iterator tag; + for (tag = tags.begin (); tag != tags.end (); ++tag) + { + task.addTag (*tag); + ++changes; + } + + for (tag = context.tagRemovals.begin (); tag != context.tagRemovals.end (); ++tag) + { + task.removeTag (*tag); + ++changes; + } + + return changes; +} + +//////////////////////////////////////////////////////////////////////////////// +int deltaAttributes (Task& task) +{ + int changes = 0; + + std::map ::iterator att; + for (att = context.task.begin (); att != context.task.end (); ++att) + { + if (att->second.name () != "uuid" && + att->second.name () != "description" && + att->second.name () != "tags") + { + // Some things don't propagate to the parent task. + if (att->second.name () == "wait" && + task.getStatus () == Task::recurring) + { + // NOP + } + + // Modifying "wait" changes status, but not for recurring parent tasks. + else if (att->second.name () == "wait") + { + if (att->second.value () == "") + { + task.remove (att->first); + task.setStatus (Task::pending); + } + else + { + task.set (att->first, att->second.value ()); + task.setStatus (Task::waiting); + } + } + + // Modifying dependencies requires adding/removing uuids. + else if (att->second.name () == "depends") + { + std::vector deps; + split (deps, att->second.value (), ','); + + std::vector ::iterator i; + for (i = deps.begin (); i != deps.end (); i++) + { + int id = atoi (i->c_str ()); + if (id < 0) + task.removeDependency (-id); + else + task.addDependency (id); + } + } + + // Now the generalized handling. + else if (att->second.value () == "") + task.remove (att->second.name ()); + else + // One of the few places where the compound attribute name is used. + task.set (att->first, att->second.value ()); + + ++changes; + } + } + + return changes; +} + +//////////////////////////////////////////////////////////////////////////////// +int deltaSubstitutions (Task& task) +{ + std::string description = task.get ("description"); + std::vector annotations; + task.getAnnotations (annotations); + + context.subst.apply (description, annotations); + + task.set ("description", description); + task.setAnnotations (annotations); + + return 1; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/main.h b/src/main.h index 170303ff3..ff4495ba1 100644 --- a/src/main.h +++ b/src/main.h @@ -49,7 +49,11 @@ void updateRecurrenceMask (std::vector &, Task&); int getDueState (const std::string&); bool nag (Task&); -// command.cpp +// helpers.cpp +std::string getFullDescription (Task&, const std::string&); +std::string getDueDate (Task&, const std::string&); +std::string onProjectChange (Task&, bool scope = true); +std::string onProjectChange (Task&, Task&); int deltaAppend (Task&); int deltaPrepend (Task&); int deltaDescription (Task&); @@ -57,17 +61,6 @@ int deltaTags (Task&); int deltaAttributes (Task&); int deltaSubstitutions (Task&); -// report.cpp -std::string getFullDescription (Task&, const std::string&); -std::string getDueDate (Task&, const std::string&); -std::string onProjectChange (Task&, bool scope = true); -std::string onProjectChange (Task&, Task&); - -// burndown.cpp -int handleReportBurndownDaily (std::string&); -int handleReportBurndownWeekly (std::string&); -int handleReportBurndownMonthly (std::string&); - // rules.cpp void initializeColorRules (); void autoColorize (Task&, Color&);