Patch #2944 2010-03-07 12:34

tpetrov

ThreadSearch sort in the list with the results
Download
2944-ThreadSearch_s.patch (12.7 KB)
Category
Plugin::FeatureAdd
Status
Accepted
Close date
2011-08-14 07:43
Assigned to
jenslody
Index: src/plugins/contrib/ThreadSearch/ThreadSearchLoggerList.h
===================================================================
--- src/plugins/contrib/ThreadSearch/ThreadSearchLoggerList.h    (revision 6200)
+++ src/plugins/contrib/ThreadSearch/ThreadSearchLoggerList.h    (working copy)
@@ -64,6 +64,8 @@
     /** Double click event handler */
     void OnLoggerListDoubleClick(wxListEvent& event);
 
+    /** Clicked in the header of the list control */
+    void OnColumnClick(wxListEvent& event);
 protected:
     /** SetListColumns
       * The SimpleListLog constructor does not set the provided columns on Linux.
@@ -110,8 +112,11 @@
     /** Deletes all items from the List */
     void DeleteListItems();
 
+private:
     wxListCtrl* m_pListLog;
     long        m_IndexOffset;
+    int         m_SortColumn;
+    bool        m_Ascending;
 };
 
 #endif // THREAD_SEARCH_LOGGER_LIST_H
Index: src/plugins/contrib/ThreadSearch/ThreadSearchLoggerList.cpp
===================================================================
--- src/plugins/contrib/ThreadSearch/ThreadSearchLoggerList.cpp    (revision 6200)
+++ src/plugins/contrib/ThreadSearch/ThreadSearchLoggerList.cpp    (working copy)
@@ -29,8 +29,10 @@
                                                InsertIndexManager::eFileSorting fileSorting,
                                                wxPanel* pParent,
                                                long id)
-                       : ThreadSearchLoggerBase(threadSearchView, threadSearchPlugin, fileSorting)
-                       , m_IndexOffset(0)
+                       : ThreadSearchLoggerBase(threadSearchView, threadSearchPlugin, fileSorting),
+                       m_IndexOffset(0),
+                       m_SortColumn(-1),
+                       m_Ascending(true)
 {
     m_pListLog = new wxListCtrl(pParent, id, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER);
     m_pListLog->SetMinSize(wxSize(100,100));
@@ -203,6 +205,7 @@
         m_pListLog->SetItem(index, 1, filename.GetFullName()); // File name
         m_pListLog->SetItem(index, 2, words[i]);               // Line index starting from 1
         m_pListLog->SetItem(index, 3, words[i+1]);             // File line matching search expression
+        m_pListLog->SetItemData(index, 0);
 
         // We update preview log for first list item
         if ( m_pListLog->GetItemCount() == 1 )
@@ -259,6 +262,10 @@
                         (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)
                         &ThreadSearchLoggerList::OnLoggerListDoubleClick, NULL, static_cast<wxEvtHandler*>(this));
 
+    pEvtHandler->Connect(id, wxEVT_COMMAND_LIST_COL_CLICK,
+                         (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction)
+                         &ThreadSearchLoggerList::OnColumnClick, NULL, static_cast<wxEvtHandler*>(this));
+
 #if wxUSE_MENUS
     pEvtHandler->Connect(id, wxEVT_CONTEXT_MENU,
             (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)
@@ -285,6 +292,10 @@
             (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)
             &ThreadSearchLoggerList::OnLoggerListDoubleClick, NULL, static_cast<wxEvtHandler*>(this));
 
+    pEvtHandler->Disconnect(id, wxEVT_COMMAND_LIST_COL_CLICK,
+                            (wxObjectEventFunction) (wxEventFunction) (wxListEventFunction)
+                            &ThreadSearchLoggerList::OnColumnClick, NULL, static_cast<wxEvtHandler*>(this));
+
 #if wxUSE_MENUS
     pEvtHandler->Disconnect(id, wxEVT_CONTEXT_MENU,
             (wxObjectEventFunction)(wxEventFunction)(wxCommandEventFunction)
@@ -399,6 +410,318 @@
         m_pListLog->SetItem(index, 1, _("========="));
         m_pListLog->SetItem(index, 2, _("==="));
         m_pListLog->SetItem(index, 3, _("============"));
+        m_pListLog->SetItemData(index, 1);
         m_IndexOffset = m_pListLog->GetItemCount();
     }
+
+    m_SortColumn = -1;
+    m_Ascending = true;
+}
+
+int Compare(long a, long b)
+{
+    return (a < b ? -1 : (a > b ? 1 : 0));
+}
+
+struct ItemLine
+{
+    long line;
+    long searchIndex;
+    bool searchHeader;
+};
+
+int SortLineAscending(long item1, long item2, long data)
+{
+    ItemLine const &i1 = *reinterpret_cast<ItemLine const *>(item1);
+    ItemLine const &i2 = *reinterpret_cast<ItemLine const *>(item2);
+
+    int c = Compare(i1.searchIndex, i2.searchIndex);
+    if (c)
+        return c;
+    if (i1.searchHeader != i2.searchHeader)
+        return i1.searchHeader ? -1 : 1;
+
+    return Compare(i1.line, i2.line);
+}
+
+int SortLineDescending(long item1, long item2, long data)
+{
+    ItemLine const &i1 = *reinterpret_cast<ItemLine const *>(item1);
+    ItemLine const &i2 = *reinterpret_cast<ItemLine const *>(item2);
+
+    int c = Compare(i1.searchIndex, i2.searchIndex);
+    if (c)
+        return c;
+    if (i1.searchHeader != i2.searchHeader)
+        return i1.searchHeader ? -1 : 1;
+
+    re
download for full patch...
jenslody 2010-03-07 14:57

I will look into it (and test, of course).

Thanks for the patch.

Jens

tpetrov 2010-04-03 01:24
jenslody 2010-04-10 10:41

As also posted in the forum ( http://forums.codeblocks.org/index.php/topic,12032.msg83887.html#msg83887 ), I applied the patch in my working copy to test it.

Looks good so far.

Most likely to be accepted after the next release.

Please remind me, if I forget it.

Thanks !!