Bug #1056
- Fix #1056: the 'projects' command now outputs abstract parents and reduces repetition by not printing parent names in front of children names. - Project name indentation is not affected by the first character being a period and/or the last character being a period. - Unit tests for above.
This commit is contained in:
committed by
Paul Beckingham
parent
a3242f7b5b
commit
be5dc8ab90
@@ -27,6 +27,7 @@
|
||||
|
||||
#define L10N // Localization complete.
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <Context.h>
|
||||
#include <ViewText.h>
|
||||
@@ -119,9 +120,22 @@ int CmdProjects::execute (std::string& output)
|
||||
view.add (Column::factory ("string.right", STRING_CMD_PROJECTS_PRI_M));
|
||||
view.add (Column::factory ("string.right", STRING_CMD_PROJECTS_PRI_H));
|
||||
|
||||
std::vector <std::string> processed;
|
||||
std::map <std::string, int>::iterator project;
|
||||
for (project = unique.begin (); project != unique.end (); ++project)
|
||||
{
|
||||
const std::vector <std::string> parents = extractParents (project->first);
|
||||
std::vector <std::string>::const_iterator parent;
|
||||
for (parent = parents.begin (); parent != parents.end (); parent++)
|
||||
{
|
||||
if (std::find (processed.begin (), processed.end (), *parent)
|
||||
== processed.end ())
|
||||
{
|
||||
int row = view.addRow ();
|
||||
view.set (row, 0, indentProject (*parent));
|
||||
processed.push_back (*parent);
|
||||
}
|
||||
}
|
||||
int row = view.addRow ();
|
||||
view.set (row, 0, (project->first == ""
|
||||
? STRING_CMD_PROJECTS_NONE
|
||||
@@ -131,6 +145,7 @@ int CmdProjects::execute (std::string& output)
|
||||
view.set (row, 3, low[project->first]);
|
||||
view.set (row, 4, medium[project->first]);
|
||||
view.set (row, 5, high[project->first]);
|
||||
processed.push_back (project->first);
|
||||
}
|
||||
|
||||
int number_projects = unique.size ();
|
||||
|
||||
36
src/util.cpp
36
src/util.cpp
@@ -602,10 +602,42 @@ const std::string indentProject (
|
||||
// Count the delimiters in *i.
|
||||
std::string prefix = "";
|
||||
std::string::size_type pos = 0;
|
||||
std::string::size_type lastpos = 0;
|
||||
while ((pos = project.find (delimiter, pos + 1)) != std::string::npos)
|
||||
prefix += whitespace;
|
||||
{
|
||||
if (pos != project.size () - 1)
|
||||
{
|
||||
prefix += whitespace;
|
||||
lastpos = pos;
|
||||
}
|
||||
}
|
||||
|
||||
return prefix + project;
|
||||
std::string child = "";
|
||||
if (lastpos == 0)
|
||||
child = project;
|
||||
else
|
||||
child = project.substr (lastpos + 1);
|
||||
|
||||
return prefix + child;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
const std::vector <std::string> extractParents (
|
||||
const std::string& project,
|
||||
const char& delimiter /* = '.' */)
|
||||
{
|
||||
std::vector <std::string> vec;
|
||||
std::string::size_type pos = 0;
|
||||
std::string::size_type copyUntil = 0;
|
||||
while ((copyUntil = project.find (delimiter, pos + 1)) != std::string::npos)
|
||||
{
|
||||
if (copyUntil != project.size () - 1)
|
||||
vec.push_back (project.substr (0, copyUntil));
|
||||
pos = copyUntil;
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -84,6 +84,10 @@ const std::string indentProject (
|
||||
const std::string& whitespace = " ",
|
||||
char delimiter = '.');
|
||||
|
||||
const std::vector <std::string> extractParents (
|
||||
const std::string&,
|
||||
const char& delimiter = '.');
|
||||
|
||||
#ifndef HAVE_TIMEGM
|
||||
time_t timegm (struct tm *tm);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user