mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Refactoring
- Combined the remains of command.cpp and report.cpp into helpers.cpp.
This commit is contained in:
parent
a2da93b681
commit
6f17e80461
4 changed files with 149 additions and 191 deletions
|
@ -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
|
||||
|
|
176
src/command.cpp
176
src/command.cpp
|
@ -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 <text.h>
|
||||
#include <Context.h>
|
||||
|
||||
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 <std::string> tags;
|
||||
context.task.getTags (tags);
|
||||
std::vector <std::string>::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 <std::string, Att>::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 <std::string> deps;
|
||||
split (deps, att->second.value (), ',');
|
||||
|
||||
std::vector <std::string>::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 <Att> annotations;
|
||||
task.getAnnotations (annotations);
|
||||
|
||||
context.subst.apply (description, annotations);
|
||||
|
||||
task.set ("description", description);
|
||||
task.setAnnotations (annotations);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// vim: ts=2 sw=2 et
|
|
@ -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 <std::string> tags;
|
||||
context.task.getTags (tags);
|
||||
std::vector <std::string>::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 <std::string, Att>::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 <std::string> deps;
|
||||
split (deps, att->second.value (), ',');
|
||||
|
||||
std::vector <std::string>::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 <Att> annotations;
|
||||
task.getAnnotations (annotations);
|
||||
|
||||
context.subst.apply (description, annotations);
|
||||
|
||||
task.set ("description", description);
|
||||
task.setAnnotations (annotations);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
17
src/main.h
17
src/main.h
|
@ -49,7 +49,11 @@ void updateRecurrenceMask (std::vector <Task>&, 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&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue