Command - undo

- Migrated handleUndo to CmdUndo.
This commit is contained in:
Paul Beckingham 2011-05-30 13:38:45 -04:00
parent 4c47748dd7
commit 2fb743992f
9 changed files with 100 additions and 19 deletions

View file

@ -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;

View file

@ -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); }

View file

@ -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&)
{

View file

@ -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)

View file

@ -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.");

54
src/commands/CmdUndo.cpp Normal file
View file

@ -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 <Context.h>
#include <CmdUndo.h>
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;
}
////////////////////////////////////////////////////////////////////////////////

42
src/commands/CmdUndo.h Normal file
View file

@ -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 <string>
#include <Command.h>
class CmdUndo : public Command
{
public:
CmdUndo ();
int execute (const std::string&, std::string&);
};
#endif
////////////////////////////////////////////////////////////////////////////////

View file

@ -63,6 +63,7 @@
#include <CmdSummary.h>
#include <CmdTags.h>
#include <CmdTip.h>
#include <CmdUndo.h>
#include <CmdUrgency.h>
#include <CmdVersion.h>
#include <Context.h>
@ -118,6 +119,7 @@ void Command::factory (std::map <std::string, Command*>& 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;

View file

@ -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&);