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; 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; return dirty;
} }
@ -364,28 +404,6 @@ FileBrowser::BrowsableList::Entry* FileBrowser::BrowsableList::FindEntry(const c
return 0; 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) FileBrowser::FileBrowser(DiskCaddy* diskCaddy, ROMs* roms, u8* deviceID, bool displayPNGIcons, ScreenBase* screenMain, ScreenBase* screenLCD, float scrollHighlightRate)
: state(State_Folders) : state(State_Folders)
, diskCaddy(diskCaddy) , diskCaddy(diskCaddy)
@ -994,15 +1012,6 @@ void FileBrowser::UpdateInputFolders()
SelectROMOrDevice(inputMappings->getKeyboardNumber()); 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(); dirty = folder.CheckBrowseNavigation();
} }

View file

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

View file

@ -194,6 +194,8 @@ bool InputMappings::CheckKeyboardBrowseMode()
else if (keyboard->KeyHeld(KEY_W) && keyboard->KeyEitherAlt() ) else if (keyboard->KeyHeld(KEY_W) && keyboard->KeyEitherAlt() )
SetKeyboardFlag(WRITEPROTECT_FLAG); SetKeyboardFlag(WRITEPROTECT_FLAG);
else else
{
if (keyboard->KeyNoModifiers())
{ {
unsigned index; unsigned index;
for (index = 0; index < sizeof(NumberKeys)/sizeof(NumberKeys[0]); index+=3) for (index = 0; index < sizeof(NumberKeys)/sizeof(NumberKeys[0]); index+=3)
@ -203,15 +205,16 @@ bool InputMappings::CheckKeyboardBrowseMode()
|| keyboard->KeyHeld(NumberKeys[index + 2]) ) || keyboard->KeyHeld(NumberKeys[index + 2]) )
{ {
SetKeyboardFlag(NUMBER_FLAG); SetKeyboardFlag(NUMBER_FLAG);
keyboardNumber = index/3; keyboardNumber = index/3; // key 1 is 0
} }
} }
for (index = KEY_A; index <= KEY_Z; ++index) for (index = KEY_A; index <= KEY_Z; ++index)
{ {
if (keyboard->KeyHeld(index)) if (keyboard->KeyHeld(index))
{ {
SetKeyboardFlag(AtoZ_FLAG); SetKeyboardFlag(LETTER_FLAG);
keyboardNumber = index-KEY_A+1; keyboardLetter = index-KEY_A+'A'; // key A is ascii 'A'
}
} }
} }
} }

View file

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

View file

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