browser fix

This commit is contained in:
dborth 2010-08-31 17:08:32 +00:00
parent d0813f8281
commit 4570bac667
2 changed files with 43 additions and 33 deletions

View File

@ -542,40 +542,7 @@ bool ParseDirEntries()
// Sort the file list
if(i >= 0)
{
qsort(browserList, browser.numEntries+i, sizeof(BROWSERENTRY), FileSortCallback);
}
// try to find and select the last loaded file
if(selectLoadedFile == 1 && res != 0 && loadedFile[0] != 0 && browser.dir[0] != 0)
{
int indexFound = -1;
for(int j=1; j < browser.numEntries + i; j++)
{
if(strcmp(browserList[j].filename, loadedFile) == 0)
{
indexFound = j;
break;
}
}
// move to this file
if(indexFound > 0)
{
if(indexFound > FILE_PAGESIZE)
{
browser.pageIndex = (ceil(indexFound/FILE_PAGESIZE*1.0)) * FILE_PAGESIZE;
if(browser.pageIndex + FILE_PAGESIZE > browser.numEntries + i)
{
browser.pageIndex = browser.numEntries + i - FILE_PAGESIZE;
}
}
browser.selIndex = indexFound;
}
selectLoadedFile = 2; // selecting done
}
browser.numEntries += i;
@ -583,6 +550,41 @@ bool ParseDirEntries()
{
dirclose(dirIter); // close directory
dirIter = NULL;
// try to find and select the last loaded file
if(selectLoadedFile == 1 && parseHalt == 0 && loadedFile[0] != 0 && browser.dir[0] != 0)
{
int indexFound = -1;
for(int j=1; j < browser.numEntries; j++)
{
if(strcmp(browserList[j].filename, loadedFile) == 0)
{
indexFound = j;
break;
}
}
// move to this file
if(indexFound > 0)
{
if(indexFound >= FILE_PAGESIZE)
{
int newIndex = (floor(indexFound/(float)FILE_PAGESIZE)) * FILE_PAGESIZE;
if(newIndex + FILE_PAGESIZE > browser.numEntries)
newIndex = browser.numEntries - FILE_PAGESIZE;
if(newIndex < 0)
newIndex = 0;
browser.pageIndex = newIndex;
}
browser.selIndex = indexFound;
}
selectLoadedFile = 2; // selecting done
}
return false; // no more entries
}
return true; // more entries

View File

@ -199,6 +199,14 @@ void GuiFileBrowser::ResetState()
void GuiFileBrowser::TriggerUpdate()
{
int newIndex = browser.selIndex-browser.pageIndex;
if(newIndex >= FILE_PAGESIZE)
newIndex = FILE_PAGESIZE-1;
else if(newIndex < 0)
newIndex = 0;
selectedItem = newIndex;
listChanged = true;
}