parent
1a37b64fe6
commit
61bf9bd3c4
|
@ -115,6 +115,8 @@
|
||||||
<Item id="42015" name="Move Down Current Line"/>
|
<Item id="42015" name="Move Down Current Line"/>
|
||||||
<Item id="42059" name="Sort Lines Lexicographically Ascending"/>
|
<Item id="42059" name="Sort Lines Lexicographically Ascending"/>
|
||||||
<Item id="42060" name="Sort Lines Lexicographically Descending"/>
|
<Item id="42060" name="Sort Lines Lexicographically Descending"/>
|
||||||
|
<Item id="42080" name="Sort Lines Lex. Ascending Ignoring Case"/>
|
||||||
|
<Item id="42081" name="Sort Lines Lex. Descending Ignoring Case"/>
|
||||||
<Item id="42061" name="Sort Lines As Integers Ascending"/>
|
<Item id="42061" name="Sort Lines As Integers Ascending"/>
|
||||||
<Item id="42062" name="Sort Lines As Integers Descending"/>
|
<Item id="42062" name="Sort Lines As Integers Descending"/>
|
||||||
<Item id="42063" name="Sort Lines As Decimals (Comma) Ascending"/>
|
<Item id="42063" name="Sort Lines As Decimals (Comma) Ascending"/>
|
||||||
|
|
|
@ -94,7 +94,7 @@ public:
|
||||||
|
|
||||||
std::vector<generic_string> sort(std::vector<generic_string> lines) override
|
std::vector<generic_string> sort(std::vector<generic_string> lines) override
|
||||||
{
|
{
|
||||||
// Note that both branches here are equivalent in the sense that they give always give the same answer.
|
// Note that both branches here are equivalent in the sense that they always give the same answer.
|
||||||
// However, if we are *not* sorting specific columns, then we get a 40% speed improvement by not calling
|
// However, if we are *not* sorting specific columns, then we get a 40% speed improvement by not calling
|
||||||
// getSortKey() so many times.
|
// getSortKey() so many times.
|
||||||
if (isSortingSpecificColumns())
|
if (isSortingSpecificColumns())
|
||||||
|
@ -130,6 +130,49 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Implementation of lexicographic sorting of lines, ignoring character casing
|
||||||
|
class LexicographicCaseInsensitiveSorter : public ISorter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LexicographicCaseInsensitiveSorter(bool isDescending, size_t fromColumn, size_t toColumn) : ISorter(isDescending, fromColumn, toColumn) { };
|
||||||
|
|
||||||
|
std::vector<generic_string> sort(std::vector<generic_string> lines) override
|
||||||
|
{
|
||||||
|
// Note that both branches here are equivalent in the sense that they always give the same answer.
|
||||||
|
// However, if we are *not* sorting specific columns, then we get a 40% speed improvement by not calling
|
||||||
|
// getSortKey() so many times.
|
||||||
|
if (isSortingSpecificColumns())
|
||||||
|
{
|
||||||
|
std::sort(lines.begin(), lines.end(), [this](generic_string a, generic_string b)
|
||||||
|
{
|
||||||
|
if (isDescending())
|
||||||
|
{
|
||||||
|
return OrdinalIgnoreCaseCompareStrings(getSortKey(a).c_str(), getSortKey(b).c_str()) > 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return OrdinalIgnoreCaseCompareStrings(getSortKey(a).c_str(), getSortKey(b).c_str()) < 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::sort(lines.begin(), lines.end(), [this](generic_string a, generic_string b)
|
||||||
|
{
|
||||||
|
if (isDescending())
|
||||||
|
{
|
||||||
|
return OrdinalIgnoreCaseCompareStrings(a.c_str(), b.c_str()) > 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return OrdinalIgnoreCaseCompareStrings(a.c_str(), b.c_str()) < 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Treat consecutive numerals as one number
|
// Treat consecutive numerals as one number
|
||||||
// Otherwise it is a lexicographic sort
|
// Otherwise it is a lexicographic sort
|
||||||
class NaturalSorter : public ISorter
|
class NaturalSorter : public ISorter
|
||||||
|
@ -139,7 +182,7 @@ public:
|
||||||
|
|
||||||
std::vector<generic_string> sort(std::vector<generic_string> lines) override
|
std::vector<generic_string> sort(std::vector<generic_string> lines) override
|
||||||
{
|
{
|
||||||
// Note that both branches here are equivalent in the sense that they give always give the same answer.
|
// Note that both branches here are equivalent in the sense that they always give the same answer.
|
||||||
// However, if we are *not* sorting specific columns, then we get a 40% speed improvement by not calling
|
// However, if we are *not* sorting specific columns, then we get a 40% speed improvement by not calling
|
||||||
// getSortKey() so many times.
|
// getSortKey() so many times.
|
||||||
if (isSortingSpecificColumns())
|
if (isSortingSpecificColumns())
|
||||||
|
|
|
@ -316,11 +316,13 @@ BEGIN
|
||||||
MENUITEM "Insert Blank Line Below Current", IDM_EDIT_BLANKLINEBELOWCURRENT
|
MENUITEM "Insert Blank Line Below Current", IDM_EDIT_BLANKLINEBELOWCURRENT
|
||||||
MENUITEM SEPARATOR
|
MENUITEM SEPARATOR
|
||||||
MENUITEM "Sort Lines Lexicographically Ascending", IDM_EDIT_SORTLINES_LEXICOGRAPHIC_ASCENDING
|
MENUITEM "Sort Lines Lexicographically Ascending", IDM_EDIT_SORTLINES_LEXICOGRAPHIC_ASCENDING
|
||||||
|
MENUITEM "Sort Lines Lex. Ascending Ignoring Case", IDM_EDIT_SORTLINES_LEXICO_CASE_INSENS_ASCENDING
|
||||||
MENUITEM "Sort Lines As Integers Ascending", IDM_EDIT_SORTLINES_INTEGER_ASCENDING
|
MENUITEM "Sort Lines As Integers Ascending", IDM_EDIT_SORTLINES_INTEGER_ASCENDING
|
||||||
MENUITEM "Sort Lines As Decimals (Comma) Ascending", IDM_EDIT_SORTLINES_DECIMALCOMMA_ASCENDING
|
MENUITEM "Sort Lines As Decimals (Comma) Ascending", IDM_EDIT_SORTLINES_DECIMALCOMMA_ASCENDING
|
||||||
MENUITEM "Sort Lines As Decimals (Dot) Ascending", IDM_EDIT_SORTLINES_DECIMALDOT_ASCENDING
|
MENUITEM "Sort Lines As Decimals (Dot) Ascending", IDM_EDIT_SORTLINES_DECIMALDOT_ASCENDING
|
||||||
MENUITEM SEPARATOR
|
MENUITEM SEPARATOR
|
||||||
MENUITEM "Sort Lines Lexicographically Descending", IDM_EDIT_SORTLINES_LEXICOGRAPHIC_DESCENDING
|
MENUITEM "Sort Lines Lexicographically Descending", IDM_EDIT_SORTLINES_LEXICOGRAPHIC_DESCENDING
|
||||||
|
MENUITEM "Sort Lines Lex. Descending Ignoring Case", IDM_EDIT_SORTLINES_LEXICO_CASE_INSENS_DESCENDING
|
||||||
MENUITEM "Sort Lines As Integers Descending", IDM_EDIT_SORTLINES_INTEGER_DESCENDING
|
MENUITEM "Sort Lines As Integers Descending", IDM_EDIT_SORTLINES_INTEGER_DESCENDING
|
||||||
MENUITEM "Sort Lines As Decimals (Comma) Descending", IDM_EDIT_SORTLINES_DECIMALCOMMA_DESCENDING
|
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 "Sort Lines As Decimals (Dot) Descending", IDM_EDIT_SORTLINES_DECIMALDOT_DESCENDING
|
||||||
|
|
|
@ -565,6 +565,8 @@ void Notepad_plus::command(int id)
|
||||||
|
|
||||||
case IDM_EDIT_SORTLINES_LEXICOGRAPHIC_ASCENDING:
|
case IDM_EDIT_SORTLINES_LEXICOGRAPHIC_ASCENDING:
|
||||||
case IDM_EDIT_SORTLINES_LEXICOGRAPHIC_DESCENDING:
|
case IDM_EDIT_SORTLINES_LEXICOGRAPHIC_DESCENDING:
|
||||||
|
case IDM_EDIT_SORTLINES_LEXICO_CASE_INSENS_ASCENDING:
|
||||||
|
case IDM_EDIT_SORTLINES_LEXICO_CASE_INSENS_DESCENDING:
|
||||||
case IDM_EDIT_SORTLINES_INTEGER_ASCENDING:
|
case IDM_EDIT_SORTLINES_INTEGER_ASCENDING:
|
||||||
case IDM_EDIT_SORTLINES_INTEGER_DESCENDING:
|
case IDM_EDIT_SORTLINES_INTEGER_DESCENDING:
|
||||||
case IDM_EDIT_SORTLINES_DECIMALCOMMA_ASCENDING:
|
case IDM_EDIT_SORTLINES_DECIMALCOMMA_ASCENDING:
|
||||||
|
@ -625,7 +627,8 @@ void Notepad_plus::command(int id)
|
||||||
bool isDescending = id == IDM_EDIT_SORTLINES_LEXICOGRAPHIC_DESCENDING ||
|
bool isDescending = id == IDM_EDIT_SORTLINES_LEXICOGRAPHIC_DESCENDING ||
|
||||||
id == IDM_EDIT_SORTLINES_INTEGER_DESCENDING ||
|
id == IDM_EDIT_SORTLINES_INTEGER_DESCENDING ||
|
||||||
id == IDM_EDIT_SORTLINES_DECIMALCOMMA_DESCENDING ||
|
id == IDM_EDIT_SORTLINES_DECIMALCOMMA_DESCENDING ||
|
||||||
id == IDM_EDIT_SORTLINES_DECIMALDOT_DESCENDING;
|
id == IDM_EDIT_SORTLINES_DECIMALDOT_DESCENDING ||
|
||||||
|
id == IDM_EDIT_SORTLINES_LEXICO_CASE_INSENS_DESCENDING;
|
||||||
|
|
||||||
_pEditView->execute(SCI_BEGINUNDOACTION);
|
_pEditView->execute(SCI_BEGINUNDOACTION);
|
||||||
std::unique_ptr<ISorter> pSorter;
|
std::unique_ptr<ISorter> pSorter;
|
||||||
|
@ -633,6 +636,10 @@ void Notepad_plus::command(int id)
|
||||||
{
|
{
|
||||||
pSorter = std::unique_ptr<ISorter>(new LexicographicSorter(isDescending, fromColumn, toColumn));
|
pSorter = std::unique_ptr<ISorter>(new LexicographicSorter(isDescending, fromColumn, toColumn));
|
||||||
}
|
}
|
||||||
|
else if (id == IDM_EDIT_SORTLINES_LEXICO_CASE_INSENS_DESCENDING || id == IDM_EDIT_SORTLINES_LEXICO_CASE_INSENS_ASCENDING)
|
||||||
|
{
|
||||||
|
pSorter = std::unique_ptr<ISorter>(new LexicographicCaseInsensitiveSorter(isDescending, fromColumn, toColumn));
|
||||||
|
}
|
||||||
else if (id == IDM_EDIT_SORTLINES_INTEGER_DESCENDING || id == IDM_EDIT_SORTLINES_INTEGER_ASCENDING)
|
else if (id == IDM_EDIT_SORTLINES_INTEGER_DESCENDING || id == IDM_EDIT_SORTLINES_INTEGER_ASCENDING)
|
||||||
{
|
{
|
||||||
pSorter = std::unique_ptr<ISorter>(new NaturalSorter(isDescending, fromColumn, toColumn));
|
pSorter = std::unique_ptr<ISorter>(new NaturalSorter(isDescending, fromColumn, toColumn));
|
||||||
|
@ -3532,6 +3539,8 @@ void Notepad_plus::command(int id)
|
||||||
case IDM_EDIT_BEGINENDSELECT:
|
case IDM_EDIT_BEGINENDSELECT:
|
||||||
case IDM_EDIT_SORTLINES_LEXICOGRAPHIC_ASCENDING:
|
case IDM_EDIT_SORTLINES_LEXICOGRAPHIC_ASCENDING:
|
||||||
case IDM_EDIT_SORTLINES_LEXICOGRAPHIC_DESCENDING:
|
case IDM_EDIT_SORTLINES_LEXICOGRAPHIC_DESCENDING:
|
||||||
|
case IDM_EDIT_SORTLINES_LEXICO_CASE_INSENS_ASCENDING:
|
||||||
|
case IDM_EDIT_SORTLINES_LEXICO_CASE_INSENS_DESCENDING:
|
||||||
case IDM_EDIT_SORTLINES_INTEGER_ASCENDING:
|
case IDM_EDIT_SORTLINES_INTEGER_ASCENDING:
|
||||||
case IDM_EDIT_SORTLINES_INTEGER_DESCENDING:
|
case IDM_EDIT_SORTLINES_INTEGER_DESCENDING:
|
||||||
case IDM_EDIT_SORTLINES_DECIMALCOMMA_ASCENDING:
|
case IDM_EDIT_SORTLINES_DECIMALCOMMA_ASCENDING:
|
||||||
|
|
|
@ -138,6 +138,8 @@ static const WinMenuKeyDefinition winKeyDefs[] =
|
||||||
{ VK_RETURN, IDM_EDIT_BLANKLINEBELOWCURRENT, true, true, true, nullptr },
|
{ VK_RETURN, IDM_EDIT_BLANKLINEBELOWCURRENT, true, true, true, nullptr },
|
||||||
{ VK_NULL, IDM_EDIT_SORTLINES_LEXICOGRAPHIC_ASCENDING, false, false, false, nullptr },
|
{ VK_NULL, IDM_EDIT_SORTLINES_LEXICOGRAPHIC_ASCENDING, false, false, false, nullptr },
|
||||||
{ VK_NULL, IDM_EDIT_SORTLINES_LEXICOGRAPHIC_DESCENDING, false, false, false, nullptr },
|
{ VK_NULL, IDM_EDIT_SORTLINES_LEXICOGRAPHIC_DESCENDING, false, false, false, nullptr },
|
||||||
|
{ VK_NULL, IDM_EDIT_SORTLINES_LEXICO_CASE_INSENS_ASCENDING, false, false, false, nullptr },
|
||||||
|
{ VK_NULL, IDM_EDIT_SORTLINES_LEXICO_CASE_INSENS_DESCENDING, false, false, false, nullptr },
|
||||||
{ VK_NULL, IDM_EDIT_SORTLINES_INTEGER_ASCENDING, false, false, false, nullptr },
|
{ VK_NULL, IDM_EDIT_SORTLINES_INTEGER_ASCENDING, false, false, false, nullptr },
|
||||||
{ VK_NULL, IDM_EDIT_SORTLINES_INTEGER_DESCENDING, false, false, false, nullptr },
|
{ VK_NULL, IDM_EDIT_SORTLINES_INTEGER_DESCENDING, false, false, false, nullptr },
|
||||||
{ VK_NULL, IDM_EDIT_SORTLINES_DECIMALCOMMA_ASCENDING, false, false, false, nullptr },
|
{ VK_NULL, IDM_EDIT_SORTLINES_DECIMALCOMMA_ASCENDING, false, false, false, nullptr },
|
||||||
|
|
|
@ -132,6 +132,8 @@
|
||||||
#define IDM_EDIT_SORTLINES_DECIMALDOT_ASCENDING (IDM_EDIT + 65)
|
#define IDM_EDIT_SORTLINES_DECIMALDOT_ASCENDING (IDM_EDIT + 65)
|
||||||
#define IDM_EDIT_SORTLINES_DECIMALDOT_DESCENDING (IDM_EDIT + 66)
|
#define IDM_EDIT_SORTLINES_DECIMALDOT_DESCENDING (IDM_EDIT + 66)
|
||||||
#define IDM_EDIT_SORTLINES_RANDOMLY (IDM_EDIT + 78)
|
#define IDM_EDIT_SORTLINES_RANDOMLY (IDM_EDIT + 78)
|
||||||
|
#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_OPENASFILE (IDM_EDIT + 73)
|
#define IDM_EDIT_OPENASFILE (IDM_EDIT + 73)
|
||||||
#define IDM_EDIT_OPENINFOLDER (IDM_EDIT + 74)
|
#define IDM_EDIT_OPENINFOLDER (IDM_EDIT + 74)
|
||||||
|
|
Loading…
Reference in New Issue