Merge branch '2.4.2' into lexer2

This commit is contained in:
Paul Beckingham 2015-02-24 17:03:11 -05:00
commit 8c6892fed6
15 changed files with 89 additions and 30 deletions

View file

@ -107,8 +107,10 @@ int CmdConfig::unsetConfigVariable (std::string name, bool confirmation /* = fal
bool change = false;
std::vector <std::string>::iterator line;
for (line = contents.begin (); line != contents.end (); ++line)
for (line = contents.begin (); line != contents.end (); )
{
bool lineDeleted = false;
// If there is a comment on the line, it must follow the pattern.
std::string::size_type comment = line->find ("#");
std::string::size_type pos = line->find (name + "=");
@ -123,10 +125,15 @@ int CmdConfig::unsetConfigVariable (std::string name, bool confirmation /* = fal
if (!confirmation ||
confirm (format (STRING_CMD_CONFIG_CONFIRM3, name)))
{
*line = "";
// vector::erase method returns a valid iterator to the next object
line = contents.erase (line);
lineDeleted = true;
change = true;
}
}
if (! lineDeleted)
line++;
}
if (change)

View file

@ -26,9 +26,11 @@
#include <cmake.h>
#include <Context.h>
#include <Filter.h>
#include <sstream>
#include <algorithm>
#include <i18n.h>
#include <util.h>
#include <text.h>
#include <CmdContext.h>
#include <CmdConfig.h>
@ -128,15 +130,35 @@ std::vector <std::string> CmdContext::getContexts ()
int CmdContext::defineContext (std::vector <std::string>& words, std::stringstream& out)
{
int rc = 0;
bool confirmation = context.config.getBoolean ("confirmation");
if (words.size () > 2)
{
std::string name = "context." + words[1];
std::string value = joinWords (words, 2);
// TODO: Check if the value is a proper filter
// Check if the value is a proper filter by filtering current pending.data
Filter filter;
std::vector <Task> filtered;
const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
try
{
context.cli.addRawFilter ("( " + value + " )");
filter.subset (pending, filtered);
}
catch (std::string exception)
{
throw format (STRING_CMD_CONTEXT_DEF_ABRT2, exception);
}
// Make user explicitly confirm filters that are matching no pending tasks
if (filtered.size () == 0)
if (confirmation &&
! confirm (format (STRING_CMD_CONTEXT_DEF_CONF, value)))
throw std::string (STRING_CMD_CONTEXT_DEF_ABRT);
// Set context definition config variable
bool confirmation = context.config.getBoolean ("confirmation");
bool success = CmdConfig::setConfigVariable (name, value, confirmation);
if (success)
@ -148,7 +170,10 @@ int CmdContext::defineContext (std::vector <std::string>& words, std::stringstre
}
}
else
throw STRING_CMD_CONTEXT_DEF_USAG;
{
out << STRING_CMD_CONTEXT_DEF_USAG << "\n";
rc = 1;
}
return rc;
}
@ -188,7 +213,10 @@ int CmdContext::deleteContext (std::vector <std::string>& words, std::stringstre
out << format (STRING_CMD_CONTEXT_DEL_FAIL, words[1]) << "\n";
}
else
throw STRING_CMD_CONTEXT_DEL_USAG;
{
out << STRING_CMD_CONTEXT_DEL_USAG << "\n";
rc = 1;
}
return rc;
}