diff options
author | Julian Eisel <julian@blender.org> | 2021-07-30 19:39:45 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2021-07-30 19:42:38 +0300 |
commit | b90887da5a37088d295fe86445cf62c9fc8fdea4 (patch) | |
tree | 1003a7273342e6a3947bb067a27ee4c72415b935 /source/blender | |
parent | 3b2a6bf8e8f87c2d1a8927637c562502af8083b9 (diff) |
Cleanup: Refactor logic of file deletion poll callback
* Early exit instead of complex if-else blocks.
* Avoid iterating over entire file list.
* Use `true`/`false` for boolean values.
* Declare variables in smaller scopes.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/space_file/file_ops.c | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index e65156167a9..7c608e2115d 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -2784,33 +2784,30 @@ void FILE_OT_rename(struct wmOperatorType *ot) static bool file_delete_poll(bContext *C) { - bool poll = ED_operator_file_active(C); + if (!ED_operator_file_active(C)) { + return false; + } + SpaceFile *sfile = CTX_wm_space_file(C); FileSelectParams *params = ED_fileselect_get_active_params(sfile); + if (!sfile || !params) { + return false; + } - if (sfile && params) { - char dir[FILE_MAX_LIBEXTRA]; - int numfiles = filelist_files_ensure(sfile->files); - int i; - int num_selected = 0; + char dir[FILE_MAX_LIBEXTRA]; + if (filelist_islibrary(sfile->files, dir, NULL)) { + return false; + } - if (filelist_islibrary(sfile->files, dir, NULL)) { - poll = 0; - } - for (i = 0; i < numfiles; i++) { - if (filelist_entry_select_index_get(sfile->files, i, CHECK_ALL)) { - num_selected++; - } - } - if (num_selected <= 0) { - poll = 0; + int numfiles = filelist_files_ensure(sfile->files); + for (int i = 0; i < numfiles; i++) { + if (filelist_entry_select_index_get(sfile->files, i, CHECK_ALL)) { + /* Has a selected file -> the operator can run. */ + return true; } } - else { - poll = 0; - } - return poll; + return false; } static bool file_delete_single(const FileSelectParams *params, |