From 23318103ed0b2da1bd9113f87d71272d06a9fd38 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 17 Aug 2015 19:14:58 -0400 Subject: [PATCH] CmdCustom: Special case sequence override --- doc/man/taskrc.5.in | 3 +++ src/commands/CmdCustom.cpp | 45 +++++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/doc/man/taskrc.5.in b/doc/man/taskrc.5.in index 76c9aa8e3..0f6f757df 100644 --- a/doc/man/taskrc.5.in +++ b/doc/man/taskrc.5.in @@ -1246,6 +1246,9 @@ This sort order now specifies that there is a listing break between each project. A listing break is simply a blank line, which provides a visual grouping. +A special sort value of "none" indicates that no sorting is required, and tasks +will be presented in the order (if any) in which they are selected. + .TP .B report.X.filter This adds a filter to the report X so that only tasks matching the filter diff --git a/src/commands/CmdCustom.cpp b/src/commands/CmdCustom.cpp index 6eacc5922..12aa23547 100644 --- a/src/commands/CmdCustom.cpp +++ b/src/commands/CmdCustom.cpp @@ -97,14 +97,47 @@ int CmdCustom::execute (std::string& output) std::vector filtered; filter.subset (filtered); - // Sort the tasks. std::vector sequence; - for (unsigned int i = 0; i < filtered.size (); ++i) - sequence.push_back (i); + if (sortOrder.size () && + sortOrder[0] == "none") + { + // If context.cli2._id_ranges is [4,3,5], yield [1,0,2], which is the sort + // order of the filtereed list, which will contain [3,4,5]. - if (sortOrder.size () != 0 && - sortOrder[0] != "none") - sort_tasks (filtered, sequence, reportSort); + sortOrder.clear (); + for (auto& i : context.cli2._id_ranges) + { + int first = strtol (i.first.c_str (), NULL, 10); + int second = strtol (i.second.c_str (), NULL, 10); + + if (first == second) + { + //sequence.push_back (first - 1); + for (unsigned int t = 0; t < filtered.size (); ++t) + if (filtered[t].id == first) + sequence.push_back (t); + } + else + { + for (int id = first; id <= second; id++) + //sequence.push_back (id - 1); + for (unsigned int t = 0; t < filtered.size (); ++t) + if (filtered[t].id == id) + sequence.push_back (t); + } + } + } + else + { + // There is a sortOrder, so sorting will take place, which means the initial + // order of sequence is ascending. + for (unsigned int i = 0; i < filtered.size (); ++i) + sequence.push_back (i); + + // Sort the tasks. + if (sortOrder.size ()) + sort_tasks (filtered, sequence, reportSort); + } // Configure the view. ViewTask view;