[Bugfix] open_plugin_browse() not showing plugins

rockbox_browse() overrides the desired dirfilter with
global_settings.dirfilter if you aren't using one of the
SHOW_ modes > NUM_FILTER_MODES (which come with their own sideeffects)

add flag BROWSE_DIRFILTER to
override global_settings.dirfilter with browse_context.dirfilter

add ability to set tc->browse to NULL to exit dirbrowse immediately

Change-Id: I2f40d394f9dc0864b2041293eda219f7436a7bf0
This commit is contained in:
William Wilgus 2023-03-18 03:28:12 -04:00
parent b6d04d1ac0
commit 0c29d1788e
3 changed files with 24 additions and 5 deletions

View file

@ -344,8 +344,25 @@ retnhash:
return hash;
}
/* only displays directories and .rock files */
static bool callback_show_item(char *name, int attr, struct tree_context *tc)
{
(void)name;
if(attr & ATTR_DIRECTORY)
{
if (strstr(tc->currdir, PLUGIN_DIR) != NULL)
return true;
tc->browse = NULL; /* exit immediately */
}
else if(attr & FILE_ATTR_ROCK)
{
return true;
}
return false;
}
/* open_plugin_browse()
* allows fthe user to browse for a plugin to set to a supplied key
* allows the user to browse for a plugin to set to a supplied key
* if key is a lang_id that is used otherwise a hash of the key is created
* for later recall of the plugin path
*/
@ -361,17 +378,18 @@ void open_plugin_browse(const char *key)
(key ? P2STR((unsigned char *)key):"No Key"), open_plugin_entry.name);
logf("OP browse %s %s", op_entry->path, op_entry->param);
if (op_entry->path[0] == '\0')
if (op_entry->path[0] == '\0' || !file_exists(op_entry->path))
strcpy(op_entry->path, PLUGIN_DIR"/");
struct browse_context browse = {
.dirfilter = SHOW_ALL,
.flags = BROWSE_SELECTONLY,
.flags = BROWSE_SELECTONLY | BROWSE_NO_CONTEXT_MENU | BROWSE_DIRFILTER,
.title = str(LANG_OPEN_PLUGIN),
.icon = Icon_Plugin,
.root = op_entry->path,
.buf = tmp_buf,
.bufsize = sizeof(tmp_buf),
.callback_show_item = callback_show_item,
};
if (rockbox_browse(&browse) == GO_TO_PREVIOUS)

View file

@ -652,7 +652,7 @@ static int dirbrowse(void)
return GO_TO_PREVIOUS; /* No files found for rockbox_browse() */
}
while(1) {
while(tc.browse) {
bool restore = false;
if (tc.dirlevel < 0)
tc.dirlevel = 0; /* shouldnt be needed.. this code needs work! */
@ -1018,7 +1018,7 @@ int rockbox_browse(struct browse_context *browse)
}
else
{
if (dirfilter != SHOW_ID3DB)
if (dirfilter != SHOW_ID3DB && (browse->flags & BROWSE_DIRFILTER) == 0)
tc.dirfilter = &global_settings.dirfilter;
tc.browse = browse;
strmemccpy(current, browse->root, MAX_PATH);

View file

@ -38,6 +38,7 @@ struct entry {
#define BROWSE_SELECTONLY 0x0001 /* exit on selecting a file */
#define BROWSE_NO_CONTEXT_MENU 0x0002 /* disable context menu */
#define BROWSE_RUNFILE 0x0004 /* do ft_open() on the file instead of browsing */
#define BROWSE_DIRFILTER 0x0080 /* override global_settings.dirfilter with browse_context.dirfilter */
#define BROWSE_SELECTED 0x0100 /* this bit is set if user selected item */