From 0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 13:23:58 +0200 Subject: Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027. --- editor/filesystem_dock.cpp | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'editor/filesystem_dock.cpp') diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 236ae16ccf..a6ba624b64 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -93,7 +93,6 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory if (display_mode == DISPLAY_MODE_TREE_ONLY) { String main_scene = ProjectSettings::get_singleton()->get("application/run/main_scene"); for (int i = 0; i < p_dir->get_file_count(); i++) { - String file_type = p_dir->get_file_type(i); if (_is_file_type_disabled_by_feature_profile(file_type)) { @@ -554,7 +553,6 @@ bool FileSystemDock::_is_file_type_disabled_by_feature_profile(const StringName StringName class_name = p_class; while (class_name != StringName()) { - if (profile->is_class_disabled(class_name)) { return true; } @@ -576,7 +574,6 @@ void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List * String file = p_path->get_file(i); if (file.to_lower().find(searched_string) != -1) { - FileInfo fi; fi.name = file; fi.type = p_path->get_file_type(i); @@ -860,9 +857,7 @@ void FileSystemDock::_file_list_activate_file(int p_idx) { void FileSystemDock::_preview_invalidated(const String &p_path) { if (file_list_display_mode == FILE_LIST_DISPLAY_THUMBNAILS && p_path.get_base_dir() == path && searched_string.length() == 0 && file_list_vb->is_visible_in_tree()) { - for (int i = 0; i < files->get_item_count(); i++) { - if (files->get_item_metadata(i) == p_path) { // Re-request preview. Array udata; @@ -1728,7 +1723,6 @@ void FileSystemDock::_file_option(int p_option, const Vector &p_selected } break; case FILE_INFO: { - } break; case FILE_REIMPORT: { @@ -1905,7 +1899,6 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da Dictionary drag_data = p_data; if (drag_data.has("favorite")) { - if (String(drag_data["favorite"]) != "all") { return false; } @@ -1976,7 +1969,6 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, Vector dirs = EditorSettings::get_singleton()->get_favorites(); if (drag_data.has("favorite")) { - if (String(drag_data["favorite"]) != "all") { return; } @@ -2350,7 +2342,6 @@ void FileSystemDock::_file_multi_selected(int p_index, bool p_selected) { } void FileSystemDock::_tree_gui_input(Ref p_event) { - Ref key = p_event; if (key.is_valid() && key->is_pressed() && !key->is_echo()) { if (ED_IS_SHORTCUT("filesystem_dock/duplicate", p_event)) { @@ -2366,7 +2357,6 @@ void FileSystemDock::_tree_gui_input(Ref p_event) { } void FileSystemDock::_file_list_gui_input(Ref p_event) { - Ref key = p_event; if (key.is_valid() && key->is_pressed() && !key->is_echo()) { if (ED_IS_SHORTCUT("filesystem_dock/duplicate", p_event)) { @@ -2451,7 +2441,6 @@ void FileSystemDock::_feature_profile_changed() { } void FileSystemDock::_bind_methods() { - ClassDB::bind_method(D_METHOD("_update_tree"), &FileSystemDock::_update_tree); ClassDB::bind_method(D_METHOD("_file_list_thumbnail_done"), &FileSystemDock::_file_list_thumbnail_done); -- cgit v1.2.3 From 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 14 May 2020 16:41:43 +0200 Subject: Style: Enforce braces around if blocks and loops Using clang-tidy's `readability-braces-around-statements`. https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html --- editor/filesystem_dock.cpp | 112 ++++++++++++++++++++++++++++++--------------- 1 file changed, 74 insertions(+), 38 deletions(-) (limited to 'editor/filesystem_dock.cpp') diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index a6ba624b64..4fdc3dc080 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -63,8 +63,9 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory // Create a tree item for the subdirectory. TreeItem *subdirectory_item = tree->create_item(p_parent); String dname = p_dir->get_name(); - if (dname == "") + if (dname == "") { dname = "res://"; + } subdirectory_item->set_text(0, dname); subdirectory_item->set_icon(0, get_theme_icon("Folder", "EditorIcons")); @@ -86,8 +87,9 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory } // Create items for all subdirectories. - for (int i = 0; i < p_dir->get_subdir_count(); i++) + for (int i = 0; i < p_dir->get_subdir_count(); i++) { parent_should_expand = (_create_tree(subdirectory_item, p_dir->get_subdir(i), uncollapsed_paths, p_select_in_favorites, p_unfold_path) || parent_should_expand); + } // Create all items for the files in the subdirectory. if (display_mode == DISPLAY_MODE_TREE_ONLY) { @@ -195,8 +197,9 @@ void FileSystemDock::_update_tree(const Vector &p_uncollapsed_paths, boo Vector favorite_paths = EditorSettings::get_singleton()->get_favorites(); for (int i = 0; i < favorite_paths.size(); i++) { String fave = favorite_paths[i]; - if (!fave.begins_with("res://")) + if (!fave.begins_with("res://")) { continue; + } Ref folder_icon = get_theme_icon("Folder", "EditorIcons"); const Color folder_color = get_theme_color("folder_icon_modulate", "FileDialog"); @@ -297,8 +300,9 @@ void FileSystemDock::_update_display_mode(bool p_force) { void FileSystemDock::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { - if (initialized) + if (initialized) { return; + } initialized = true; EditorFeatureProfileManager::get_singleton()->connect("current_feature_profile_changed", callable_mp(this, &FileSystemDock::_feature_profile_changed)); @@ -349,8 +353,9 @@ void FileSystemDock::_notification(int p_what) { Dictionary dd = get_viewport()->gui_get_drag_data(); if (tree->is_visible_in_tree() && dd.has("type")) { if (dd.has("favorite")) { - if ((String(dd["favorite"]) == "all")) + if ((String(dd["favorite"]) == "all")) { tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN); + } } else if ((String(dd["type"]) == "files") || (String(dd["type"]) == "files_and_dirs") || (String(dd["type"]) == "resource")) { tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM | Tree::DROP_MODE_INBETWEEN); } @@ -404,13 +409,15 @@ void FileSystemDock::_tree_multi_selected(Object *p_item, int p_column, bool p_s call_deferred("_update_import_dock"); // Return if we don't select something new. - if (!p_selected) + if (!p_selected) { return; + } // Tree item selected. TreeItem *selected = tree->get_selected(); - if (!selected) + if (!selected) { return; + } TreeItem *favorites_item = tree->get_root()->get_children(); if (selected->get_parent() == favorites_item && !String(selected->get_metadata(0)).ends_with("/")) { @@ -432,10 +439,11 @@ void FileSystemDock::_tree_multi_selected(Object *p_item, int p_column, bool p_s } String FileSystemDock::get_selected_path() const { - if (path.ends_with("/")) + if (path.ends_with("/")) { return path; - else + } else { return path.get_base_dir(); + } } String FileSystemDock::get_current_path() const { @@ -504,8 +512,9 @@ void FileSystemDock::_file_list_thumbnail_done(const String &p_path, const Refget_item_count() && files->get_item_text(idx) == file && files->get_item_metadata(idx) == p_path) { if (file_list_display_mode == FILE_LIST_DISPLAY_LIST) { - if (p_small_preview.is_valid()) + if (p_small_preview.is_valid()) { files->set_item_icon(idx, p_small_preview); + } } else { files->set_item_icon(idx, p_preview); } @@ -563,8 +572,9 @@ bool FileSystemDock::_is_file_type_disabled_by_feature_profile(const StringName } void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List *matches, int p_max_items) { - if (matches->size() > p_max_items) + if (matches->size() > p_max_items) { return; + } for (int i = 0; i < p_path->get_subdir_count(); i++) { _search(p_path->get_subdir(i), matches, p_max_items); @@ -586,8 +596,9 @@ void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List * } matches->push_back(fi); - if (matches->size() > p_max_items) + if (matches->size() > p_max_items) { return; + } } } } @@ -597,8 +608,9 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { Set cselection; if (p_keep_selection) { for (int i = 0; i < files->get_item_count(); i++) { - if (files->is_selected(i)) + if (files->is_selected(i)) { cselection.insert(files->get_item_text(i)); + } } } @@ -701,8 +713,9 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { file = path.get_file(); efd = EditorFileSystem::get_singleton()->get_filesystem_path(directory); } - if (!efd) + if (!efd) { return; + } if (searched_string.length() > 0) { // Display the search results. @@ -714,8 +727,9 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { files->add_item("..", folder_icon, true); String bd = directory.get_base_dir(); - if (bd != "res://" && !bd.ends_with("/")) + if (bd != "res://" && !bd.ends_with("/")) { bd += "/"; + } files->set_item_metadata(files->get_item_count() - 1, bd); files->set_item_selectable(files->get_item_count() - 1, false); @@ -801,8 +815,9 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { } // Select the items. - if (cselection.has(fname)) + if (cselection.has(fname)) { files->select(item_index, false); + } if (!p_keep_selection && file != "" && fname == file) { files->select(item_index, true); @@ -902,15 +917,17 @@ void FileSystemDock::_set_scanning_mode() { } void FileSystemDock::_fw_history() { - if (history_pos < history.size() - 1) + if (history_pos < history.size() - 1) { history_pos++; + } _update_history(); } void FileSystemDock::_bw_history() { - if (history_pos > 0) + if (history_pos > 0) { history_pos--; + } _update_history(); } @@ -950,8 +967,9 @@ void FileSystemDock::_push_to_history() { } void FileSystemDock::_get_all_items_in_dir(EditorFileSystemDirectory *efsd, Vector &files, Vector &folders) const { - if (efsd == nullptr) + if (efsd == nullptr) { return; + } for (int i = 0; i < efsd->get_subdir_count(); i++) { folders.push_back(efsd->get_subdir(i)->get_path()); @@ -1106,8 +1124,9 @@ void FileSystemDock::_update_resource_paths_after_move(const Map for (int i = 0; i < EditorNode::get_editor_data().get_edited_scene_count(); i++) { String path; if (i == EditorNode::get_editor_data().get_edited_scene()) { - if (!get_tree()->get_edited_scene_root()) + if (!get_tree()->get_edited_scene_root()) { continue; + } path = get_tree()->get_edited_scene_root()->get_filename(); } else { @@ -1138,8 +1157,9 @@ void FileSystemDock::_update_dependencies_after_move(const Map & print_verbose("Remapping dependencies for: " + file); Error err = ResourceLoader::rename_dependencies(file, p_renames); if (err == OK) { - if (ResourceLoader::get_resource_type(file) == "PackedScene") + if (ResourceLoader::get_resource_type(file) == "PackedScene") { editor->reload_scene(file); + } } else { EditorNode::get_singleton()->add_io_error(TTR("Unable to update dependencies:") + "\n" + remaps[i] + "\n"); } @@ -1267,8 +1287,9 @@ void FileSystemDock::_make_scene_confirm() { break; } } - if (!extension_correct) + if (!extension_correct) { scene_name = scene_name.get_basename() + ".tscn"; + } scene_name = directory.plus_file(scene_name); @@ -1621,8 +1642,9 @@ void FileSystemDock::_file_option(int p_option, const Vector &p_selected } EditorSettings::get_singleton()->set_favorites(favorites); _update_tree(_compute_uncollapsed_paths()); - if (path == "Favorites") + if (path == "Favorites") { _update_file_list(true); + } } break; case FILE_DEPENDENCIES: { @@ -1807,10 +1829,11 @@ void FileSystemDock::_search_changed(const String &p_text, const Control *p_from searched_string = p_text.to_lower(); - if (p_from == tree_search_box) + if (p_from == tree_search_box) { file_list_search_box->set_text(searched_string); - else // File_list_search_box. + } else { // File_list_search_box. tree_search_box->set_text(searched_string); + } bool unfold_path = (p_text == String() && path != String()); switch (display_mode) { @@ -1843,8 +1866,9 @@ void FileSystemDock::focus_on_filter() { } void FileSystemDock::set_file_list_display_mode(FileListDisplayMode p_mode) { - if (p_mode == file_list_display_mode) + if (p_mode == file_list_display_mode) { return; + } _toggle_file_display(); } @@ -1885,8 +1909,9 @@ Variant FileSystemDock::get_drag_data_fw(const Point2 &p_point, Control *p_from) all_not_favorites = true; } - if (paths.empty()) + if (paths.empty()) { return Variant(); + } Dictionary drag_data = EditorNode::get_singleton()->drag_files_and_dirs(paths, p_from); if (!all_not_favorites) { @@ -1905,8 +1930,9 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da // Moving favorite around. TreeItem *ti = tree->get_item_at_position(p_point); - if (!ti) + if (!ti) { return false; + } int drop_section = tree->get_drop_section_at_position(p_point); TreeItem *favorites_item = tree->get_root()->get_children(); @@ -1940,19 +1966,22 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da bool favorite; _get_drag_target_folder(to_dir, favorite, p_point, p_from); - if (favorite) + if (favorite) { return true; + } - if (to_dir.empty()) + if (to_dir.empty()) { return false; + } // Attempting to move a folder into itself will fail later, // rather than bring up a message don't try to do it in the first place. to_dir = to_dir.ends_with("/") ? to_dir : (to_dir + "/"); Vector fnames = drag_data["files"]; for (int i = 0; i < fnames.size(); ++i) { - if (fnames[i].ends_with("/") && to_dir.begins_with(fnames[i])) + if (fnames[i].ends_with("/") && to_dir.begins_with(fnames[i])) { return false; + } } return true; @@ -1962,8 +1991,9 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da } void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { - if (!can_drop_data_fw(p_point, p_data, p_from)) + if (!can_drop_data_fw(p_point, p_data, p_from)) { return; + } Dictionary drag_data = p_data; Vector dirs = EditorSettings::get_singleton()->get_favorites(); @@ -1974,8 +2004,9 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, } // Moving favorite around. TreeItem *ti = tree->get_item_at_position(p_point); - if (!ti) + if (!ti) { return; + } int drop_section = tree->get_drop_section_at_position(p_point); int drop_position; @@ -2022,8 +2053,9 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, EditorSettings::get_singleton()->set_favorites(dirs); _update_tree(_compute_uncollapsed_paths()); - if (display_mode == DISPLAY_MODE_SPLIT && path == "Favorites") + if (display_mode == DISPLAY_MODE_SPLIT && path == "Favorites") { _update_file_list(true); + } return; } @@ -2282,8 +2314,9 @@ void FileSystemDock::_file_list_rmb_select(int p_item, const Vector2 &p_pos) { // Right click is pressed in the file list. Vector paths; for (int i = 0; i < files->get_item_count(); i++) { - if (!files->is_selected(i)) + if (!files->is_selected(i)) { continue; + } if (files->get_item_text(p_item) == "..") { files->unselect(i); continue; @@ -2303,8 +2336,9 @@ void FileSystemDock::_file_list_rmb_select(int p_item, const Vector2 &p_pos) { void FileSystemDock::_file_list_rmb_pressed(const Vector2 &p_pos) { // Right click on empty space for file list. - if (searched_string.length() > 0) + if (searched_string.length() > 0) { return; + } file_list_popup->clear(); file_list_popup->set_size(Size2(1, 1)); @@ -2372,8 +2406,9 @@ void FileSystemDock::_file_list_gui_input(Ref p_event) { } void FileSystemDock::_update_import_dock() { - if (!import_dock_needs_update) + if (!import_dock_needs_update) { return; + } // List selected. Vector selected; @@ -2384,8 +2419,9 @@ void FileSystemDock::_update_import_dock() { } else { // Use the file list. for (int i = 0; i < files->get_item_count(); i++) { - if (!files->is_selected(i)) + if (!files->is_selected(i)) { continue; + } selected.push_back(files->get_item_metadata(i)); } -- cgit v1.2.3