mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-21 07:43:08 +02:00
Silver Bullet - snapshot
- Project working - Priority working - Tags working - Description working
This commit is contained in:
parent
0c775f7998
commit
c7d0b1c21b
1 changed files with 114 additions and 67 deletions
135
src/edit.cpp
135
src/edit.cpp
|
@ -34,7 +34,7 @@
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
static std::string findSimpleValue (
|
static std::string findValue (
|
||||||
const std::string& text,
|
const std::string& text,
|
||||||
const std::string& name)
|
const std::string& name)
|
||||||
{
|
{
|
||||||
|
@ -48,7 +48,6 @@ static std::string findSimpleValue (
|
||||||
found + name.length (),
|
found + name.length (),
|
||||||
eol - (found + name.length ()));
|
eol - (found + name.length ()));
|
||||||
|
|
||||||
std::cout << "value '" << value << "'" << std::endl;
|
|
||||||
return trim (value, "\t ");
|
return trim (value, "\t ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +56,7 @@ static std::string findSimpleValue (
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
static std::string findSimpleDate (
|
static std::string findDate (
|
||||||
Config& conf,
|
Config& conf,
|
||||||
const std::string& text,
|
const std::string& text,
|
||||||
const std::string& name)
|
const std::string& name)
|
||||||
|
@ -72,7 +71,6 @@ static std::string findSimpleDate (
|
||||||
found + name.length (),
|
found + name.length (),
|
||||||
eol - (found + name.length ()));
|
eol - (found + name.length ()));
|
||||||
|
|
||||||
std::cout << "value '" << value << "'" << std::endl;
|
|
||||||
Date dt (trim (value, "\t "), conf.get ("dateformat", "m/d/Y"));
|
Date dt (trim (value, "\t "), conf.get ("dateformat", "m/d/Y"));
|
||||||
char epoch [16];
|
char epoch [16];
|
||||||
sprintf (epoch, "%d", (int)dt.toEpoch ());
|
sprintf (epoch, "%d", (int)dt.toEpoch ());
|
||||||
|
@ -177,10 +175,8 @@ static std::string formatTask (Config& conf, T task)
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
static void parseTask (Config& conf, T& task, const std::string& after)
|
static void parseTask (Config& conf, T& task, const std::string& after)
|
||||||
{
|
{
|
||||||
std::string value;
|
// project
|
||||||
|
std::string value = findValue (after, "Project:");
|
||||||
// Project
|
|
||||||
value = findSimpleValue (after, "Project:");
|
|
||||||
if (task.getAttribute ("project") != value)
|
if (task.getAttribute ("project") != value)
|
||||||
{
|
{
|
||||||
if (value != "")
|
if (value != "")
|
||||||
|
@ -195,15 +191,18 @@ static void parseTask (Config& conf, T& task, const std::string& after)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Priority
|
// priority
|
||||||
value = findSimpleValue (after, "Priority:");
|
value = findValue (after, "Priority:");
|
||||||
if (task.getAttribute ("priority") != value)
|
if (task.getAttribute ("priority") != value)
|
||||||
{
|
{
|
||||||
if (value != "")
|
if (value != "")
|
||||||
|
{
|
||||||
|
if (validPriority (value))
|
||||||
{
|
{
|
||||||
std::cout << "Priority modified." << std::endl;
|
std::cout << "Priority modified." << std::endl;
|
||||||
task.setAttribute ("priority", value);
|
task.setAttribute ("priority", value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "Priority deleted." << std::endl;
|
std::cout << "Priority deleted." << std::endl;
|
||||||
|
@ -211,15 +210,15 @@ static void parseTask (Config& conf, T& task, const std::string& after)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tags
|
// tags
|
||||||
value = findSimpleValue (after, "tags");
|
value = findValue (after, "Tags:");
|
||||||
std::vector <std::string> tags;
|
std::vector <std::string> tags;
|
||||||
split (tags, value, ' ');
|
split (tags, value, ' ');
|
||||||
task.removeTags ();
|
task.removeTags ();
|
||||||
task.addTags (tags);
|
task.addTags (tags);
|
||||||
|
|
||||||
// description.
|
// description.
|
||||||
value = findSimpleValue (after, "Description: ");
|
value = findValue (after, "Description: ");
|
||||||
if (task.getDescription () != value)
|
if (task.getDescription () != value)
|
||||||
{
|
{
|
||||||
if (value != "")
|
if (value != "")
|
||||||
|
@ -228,60 +227,88 @@ static void parseTask (Config& conf, T& task, const std::string& after)
|
||||||
task.setDescription (value);
|
task.setDescription (value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
std::cout << "Cannot remove description." << std::endl;
|
throw std::string ("Cannot remove description.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// entry
|
// entry
|
||||||
value = findSimpleDate (conf, after, "Created:");
|
/*
|
||||||
if (task.getAttribute ("entry") != value)
|
value = findDate (conf, after, "Created:");
|
||||||
{
|
|
||||||
if (value != "")
|
if (value != "")
|
||||||
|
{
|
||||||
|
Date original (::atoi (task.getAttribute ("entry").c_str ()));
|
||||||
|
Date edited (::atoi (value.c_str ()));
|
||||||
|
|
||||||
|
if (!original.sameDay (edited))
|
||||||
{
|
{
|
||||||
std::cout << "Creation date modified." << std::endl;
|
std::cout << "Creation date modified." << std::endl;
|
||||||
task.setAttribute ("entry", value);
|
task.setAttribute ("entry", value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
std::cout << "Cannot remove creation date." << std::endl;
|
std::cout << "Cannot remove creation date." << std::endl;
|
||||||
}
|
*/
|
||||||
|
|
||||||
// start
|
// start
|
||||||
value = findSimpleDate (conf, after, "Start:");
|
/*
|
||||||
if (task.getAttribute ("start") != value)
|
value = findDate (conf, after, "Start:");
|
||||||
{
|
|
||||||
if (value != "")
|
if (value != "")
|
||||||
|
{
|
||||||
|
Date original (::atoi (task.getAttribute ("start").c_str ()));
|
||||||
|
Date edited (::atoi (value.c_str ()));
|
||||||
|
|
||||||
|
if (!original.sameDay (edited))
|
||||||
{
|
{
|
||||||
std::cout << "Start date modified." << std::endl;
|
std::cout << "Start date modified." << std::endl;
|
||||||
task.setAttribute ("start", value);
|
task.setAttribute ("start", value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
std::cout << "Cannot remove start date" << std::endl;
|
{
|
||||||
|
Date original (::atoi (task.getAttribute ("start").c_str ()));
|
||||||
|
Date edited (::atoi (value.c_str ()));
|
||||||
|
|
||||||
|
if (!original.sameDay (edited))
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::cout << "Cannot remove start date." << std::endl;
|
||||||
|
}
|
||||||
|
*/
|
||||||
// end
|
// end
|
||||||
value = findSimpleDate (conf, after, "Ended:");
|
/*
|
||||||
if (task.getAttribute ("end") != value)
|
value = findDate (conf, after, "Ended:");
|
||||||
{
|
|
||||||
if (value != "")
|
if (value != "")
|
||||||
|
{
|
||||||
|
Date original (::atoi (task.getAttribute ("end").c_str ()));
|
||||||
|
Date edited (::atoi (value.c_str ()));
|
||||||
|
|
||||||
|
if (!original.sameDay (edited))
|
||||||
{
|
{
|
||||||
std::cout << "Done date modified." << std::endl;
|
std::cout << "Done date modified." << std::endl;
|
||||||
task.setAttribute ("end", value);
|
task.setAttribute ("end", value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "Done date removed." << std::endl;
|
std::cout << "Done date removed." << std::endl;
|
||||||
task.removeAttribute ("end");
|
task.removeAttribute ("end");
|
||||||
}
|
}
|
||||||
}
|
*/
|
||||||
|
|
||||||
// due
|
// due
|
||||||
value = findSimpleDate (conf, after, "Due:");
|
/*
|
||||||
if (task.getAttribute ("due") != value)
|
value = findDate (conf, after, "Due:");
|
||||||
{
|
|
||||||
if (value != "")
|
if (value != "")
|
||||||
|
{
|
||||||
|
Date original (::atoi (task.getAttribute ("due").c_str ()));
|
||||||
|
Date edited (::atoi (value.c_str ()));
|
||||||
|
|
||||||
|
if (!original.sameDay (edited))
|
||||||
{
|
{
|
||||||
std::cout << "Due date modified." << std::endl;
|
std::cout << "Due date modified." << std::endl;
|
||||||
task.setAttribute ("due", value);
|
task.setAttribute ("due", value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (task.getStatus () == T::recurring ||
|
if (task.getStatus () == T::recurring ||
|
||||||
|
@ -295,27 +322,34 @@ static void parseTask (Config& conf, T& task, const std::string& after)
|
||||||
task.removeAttribute ("due");
|
task.removeAttribute ("due");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
*/
|
||||||
|
|
||||||
// until
|
// until
|
||||||
value = findSimpleDate (conf, after, "Until:");
|
/*
|
||||||
if (task.getAttribute ("until") != value)
|
value = findDate (conf, after, "Until:");
|
||||||
{
|
|
||||||
if (value != "")
|
if (value != "")
|
||||||
|
{
|
||||||
|
Date original (::atoi (task.getAttribute ("until").c_str ()));
|
||||||
|
Date edited (::atoi (value.c_str ()));
|
||||||
|
|
||||||
|
if (!original.sameDay (edited))
|
||||||
{
|
{
|
||||||
std::cout << "Until date modified." << std::endl;
|
std::cout << "Until date modified." << std::endl;
|
||||||
task.setAttribute ("until", value);
|
task.setAttribute ("until", value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "Until date removed." << std::endl;
|
std::cout << "Until date removed." << std::endl;
|
||||||
task.removeAttribute ("until");
|
task.removeAttribute ("until");
|
||||||
}
|
}
|
||||||
}
|
*/
|
||||||
|
|
||||||
// recur
|
// recur
|
||||||
value = findSimpleValue (after, "Recur:");
|
/*
|
||||||
if (value != task.getAttribute ("recur"))
|
value = findValue (after, "Recur:");
|
||||||
|
if (value != task.getAttribute ("recur") &&
|
||||||
|
validDuration (value))
|
||||||
{
|
{
|
||||||
if (value != "")
|
if (value != "")
|
||||||
{
|
{
|
||||||
|
@ -328,9 +362,11 @@ static void parseTask (Config& conf, T& task, const std::string& after)
|
||||||
task.removeAttribute ("recur");
|
task.removeAttribute ("recur");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// parent
|
// parent
|
||||||
value = findSimpleValue (after, "Parent:");
|
/*
|
||||||
|
value = findValue (after, "Parent:");
|
||||||
if (value != task.getAttribute ("parent"))
|
if (value != task.getAttribute ("parent"))
|
||||||
{
|
{
|
||||||
if (value != "")
|
if (value != "")
|
||||||
|
@ -344,9 +380,11 @@ static void parseTask (Config& conf, T& task, const std::string& after)
|
||||||
task.removeAttribute ("parent");
|
task.removeAttribute ("parent");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// fg
|
// fg
|
||||||
value = findSimpleValue (after, "Foreground color:");
|
/*
|
||||||
|
value = findValue (after, "Foreground color:");
|
||||||
if (value != task.getAttribute ("fg"))
|
if (value != task.getAttribute ("fg"))
|
||||||
{
|
{
|
||||||
if (value != "")
|
if (value != "")
|
||||||
|
@ -360,9 +398,11 @@ static void parseTask (Config& conf, T& task, const std::string& after)
|
||||||
task.removeAttribute ("fg");
|
task.removeAttribute ("fg");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// bg
|
// bg
|
||||||
value = findSimpleValue (after, "Background color:");
|
/*
|
||||||
|
value = findValue (after, "Background color:");
|
||||||
if (value != task.getAttribute ("bg"))
|
if (value != task.getAttribute ("bg"))
|
||||||
{
|
{
|
||||||
if (value != "")
|
if (value != "")
|
||||||
|
@ -376,8 +416,10 @@ static void parseTask (Config& conf, T& task, const std::string& after)
|
||||||
task.removeAttribute ("bg");
|
task.removeAttribute ("bg");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Annotations
|
// Annotations
|
||||||
|
/*
|
||||||
std::map <time_t, std::string> annotations;
|
std::map <time_t, std::string> annotations;
|
||||||
std::string::size_type found = 0;
|
std::string::size_type found = 0;
|
||||||
while ((found = after.find ("Annotation:", found)) != std::string::npos)
|
while ((found = after.find ("Annotation:", found)) != std::string::npos)
|
||||||
|
@ -401,6 +443,7 @@ static void parseTask (Config& conf, T& task, const std::string& after)
|
||||||
}
|
}
|
||||||
|
|
||||||
task.setAnnotations (annotations);
|
task.setAnnotations (annotations);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -434,15 +477,19 @@ std::string handleEdit (TDB& tdb, T& task, Config& conf)
|
||||||
|
|
||||||
// Determine correct editor: .taskrc:editor > $VISUAL > $EDITOR > vi
|
// Determine correct editor: .taskrc:editor > $VISUAL > $EDITOR > vi
|
||||||
std::string editor = conf.get ("editor", "");
|
std::string editor = conf.get ("editor", "");
|
||||||
if (editor == "") editor = getenv ("VISUAL");
|
char* peditor = getenv ("VISUAL");
|
||||||
if (editor == "") editor = getenv ("EDITOR");
|
if (editor == "" && peditor) editor = std::string (peditor);
|
||||||
|
peditor = getenv ("EDITOR");
|
||||||
|
if (editor == "" && peditor) editor = std::string (peditor);
|
||||||
if (editor == "") editor = "vi";
|
if (editor == "") editor = "vi";
|
||||||
|
|
||||||
|
// Complete the command line.
|
||||||
|
editor += " ";
|
||||||
|
editor += file;
|
||||||
|
|
||||||
ARE_THESE_REALLY_HARMFUL:
|
ARE_THESE_REALLY_HARMFUL:
|
||||||
// Launch the editor.
|
// Launch the editor.
|
||||||
std::cout << "Launching '" << editor << "' now..." << std::endl;
|
std::cout << "Launching '" << editor << "' now..." << std::endl;
|
||||||
editor += " ";
|
|
||||||
editor += file;
|
|
||||||
system (editor.c_str ());
|
system (editor.c_str ());
|
||||||
std::cout << "Editing complete." << std::endl;
|
std::cout << "Editing complete." << std::endl;
|
||||||
|
|
||||||
|
@ -476,7 +523,7 @@ ARE_THESE_REALLY_HARMFUL:
|
||||||
|
|
||||||
if (oops)
|
if (oops)
|
||||||
{
|
{
|
||||||
std::cout << problem << std::endl;
|
std::cout << "Error: " << problem << std::endl;
|
||||||
|
|
||||||
// Preserve the edits.
|
// Preserve the edits.
|
||||||
before = after;
|
before = after;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue