diff --git a/src/Cmd.cpp b/src/Cmd.cpp index 7fb56442c..b09639610 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -153,7 +153,6 @@ void Cmd::load () commands.push_back ("duplicate"); commands.push_back ("import"); commands.push_back ("log"); - commands.push_back ("prepend"); commands.push_back ("start"); commands.push_back ("stop"); commands.push_back ("summary"); @@ -256,7 +255,6 @@ bool Cmd::isWriteCommand () command == "duplicate" || command == "import" || command == "log" || - command == "prepend" || command == "pull" || command == "start" || command == "stop" || diff --git a/src/Context.cpp b/src/Context.cpp index 3227bae9c..1b590cd34 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -262,7 +262,6 @@ int Context::dispatch (std::string &out) else if (cmd.command == "add") { rc = handleAdd (out); } else if (cmd.command == "log") { rc = handleLog (out); } else if (cmd.command == "append") { rc = handleAppend (out); } - else if (cmd.command == "prepend") { rc = handlePrepend (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); } diff --git a/src/command.cpp b/src/command.cpp index 67edb04d4..333e18266 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -1164,90 +1164,6 @@ int handleAppend (std::string& outs) return rc; } -//////////////////////////////////////////////////////////////////////////////// -int handlePrepend (std::string& outs) -{ - if (!context.task.has ("description")) - throw std::string ("Additional text must be provided."); - - int rc = 0; - int count = 0; - std::stringstream out; - - std::vector tasks; - context.tdb.lock (context.config.getBoolean ("locking")); - Filter filter; - context.tdb.loadPending (tasks, filter); - - // Filter sequence. - std::vector all = tasks; - 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) - { - foreach (other, all) - { - if (other->id == task->id || // Self - (task->has ("parent") && - task->get ("parent") == other->get ("parent")) || // Sibling - other->get ("uuid") == task->get ("parent")) // Parent - { - Task before (*other); - - // A non-zero value forces a file write. - int changes = 0; - - // Apply other deltas. - changes += deltaPrepend (*other); - changes += deltaTags (*other); - changes += deltaAttributes (*other); - changes += deltaSubstitutions (*other); - - if (taskDiff (before, *other)) - { - // Only allow valid tasks. - other->validate (); - - if (changes && permission.confirmed (before, taskDifferences (before, *other) + "Are you sure?")) - { - context.tdb.update (*other); - - if (context.config.getBoolean ("echo.command")) - out << "Prepended '" - << context.task.get ("description") - << "' to task " - << other->id - << ".\n"; - - if (before.get ("project") != other->get ("project")) - context.footnote (onProjectChange (before, *other)); - - ++count; - } - } - } - } - } - - context.tdb.commit (); - context.tdb.unlock (); - - if (context.config.getBoolean ("echo.command")) - out << "Prepended " << count << " task" << (count == 1 ? ".\n" : "s.\n"); - - outs = out.str (); - return rc; -} - //////////////////////////////////////////////////////////////////////////////// int handleDuplicate (std::string& outs) { diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index c494ff92d..544edb90a 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -17,6 +17,7 @@ set (commands_SRCS Command.cpp Command.h CmdInfo.cpp CmdInfo.h CmdInstall.cpp CmdInstall.h CmdLogo.cpp CmdLogo.h + CmdPrepend.cpp CmdPrepend.h CmdProjects.cpp CmdProjects.h CmdShell.cpp CmdShell.h CmdShow.cpp CmdShow.h diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index 301b75b14..504fb3c45 100644 --- a/src/commands/CmdHelp.cpp +++ b/src/commands/CmdHelp.cpp @@ -100,10 +100,6 @@ int CmdHelp::execute (const std::string& command_line, std::string& output) view.set (row, 1, "task append ID [tags] [attrs] desc..."); view.set (row, 2, "Appends more description to an existing task."); - row = view.addRow (); - view.set (row, 1, "task prepend ID [tags] [attrs] desc..."); - view.set (row, 2, "Prepends more description to an existing task."); - row = view.addRow (); view.set (row, 1, "task annotate ID desc..."); view.set (row, 2, "Adds an annotation to an existing task."); diff --git a/src/commands/CmdPrepend.cpp b/src/commands/CmdPrepend.cpp new file mode 100644 index 000000000..b16575c37 --- /dev/null +++ b/src/commands/CmdPrepend.cpp @@ -0,0 +1,132 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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; + +//////////////////////////////////////////////////////////////////////////////// +CmdPrepend::CmdPrepend () +{ + _keyword = "prepend"; + _usage = "task prepend [tags] [attrs] desc..."; + _description = "Prepends more description to an existing task."; + _read_only = false; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdPrepend::execute (const std::string& command_line, std::string& output) +{ + if (!context.task.has ("description")) + throw std::string ("Additional text must be provided."); + + int rc = 0; + int count = 0; + std::stringstream out; + + std::vector tasks; + context.tdb.lock (context.config.getBoolean ("locking")); + Filter filter; + context.tdb.loadPending (tasks, filter); + + // Filter sequence. + std::vector all = tasks; + 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) + { + std::vector ::iterator other; + for (other = all.begin (); other != all.end (); ++other) + { + if (other->id == task->id || // Self + (task->has ("parent") && + task->get ("parent") == other->get ("parent")) || // Sibling + other->get ("uuid") == task->get ("parent")) // Parent + { + Task before (*other); + + // A non-zero value forces a file write. + int changes = 0; + + // Apply other deltas. + changes += deltaPrepend (*other); + changes += deltaTags (*other); + changes += deltaAttributes (*other); + changes += deltaSubstitutions (*other); + + if (taskDiff (before, *other)) + { + // Only allow valid tasks. + other->validate (); + + if (changes && permission.confirmed (before, taskDifferences (before, *other) + "Are you sure?")) + { + context.tdb.update (*other); + + if (context.config.getBoolean ("echo.command")) + out << "Prepended '" + << context.task.get ("description") + << "' to task " + << other->id + << ".\n"; + + if (before.get ("project") != other->get ("project")) + context.footnote (onProjectChange (before, *other)); + + ++count; + } + } + } + } + } + + context.tdb.commit (); + context.tdb.unlock (); + + if (context.config.getBoolean ("echo.command")) + out << "Prepended " << count << " task" << (count == 1 ? ".\n" : "s.\n"); + + output = out.str (); + return rc; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdPrepend.h b/src/commands/CmdPrepend.h new file mode 100644 index 000000000..8ef556dfe --- /dev/null +++ b/src/commands/CmdPrepend.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_CMDPREPEND +#define INCLUDED_CMDPREPEND +#define L10N // Localization complete. + +#include +#include + +class CmdPrepend : public Command +{ +public: + CmdPrepend (); + int execute (const std::string&, std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index 070e36e45..a4b662e7c 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -70,6 +71,7 @@ void Command::factory (std::map & all) c = new CmdInfo (); all[c->keyword ()] = c; c = new CmdInstall (); all[c->keyword ()] = c; c = new CmdLogo (); all[c->keyword ()] = c; + c = new CmdPrepend (); all[c->keyword ()] = c; c = new CmdProjects (); all[c->keyword ()] = c; c = new CmdShell (); all[c->keyword ()] = c; c = new CmdShow (); all[c->keyword ()] = c; diff --git a/src/main.h b/src/main.h index d3e094692..41b7badc4 100644 --- a/src/main.h +++ b/src/main.h @@ -53,7 +53,6 @@ bool nag (Task&); int handleAdd (std::string&); int handleLog (std::string&); int handleAppend (std::string&); -int handlePrepend (std::string&); int handleDone (std::string&); int handleModify (std::string&); int handleCompletionConfig (std::string&);