Changeset 2914


Ignore:
Timestamp:
Aug 23, 2007, 7:21:42 PM (15 years ago)
Author:
charles
Message:
  • fix the torrent list's flicker on periodic refresh by resorting only when it's needed
Location:
trunk/wx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wx/torrent-list.cc

    r2849 r2914  
    1919 */
    2020
    21 #include <iostream>
    2221#include <wx/intl.h>
    2322#include <torrent-list.h>
     
    535534}
    536535
     536bool
     537TorrentListCtrl :: IsSorted( ) const
     538{
     539    bool is_sorted = true;
     540    long prevItem=-1, curItem=-1;
     541
     542    uglyHack = const_cast<TorrentListCtrl*>(this);
     543    while( is_sorted )
     544    {
     545        prevItem = curItem;
     546        curItem = GetNextItem( curItem, wxLIST_NEXT_ALL, wxLIST_STATE_DONTCARE );
     547        if ( curItem == -1 )
     548            break;
     549        if( prevItem>=0 && curItem>=0 )
     550            if( Compare( prevItem, curItem, prevSortCol ) > 0 )
     551                is_sorted = false;
     552    }
     553    uglyHack = 0;
     554
     555    return is_sorted;
     556}
     557
    537558void
    538559TorrentListCtrl :: Resort( )
    539560{
    540     uglyHack = this;
    541 
    542561    myConfig->Write( _T("torrent-sort-column"), columnKeys[abs(prevSortCol)] );
    543562    myConfig->Write( _T("torrent-sort-is-descending"), prevSortCol < 0 );
    544563
    545     SortItems( Compare, prevSortCol );
    546 
    547     const int n = GetItemCount ();
    548     str2int_t tmp;
    549     for( int i=0; i<n; ++i ) {
    550         int idx = GetItemData( i );
    551         const tr_info_t* info = tr_torrentInfo( myTorrents[idx] );
    552         tmp[info->hashString] = i;
    553     }
    554     myHashToItem.swap( tmp );
    555     uglyHack = NULL;
     564    if( !IsSorted ( ) )
     565    {
     566        uglyHack = this;
     567        SortItems( Compare, prevSortCol );
     568
     569        const int n = GetItemCount ();
     570        str2int_t tmp;
     571        for( int i=0; i<n; ++i ) {
     572            int idx = GetItemData( i );
     573            const tr_info_t* info = tr_torrentInfo( myTorrents[idx] );
     574            tmp[info->hashString] = i;
     575        }
     576        myHashToItem.swap( tmp );
     577        uglyHack = NULL;
     578    }
    556579}
    557580
  • trunk/wx/torrent-list.h

    r2849 r2914  
    121121        void OnItemSelected( wxListEvent& );
    122122        void OnItemDeselected( wxListEvent& );
    123 
     123        bool IsSorted( ) const;
    124124
    125125    private:
Note: See TracChangeset for help on using the changeset viewer.