diff options
author | Paul Golter <paulgolter> | 2021-10-14 15:40:48 +0300 |
---|---|---|
committer | Sebastian Parborg <darkdefende@gmail.com> | 2021-10-14 15:42:43 +0300 |
commit | 240345842dd1594709433df1ff3448c55968254d (patch) | |
tree | e16d86c3e2b1f43e1c2750cb9631b81f64aaa551 /source/blender/editors/space_file | |
parent | 9ca567bc4e99403c2574f823922933da5cbc20ec (diff) |
Filebrowser: Expose file select functions for File Browser to Python API.
This patch adds activate_file_by_relative_path(relative_path="") and
deselect_all() function to the space api of the File Browser. While the
first sets the active file and adds it to the selection based on a
relative path to the current File Browser directory the second one
deselects all files but does not change the active file.
Differential Revision: https://developer.blender.org/D12826
Reviewed by: Julian Eisel
Diffstat (limited to 'source/blender/editors/space_file')
-rw-r--r-- | source/blender/editors/space_file/filesel.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index 83b33fe8aa9..fc9fc6799e1 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -528,6 +528,43 @@ void ED_fileselect_activate_by_id(SpaceFile *sfile, ID *asset_id, const bool def WM_main_add_notifier(NC_ASSET | NA_SELECTED, NULL); } +static void on_reload_select_by_relpath(SpaceFile *sfile, onReloadFnData custom_data) +{ + char *relative_path = (char *)custom_data; + ED_fileselect_activate_by_relpath(sfile, relative_path); +} + +void ED_fileselect_activate_by_relpath(SpaceFile *sfile, const char *relative_path) +{ + /* If there are filelist operations running now ("pending" true) or soon ("force reset" true), + * there is a fair chance that the to-be-activated file at relative_path will only be present + * after these operations have completed. Defer activation until then. */ + struct FileList *files = sfile->files; + if (files == NULL || filelist_pending(files) || filelist_needs_force_reset(files)) { + file_on_reload_callback_register(sfile, on_reload_select_by_relpath, relative_path); + return; + } + + FileSelectParams *params = ED_fileselect_get_active_params(sfile); + const int num_files_filtered = filelist_files_ensure(files); + + for (int file_index = 0; file_index < num_files_filtered; ++file_index) { + const FileDirEntry *file = filelist_file(files, file_index); + + if (STREQ(file->relpath, relative_path)) { + params->active_file = file_index; + filelist_entry_select_set(files, file, FILE_SEL_ADD, FILE_SEL_SELECTED, CHECK_ALL); + } + } + WM_main_add_notifier(NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); +} + +void ED_fileselect_deselect_all(SpaceFile *sfile) +{ + file_select_deselect_all(sfile, FILE_SEL_SELECTED); + WM_main_add_notifier(NC_SPACE | ND_SPACE_FILE_PARAMS, NULL); +} + /* The subset of FileSelectParams.flag items we store into preferences. Note that FILE_SORT_ALPHA * may also be remembered, but only conditionally. */ #define PARAMS_FLAGS_REMEMBERED (FILE_HIDE_DOT) |