diff --git a/src/Cmd.cpp b/src/Cmd.cpp index 0f7b5b22e..3a58ef882 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -134,7 +134,6 @@ void Cmd::load () commands.push_back ("export.csv"); commands.push_back ("export.ical"); commands.push_back ("export.yaml"); - commands.push_back ("annotate"); commands.push_back ("denotate"); commands.push_back ("calendar"); commands.push_back ("colors"); @@ -229,7 +228,6 @@ bool Cmd::isReadOnlyCommand () bool Cmd::isWriteCommand () { if (command == "merge" || - command == "annotate" || command == "denotate" || command == "delete" || command == "done" || diff --git a/src/Context.cpp b/src/Context.cpp index 424f77537..6571880e8 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -252,7 +252,6 @@ int Context::dispatch (std::string &out) else if (cmd.command == "summary") { rc = handleReportSummary (out); } else if (cmd.command == "calendar") { rc = handleReportCalendar (out); } else if (cmd.command == "timesheet") { rc = handleReportTimesheet (out); } - else if (cmd.command == "annotate") { rc = handleAnnotate (out); } else if (cmd.command == "denotate") { rc = handleDenotate (out); } else if (cmd.command == "done") { rc = handleDone (out); } else if (cmd.command == "delete") { rc = handleDelete (out); } diff --git a/src/command.cpp b/src/command.cpp index 5f62078c5..8f07a118d 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -1207,67 +1207,6 @@ int handleColor (std::string& outs) return rc; } -//////////////////////////////////////////////////////////////////////////////// -int handleAnnotate (std::string& outs) -{ - int rc = 0; - - if (!context.task.has ("description")) - throw std::string ("Cannot apply a blank annotation."); - - if (context.sequence.size () == 0) - throw std::string ("ID needed to apply an annotation."); - - std::stringstream out; - - std::vector tasks; - context.tdb.lock (context.config.getBoolean ("locking")); - Filter filter; - context.tdb.loadPending (tasks, filter); - - // Filter sequence. - context.filter.applySequence (tasks, context.sequence); - if (tasks.size () == 0) - { - std::cout << "No tasks specified.\n"; - return 1; - } - - Permission permission; - if (context.sequence.size () > (size_t) context.config.getInteger ("bulk")) - permission.bigSequence (); - - foreach (task, tasks) - { - Task before (*task); - task->addAnnotation (context.task.get ("description")); - - if (taskDiff (before, *task)) - { - // Only allow valid tasks. - task->validate (); - - if (permission.confirmed (before, taskDifferences (before, *task) + "Proceed with change?")) - { - context.tdb.update (*task); - - if (context.config.getBoolean ("echo.command")) - out << "Annotated " - << task->id - << " with '" - << context.task.get ("description") - << "'.\n"; - } - } - } - - context.tdb.commit (); - context.tdb.unlock (); - - outs = out.str (); - return rc; -} - //////////////////////////////////////////////////////////////////////////////// int handleDenotate (std::string& outs) { diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index 79737161b..30d4fdeef 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -7,6 +7,7 @@ include_directories (${CMAKE_SOURCE_DIR} set (commands_SRCS Command.cpp Command.h CmdAdd.cpp CmdAdd.h + CmdAnnotate.cpp CmdAnnotate.h CmdAppend.cpp CmdAppend.h CmdBurndown.cpp CmdBurndown.h CmdCommands.cpp CmdCommands.h diff --git a/src/commands/CmdAnnotate.cpp b/src/commands/CmdAnnotate.cpp new file mode 100644 index 000000000..018f09353 --- /dev/null +++ b/src/commands/CmdAnnotate.cpp @@ -0,0 +1,108 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 +#include +#include +#include + +extern Context context; + +//////////////////////////////////////////////////////////////////////////////// +CmdAnnotate::CmdAnnotate () +{ + _keyword = "annotate"; + _usage = "task annotate ID desc..."; + _description = "Adds an annotation to an existing task."; + _read_only = false; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdAnnotate::execute (const std::string&, std::string& output) +{ + int rc = 0; + + if (!context.task.has ("description")) + throw std::string ("Cannot apply a blank annotation."); + + if (context.sequence.size () == 0) + throw std::string ("ID needed to apply an annotation."); + + std::stringstream out; + + std::vector tasks; + context.tdb.lock (context.config.getBoolean ("locking")); + Filter filter; + context.tdb.loadPending (tasks, filter); + + // Filter sequence. + context.filter.applySequence (tasks, context.sequence); + if (tasks.size () == 0) + { + context.footnote ("No tasks specified."); + return 1; + } + + Permission permission; + if (context.sequence.size () > (size_t) context.config.getInteger ("bulk")) + permission.bigSequence (); + + std::vector ::iterator task; + for (task = tasks.begin (); task != tasks.end (); ++task) + { + Task before (*task); + task->addAnnotation (context.task.get ("description")); + + if (taskDiff (before, *task)) + { + // Only allow valid tasks. + task->validate (); + + if (permission.confirmed (before, taskDifferences (before, *task) + "Proceed with change?")) + { + context.tdb.update (*task); + + if (context.config.getBoolean ("echo.command")) + out << "Annotated " + << task->id + << " with '" + << context.task.get ("description") + << "'.\n"; + } + } + } + + context.tdb.commit (); + context.tdb.unlock (); + + output = out.str (); + return rc; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdAnnotate.h b/src/commands/CmdAnnotate.h new file mode 100644 index 000000000..8a820bba5 --- /dev/null +++ b/src/commands/CmdAnnotate.h @@ -0,0 +1,42 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 +// +//////////////////////////////////////////////////////////////////////////////// +#ifndef INCLUDED_CMDANNOTATE +#define INCLUDED_CMDANNOTATE +#define L10N // Localization complete. + +#include +#include + +class CmdAnnotate : public Command +{ +public: + CmdAnnotate (); + int execute (const std::string&, std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index 24a6b1764..a07462b1c 100644 --- a/src/commands/CmdHelp.cpp +++ b/src/commands/CmdHelp.cpp @@ -88,10 +88,6 @@ int CmdHelp::execute (const std::string&, std::string& output) } /* - row = view.addRow (); - view.set (row, 1, "task annotate ID desc..."); - view.set (row, 2, "Adds an annotation to an existing task."); - row = view.addRow (); view.set (row, 1, "task denotate ID desc..."); view.set (row, 2, "Deletes an annotation of an existing task."); diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index e9fd13d3a..7eca70fc4 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,7 @@ void Command::factory (std::map & all) Command* c; c = new CmdAdd (); all[c->keyword ()] = c; + c = new CmdAnnotate (); all[c->keyword ()] = c; c = new CmdAppend (); all[c->keyword ()] = c; c = new CmdBurndownDaily (); all[c->keyword ()] = c; c = new CmdBurndownMonthly (); all[c->keyword ()] = c; diff --git a/src/main.h b/src/main.h index 874168135..16b4e12ba 100644 --- a/src/main.h +++ b/src/main.h @@ -59,7 +59,6 @@ int handleDelete (std::string&); int handleStart (std::string&); int handleStop (std::string&); int handleColor (std::string&); -int handleAnnotate (std::string&); int handleDenotate (std::string&); int handleDuplicate (std::string&); void handleUndo ();