Add ability to reverse line order

Fix #9837, close #9839
This commit is contained in:
debiedowner 2021-05-07 13:09:34 +03:00 committed by Don HO
parent 70515c878b
commit ddd4448192
6 changed files with 22 additions and 0 deletions

View File

@ -129,6 +129,7 @@ The comments are here for explanation, it's not necessary to translate them.
<Item id="42064" name="Sort Lines As Decimals (Comma) Descending"/>
<Item id="42065" name="Sort Lines As Decimals (Dot) Ascending"/>
<Item id="42066" name="Sort Lines As Decimals (Dot) Descending"/>
<Item id="42083" name="Reverse Line Order"/>
<Item id="42078" name="Sort Lines Randomly"/>
<Item id="42016" name="&amp;UPPERCASE"/>
<Item id="42017" name="&amp;lowercase"/>

View File

@ -426,6 +426,18 @@ protected:
}
};
class ReverseSorter : public ISorter
{
public:
ReverseSorter(bool isDescending, size_t fromColumn, size_t toColumn) : ISorter(isDescending, fromColumn, toColumn) { };
std::vector<generic_string> sort(std::vector<generic_string> lines) override
{
std::reverse(lines.begin(), lines.end());
return lines;
}
};
class RandomSorter : public ISorter
{
public:

View File

@ -451,6 +451,7 @@ BEGIN
MENUITEM "Sort Lines As Decimals (Comma) Descending", IDM_EDIT_SORTLINES_DECIMALCOMMA_DESCENDING
MENUITEM "Sort Lines As Decimals (Dot) Descending", IDM_EDIT_SORTLINES_DECIMALDOT_DESCENDING
MENUITEM SEPARATOR
MENUITEM "Reverse Line Order", IDM_EDIT_SORTLINES_REVERSE_ORDER
MENUITEM "Sort Lines Randomly", IDM_EDIT_SORTLINES_RANDOMLY
END
POPUP "Comment/Uncomment"

View File

@ -577,6 +577,7 @@ void Notepad_plus::command(int id)
case IDM_EDIT_SORTLINES_DECIMALCOMMA_DESCENDING:
case IDM_EDIT_SORTLINES_DECIMALDOT_ASCENDING:
case IDM_EDIT_SORTLINES_DECIMALDOT_DESCENDING:
case IDM_EDIT_SORTLINES_REVERSE_ORDER:
case IDM_EDIT_SORTLINES_RANDOMLY:
{
std::lock_guard<std::mutex> lock(command_mutex);
@ -657,6 +658,10 @@ void Notepad_plus::command(int id)
{
pSorter = std::unique_ptr<ISorter>(new DecimalDotSorter(isDescending, fromColumn, toColumn));
}
else if (id == IDM_EDIT_SORTLINES_REVERSE_ORDER)
{
pSorter = std::unique_ptr<ISorter>(new ReverseSorter(isDescending, fromColumn, toColumn));
}
else
{
pSorter = std::unique_ptr<ISorter>(new RandomSorter(isDescending, fromColumn, toColumn));
@ -3688,6 +3693,7 @@ void Notepad_plus::command(int id)
case IDM_EDIT_SORTLINES_DECIMALCOMMA_DESCENDING:
case IDM_EDIT_SORTLINES_DECIMALDOT_ASCENDING:
case IDM_EDIT_SORTLINES_DECIMALDOT_DESCENDING:
case IDM_EDIT_SORTLINES_REVERSE_ORDER:
case IDM_EDIT_SORTLINES_RANDOMLY:
case IDM_EDIT_BLANKLINEABOVECURRENT:
case IDM_EDIT_BLANKLINEBELOWCURRENT:

View File

@ -135,6 +135,7 @@ static const WinMenuKeyDefinition winKeyDefs[] =
{ VK_NULL, IDM_EDIT_SORTLINES_DECIMALCOMMA_DESCENDING, false, false, false, nullptr },
{ VK_NULL, IDM_EDIT_SORTLINES_DECIMALDOT_ASCENDING, false, false, false, nullptr },
{ VK_NULL, IDM_EDIT_SORTLINES_DECIMALDOT_DESCENDING, false, false, false, nullptr },
{ VK_NULL, IDM_EDIT_SORTLINES_REVERSE_ORDER, false, false, false, nullptr },
{ VK_NULL, IDM_EDIT_SORTLINES_RANDOMLY, false, false, false, nullptr },
{ VK_Q, IDM_EDIT_BLOCK_COMMENT, true, false, false, nullptr },
{ VK_K, IDM_EDIT_BLOCK_COMMENT_SET, true, false, false, nullptr },

View File

@ -164,6 +164,7 @@
#define IDM_EDIT_SORTLINES_LEXICO_CASE_INSENS_ASCENDING (IDM_EDIT + 80)
#define IDM_EDIT_SORTLINES_LEXICO_CASE_INSENS_DESCENDING (IDM_EDIT + 81)
#define IDM_EDIT_COPY_LINK (IDM_EDIT + 82)
#define IDM_EDIT_SORTLINES_REVERSE_ORDER (IDM_EDIT + 83)
#define IDM_EDIT_AUTOCOMPLETE (50000 + 0)
#define IDM_EDIT_AUTOCOMPLETE_CURRENTFILE (50000 + 1)