From 78318f90a72f7eff3acad0ba21af2138b8878a35 Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Sat, 14 Feb 2015 04:21:54 +0100 Subject: [PATCH 1/2] todolist column can be sorted --- src/ce_todolist.lfm | 1 + src/ce_todolist.pas | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/ce_todolist.lfm b/src/ce_todolist.lfm index b3e6f5f8..fb0d5ef5 100644 --- a/src/ce_todolist.lfm +++ b/src/ce_todolist.lfm @@ -95,6 +95,7 @@ inherited CETodoListWidget: TCETodoListWidget Width = 75 end> ReadOnly = True + SortType = stText TabOrder = 1 ViewStyle = vsReport end diff --git a/src/ce_todolist.pas b/src/ce_todolist.pas index 891e9dbc..cced6d6a 100644 --- a/src/ce_todolist.pas +++ b/src/ce_todolist.pas @@ -91,6 +91,8 @@ type procedure procOutputDbg(sender: TObject); procedure clearTodoList; procedure fillTodoList; + procedure lstItemsColumnClick(Sender : TObject; Column : TListColumn); + procedure lstItemsCompare(Sender : TObject; item1, item2: TListItem;Data : Integer; var Compare : Integer); procedure lstItemsDoubleClick(sender: TObject); procedure btnRefreshClick(sender: TObject); procedure filterItems(sender: TObject); @@ -175,6 +177,8 @@ begin fTodos := TTodoItems.Create(self); lstItems.OnDblClick := @lstItemsDoubleClick; btnRefresh.OnClick := @btnRefreshClick; + lstItems.OnColumnClick:= @lstItemsColumnClick; + lstItems.OnCompare := @lstItemsCompare; fAutoRefresh := true; mnuAutoRefresh.Checked := true; // http://bugs.freepascal.org/view.php?id=27137 @@ -471,6 +475,45 @@ begin fDoc.SelectLine; end; +procedure TCETodoListWidget.lstItemsColumnClick(Sender : TObject; Column : + TListColumn); +var + curr: TListItem; +begin + if lstItems.Selected = nil then exit; + curr := lstItems.Selected; + // + if lstItems.SortDirection = sdAscending then + lstItems.SortDirection := sdDescending + else lstItems.SortDirection := sdAscending; + lstItems.SortColumn := Column.Index; + lstItems.Selected := nil; + lstItems.Selected := curr; + lstItems.Update; +end; + +procedure TCETodoListWidget.lstItemsCompare(Sender : TObject; item1, item2: + TListItem;Data : Integer; var Compare : Integer); +var + txt1, txt2: string; + col: Integer; +begin + txt1 := ''; + txt2 := ''; + col := lstItems.SortColumn; + if col = 0 then + begin + txt1 := item1.Caption; + txt2 := item2.Caption; + end else + begin + if col < item1.SubItems.Count then txt1 := item1.SubItems.Strings[col]; + if col < item2.SubItems.Count then txt2 := item2.SubItems.Strings[col]; + end; + Compare := AnsiCompareStr(txt1, txt2); + if lstItems.SortDirection = sdDescending then Compare := -Compare; +end; + procedure TCETodoListWidget.btnRefreshClick(sender: TObject); begin callToolProcess; From 9c25a5e206504364edf6ac5b2b62e4951586be68 Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Sat, 14 Feb 2015 04:40:01 +0100 Subject: [PATCH 2/2] tweaked getContext --- src/ce_todolist.pas | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/ce_todolist.pas b/src/ce_todolist.pas index cced6d6a..f1b4bf65 100644 --- a/src/ce_todolist.pas +++ b/src/ce_todolist.pas @@ -251,7 +251,6 @@ end; procedure TCETodoListWidget.docChanged(aDoc: TCESynMemo); begin - if fDoc <> aDoc then exit; end; procedure TCETodoListWidget.docClosing(aDoc: TCESynMemo); @@ -298,15 +297,12 @@ end; {$REGION Todo list things ------------------------------------------------------} function TCETodoListWidget.getContext: TTodoContext; begin - result := tcNone; - // - if ((fProj = nil) and (fDoc = nil)) then exit; + if ((fProj = nil) and (fDoc = nil)) then exit(tcNone); if ((fProj = nil) and (fDoc <> nil)) then exit(tcFile); if ((fProj <> nil) and (fDoc = nil)) then exit(tcProject); // - result := tcFile; - if not FileExists(fDoc.fileName) then exit; - if fProj.isProjectSource(fDoc.fileName) then exit(tcProject); + if fProj.isProjectSource(fDoc.fileName) then + exit(tcProject) else exit(tcFile); end; procedure TCETodoListWidget.killToolProcess;