[NEW_FEATURE] Add line sorting feature (in progress).

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1148 f5eea248-9336-0410-98b8-ebc06183d4e3
remotes/trunk
Don Ho 2013-11-17 23:51:09 +00:00
parent 1d0b91e536
commit 806dee917d
3 changed files with 93 additions and 7 deletions

View File

@ -5267,7 +5267,7 @@ struct Quote{
const char *_quote; const char *_quote;
}; };
const int nbQuote = 161; const int nbQuote = 171;
Quote quotes[nbQuote] = { Quote quotes[nbQuote] = {
{"Notepad++", "Good programmers use Notepad++ to code.\nExtreme programmers use MS Word to code, in Comic Sans, center aligned."}, {"Notepad++", "Good programmers use Notepad++ to code.\nExtreme programmers use MS Word to code, in Comic Sans, center aligned."},
{"Martin Golding", "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."}, {"Martin Golding", "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."},
@ -5419,6 +5419,16 @@ Quote quotes[nbQuote] = {
{"Anonymous #117", "A Native American was asked:\n\"Do you celebrate Columbus day?\"\nHe replied:\n\"I don't know, do Jews celebrate Hitler's birthday?\""}, {"Anonymous #117", "A Native American was asked:\n\"Do you celebrate Columbus day?\"\nHe replied:\n\"I don't know, do Jews celebrate Hitler's birthday?\""},
{"Anonymous #118", "I love necrophilia, but i can't stand the awkward silences."}, {"Anonymous #118", "I love necrophilia, but i can't stand the awkward silences."},
{"Anonymous #119", "\"I'm gonna Google that. BING that, Bing that, sorry.\"\n- The CEO of Bing (many times per day still)"}, {"Anonymous #119", "\"I'm gonna Google that. BING that, Bing that, sorry.\"\n- The CEO of Bing (many times per day still)"},
{"Anonymous #120", "Life is what happens to you while you're looking at your smartphone."},
{"Anonymous #121", "Thing to do today:\n1. Get up\n2. Go back to bed"},
{"Anonymous #122", "Nerd?\nI prefer the term \"Intellectual badass\"."},
{"Anonymous #123", "How can you face your problem if your problem is your face?"},
{"Anonymous #124", "YOLOLO:\nYou Only LOL Once."},
{"Anonymous #125", "Pooping with the door opened is the meaning of true freedom."},
{"Anonymous #126", "Social media does not make people stupid.\nIt just makes stupid people more visible."},
{"Anonymous #127", "Don't give up your dreams.\nKeep sleeping."},
{"Anonymous #128", "I love sleep.\nNot because I'm lazy.\nBut because my dreams are better than my real life."},
{"Anonymous #129", "Without nipples, tits are pointless."},
{"Barack Obama", "Yes, we scan!"}, {"Barack Obama", "Yes, we scan!"},
{"George W. Bush", "Where is my Nobel prize?\nI bombed people too."}, {"George W. Bush", "Where is my Nobel prize?\nI bombed people too."},
{"Gandhi", "Earth provides enough to satisfy every man's need, but not every man's greed."}, {"Gandhi", "Earth provides enough to satisfy every man's need, but not every man's greed."},

View File

@ -2885,7 +2885,72 @@ void ScintillaEditView::insertNewLineBelowCurrentLine()
} }
execute(SCI_SETEMPTYSELECTION, execute(SCI_POSITIONFROMLINE, current_line + 1)); execute(SCI_SETEMPTYSELECTION, execute(SCI_POSITIONFROMLINE, current_line + 1));
} }
/*
// Get the first left index, in which the value greater or equal than pivot's one
// If no one is greater than pivot, then pivot's index will be returned
size_t ScintillaEditView::getLeftLineIndex(size_t leftIndex, size_t pivotIndex)
{
size_t i = leftIndex;
while (i < pivotIndex)
{
size_t iLine = getGreaterLineBetween(i, pivotIndex);
if (iLine == pivotIndex)
i++;
else
break;
}
return i;
}
// Get the first right index, in which the value smaller or equal than pivot's one
// If no one is smaller or equal than pivot, then pivot's index will be returned
size_t ScintillaEditView::getRightLineIndex(size_t rightIndex, size_t pivotIndex)
{
size_t i = rightIndex;
while (i > pivotIndex)
{
size_t iLine = getGreaterLineBetween(i, pivotIndex);
if (iLine == i)
i--;
else
break;
}
return i;
}
size_t ScintillaEditView::getGreaterLineBetween(size_t l1, size_t l2)
{
int line1Len = execute(SCI_LINELENGTH, l1);
int line2Len = execute(SCI_LINELENGTH, l2);
char *line1text = new char[line1Len + 1];
char *line2text = new char[line2Len + 1];
execute(SCI_GETLINE, l1, (LPARAM)line1text);
line1text[line1Len] = '\0';
execute(SCI_GETLINE, l2, (LPARAM)line2text);
line2text[line2Len] = '\0';
string s1 = line1text;
string s2 = line2text;
size_t res;
if (s1.compare(s2) > 0)
res = l1;
else
res = l2
delete[] line1text;
delete[] line2text;
return res;
}
size_t ScintillaEditView::getRandomPivot(size_t /*fromLine*/, size_t /*toLine*/)
{
return 2;
}
void ScintillaEditView::quickSortLines(size_t fromLine, size_t toLine) void ScintillaEditView::quickSortLines(size_t fromLine, size_t toLine)
{ {
if (fromLine == toLine) if (fromLine == toLine)
@ -2898,12 +2963,17 @@ void ScintillaEditView::quickSortLines(size_t fromLine, size_t toLine)
size_t leftIndex = fromLine; size_t leftIndex = fromLine;
size_t rightIndex = toLine; size_t rightIndex = toLine;
for (size_t i = fromLine, j = toLine; i <= pivotIndex; ++i) while (leftIndex != rightIndex)
{ {
if (val(leftIndex) <= val(pivotIndex)) leftIndex = getLeftLineIndex(leftIndex, pivotIndex); // get the first left index, in which the value greater or equal than pivot's one
++leftIndex; rightIndex = getRightLineIndex(rightIndex, pivotIndex); // get the first right index, in which the value smaller or equal than pivot's one
swapLines(leftIndex, rightIndex);
//if (val(leftIndex) <= val(pivotIndex))
// ++leftIndex;
//for (size_t j = toLine; i >= pivotIndex; --j) //for (size_t j = toLine; i >= pivotIndex; --j)
//{ //{
@ -2916,7 +2986,7 @@ void ScintillaEditView::quickSortLines(size_t fromLine, size_t toLine)
// check the right side recursively // check the right side recursively
quickSortLines(pivotIndex + 1, toLine); quickSortLines(pivotIndex + 1, toLine);
} }
*/
bool ScintillaEditView::swapLines(size_t line1, size_t line2) bool ScintillaEditView::swapLines(size_t line1, size_t line2)
{ {

View File

@ -657,7 +657,7 @@ public:
}; };
void scrollPosToCenter(int pos); void scrollPosToCenter(int pos);
bool swapLines(size_t line1, size_t line2); bool swapLines(size_t line1, size_t line2);
//void quickSortLines(size_t fromLine, size_t toLine); void quickSortLines(size_t fromLine, size_t toLine);
protected: protected:
static HINSTANCE _hLib; static HINSTANCE _hLib;
@ -956,6 +956,12 @@ protected:
pair<int, int> getWordRange(); pair<int, int> getWordRange();
bool expandWordSelection(); bool expandWordSelection();
// For the quicksort on lines
size_t getLeftLineIndex(size_t leftIndex, size_t pivotIndex);
size_t getRightLineIndex(size_t rightIndex, size_t pivotIndex);
size_t getGreaterLineBetween(size_t l1, size_t l2);
size_t getRandomPivot(size_t fromLine, size_t toLine);
}; };
#endif //SCINTILLA_EDIT_VIEW_H #endif //SCINTILLA_EDIT_VIEW_H