From 2fb743992fe67430b4c547738b93438eef42d5a2 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 30 May 2011 13:38:45 -0400 Subject: [PATCH] Command - undo - Migrated handleUndo to CmdUndo. --- src/Cmd.cpp | 4 +-- src/Context.cpp | 1 - src/command.cpp | 10 ------- src/commands/CMakeLists.txt | 1 + src/commands/CmdHelp.cpp | 4 --- src/commands/CmdUndo.cpp | 54 +++++++++++++++++++++++++++++++++++++ src/commands/CmdUndo.h | 42 +++++++++++++++++++++++++++++ src/commands/Command.cpp | 2 ++ src/main.h | 1 - 9 files changed, 100 insertions(+), 19 deletions(-) create mode 100644 src/commands/CmdUndo.cpp create mode 100644 src/commands/CmdUndo.h diff --git a/src/Cmd.cpp b/src/Cmd.cpp index e068fbe76..f5dc1d996 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -132,7 +132,6 @@ void Cmd::load () commands.push_back ("delete"); commands.push_back ("done"); commands.push_back ("timesheet"); - commands.push_back ("undo"); commands.push_back ("merge"); commands.push_back ("push"); commands.push_back ("pull"); @@ -207,8 +206,7 @@ bool Cmd::isWriteCommand () if (command == "merge" || command == "delete" || command == "done" || - command == "pull" || - command == "undo") + command == "pull") return true; return false; diff --git a/src/Context.cpp b/src/Context.cpp index 16534f60f..ca1ffa7f1 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -252,7 +252,6 @@ int Context::dispatch (std::string &out) if (cmd.command == "timesheet") { rc = handleReportTimesheet (out); } else if (cmd.command == "done") { rc = handleDone (out); } else if (cmd.command == "delete") { rc = handleDelete (out); } - else if (cmd.command == "undo") { handleUndo ( ); } else if (cmd.command == "merge") { tdb.gc (); handleMerge (out); } else if (cmd.command == "push") { handlePush (out); } diff --git a/src/command.cpp b/src/command.cpp index 8948d3b5e..1dddcd9a6 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -51,16 +51,6 @@ extern Context context; -//////////////////////////////////////////////////////////////////////////////// -void handleUndo () -{ - context.disallowModification (); - - context.tdb.lock (context.config.getBoolean ("locking")); - context.tdb.undo (); - context.tdb.unlock (); -} - //////////////////////////////////////////////////////////////////////////////// void handleMerge (std::string&) { diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index 65659eb6d..2b686c9f5 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -41,6 +41,7 @@ set (commands_SRCS Command.cpp Command.h CmdSummary.cpp CmdSummary.h CmdTags.cpp CmdTags.h CmdTip.cpp CmdTip.h + CmdUndo.cpp CmdUndo.h CmdUrgency.cpp CmdUrgency.h CmdVersion.cpp CmdVersion.h) diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index 95b3e6390..dc920be43 100644 --- a/src/commands/CmdHelp.cpp +++ b/src/commands/CmdHelp.cpp @@ -103,10 +103,6 @@ int CmdHelp::execute (const std::string&, std::string& output) view.set (row, 1, "task ID"); view.set (row, 2, "Specifying an ID without a command invokes the 'info' command."); - row = view.addRow (); - view.set (row, 1, "task undo"); - view.set (row, 2, "Reverts the most recent action."); - row = view.addRow (); view.set (row, 1, "task delete ID"); view.set (row, 2, "Deletes the specified task."); diff --git a/src/commands/CmdUndo.cpp b/src/commands/CmdUndo.cpp new file mode 100644 index 000000000..66f6d7031 --- /dev/null +++ b/src/commands/CmdUndo.cpp @@ -0,0 +1,54 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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; + +//////////////////////////////////////////////////////////////////////////////// +CmdUndo::CmdUndo () +{ + _keyword = "undo"; + _usage = "task undo"; + _description = "Reverts the most recent change to a task."; + _read_only = false; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdUndo::execute (const std::string&, std::string& output) +{ + context.disallowModification (); + + context.tdb.lock (context.config.getBoolean ("locking")); + context.tdb.undo (); + context.tdb.unlock (); + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdUndo.h b/src/commands/CmdUndo.h new file mode 100644 index 000000000..471801622 --- /dev/null +++ b/src/commands/CmdUndo.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_CMDUNDO +#define INCLUDED_CMDUNDO +#define L10N // Localization complete. + +#include +#include + +class CmdUndo : public Command +{ +public: + CmdUndo (); + int execute (const std::string&, std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index 895f15ff5..30ef297ca 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -63,6 +63,7 @@ #include #include #include +#include #include #include #include @@ -118,6 +119,7 @@ void Command::factory (std::map & all) c = new CmdSummary (); all[c->keyword ()] = c; c = new CmdTags (); all[c->keyword ()] = c; c = new CmdTip (); all[c->keyword ()] = c; + c = new CmdUndo (); all[c->keyword ()] = c; c = new CmdUrgency (); all[c->keyword ()] = c; c = new CmdVersion (); all[c->keyword ()] = c; c = new CmdZshCommands (); all[c->keyword ()] = c; diff --git a/src/main.h b/src/main.h index 014c68828..3a0e06913 100644 --- a/src/main.h +++ b/src/main.h @@ -53,7 +53,6 @@ bool nag (Task&); int handleDone (std::string&); int handleModify (std::string&); int handleDelete (std::string&); -void handleUndo (); void handleMerge (std::string&); void handlePush (std::string&); void handlePull (std::string&);