revisit file selector
authorkub <derkub@gmail.com>
Thu, 23 Nov 2023 20:56:44 +0000 (20:56 +0000)
committernotaz <notasas@gmail.com>
Sun, 10 Dec 2023 21:23:07 +0000 (23:23 +0200)
- display help
- add draw callback for window resizing
- fix small memory leak

menu.c

diff --git a/menu.c b/menu.c
index ae61038..5d96b7e 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -994,10 +994,11 @@ static int dirent_seek_char(struct dirent **namelist, int len, int sel, char c)
        return i;\r
 }\r
 \r
-static const char *menu_loop_romsel(char *curr_path, int len,\r
+static const char *menu_loop_romsel_d(char *curr_path, int len,\r
        const char **filter_exts,\r
        int (*extra_filter)(struct dirent **namelist, int count,\r
-                           const char *basedir))\r
+                           const char *basedir),\r
+       void (*draw_prep)(void))\r
 {\r
        static char rom_fname_reload[256]; // used for scratch and return\r
        char sel_fname[256];\r
@@ -1020,13 +1021,12 @@ static const char *menu_loop_romsel(char *curr_path, int len,
                        curr_path_restore = p;\r
                        snprintf(sel_fname, sizeof(sel_fname), "%s", p + 1);\r
                }\r
-\r
-               if (rom_fname_reload[0] == 0)\r
-                       show_help = 2;\r
        }\r
+       show_help = 2;\r
 \r
 rescan:\r
        if (namelist != NULL) {\r
+               n += !n;\r
                while (n-- > 0)\r
                        free(namelist[n]);\r
                free(namelist);\r
@@ -1099,6 +1099,8 @@ rescan:
 \r
        for (;;)\r
        {\r
+               if (draw_prep != NULL)\r
+                       draw_prep();\r
                draw_dirlist(curr_path, namelist, n, sel, show_help);\r
                inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT\r
                        | PBTN_L|PBTN_R|PBTN_MA2|PBTN_MA3|PBTN_MOK|PBTN_MBACK\r
@@ -1107,6 +1109,7 @@ rescan:
                        g_menu_filter_off = !g_menu_filter_off;\r
                        snprintf(sel_fname, sizeof(sel_fname), "%s",\r
                                namelist[sel]->d_name);\r
+                       show_help = 2;\r
                        goto rescan;\r
                }\r
                int last = n ? n-1 : 0;\r
@@ -1156,7 +1159,7 @@ rescan:
                                        strcat(newdir, "/");\r
                                        strcat(newdir, namelist[sel]->d_name);\r
                                }\r
-                               ret = menu_loop_romsel(newdir, newlen, filter_exts, extra_filter);\r
+                               ret = menu_loop_romsel_d(newdir, newlen, filter_exts, extra_filter, draw_prep);\r
                                free(newdir);\r
                                break;\r
                        }\r
@@ -1190,6 +1193,14 @@ rescan:
        return ret;\r
 }\r
 \r
+static const char *menu_loop_romsel(char *curr_path, int len,\r
+       const char **filter_exts,\r
+       int (*extra_filter)(struct dirent **namelist, int count,\r
+                           const char *basedir))\r
+{\r
+       return menu_loop_romsel_d(curr_path, len, filter_exts, extra_filter, NULL);\r
+}\r
+\r
 // ------------ savestate loader ------------\r
 \r
 #define STATE_SLOT_COUNT 10\r