From f0f5decf2217e91913a30552c1ef209732a88d05 Mon Sep 17 00:00:00 2001 From: FRex Date: Mon, 22 Nov 2021 23:18:55 +0100 Subject: [PATCH] added ctrl k to sort todo lists --- allnotes.txt | 7 +++++++ mainunit.lfm | 6 +++++- mainunit.pas | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/allnotes.txt b/allnotes.txt index b5d660e..a99ceb0 100644 --- a/allnotes.txt +++ b/allnotes.txt @@ -15987,6 +15987,13 @@ Ctrl + O - open URL or hashtag that's selected or (if nothing's selected) under Ctrl + F when in main text area will open a simple search +Ctrl + K - sorts a TODO list (putting done at the end), try: +[ ] item 1 +[x] item 2 +[x] item 3 +[ ] item 4 +[x] item 5 + Double click on status bar to open the directory Botes is in. Create old directory there to get a duplicate of every saved file. diff --git a/mainunit.lfm b/mainunit.lfm index 13c3f67..ec72e99 100644 --- a/mainunit.lfm +++ b/mainunit.lfm @@ -478,10 +478,14 @@ object Form1: TForm1 item Command = ecUserDefined0 ShortCut = 16452 - end + end item Command = ecUserDefined1 ShortCut = 16463 + end + item + Command = ecUserDefined2 + ShortCut = 16459 end> MouseActions = <> MouseTextActions = <> diff --git a/mainunit.pas b/mainunit.pas index f1d5d65..31dfbf2 100644 --- a/mainunit.pas +++ b/mainunit.pas @@ -92,6 +92,7 @@ TForm1 = class(TForm) procedure MoveCursorToNextFind; procedure SaveCaretAndView(tabindex: integer); procedure LoadCaretAndView(tabindex: integer); + procedure SortTodoListAroundCurrentLine; { private declarations } public { public declarations } @@ -514,6 +515,62 @@ procedure TForm1.TextEditorCommandProcessed(Sender: TObject; end; //if command is user defined first + 1 + if Command = (ecUserDefinedFirst + 2) then + SortTodoListAroundCurrentLine; +end; + +function IsTodoLine(line: string): boolean; +begin + Exit((line.Substring(0, 3) = '[ ]') or (line.Substring(0, 3) = '[x]')); +end; + +procedure TForm1.SortTodoListAroundCurrentLine; +var + firstTodo, lastTodo, cur: integer; + completed, pending: TStringList; + line: string; +begin + if not IsTodoLine(TextEditor.Lines[TextEditor.CaretY - 1]) then + Exit; + + for cur := TextEditor.CaretY - 1 downto 0 do + begin + if not IsTodoLine(TextEditor.Lines[cur]) then + break; + firstTodo := cur; + end; + + for cur := TextEditor.CaretY - 1 to TextEditor.Lines.Count - 1 do + begin + if not IsTodoLine(TextEditor.Lines[cur]) then + break; + lastTodo := cur; + end; + + completed := TStringList.Create; + pending := TStringList.Create; + + for cur := firstTodo to lastTodo do + if TextEditor.Lines[cur][2] = 'x' then + completed.Append(TextEditor.Lines[cur]) + else + pending.Append(TextEditor.Lines[cur]); + + TextEditor.BeginUpdate; + for cur := firstTodo to lastTodo do + begin + if (cur - firstTodo) < pending.Count then + line := pending[cur - firstTodo] + else + line := completed[cur - firstTodo - pending.Count]; + + TextEditor.TextBetweenPoints[TPoint.Create(0, cur + 1), + TPoint.Create(maxLongint, cur + 1)] := line; + end; + TextEditor.EndUpdate; + + completed.Free; + pending.Free; end; procedure TForm1.TextEditorEnter(Sender: TObject);