Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

[Feature] shortcuts_view plugin remember last item and return to it on menu cancel

Also adds the ability to supply a directory without the final slash
you then are take to the directory but have the ability to travel
up one level above before exiting
when you hit cancel

Change-Id: I1091fbe496e2c7c34ecb2113ab1cd31b0c678d9d

authored by

William Wilgus and committed by
William Wilgus
3c9233e9 db477bde

+20 -14
+20 -14
apps/plugins/shortcuts/shortcuts_view.c
··· 43 43 char *buffer, size_t buffer_len); 44 44 45 45 /* Returns LOOP_EXIT iff we should leave the main loop */ 46 - int list_sc(void); 46 + int list_sc(int *selected_item); 47 47 48 48 int goto_entry(char *file_or_dir); 49 49 bool ends_with(char *str, char *suffix); ··· 98 98 } 99 99 100 100 101 - int list_sc(void) 101 + int list_sc(int *selected_item) 102 102 { 103 - int selected_item = 0; 104 103 enum sc_list_action_type action = SCLA_NONE; 105 104 struct gui_synclist gui_sc; 106 105 ··· 110 109 rb->gui_synclist_set_title(&gui_sc, 111 110 (user_file?"Shortcuts (sealed)":"Shortcuts (editable)"), NOICON); 112 111 rb->gui_synclist_set_nb_items(&gui_sc, sc_file.entry_cnt); 113 - rb->gui_synclist_select_item(&gui_sc, 0); 112 + rb->gui_synclist_select_item(&gui_sc, *selected_item); 114 113 115 114 /* Draw the prepared widget to the LCD now */ 116 115 action = draw_sc_list(&gui_sc); ··· 119 118 } 120 119 121 120 /* which item do we action? */ 122 - selected_item = rb->gui_synclist_get_sel_pos(&gui_sc); 121 + *selected_item = rb->gui_synclist_get_sel_pos(&gui_sc); 123 122 124 - if (!is_valid_index(&sc_file, selected_item)) { 123 + if (!is_valid_index(&sc_file, *selected_item)) { 125 124 /* This should never happen */ 126 125 rb->splash(HZ*2, "Bad entry selected!"); 127 126 return PLUGIN_ERROR; ··· 132 131 * in the filebrowser tree */ 133 132 switch(action) { 134 133 case SCLA_SELECT: 135 - return goto_entry(sc_file.entries[selected_item].path); 134 + return goto_entry(sc_file.entries[*selected_item].path); 136 135 case SCLA_DELETE: 137 - rb->splashf(HZ, "Deleting %s", sc_file.entries[selected_item].disp); 138 - remove_entry(&sc_file, selected_item); 136 + rb->splashf(HZ, "Deleting %s", sc_file.entries[*selected_item].disp); 137 + remove_entry(&sc_file, *selected_item); 139 138 dump_sc_file(&sc_file, link_filename); 140 139 return (sc_file.entry_cnt == 0)? LOOP_EXIT : PLUGIN_OK; 141 140 default: ··· 180 179 (void)name; 181 180 if(attr & ATTR_DIRECTORY) 182 181 { 183 - if ((tc->browse->flags & BROWSE_SELECTED) == 0 && 184 - rb->strlen(tc->currdir) < root_len) 182 + if ((tc->browse->flags & BROWSE_SELECTED) == 0) 185 183 { 186 - tc->is_browsing = false; /* exit immediately */ 184 + size_t curlen = rb->strlen(tc->currdir); 185 + if (curlen < root_len) 186 + tc->is_browsing = false; /* exit immediately */ 187 + else if (curlen == root_len) 188 + tc->browse->title = tc->currdir; 187 189 } 188 190 } 189 191 ··· 202 204 .bufsize = bufsz, 203 205 .callback_show_item = callback_show_item, 204 206 }; 207 + 208 + /* if the final slash isn't included return brings you up a level, feature not bug. */ 205 209 root_len = 0; 206 210 char *name = rb->strrchr(path, '/'); 207 211 if (name) ··· 215 219 { 216 220 DEBUGF("Trying to go to '%s'...\n", file_or_dir); 217 221 218 - bool is_dir = ends_with(file_or_dir, PATH_SEPARATOR); 222 + bool is_dir = ends_with(file_or_dir, PATH_SEPARATOR) || rb->dir_exists(file_or_dir); 219 223 bool exists; 220 224 char *what; 221 225 if (is_dir) { ··· 297 301 FOR_NB_SCREENS(i) 298 302 rb->viewportmanager_theme_enable(i, true, NULL); 299 303 304 + int selected_item = 0; 300 305 do { 301 306 /* Display a menu to choose between the entries */ 302 - ret = list_sc(); 307 + DEBUGF("list_sc(%d)\n", selected_item); 308 + ret = list_sc(&selected_item); 303 309 } while (ret == PLUGIN_OK); 304 310 if (ret == LOOP_EXIT) 305 311 ret = PLUGIN_OK;