diff --git a/menu.cpp b/menu.cpp index b696c53..dc81a00 100644 --- a/menu.cpp +++ b/menu.cpp @@ -3992,6 +3992,10 @@ void HandleUI(void) if (flist_nDirEntries()) { + static char prefix[256]; + static unsigned long prefix_typing_timer = 0; + int prefix_len = strlen(prefix); + ScrollLongName(); // scrolls file name if longer than display line if (c == KEY_HOME) @@ -4019,6 +4023,17 @@ void HandleUI(void) menustate = MENU_FILE_SELECT1; } + if (c == KEY_BACKSPACE && prefix_len > 0) + { + memset(prefix, 0, 256); + prefix_typing_timer = 0; + + printf("Prefix is: %s\n", prefix); + ScanDirectory(selPath, SCANF_INIT, fs_pFileExt, fs_Options); + + menustate = MENU_FILE_SELECT1; + } + if (down) // scroll down one entry { ScanDirectory(selPath, SCANF_NEXT, fs_pFileExt, fs_Options); @@ -4035,14 +4050,37 @@ void HandleUI(void) int i; if ((i = GetASCIIKey(c)) > 1) { - // find an entry beginning with given character - ScanDirectory(selPath, i, fs_pFileExt, fs_Options); + if (CheckTimer(prefix_typing_timer)) + { + memset(prefix, 0, 256); + prefix[0] = (char)i; + + // You need both ScanDirectory calls here: the first + // call "clears" the prefix, the second one scrolls to + // the right place in the list + ScanDirectory(selPath, SCANF_INIT, fs_pFileExt, fs_Options); + ScanDirectory(selPath, i, fs_pFileExt, fs_Options); + } + else if (prefix_len < 255) + { + prefix[prefix_len] = (char)i; + + ScanDirectory(selPath, SCANF_INIT, fs_pFileExt, fs_Options, prefix); + } + + prefix_typing_timer = GetTimer(2000); + printf("Prefix is: %s\n", prefix); + menustate = MENU_FILE_SELECT1; } } if (select) { + memset(prefix, 0, 256); + prefix_typing_timer = 0; + printf("Prefix is: %s\n", prefix); + static char name[256]; char type = flist_SelectedItem()->de.d_type; memcpy(name, flist_SelectedItem()->de.d_name, sizeof(name));