From 33a74941c5fd4efb6eefcaace3315d3e2b65681f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 3 Jul 2020 17:30:31 +0200 Subject: Cleanup: Editors, Clang-Tidy else-after-return fixes This addresses warnings from Clang-Tidy's `readability-else-after-return` rule in the `source/blender/editors` module. No functional changes. --- source/blender/editors/space_file/file_ops.c | 2 +- source/blender/editors/space_file/filelist.c | 159 +++++++++++++-------------- source/blender/editors/space_file/filesel.c | 13 +-- source/blender/editors/space_file/fsmenu.c | 19 ++-- 4 files changed, 92 insertions(+), 101 deletions(-) (limited to 'source/blender/editors/space_file') diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 6552dfc18f3..45e45093238 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -778,7 +778,7 @@ static bool file_walk_select_do(bContext *C, } /* if we don't extend, selecting '..' (index == 0) is allowed so * using key selection to go to parent directory is possible */ - else if (active_new != 0) { + if (active_new != 0) { /* select initial file */ active_new = active_old; } diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 6b39dc4ae15..cb785495ad5 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -637,11 +637,10 @@ static bool is_hidden_dot_filename(const char *filename, FileListInternEntry *fi if (filename[0] == '.' && !ELEM(filename[1], '.', '\0')) { return true; /* ignore .file */ } - else { - int len = strlen(filename); - if ((len > 0) && (filename[len - 1] == '~')) { - return true; /* ignore file~ */ - } + + int len = strlen(filename); + if ((len > 0) && (filename[len - 1] == '~')) { + return true; /* ignore file~ */ } /* filename might actually be a piece of path, in which case we have to check all its parts. */ @@ -1011,43 +1010,41 @@ static int filelist_geticon_ex(FileDirEntry *file, if (FILENAME_IS_PARENT(file->relpath)) { return is_main ? ICON_FILE_PARENT : ICON_NONE; } - else if (typeflag & FILE_TYPE_APPLICATIONBUNDLE) { + if (typeflag & FILE_TYPE_APPLICATIONBUNDLE) { return ICON_UGLYPACKAGE; } - else if (typeflag & FILE_TYPE_BLENDER) { + if (typeflag & FILE_TYPE_BLENDER) { return ICON_FILE_BLEND; } - else if (is_main) { + if (is_main) { /* Do not return icon for folders if icons are not 'main' draw type * (e.g. when used over previews). */ return (file->attributes & FILE_ATTR_ANY_LINK) ? ICON_FOLDER_REDIRECT : ICON_FILE_FOLDER; } - else { - /* If this path is in System list or path cache then use that icon. */ - struct FSMenu *fsmenu = ED_fsmenu_get(); - FSMenuCategory categories[] = { - FS_CATEGORY_SYSTEM, - FS_CATEGORY_SYSTEM_BOOKMARKS, - FS_CATEGORY_OTHER, - }; - - for (int i = 0; i < ARRAY_SIZE(categories); i++) { - FSMenuEntry *tfsm = ED_fsmenu_get_category(fsmenu, categories[i]); - char fullpath[FILE_MAX_LIBEXTRA]; - char *target = fullpath; - if (file->redirection_path) { - target = file->redirection_path; - } - else { - BLI_join_dirfile(fullpath, sizeof(fullpath), root, file->relpath); - BLI_path_slash_ensure(fullpath); - } - for (; tfsm; tfsm = tfsm->next) { - if (STREQ(tfsm->path, target)) { - /* Never want a little folder inside a large one. */ - return (tfsm->icon == ICON_FILE_FOLDER) ? ICON_NONE : tfsm->icon; - } + /* If this path is in System list or path cache then use that icon. */ + struct FSMenu *fsmenu = ED_fsmenu_get(); + FSMenuCategory categories[] = { + FS_CATEGORY_SYSTEM, + FS_CATEGORY_SYSTEM_BOOKMARKS, + FS_CATEGORY_OTHER, + }; + + for (int i = 0; i < ARRAY_SIZE(categories); i++) { + FSMenuEntry *tfsm = ED_fsmenu_get_category(fsmenu, categories[i]); + char fullpath[FILE_MAX_LIBEXTRA]; + char *target = fullpath; + if (file->redirection_path) { + target = file->redirection_path; + } + else { + BLI_join_dirfile(fullpath, sizeof(fullpath), root, file->relpath); + BLI_path_slash_ensure(fullpath); + } + for (; tfsm; tfsm = tfsm->next) { + if (STREQ(tfsm->path, target)) { + /* Never want a little folder inside a large one. */ + return (tfsm->icon == ICON_FILE_FOLDER) ? ICON_NONE : tfsm->icon; } } } @@ -1055,10 +1052,10 @@ static int filelist_geticon_ex(FileDirEntry *file, if (file->attributes & FILE_ATTR_OFFLINE) { return ICON_ERROR; } - else if (file->attributes & FILE_ATTR_TEMPORARY) { + if (file->attributes & FILE_ATTR_TEMPORARY) { return ICON_FILE_CACHE; } - else if (file->attributes & FILE_ATTR_SYSTEM) { + if (file->attributes & FILE_ATTR_SYSTEM) { return ICON_SYSTEM; } } @@ -1066,49 +1063,49 @@ static int filelist_geticon_ex(FileDirEntry *file, if (typeflag & FILE_TYPE_BLENDER) { return ICON_FILE_BLEND; } - else if (typeflag & FILE_TYPE_BLENDER_BACKUP) { + if (typeflag & FILE_TYPE_BLENDER_BACKUP) { return ICON_FILE_BACKUP; } - else if (typeflag & FILE_TYPE_IMAGE) { + if (typeflag & FILE_TYPE_IMAGE) { return ICON_FILE_IMAGE; } - else if (typeflag & FILE_TYPE_MOVIE) { + if (typeflag & FILE_TYPE_MOVIE) { return ICON_FILE_MOVIE; } - else if (typeflag & FILE_TYPE_PYSCRIPT) { + if (typeflag & FILE_TYPE_PYSCRIPT) { return ICON_FILE_SCRIPT; } - else if (typeflag & FILE_TYPE_SOUND) { + if (typeflag & FILE_TYPE_SOUND) { return ICON_FILE_SOUND; } - else if (typeflag & FILE_TYPE_FTFONT) { + if (typeflag & FILE_TYPE_FTFONT) { return ICON_FILE_FONT; } - else if (typeflag & FILE_TYPE_BTX) { + if (typeflag & FILE_TYPE_BTX) { return ICON_FILE_BLANK; } - else if (typeflag & FILE_TYPE_COLLADA) { + if (typeflag & FILE_TYPE_COLLADA) { return ICON_FILE_3D; } - else if (typeflag & FILE_TYPE_ALEMBIC) { + if (typeflag & FILE_TYPE_ALEMBIC) { return ICON_FILE_3D; } - else if (typeflag & FILE_TYPE_USD) { + if (typeflag & FILE_TYPE_USD) { return ICON_FILE_3D; } - else if (typeflag & FILE_TYPE_VOLUME) { + if (typeflag & FILE_TYPE_VOLUME) { return ICON_FILE_VOLUME; } - else if (typeflag & FILE_TYPE_OBJECT_IO) { + if (typeflag & FILE_TYPE_OBJECT_IO) { return ICON_FILE_3D; } - else if (typeflag & FILE_TYPE_TEXT) { + if (typeflag & FILE_TYPE_TEXT) { return ICON_FILE_TEXT; } - else if (typeflag & FILE_TYPE_ARCHIVE) { + if (typeflag & FILE_TYPE_ARCHIVE) { return ICON_FILE_ARCHIVE; } - else if (typeflag & FILE_TYPE_BLENDERLIB) { + if (typeflag & FILE_TYPE_BLENDERLIB) { const int ret = UI_idcode_icon_get(file->blentype); if (ret != ICON_NONE) { return ret; @@ -1145,9 +1142,7 @@ static bool filelist_checkdir_dir(struct FileList *UNUSED(filelist), parent_dir_until_exists_or_default_root(r_dir); return true; } - else { - return BLI_is_dir(r_dir); - } + return BLI_is_dir(r_dir); } static bool filelist_checkdir_lib(struct FileList *UNUSED(filelist), @@ -2118,7 +2113,7 @@ void filelist_cache_previews_set(FileList *filelist, const bool use_previews) return; } /* Do not start preview work while listing, gives nasty flickering! */ - else if (use_previews && (filelist->flags & FL_IS_READY)) { + if (use_previews && (filelist->flags & FL_IS_READY)) { cache->flags |= FLC_PREVIEWS_ACTIVE; BLI_assert((cache->previews_pool == NULL) && (cache->previews_done == NULL)); @@ -2227,67 +2222,65 @@ int ED_path_extension_type(const char *path) if (BLO_has_bfile_extension(path)) { return FILE_TYPE_BLENDER; } - else if (file_is_blend_backup(path)) { + if (file_is_blend_backup(path)) { return FILE_TYPE_BLENDER_BACKUP; } - else if (BLI_path_extension_check(path, ".app")) { + if (BLI_path_extension_check(path, ".app")) { return FILE_TYPE_APPLICATIONBUNDLE; } - else if (BLI_path_extension_check(path, ".py")) { + if (BLI_path_extension_check(path, ".py")) { return FILE_TYPE_PYSCRIPT; } - else if (BLI_path_extension_check_n(path, - ".txt", - ".glsl", - ".osl", - ".data", - ".pov", - ".ini", - ".mcr", - ".inc", - ".fountain", - NULL)) { + if (BLI_path_extension_check_n(path, + ".txt", + ".glsl", + ".osl", + ".data", + ".pov", + ".ini", + ".mcr", + ".inc", + ".fountain", + NULL)) { return FILE_TYPE_TEXT; } - else if (BLI_path_extension_check_n(path, ".ttf", ".ttc", ".pfb", ".otf", ".otc", NULL)) { + if (BLI_path_extension_check_n(path, ".ttf", ".ttc", ".pfb", ".otf", ".otc", NULL)) { return FILE_TYPE_FTFONT; } - else if (BLI_path_extension_check(path, ".btx")) { + if (BLI_path_extension_check(path, ".btx")) { return FILE_TYPE_BTX; } - else if (BLI_path_extension_check(path, ".dae")) { + if (BLI_path_extension_check(path, ".dae")) { return FILE_TYPE_COLLADA; } - else if (BLI_path_extension_check(path, ".abc")) { + if (BLI_path_extension_check(path, ".abc")) { return FILE_TYPE_ALEMBIC; } - else if (BLI_path_extension_check_n(path, ".usd", ".usda", ".usdc", NULL)) { + if (BLI_path_extension_check_n(path, ".usd", ".usda", ".usdc", NULL)) { return FILE_TYPE_USD; } - else if (BLI_path_extension_check(path, ".vdb")) { + if (BLI_path_extension_check(path, ".vdb")) { return FILE_TYPE_VOLUME; } - else if (BLI_path_extension_check(path, ".zip")) { + if (BLI_path_extension_check(path, ".zip")) { return FILE_TYPE_ARCHIVE; } - else if (BLI_path_extension_check_n(path, ".obj", ".3ds", ".fbx", ".glb", ".gltf", NULL)) { + if (BLI_path_extension_check_n(path, ".obj", ".3ds", ".fbx", ".glb", ".gltf", NULL)) { return FILE_TYPE_OBJECT_IO; } - else if (BLI_path_extension_check_array(path, imb_ext_image)) { + if (BLI_path_extension_check_array(path, imb_ext_image)) { return FILE_TYPE_IMAGE; } - else if (BLI_path_extension_check(path, ".ogg")) { + if (BLI_path_extension_check(path, ".ogg")) { if (IMB_isanim(path)) { return FILE_TYPE_MOVIE; } - else { - return FILE_TYPE_SOUND; - } + return FILE_TYPE_SOUND; } - else if (BLI_path_extension_check_array(path, imb_ext_movie)) { + if (BLI_path_extension_check_array(path, imb_ext_movie)) { return FILE_TYPE_MOVIE; } - else if (BLI_path_extension_check_array(path, imb_ext_audio)) { + if (BLI_path_extension_check_array(path, imb_ext_audio)) { return FILE_TYPE_SOUND; } return 0; diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index 3b62941af83..e6c40dce9c8 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -438,13 +438,12 @@ int ED_fileselect_layout_numfiles(FileLayout *layout, ARegion *region) numfiles = (int)((float)(x_view + x_over) / (float)(x_item)); return numfiles * layout->rows; } - else { - const int y_item = layout->tile_h + (2 * layout->tile_border_y); - const int y_view = (int)(BLI_rctf_size_y(®ion->v2d.cur)) - layout->offset_top; - const int y_over = y_item - (y_view % y_item); - numfiles = (int)((float)(y_view + y_over) / (float)(y_item)); - return numfiles * layout->flow_columns; - } + + const int y_item = layout->tile_h + (2 * layout->tile_border_y); + const int y_view = (int)(BLI_rctf_size_y(®ion->v2d.cur)) - layout->offset_top; + const int y_over = y_item - (y_view % y_item); + numfiles = (int)((float)(y_view + y_over) / (float)(y_item)); + return numfiles * layout->flow_columns; } static bool is_inside(int x, int y, int cols, int rows) diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c index b03df01a02b..bff81201d60 100644 --- a/source/blender/editors/space_file/fsmenu.c +++ b/source/blender/editors/space_file/fsmenu.c @@ -307,14 +307,13 @@ char *ED_fsmenu_entry_get_name(struct FSMenuEntry *fsentry) if (fsentry->name[0]) { return fsentry->name; } - else { - /* Here we abuse fsm_iter->name, keeping first char NULL. */ - char *name = fsentry->name + 1; - size_t name_size = sizeof(fsentry->name) - 1; - fsmenu_entry_generate_name(fsentry, name, name_size); - return name; - } + /* Here we abuse fsm_iter->name, keeping first char NULL. */ + char *name = fsentry->name + 1; + size_t name_size = sizeof(fsentry->name) - 1; + + fsmenu_entry_generate_name(fsentry, name, name_size); + return name; } void ED_fsmenu_entry_set_name(struct FSMenuEntry *fsentry, const char *name) @@ -411,7 +410,7 @@ void fsmenu_insert_entry(struct FSMenu *fsmenu, } return; } - else if ((flag & FS_INSERT_SORTED) && cmp_ret < 0) { + if ((flag & FS_INSERT_SORTED) && cmp_ret < 0) { break; } } @@ -948,10 +947,10 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks) /* Hide share not usable to the user. */ continue; } - else if (!STRPREFIX(mnt->mnt_fsname, "/dev")) { + if (!STRPREFIX(mnt->mnt_fsname, "/dev")) { continue; } - else if (STRPREFIX(mnt->mnt_fsname, "/dev/loop")) { + if (STRPREFIX(mnt->mnt_fsname, "/dev/loop")) { /* The dev/loop* entries are SNAPS used by desktop environment * (Gnome) no need for them to show up in the list. */ continue; -- cgit v1.2.3