diff --git a/src/Cmd.cpp b/src/Cmd.cpp index 3a58ef882..dccbdc4f7 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 ("denotate"); commands.push_back ("calendar"); commands.push_back ("colors"); commands.push_back ("config"); @@ -228,7 +227,6 @@ bool Cmd::isReadOnlyCommand () bool Cmd::isWriteCommand () { if (command == "merge" || - command == "denotate" || command == "delete" || command == "done" || command == "duplicate" || diff --git a/src/Context.cpp b/src/Context.cpp index 6571880e8..cb7c5e10e 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 == "denotate") { rc = handleDenotate (out); } else if (cmd.command == "done") { rc = handleDone (out); } else if (cmd.command == "delete") { rc = handleDelete (out); } else if (cmd.command == "start") { rc = handleStart (out); } diff --git a/src/command.cpp b/src/command.cpp index 8f07a118d..82c52c0f9 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -1207,105 +1207,6 @@ int handleColor (std::string& outs) return rc; } -//////////////////////////////////////////////////////////////////////////////// -int handleDenotate (std::string& outs) -{ - int rc = 0; - - if (!context.task.has ("description")) - throw std::string ("Description needed to delete an annotation."); - - if (context.sequence.size () == 0) - throw std::string ("A task ID is needed to delete an annotation."); - - bool sensitive = context.config.getBoolean ("search.case.sensitive"); - - std::stringstream out; - - std::vector tasks; - context.tdb.lock (context.config.getBoolean ("locking")); - Filter filter; - context.tdb.loadPending (tasks, filter); - - 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); - std::string desc = context.task.get ("description"); - std::vector annotations; - task->getAnnotations (annotations); - - if (annotations.size () == 0) - throw std::string ("The specified task has no annotations that can be deleted."); - - std::vector ::iterator i; - std::string anno; - bool match = false;; - for (i = annotations.begin (); i != annotations.end (); ++i) - { - anno = i->value (); - if (anno == desc) - { - match = true; - annotations.erase (i); - task->setAnnotations (annotations); - break; - } - } - if (!match) - { - for (i = annotations.begin (); i != annotations.end (); ++i) - { - anno = i->value (); - std::string::size_type loc = find (anno, desc, sensitive); - - if (loc != std::string::npos) - { - match = true; - annotations.erase (i); - task->setAnnotations (annotations); - break; - } - } - } - - 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 << "Found annotation '" - << anno - << "' and deleted it.\n"; - } - } - else - out << "Did not find any matching annotation to be deleted for '" - << desc - << "'.\n"; - } - - context.tdb.commit (); - context.tdb.unlock (); - - outs = out.str (); - return rc; -} - //////////////////////////////////////////////////////////////////////////////// int deltaAppend (Task& task) { diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index 30d4fdeef..6bffe024b 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -13,6 +13,7 @@ set (commands_SRCS Command.cpp Command.h CmdCommands.cpp CmdCommands.h CmdCount.cpp CmdCount.h CmdCustom.cpp CmdCustom.h + CmdDenotate.cpp CmdDenotate.h CmdDiagnostics.cpp CmdDiagnostics.h CmdEdit.cpp CmdEdit.h CmdExec.cpp CmdExec.h diff --git a/src/commands/CmdDenotate.cpp b/src/commands/CmdDenotate.cpp new file mode 100644 index 000000000..0e48546cf --- /dev/null +++ b/src/commands/CmdDenotate.cpp @@ -0,0 +1,147 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 +#include + +extern Context context; + +//////////////////////////////////////////////////////////////////////////////// +CmdDenotate::CmdDenotate () +{ + _keyword = "denotate"; + _usage = "task denotate ID desc..."; + _description = "Deletes an annotation from an existing task."; + _read_only = false; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdDenotate::execute (const std::string&, std::string& output) +{ + int rc = 0; + + if (!context.task.has ("description")) + throw std::string ("Description needed to delete an annotation."); + + if (context.sequence.size () == 0) + throw std::string ("A task ID is needed to delete an annotation."); + + bool sensitive = context.config.getBoolean ("search.case.sensitive"); + + std::stringstream out; + + std::vector tasks; + context.tdb.lock (context.config.getBoolean ("locking")); + Filter filter; + context.tdb.loadPending (tasks, filter); + + 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); + std::string desc = context.task.get ("description"); + std::vector annotations; + task->getAnnotations (annotations); + + if (annotations.size () == 0) + throw std::string ("The specified task has no annotations that can be deleted."); + + std::vector ::iterator i; + std::string anno; + bool match = false;; + for (i = annotations.begin (); i != annotations.end (); ++i) + { + anno = i->value (); + if (anno == desc) + { + match = true; + annotations.erase (i); + task->setAnnotations (annotations); + break; + } + } + if (!match) + { + for (i = annotations.begin (); i != annotations.end (); ++i) + { + anno = i->value (); + std::string::size_type loc = find (anno, desc, sensitive); + + if (loc != std::string::npos) + { + match = true; + annotations.erase (i); + task->setAnnotations (annotations); + break; + } + } + } + + 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 << "Found annotation '" + << anno + << "' and deleted it.\n"; + } + } + else + out << "Did not find any matching annotation to be deleted for '" + << desc + << "'.\n"; + } + + context.tdb.commit (); + context.tdb.unlock (); + + output = out.str (); + return rc; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdDenotate.h b/src/commands/CmdDenotate.h new file mode 100644 index 000000000..4a43d4ea5 --- /dev/null +++ b/src/commands/CmdDenotate.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_CMDDENOTATE +#define INCLUDED_CMDDENOTATE +#define L10N // Localization complete. + +#include +#include + +class CmdDenotate : public Command +{ +public: + CmdDenotate (); + int execute (const std::string&, std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index a07462b1c..1fb83f053 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 denotate ID desc..."); - view.set (row, 2, "Deletes an annotation of an existing task."); - row = view.addRow (); view.set (row, 1, "task ID [tags] [attrs] [desc...]"); view.set (row, 2, "Modifies the existing task with provided arguments."); diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index 7eca70fc4..ee59b62ac 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -75,6 +76,7 @@ void Command::factory (std::map & all) c = new CmdCompletionTags (); all[c->keyword ()] = c; c = new CmdCompletionVersion (); all[c->keyword ()] = c; c = new CmdCount (); all[c->keyword ()] = c; + c = new CmdDenotate (); all[c->keyword ()] = c; c = new CmdDiagnostics (); all[c->keyword ()] = c; c = new CmdEdit (); all[c->keyword ()] = c; c = new CmdExec (); all[c->keyword ()] = c; diff --git a/src/main.h b/src/main.h index 16b4e12ba..b3786ddb0 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 handleDenotate (std::string&); int handleDuplicate (std::string&); void handleUndo (); void handleMerge (std::string&);