mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Code Reorganization - Silver Bullet
- Broke out Silver Bullet feature into separate edit.cpp file. Because it is big.
This commit is contained in:
parent
da8c3c1a16
commit
ee06280808
5 changed files with 165 additions and 124 deletions
|
@ -1,2 +1,2 @@
|
|||
bin_PROGRAMS = task
|
||||
task_SOURCES = Config.cpp Date.cpp T.cpp TDB.cpp Table.cpp Grid.cpp Timer.cpp color.cpp parse.cpp task.cpp command.cpp report.cpp util.cpp text.cpp rules.cpp import.cpp Config.h Date.h T.h TDB.h Table.h Grid.h Timer.h color.h task.h
|
||||
task_SOURCES = Config.cpp Date.cpp T.cpp TDB.cpp Table.cpp Grid.cpp Timer.cpp color.cpp parse.cpp task.cpp command.cpp edit.cpp report.cpp util.cpp text.cpp rules.cpp import.cpp Config.h Date.h T.h TDB.h Table.h Grid.h Timer.h color.h task.h
|
||||
|
|
|
@ -46,8 +46,8 @@ PROGRAMS = $(bin_PROGRAMS)
|
|||
am_task_OBJECTS = Config.$(OBJEXT) Date.$(OBJEXT) T.$(OBJEXT) \
|
||||
TDB.$(OBJEXT) Table.$(OBJEXT) Grid.$(OBJEXT) Timer.$(OBJEXT) \
|
||||
color.$(OBJEXT) parse.$(OBJEXT) task.$(OBJEXT) \
|
||||
command.$(OBJEXT) report.$(OBJEXT) util.$(OBJEXT) \
|
||||
text.$(OBJEXT) rules.$(OBJEXT) import.$(OBJEXT)
|
||||
command.$(OBJEXT) edit.$(OBJEXT) report.$(OBJEXT) \
|
||||
util.$(OBJEXT) text.$(OBJEXT) rules.$(OBJEXT) import.$(OBJEXT)
|
||||
task_OBJECTS = $(am_task_OBJECTS)
|
||||
task_LDADD = $(LDADD)
|
||||
DEFAULT_INCLUDES = -I. -I$(top_builddir)@am__isrc@
|
||||
|
@ -155,7 +155,7 @@ sysconfdir = @sysconfdir@
|
|||
target_alias = @target_alias@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
task_SOURCES = Config.cpp Date.cpp T.cpp TDB.cpp Table.cpp Grid.cpp Timer.cpp color.cpp parse.cpp task.cpp command.cpp report.cpp util.cpp text.cpp rules.cpp import.cpp Config.h Date.h T.h TDB.h Table.h Grid.h Timer.h color.h task.h
|
||||
task_SOURCES = Config.cpp Date.cpp T.cpp TDB.cpp Table.cpp Grid.cpp Timer.cpp color.cpp parse.cpp task.cpp command.cpp edit.cpp report.cpp util.cpp text.cpp rules.cpp import.cpp Config.h Date.h T.h TDB.h Table.h Grid.h Timer.h color.h task.h
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
|
@ -231,6 +231,7 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Timer.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/color.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/command.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/edit.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/import.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parse.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/report.Po@am__quote@
|
||||
|
|
119
src/command.cpp
119
src/command.cpp
|
@ -28,19 +28,12 @@
|
|||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <pwd.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "Config.h"
|
||||
#include "Date.h"
|
||||
#include "Table.h"
|
||||
#include "color.h"
|
||||
#include "TDB.h"
|
||||
#include "T.h"
|
||||
#include "task.h"
|
||||
|
||||
#ifdef HAVE_LIBNCURSES
|
||||
|
@ -860,118 +853,6 @@ std::string handleDuplicate (TDB& tdb, T& task, Config& conf)
|
|||
return out.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static const char* leftDelim = "<<";
|
||||
static const char* rightDelim = ">>";
|
||||
static std::string findValue (const std::string& text, const std::string& name)
|
||||
{
|
||||
// Look for /^\s+name:\s+<<(.*)>>/
|
||||
// Extract
|
||||
// Trim
|
||||
// Join
|
||||
return "";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Introducing the Silver Bullet. This feature is the catch-all fixative for
|
||||
// various other ills. This is like opening up the hood and going in with a
|
||||
// wrench. To be used sparingly.
|
||||
std::string handleEdit (TDB& tdb, T& task, Config& conf)
|
||||
{
|
||||
std::stringstream out;
|
||||
std::vector <T> all;
|
||||
tdb.pendingT (all);
|
||||
|
||||
filterSequence (all, task);
|
||||
foreach (seq, all)
|
||||
{
|
||||
// Check for file permissions.
|
||||
std::string dataLocation = expandPath (conf.get ("data.location"));
|
||||
if (access (dataLocation.c_str (), X_OK))
|
||||
throw std::string ("Your data.location directory is not writable.");
|
||||
|
||||
// Create a temp file name in data.location.
|
||||
std::stringstream pattern;
|
||||
pattern << dataLocation << "/task." << seq->getId () << ".XXXXXX";
|
||||
char cpattern [PATH_MAX];
|
||||
strcpy (cpattern, pattern.str ().c_str ());
|
||||
char* file = mktemp (cpattern);
|
||||
|
||||
// Format the contents, T -> text.
|
||||
std::stringstream before;
|
||||
before << "# The 'task edit <id>' command allows you to modify all aspects of a task" << std::endl
|
||||
<< "# using a text editor. What is shown below is a representation of the" << std::endl
|
||||
<< "# task in all it's detail. Modify what you wish, and if you save and" << std::endl
|
||||
<< "# quit your editor, task will read this file and try to make sense of" << std::endl
|
||||
<< "# what changed, and apply those changes. If you quit your editor without" << std::endl
|
||||
<< "# saving or making any modifications, task will do nothing." << std::endl
|
||||
<< "#" << std::endl
|
||||
<< "# Lines that begin with # are comments, and will be ignored by task." << std::endl
|
||||
|
||||
<< "# Edit only the items within the marks "
|
||||
<< leftDelim << " " << rightDelim << "."
|
||||
<< "All other edits will be ignored." << std::endl
|
||||
|
||||
<< "# Externally Visible" << std::endl
|
||||
<< " ID: " << seq->getId () << std::endl
|
||||
<< " Status: " << leftDelim << seq->getStatus () << rightDelim << std::endl
|
||||
<< " Project: " << leftDelim << seq->getAttribute ("project") << rightDelim << std::endl
|
||||
<< " Priority: " << leftDelim << seq->getAttribute ("priority") << rightDelim << std::endl;
|
||||
|
||||
std::vector <std::string> tags;
|
||||
seq->getTags (tags);
|
||||
std::string allTags;
|
||||
join (allTags, " ", tags);
|
||||
before << " Tags: " << leftDelim << allTags << rightDelim << std::endl;
|
||||
|
||||
std::map <time_t, std::string> annotations;
|
||||
seq->getAnnotations (annotations);
|
||||
foreach (anno, annotations)
|
||||
before << " Annotation: " << leftDelim << anno->first << " " << anno->second << rightDelim << std::endl;
|
||||
|
||||
before << " Description: " << leftDelim << seq->getDescription () << rightDelim << std::endl
|
||||
|
||||
<< "# Internals" << std::endl
|
||||
<< " Start: " << leftDelim << seq->getAttribute ("start") << rightDelim << std::endl
|
||||
<< " End: " << leftDelim << seq->getAttribute ("end") << rightDelim << std::endl
|
||||
<< " Due: " << leftDelim << seq->getAttribute ("due") << rightDelim << std::endl
|
||||
<< " Recur: " << leftDelim << seq->getAttribute ("recur") << rightDelim << std::endl
|
||||
<< " Mask: " << leftDelim << seq->getAttribute ("mask") << rightDelim << std::endl
|
||||
<< " iMask: " << leftDelim << seq->getAttribute ("imask") << rightDelim << std::endl;
|
||||
|
||||
// Write to file.
|
||||
spit (file, before.str ());
|
||||
|
||||
// Determine correct editor: .taskrc:editor > $VISUAL > $EDITOR > vi
|
||||
std::string editor = conf.get ("editor", "");
|
||||
if (editor == "") editor = getenv ("VISUAL");
|
||||
if (editor == "") editor = getenv ("EDITOR");
|
||||
if (editor == "") editor = "vi";
|
||||
|
||||
// Launch the editor.
|
||||
editor += " ";
|
||||
editor += file;
|
||||
system (editor.c_str ());
|
||||
|
||||
// Slurp file.
|
||||
std::string after;
|
||||
slurp (file, after, true);
|
||||
|
||||
// Update seq based on what can be parsed back out of the file.
|
||||
seq->setAttribute ("Project", findValue (after, "Project"));
|
||||
seq->setAttribute ("Priority", findValue (after, "Priority"));
|
||||
seq->setDescription ( findValue (after, "Description"));
|
||||
|
||||
// Modify task.
|
||||
tdb.modifyT (*seq);
|
||||
|
||||
// Cleanup.
|
||||
unlink (file);
|
||||
}
|
||||
|
||||
return out.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string handleColor (Config& conf)
|
||||
{
|
||||
|
|
157
src/edit.cpp
Normal file
157
src/edit.cpp
Normal file
|
@ -0,0 +1,157 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// task - a command line task list manager.
|
||||
//
|
||||
// Copyright 2006 - 2009, Paul Beckingham.
|
||||
// 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 <iostream>
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "task.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static std::string findSimpleValue (const std::string& text, const std::string& name)
|
||||
{
|
||||
// Look for /^\s+name:\s+(.*)$/
|
||||
// Extract
|
||||
// Trim
|
||||
// Join
|
||||
return "";
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static std::string formatTask (T task)
|
||||
{
|
||||
std::stringstream before;
|
||||
before << "# The 'task edit <id>' command allows you to modify all aspects of a task" << std::endl
|
||||
<< "# using a text editor. What is shown below is a representation of the" << std::endl
|
||||
<< "# task in all it's detail. Modify what you wish, and if you save and" << std::endl
|
||||
<< "# quit your editor, task will read this file and try to make sense of" << std::endl
|
||||
<< "# what changed, and apply those changes. If you quit your editor without" << std::endl
|
||||
<< "# saving or making any modifications, task will do nothing." << std::endl
|
||||
<< "#" << std::endl
|
||||
<< "# Lines that begin with # are comments, and will be ignored by task." << std::endl
|
||||
<< "# All other edits will be ignored." << std::endl
|
||||
<< "#" << std::endl
|
||||
<< "# Things you probably want to edit" << std::endl
|
||||
<< " ID: " << task.getId () << std::endl
|
||||
<< " Status: " << task.getStatus () << std::endl
|
||||
<< " Project: " << task.getAttribute ("project") << std::endl
|
||||
<< " Priority: " << task.getAttribute ("priority") << std::endl;
|
||||
|
||||
std::vector <std::string> tags;
|
||||
task.getTags (tags);
|
||||
std::string allTags;
|
||||
join (allTags, " ", tags);
|
||||
before << " Tags: " << allTags << std::endl;
|
||||
|
||||
std::map <time_t, std::string> annotations;
|
||||
task.getAnnotations (annotations);
|
||||
foreach (anno, annotations)
|
||||
before << " Annotation: " << anno->first << " " << anno->second << std::endl;
|
||||
|
||||
before << " Description: " << task.getDescription () << std::endl
|
||||
<< "#" << std::endl
|
||||
<< "# Things you should be very careful about editing" << std::endl
|
||||
<< " Start: " << task.getAttribute ("start") << std::endl
|
||||
<< " End: " << task.getAttribute ("end") << std::endl
|
||||
<< " Due: " << task.getAttribute ("due") << std::endl
|
||||
<< "#" << std::endl
|
||||
<< "# Things you should not edit, but can" << std::endl
|
||||
<< " Recur: " << task.getAttribute ("recur") << std::endl
|
||||
<< " Mask: " << task.getAttribute ("mask") << std::endl
|
||||
<< " iMask: " << task.getAttribute ("imask") << std::endl;
|
||||
|
||||
return before.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
static void parseTask (T& task, const std::string& before, const std::string& after)
|
||||
{
|
||||
task.setAttribute ("Project", findSimpleValue (after, "Project"));
|
||||
task.setAttribute ("Priority", findSimpleValue (after, "Priority"));
|
||||
task.setDescription ( findSimpleValue (after, "Description"));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Introducing the Silver Bullet. This feature is the catch-all fixative for
|
||||
// various other ills. This is like opening up the hood and going in with a
|
||||
// wrench. To be used sparingly.
|
||||
std::string handleEdit (TDB& tdb, T& task, Config& conf)
|
||||
{
|
||||
std::stringstream out;
|
||||
std::vector <T> all;
|
||||
tdb.pendingT (all);
|
||||
|
||||
filterSequence (all, task);
|
||||
foreach (seq, all)
|
||||
{
|
||||
// Check for file permissions.
|
||||
std::string dataLocation = expandPath (conf.get ("data.location"));
|
||||
if (access (dataLocation.c_str (), X_OK))
|
||||
throw std::string ("Your data.location directory is not writable.");
|
||||
|
||||
// Create a temp file name in data.location.
|
||||
std::stringstream pattern;
|
||||
pattern << dataLocation << "/task." << seq->getId () << ".XXXXXX";
|
||||
char cpattern [PATH_MAX];
|
||||
strcpy (cpattern, pattern.str ().c_str ());
|
||||
char* file = mktemp (cpattern);
|
||||
|
||||
// Format the contents, T -> text, write to a file.
|
||||
std::string before = formatTask (*seq);
|
||||
spit (file, before);
|
||||
|
||||
// Determine correct editor: .taskrc:editor > $VISUAL > $EDITOR > vi
|
||||
std::string editor = conf.get ("editor", "");
|
||||
if (editor == "") editor = getenv ("VISUAL");
|
||||
if (editor == "") editor = getenv ("EDITOR");
|
||||
if (editor == "") editor = "vi";
|
||||
|
||||
// Launch the editor.
|
||||
editor += " ";
|
||||
editor += file;
|
||||
system (editor.c_str ());
|
||||
|
||||
// Slurp file.
|
||||
std::string after;
|
||||
slurp (file, after, true);
|
||||
|
||||
// Update seq based on what can be parsed back out of the file.
|
||||
parseTask (*seq, before, after);
|
||||
|
||||
// Modify task.
|
||||
tdb.modifyT (*seq);
|
||||
|
||||
// Cleanup.
|
||||
unlink (file);
|
||||
}
|
||||
|
||||
return out.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
|
@ -90,7 +90,6 @@ std::string handleUndo (TDB&, T&, Config&);
|
|||
std::string handleColor (Config&);
|
||||
std::string handleAnnotate (TDB&, T&, Config&);
|
||||
std::string handleDuplicate (TDB&, T&, Config&);
|
||||
std::string handleEdit (TDB&, T&, Config&);
|
||||
T findT (int, const std::vector <T>&);
|
||||
int deltaAppend (T&, T&);
|
||||
int deltaDescription (T&, T&);
|
||||
|
@ -98,6 +97,9 @@ int deltaTags (T&, T&);
|
|||
int deltaAttributes (T&, T&);
|
||||
int deltaSubstitutions (T&, T&);
|
||||
|
||||
// edit.cpp
|
||||
std::string handleEdit (TDB&, T&, Config&);
|
||||
|
||||
// report.cpp
|
||||
void filterSequence (std::vector<T>&, T&);
|
||||
void filter (std::vector<T>&, T&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue