From df58673e65b879452fce1ba230d8455bf7290e8f Mon Sep 17 00:00:00 2001 From: penfold42 Date: Wed, 1 Aug 2018 00:43:52 +1000 Subject: [PATCH] pressing a-z will jump to the next list entry starting with that letter --- src/FileBrowser.cpp | 71 ++++++++++++++++++++++++------------------- src/FileBrowser.h | 1 - src/InputMappings.cpp | 29 ++++++++++-------- src/InputMappings.h | 9 ++++-- src/Keyboard.h | 4 +++ 5 files changed, 67 insertions(+), 47 deletions(-) diff --git a/src/FileBrowser.cpp b/src/FileBrowser.cpp index 74337f8..518fd6c 100644 --- a/src/FileBrowser.cpp +++ b/src/FileBrowser.cpp @@ -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(); } diff --git a/src/FileBrowser.h b/src/FileBrowser.h index 4db2861..d6de6cc 100644 --- a/src/FileBrowser.h +++ b/src/FileBrowser.h @@ -151,7 +151,6 @@ public: }; Entry* FindEntry(const char* name); - Entry* FindNextPartialEntry(const char* name, int match_len); int FindNextAutoName(char* basename); void RefreshViews(); diff --git a/src/InputMappings.cpp b/src/InputMappings.cpp index 62443d1..1e23883 100644 --- a/src/InputMappings.cpp +++ b/src/InputMappings.cpp @@ -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' + } } } } diff --git a/src/InputMappings.h b/src/InputMappings.h index f4cd801..9bf610b 100644 --- a/src/InputMappings.h +++ b/src/InputMappings.h @@ -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; diff --git a/src/Keyboard.h b/src/Keyboard.h index ad0e631..774ef6c 100644 --- a/src/Keyboard.h +++ b/src/Keyboard.h @@ -348,5 +348,9 @@ public: { return (modifier & (KEY_MOD_LALT | KEY_MOD_RALT) ); } + inline bool KeyNoModifiers() + { + return (!modifier ); + } }; #endif