diff --git a/uppsrc/CtrlLib/FileSel.cpp b/uppsrc/CtrlLib/FileSel.cpp index bcd9968af..6167c6622 100644 --- a/uppsrc/CtrlLib/FileSel.cpp +++ b/uppsrc/CtrlLib/FileSel.cpp @@ -365,31 +365,47 @@ void LazyFileIcons::Do() return; } int tm = GetTickCount(); - while(pos < list->GetCount()) { + while(pos < ndx.GetCount()) { if((int)GetTickCount() - tm > ptime) { ptime = 50; Restart(0); return; } - const FileList::File& f = list->Get(pos); - if(ToLower(GetFileExt(f.name)) == ".exe") { - int t0 = GetTickCount(); + int ii = ndx[pos]; + if(ii < 0 || ii >= list->GetCount()) + return; + const FileList::File& f = list->Get(ii); + int t0 = GetTickCount(); #ifdef PLATFORM_WIN32 - Image img = GetFileIcon(AppendFileName(dir, f.name), f.isdir, f.unixexe, false, quick); + Image img = GetFileIcon(AppendFileName(dir, f.name), f.isdir, f.unixexe, false, quick); #else - Image img = GetFileIcon(dir, f.name, f.isdir, f.unixexe, false); + Image img = GetFileIcon(dir, f.name, f.isdir, f.unixexe, false); #endif - WhenIcon(f.isdir, f.name, img); - if(f.hidden) - img = Contrast(img, 200); - list->SetIcon(pos, img); - if(GetTickCount() - t0 > 500/* || GetTickCount() - start > 1500*/) - return; - } + WhenIcon(f.isdir, f.name, img); + if(f.hidden) + img = Contrast(img, 200); + list->SetIcon(ii, img); + if(GetTickCount() - t0 > 700) + return; pos++; } } +void LazyFileIcons::ReOrder() +{ + ndx.Clear(); + Vector len; + for(int i = 0; i < list->GetCount(); i++) { + const FileList::File& f = list->Get(i); + if(ToLower(GetFileExt(f.name)) == ".exe" && !f.isdir) { + ndx.Add(i); + len.Add((int)min((int64)INT_MAX, f.length)); + } + } + IndexSort(len, ndx); + Restart(0); +} + void LazyFileIcons::Start(FileList& list_, const String& dir_, Callback3 WhenIcon_) { list = &list_; @@ -399,7 +415,7 @@ void LazyFileIcons::Start(FileList& list_, const String& dir_, Callback3 ndx; Callback3 WhenIcon; void Do(); void Restart(int delay) { tm.KillSet(delay, callback(this, &LazyFileIcons::Do)); } public: + void ReOrder(); void Start(FileList& list_, const String& dir_, Callback3 WhenIcon_); };