From e3097bf92c9fc74ed3b724caf338dd24d7f21621 Mon Sep 17 00:00:00 2001 From: William Wilgus Date: Tue, 30 Jul 2024 12:47:36 -0400 Subject: [Feature] File Picker Plugin allows viewers to pop a file browser to let the user pick a relevant file which then gets run by the viewer (only lua so far) Change-Id: I7e6b4c2827fab5e9f596d336f546100636c4b871 --- apps/plugins/lua/rocklua.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'apps/plugins/lua') diff --git a/apps/plugins/lua/rocklua.c b/apps/plugins/lua/rocklua.c index 3cf0fce945..650c4d6dae 100644 --- a/apps/plugins/lua/rocklua.c +++ b/apps/plugins/lua/rocklua.c @@ -241,6 +241,20 @@ static void display_traceback(const char *errstr) rb->splash(10 * HZ, errstr); #endif } + +int browse_scripts(void) +{ + static char buf[MAX_PATH]; + const char *fname = rb->plugin_get_current_filename(); + /* strip plugin dir to save space in the param buffer */ + if (rb->strncmp(fname, PLUGIN_DIR, sizeof(PLUGIN_DIR) - 1) == 0) + fname += sizeof(PLUGIN_DIR) - 1; /* leave slash */ + /* -r return to this plugin, -f looking for lua files, + -s start in lua_scripts, -d lock to that directory */ + snprintf(buf, sizeof(buf), "-r'%s'-f'.lua'-s'%s'-d", + fname, PLUGIN_DEMOS_DIR"/lua_scripts/"); + return rb->plugin_open(VIEWERS_DIR "/file_picker.rock", buf); +} /***************** Plugin Entry Point *****************/ enum plugin_status plugin_start(const void* parameter) { @@ -249,7 +263,10 @@ enum plugin_status plugin_start(const void* parameter) if (parameter == NULL) { if (!Ls) + { rb->splash(HZ, "Play a .lua file!"); + return browse_scripts(); + } } else { -- cgit v1.2.3