pressing a-z will jump to the next list entry starting with that letter

This commit is contained in:
penfold42 2018-08-01 00:43:52 +10:00
parent 8fe97363e7
commit df58673e65
5 changed files with 67 additions and 47 deletions

View file

@ -308,6 +308,46 @@ bool FileBrowser::BrowsableListView::CheckBrowseNavigation(bool pageOnly)
dirty = true;
}
// check for keys a-z
if (inputMappings->BrowseLetter())
{
char temp[8];
unsigned found=0;
u32 i=0;
snprintf (temp, sizeof(temp), "%c", inputMappings->getKeyboardLetter());
// first look from next to last
for (i=1+list->currentIndex; i <= numberOfEntriesMinus1 ; i++)
{
FileBrowser::BrowsableList::Entry* entry = &list->entries[i];
if (strncasecmp(temp, entry->filImage.fname, 1) == 0)
{
found=i;
break;
}
}
if (!found)
{
// look from first to previous
for (i=0; i< 1+list->currentIndex ; i++)
{
FileBrowser::BrowsableList::Entry* entry = &list->entries[i];
if (strncasecmp(temp, entry->filImage.fname, 1) == 0)
{
found=i;
break;
}
}
}
if (found)
{
list->currentIndex=found;
list->SetCurrent();
dirty = true;
}
}
return dirty;
}
@ -364,28 +404,6 @@ FileBrowser::BrowsableList::Entry* FileBrowser::BrowsableList::FindEntry(const c
return 0;
}
FileBrowser::BrowsableList::Entry* FileBrowser::BrowsableList::FindNextPartialEntry(const char* name, int match_len)
{
int index;
int len = (int)entries.size();
for (index = 0; index < len; ++index)
{
Entry* entry = &entries[index];
if (match_len) // partial match
{
if (strncasecmp(name, entry->filImage.fname, match_len) == 0)
return entry;
}
else // full match
{
if (strcasecmp(name, entry->filImage.fname) == 0)
return entry;
}
}
return 0;
}
FileBrowser::FileBrowser(DiskCaddy* diskCaddy, ROMs* roms, u8* deviceID, bool displayPNGIcons, ScreenBase* screenMain, ScreenBase* screenLCD, float scrollHighlightRate)
: state(State_Folders)
, diskCaddy(diskCaddy)
@ -994,15 +1012,6 @@ void FileBrowser::UpdateInputFolders()
SelectROMOrDevice(inputMappings->getKeyboardNumber());
}
// check for keys a-z
if ( keyboard->KeyAnyHeld() && !keyboard->KeyEitherAlt() )
for (unsigned i=KEY_A; i<=KEY_Z; i++)
{
if (keyboard->KeyPressed( i ))
{
char ascKey = i-KEY_A+'A';
}
}
dirty = folder.CheckBrowseNavigation();
}

View file

@ -151,7 +151,6 @@ public:
};
Entry* FindEntry(const char* name);
Entry* FindNextPartialEntry(const char* name, int match_len);
int FindNextAutoName(char* basename);
void RefreshViews();

View file

@ -195,23 +195,26 @@ bool InputMappings::CheckKeyboardBrowseMode()
SetKeyboardFlag(WRITEPROTECT_FLAG);
else
{
unsigned index;
for (index = 0; index < sizeof(NumberKeys)/sizeof(NumberKeys[0]); index+=3)
if (keyboard->KeyNoModifiers())
{
if (keyboard->KeyHeld(NumberKeys[index])
|| keyboard->KeyHeld(NumberKeys[index + 1])
|| keyboard->KeyHeld(NumberKeys[index + 2]) )
unsigned index;
for (index = 0; index < sizeof(NumberKeys)/sizeof(NumberKeys[0]); index+=3)
{
SetKeyboardFlag(NUMBER_FLAG);
keyboardNumber = index/3;
if (keyboard->KeyHeld(NumberKeys[index])
|| keyboard->KeyHeld(NumberKeys[index + 1])
|| keyboard->KeyHeld(NumberKeys[index + 2]) )
{
SetKeyboardFlag(NUMBER_FLAG);
keyboardNumber = index/3; // key 1 is 0
}
}
}
for (index = KEY_A; index <= KEY_Z; ++index)
{
if (keyboard->KeyHeld(index))
for (index = KEY_A; index <= KEY_Z; ++index)
{
SetKeyboardFlag(AtoZ_FLAG);
keyboardNumber = index-KEY_A+1;
if (keyboard->KeyHeld(index))
{
SetKeyboardFlag(LETTER_FLAG);
keyboardLetter = index-KEY_A+'A'; // key A is ascii 'A'
}
}
}
}

View file

@ -41,7 +41,7 @@
#define AUTOLOAD_FLAG (1 << 15)
#define FAKERESET_FLAG (1 << 16)
#define WRITEPROTECT_FLAG (1 << 17)
#define AtoZ_FLAG (1 << 18)
#define LETTER_FLAG (1 << 18)
// dont exceed 32!!
const unsigned NumberKeys[33] =
@ -203,8 +203,13 @@ public:
return KeyboardFlag(NUMBER_FLAG);
}
inline bool BrowseLetter()
{
return KeyboardFlag(LETTER_FLAG);
}
inline unsigned getKeyboardNumber() { return keyboardNumber; }
inline unsigned getKeyboardLetter() { return keyboardLetter; }
inline char getKeyboardLetter() { return (char) keyboardLetter; }
// Used by the 2 cores so need to be volatile
//volatile static unsigned directDiskSwapRequest;

View file

@ -348,5 +348,9 @@ public:
{
return (modifier & (KEY_MOD_LALT | KEY_MOD_RALT) );
}
inline bool KeyNoModifiers()
{
return (!modifier );
}
};
#endif