User can now type more than one letter to narrow down the search.
This commit is contained in:
parent
9b902f19bf
commit
07143696fe
2 changed files with 76 additions and 23 deletions
|
@ -333,6 +333,18 @@ bool FileBrowser::BrowsableListView::CheckBrowseNavigation(bool pageOnly)
|
||||||
return dirty;
|
return dirty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileBrowser::BrowsableList::BrowsableList()
|
||||||
|
: current(0)
|
||||||
|
, currentIndex(0)
|
||||||
|
, currentHighlightTime(0)
|
||||||
|
, scrollHighlightRate(0)
|
||||||
|
, searchPrefixIndex(0)
|
||||||
|
, searchLastKeystrokeTime(0)
|
||||||
|
{
|
||||||
|
lastUpdateTime = read32(ARM_SYSTIMER_CLO);
|
||||||
|
searchPrefix[0] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void FileBrowser::BrowsableList::ClearSelections()
|
void FileBrowser::BrowsableList::ClearSelections()
|
||||||
{
|
{
|
||||||
u32 entryIndex;
|
u32 entryIndex;
|
||||||
|
@ -368,6 +380,21 @@ bool FileBrowser::BrowsableList::CheckBrowseNavigation()
|
||||||
|
|
||||||
bool dirty = false;
|
bool dirty = false;
|
||||||
u32 index;
|
u32 index;
|
||||||
|
|
||||||
|
// Calculate the number of micro seconds since we were last called.
|
||||||
|
u32 updateTime = read32(ARM_SYSTIMER_CLO);
|
||||||
|
u32 timeDelta;
|
||||||
|
if (updateTime < lastUpdateTime)
|
||||||
|
timeDelta = updateTime + (0xffffffff - lastUpdateTime); // wrapped
|
||||||
|
else
|
||||||
|
timeDelta = updateTime - lastUpdateTime;
|
||||||
|
lastUpdateTime = updateTime;
|
||||||
|
|
||||||
|
if (searchPrefixIndex != 0) // Are they typing?
|
||||||
|
{
|
||||||
|
searchLastKeystrokeTime += timeDelta;
|
||||||
|
}
|
||||||
|
|
||||||
for (index = 0; index < views.size(); ++index)
|
for (index = 0; index < views.size(); ++index)
|
||||||
{
|
{
|
||||||
dirty |= views[index].CheckBrowseNavigation(index != 0);
|
dirty |= views[index].CheckBrowseNavigation(index != 0);
|
||||||
|
@ -380,11 +407,21 @@ bool FileBrowser::BrowsableList::CheckBrowseNavigation()
|
||||||
unsigned found=0;
|
unsigned found=0;
|
||||||
u32 i=0;
|
u32 i=0;
|
||||||
|
|
||||||
|
searchLastKeystrokeTime = 0;
|
||||||
|
|
||||||
|
searchPrefix[searchPrefixIndex] = searchChar;
|
||||||
|
if (searchPrefixIndex < KEYBOARD_SEARCH_BUFFER_SIZE - 1)
|
||||||
|
{
|
||||||
|
searchPrefixIndex++;
|
||||||
|
searchPrefix[searchPrefixIndex] = 0;
|
||||||
|
dirty |= 1;
|
||||||
|
}
|
||||||
|
|
||||||
// first look from next to last
|
// first look from next to last
|
||||||
for (i=1+currentIndex; i <= numberOfEntriesMinus1 ; i++)
|
for (i=1+currentIndex; i <= numberOfEntriesMinus1 ; i++)
|
||||||
{
|
{
|
||||||
FileBrowser::BrowsableList::Entry* entry = &entries[i];
|
FileBrowser::BrowsableList::Entry* entry = &entries[i];
|
||||||
if (strncasecmp(&searchChar, entry->filImage.fname, 1) == 0)
|
if (strncasecmp(searchPrefix, entry->filImage.fname, searchPrefixIndex) == 0)
|
||||||
{
|
{
|
||||||
found=i;
|
found=i;
|
||||||
break;
|
break;
|
||||||
|
@ -396,7 +433,7 @@ bool FileBrowser::BrowsableList::CheckBrowseNavigation()
|
||||||
for (i=0; i< 1+currentIndex ; i++)
|
for (i=0; i< 1+currentIndex ; i++)
|
||||||
{
|
{
|
||||||
FileBrowser::BrowsableList::Entry* entry = &entries[i];
|
FileBrowser::BrowsableList::Entry* entry = &entries[i];
|
||||||
if (strncasecmp(&searchChar, entry->filImage.fname, 1) == 0)
|
if (strncasecmp(searchPrefix, entry->filImage.fname, searchPrefixIndex) == 0)
|
||||||
{
|
{
|
||||||
found=i;
|
found=i;
|
||||||
break;
|
break;
|
||||||
|
@ -411,17 +448,28 @@ bool FileBrowser::BrowsableList::CheckBrowseNavigation()
|
||||||
dirty |= 1;
|
dirty |= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (inputMappings->BrowseHome())
|
else
|
||||||
{
|
{
|
||||||
currentIndex = 0;
|
if (searchLastKeystrokeTime > 500000)
|
||||||
SetCurrent();
|
{
|
||||||
dirty |= 1;
|
searchPrefixIndex = 0;
|
||||||
}
|
searchPrefix[0] = 0;
|
||||||
else if (inputMappings->BrowseEnd())
|
searchLastKeystrokeTime = 0;
|
||||||
{
|
dirty |= 1;
|
||||||
currentIndex = numberOfEntriesMinus1;
|
}
|
||||||
SetCurrent();
|
|
||||||
dirty |= 1;
|
if (inputMappings->BrowseHome())
|
||||||
|
{
|
||||||
|
currentIndex = 0;
|
||||||
|
SetCurrent();
|
||||||
|
dirty |= 1;
|
||||||
|
}
|
||||||
|
else if (inputMappings->BrowseEnd())
|
||||||
|
{
|
||||||
|
currentIndex = numberOfEntriesMinus1;
|
||||||
|
SetCurrent();
|
||||||
|
dirty |= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return dirty;
|
return dirty;
|
||||||
}
|
}
|
||||||
|
@ -660,12 +708,11 @@ void FileBrowser::RefeshDisplayForBrowsableList(FileBrowser::BrowsableList* brow
|
||||||
|
|
||||||
void FileBrowser::RefeshDisplay()
|
void FileBrowser::RefeshDisplay()
|
||||||
{
|
{
|
||||||
|
u32 textColour = Colour(VIC2_COLOUR_INDEX_LGREEN);
|
||||||
|
u32 bgColour = Colour(VIC2_COLOUR_INDEX_GREY);
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
if (f_getcwd(buffer, 1024) == FR_OK)
|
if (f_getcwd(buffer, 1024) == FR_OK)
|
||||||
{
|
{
|
||||||
u32 textColour = Colour(VIC2_COLOUR_INDEX_LGREEN);
|
|
||||||
u32 bgColour = Colour(VIC2_COLOUR_INDEX_GREY);
|
|
||||||
|
|
||||||
screenMain->ClearArea(0, 0, (int)screenMain->Width(), 17, bgColour);
|
screenMain->ClearArea(0, 0, (int)screenMain->Width(), 17, bgColour);
|
||||||
screenMain->PrintText(false, 0, 0, buffer, textColour, bgColour);
|
screenMain->PrintText(false, 0, 0, buffer, textColour, bgColour);
|
||||||
}
|
}
|
||||||
|
@ -679,6 +726,12 @@ void FileBrowser::RefeshDisplay()
|
||||||
|
|
||||||
DisplayPNG();
|
DisplayPNG();
|
||||||
DisplayStatusBar();
|
DisplayStatusBar();
|
||||||
|
|
||||||
|
if (folder.searchPrefixIndex > 0)
|
||||||
|
{
|
||||||
|
u32 y = screenMain->ScaleY(STATUS_BAR_POSITION_Y);
|
||||||
|
screenMain->PrintText(false, 0, y, folder.searchPrefix, textColour, bgColour);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileBrowser::CheckForPNG(const char* filename, FILINFO& filIcon)
|
bool FileBrowser::CheckForPNG(const char* filename, FILINFO& filIcon)
|
||||||
|
@ -843,7 +896,7 @@ void FileBrowser::Update()
|
||||||
{
|
{
|
||||||
InputMappings* inputMappings = InputMappings::Instance();
|
InputMappings* inputMappings = InputMappings::Instance();
|
||||||
|
|
||||||
if ( inputMappings->CheckKeyboardBrowseMode() || inputMappings->CheckButtonsBrowseMode() )
|
if ( inputMappings->CheckKeyboardBrowseMode() || inputMappings->CheckButtonsBrowseMode() || (folder.searchPrefixIndex != 0) )
|
||||||
UpdateInputFolders();
|
UpdateInputFolders();
|
||||||
|
|
||||||
UpdateCurrentHighlight();
|
UpdateCurrentHighlight();
|
||||||
|
|
|
@ -48,6 +48,8 @@
|
||||||
|
|
||||||
#define STATUS_BAR_POSITION_Y (40 * 16 + 10)
|
#define STATUS_BAR_POSITION_Y (40 * 16 + 10)
|
||||||
|
|
||||||
|
#define KEYBOARD_SEARCH_BUFFER_SIZE 512
|
||||||
|
|
||||||
class FileBrowser
|
class FileBrowser
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -95,13 +97,7 @@ public:
|
||||||
class BrowsableList
|
class BrowsableList
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BrowsableList()
|
BrowsableList();
|
||||||
: current(0)
|
|
||||||
, currentIndex(0)
|
|
||||||
, currentHighlightTime(0)
|
|
||||||
, scrollHighlightRate(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Clear()
|
void Clear()
|
||||||
{
|
{
|
||||||
|
@ -163,6 +159,10 @@ public:
|
||||||
float currentHighlightTime;
|
float currentHighlightTime;
|
||||||
float scrollHighlightRate;
|
float scrollHighlightRate;
|
||||||
|
|
||||||
|
u32 lastUpdateTime;
|
||||||
|
char searchPrefix[KEYBOARD_SEARCH_BUFFER_SIZE];
|
||||||
|
u32 searchPrefixIndex;
|
||||||
|
u32 searchLastKeystrokeTime;
|
||||||
std::vector<BrowsableListView> views;
|
std::vector<BrowsableListView> views;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue