diff --git a/wx/torrent-list.cc b/wx/torrent-list.cc index 8c1dac512..354361e72 100644 --- a/wx/torrent-list.cc +++ b/wx/torrent-list.cc @@ -18,7 +18,6 @@ * $Id$ */ -#include #include #include @@ -534,25 +533,49 @@ TorrentListCtrl :: Sort( int column ) Resort (); } +bool +TorrentListCtrl :: IsSorted( ) const +{ + bool is_sorted = true; + long prevItem=-1, curItem=-1; + + uglyHack = const_cast(this); + while( is_sorted ) + { + prevItem = curItem; + curItem = GetNextItem( curItem, wxLIST_NEXT_ALL, wxLIST_STATE_DONTCARE ); + if ( curItem == -1 ) + break; + if( prevItem>=0 && curItem>=0 ) + if( Compare( prevItem, curItem, prevSortCol ) > 0 ) + is_sorted = false; + } + uglyHack = 0; + + return is_sorted; +} + void TorrentListCtrl :: Resort( ) { - uglyHack = this; - myConfig->Write( _T("torrent-sort-column"), columnKeys[abs(prevSortCol)] ); myConfig->Write( _T("torrent-sort-is-descending"), prevSortCol < 0 ); - SortItems( Compare, prevSortCol ); + if( !IsSorted ( ) ) + { + uglyHack = this; + SortItems( Compare, prevSortCol ); - const int n = GetItemCount (); - str2int_t tmp; - for( int i=0; ihashString] = i; + const int n = GetItemCount (); + str2int_t tmp; + for( int i=0; ihashString] = i; + } + myHashToItem.swap( tmp ); + uglyHack = NULL; } - myHashToItem.swap( tmp ); - uglyHack = NULL; } /*** diff --git a/wx/torrent-list.h b/wx/torrent-list.h index 8e40088cc..b9e2d0c06 100644 --- a/wx/torrent-list.h +++ b/wx/torrent-list.h @@ -120,7 +120,7 @@ class TorrentListCtrl: public wxListCtrl void OnSort( wxListEvent& ); void OnItemSelected( wxListEvent& ); void OnItemDeselected( wxListEvent& ); - + bool IsSorted( ) const; private: tr_handle_t * myHandle;