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/editor_help_search.cpp | 36 ------------------------------------ 1 file changed, 36 deletions(-) (limited to 'editor/editor_help_search.cpp') diff --git a/editor/editor_help_search.cpp b/editor/editor_help_search.cpp index 1a865de23d..936288b176 100644 --- a/editor/editor_help_search.cpp +++ b/editor/editor_help_search.cpp @@ -36,7 +36,6 @@ #include "editor_scale.h" void EditorHelpSearch::_update_icons() { - search_box->set_right_icon(results_tree->get_theme_icon("Search", "EditorIcons")); search_box->set_clear_button_enabled(true); search_box->add_theme_icon_override("right_icon", results_tree->get_theme_icon("Search", "EditorIcons")); @@ -48,7 +47,6 @@ void EditorHelpSearch::_update_icons() { } void EditorHelpSearch::_update_results() { - String term = search_box->get_text(); int search_flags = filter_combo->get_selected_id(); @@ -62,7 +60,6 @@ void EditorHelpSearch::_update_results() { } void EditorHelpSearch::_search_box_gui_input(const Ref &p_event) { - // Redirect up and down navigational key events to the results list. Ref key = p_event; if (key.is_valid()) { @@ -79,17 +76,14 @@ void EditorHelpSearch::_search_box_gui_input(const Ref &p_event) { } void EditorHelpSearch::_search_box_text_changed(const String &p_text) { - _update_results(); } void EditorHelpSearch::_filter_combo_item_selected(int p_option) { - _update_results(); } void EditorHelpSearch::_confirmed() { - TreeItem *item = results_tree->get_selected(); if (!item) return; @@ -103,7 +97,6 @@ void EditorHelpSearch::_confirmed() { } void EditorHelpSearch::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_VISIBILITY_CHANGED: { if (!is_visible()) { @@ -113,17 +106,14 @@ void EditorHelpSearch::_notification(int p_what) { } } break; case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - _update_icons(); } break; case NOTIFICATION_ENTER_TREE: { - connect("confirmed", callable_mp(this, &EditorHelpSearch::_confirmed)); _update_icons(); } break; case NOTIFICATION_PROCESS: { - // Update background search. if (search.is_valid()) { if (search->work()) { @@ -148,17 +138,14 @@ void EditorHelpSearch::_notification(int p_what) { } void EditorHelpSearch::_bind_methods() { - ADD_SIGNAL(MethodInfo("go_to_help")); } void EditorHelpSearch::popup_dialog() { - popup_dialog(search_box->get_text()); } void EditorHelpSearch::popup_dialog(const String &p_term) { - // Restore valid window bounds or pop up at default size. Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "search_help", Rect2()); if (saved_size != Rect2()) @@ -182,7 +169,6 @@ void EditorHelpSearch::popup_dialog(const String &p_term) { } EditorHelpSearch::EditorHelpSearch() { - old_search = false; set_hide_on_ok(false); @@ -254,7 +240,6 @@ EditorHelpSearch::EditorHelpSearch() { } bool EditorHelpSearch::Runner::_is_class_disabled_by_feature_profile(const StringName &p_class) { - Ref profile = EditorFeatureProfileManager::get_singleton()->get_current_profile(); if (profile.is_null()) { return false; @@ -262,7 +247,6 @@ bool EditorHelpSearch::Runner::_is_class_disabled_by_feature_profile(const Strin StringName class_name = p_class; while (class_name != StringName()) { - if (!ClassDB::class_exists(class_name)) { return false; } @@ -277,7 +261,6 @@ bool EditorHelpSearch::Runner::_is_class_disabled_by_feature_profile(const Strin } bool EditorHelpSearch::Runner::_slice() { - bool phase_done = false; switch (phase) { case PHASE_MATCH_CLASSES_INIT: @@ -314,7 +297,6 @@ bool EditorHelpSearch::Runner::_slice() { } bool EditorHelpSearch::Runner::_phase_match_classes_init() { - iterator_doc = EditorHelp::get_doc_data()->class_list.front(); matches.clear(); matched_item = nullptr; @@ -323,10 +305,8 @@ bool EditorHelpSearch::Runner::_phase_match_classes_init() { } bool EditorHelpSearch::Runner::_phase_match_classes() { - DocData::ClassDoc &class_doc = iterator_doc->value(); if (!_is_class_disabled_by_feature_profile(class_doc.name)) { - matches[class_doc.name] = ClassMatch(); ClassMatch &match = matches[class_doc.name]; @@ -376,7 +356,6 @@ bool EditorHelpSearch::Runner::_phase_match_classes() { } bool EditorHelpSearch::Runner::_phase_class_items_init() { - iterator_match = matches.front(); results_tree->clear(); @@ -387,7 +366,6 @@ bool EditorHelpSearch::Runner::_phase_class_items_init() { } bool EditorHelpSearch::Runner::_phase_class_items() { - ClassMatch &match = iterator_match->value(); if (search_flags & SEARCH_SHOW_HIERARCHY) { @@ -403,14 +381,12 @@ bool EditorHelpSearch::Runner::_phase_class_items() { } bool EditorHelpSearch::Runner::_phase_member_items_init() { - iterator_match = matches.front(); return true; } bool EditorHelpSearch::Runner::_phase_member_items() { - ClassMatch &match = iterator_match->value(); TreeItem *parent = (search_flags & SEARCH_SHOW_HIERARCHY) ? class_items[match.doc->name] : root_item; @@ -430,14 +406,12 @@ bool EditorHelpSearch::Runner::_phase_member_items() { } bool EditorHelpSearch::Runner::_phase_select_match() { - if (matched_item) matched_item->select(0); return true; } bool EditorHelpSearch::Runner::_match_string(const String &p_term, const String &p_string) const { - if (search_flags & SEARCH_CASE_SENSITIVE) return p_term.is_subsequence_of(p_string); else @@ -445,7 +419,6 @@ bool EditorHelpSearch::Runner::_match_string(const String &p_term, const String } void EditorHelpSearch::Runner::_match_item(TreeItem *p_item, const String &p_text) { - if (!matched_item) { if (search_flags & SEARCH_CASE_SENSITIVE) { if (p_text.casecmp_to(term) == 0) @@ -458,7 +431,6 @@ void EditorHelpSearch::Runner::_match_item(TreeItem *p_item, const String &p_tex } TreeItem *EditorHelpSearch::Runner::_create_class_hierarchy(const ClassMatch &p_match) { - if (class_items.has(p_match.doc->name)) return class_items[p_match.doc->name]; @@ -479,7 +451,6 @@ TreeItem *EditorHelpSearch::Runner::_create_class_hierarchy(const ClassMatch &p_ } TreeItem *EditorHelpSearch::Runner::_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray) { - Ref icon = empty_icon; if (ui_service->has_theme_icon(p_doc->name, "EditorIcons")) icon = ui_service->get_theme_icon(p_doc->name, "EditorIcons"); @@ -505,7 +476,6 @@ TreeItem *EditorHelpSearch::Runner::_create_class_item(TreeItem *p_parent, const } TreeItem *EditorHelpSearch::Runner::_create_method_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc) { - String tooltip = p_doc->return_type + " " + p_class_doc->name + "." + p_doc->name + "("; for (int i = 0; i < p_doc->arguments.size(); i++) { const DocData::ArgumentDoc &arg = p_doc->arguments[i]; @@ -520,7 +490,6 @@ TreeItem *EditorHelpSearch::Runner::_create_method_item(TreeItem *p_parent, cons } TreeItem *EditorHelpSearch::Runner::_create_signal_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::MethodDoc *p_doc) { - String tooltip = p_doc->return_type + " " + p_class_doc->name + "." + p_doc->name + "("; for (int i = 0; i < p_doc->arguments.size(); i++) { const DocData::ArgumentDoc &arg = p_doc->arguments[i]; @@ -535,13 +504,11 @@ TreeItem *EditorHelpSearch::Runner::_create_signal_item(TreeItem *p_parent, cons } TreeItem *EditorHelpSearch::Runner::_create_constant_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::ConstantDoc *p_doc) { - String tooltip = p_class_doc->name + "." + p_doc->name; return _create_member_item(p_parent, p_class_doc->name, "MemberConstant", p_doc->name, TTRC("Constant"), "constant", tooltip); } TreeItem *EditorHelpSearch::Runner::_create_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::PropertyDoc *p_doc) { - String tooltip = p_doc->type + " " + p_class_doc->name + "." + p_doc->name; tooltip += "\n " + p_class_doc->name + "." + p_doc->setter + "(value) setter"; tooltip += "\n " + p_class_doc->name + "." + p_doc->getter + "() getter"; @@ -549,13 +516,11 @@ TreeItem *EditorHelpSearch::Runner::_create_property_item(TreeItem *p_parent, co } TreeItem *EditorHelpSearch::Runner::_create_theme_property_item(TreeItem *p_parent, const DocData::ClassDoc *p_class_doc, const DocData::PropertyDoc *p_doc) { - String tooltip = p_doc->type + " " + p_class_doc->name + "." + p_doc->name; return _create_member_item(p_parent, p_class_doc->name, "MemberTheme", p_doc->name, TTRC("Theme Property"), "theme_item", tooltip); } TreeItem *EditorHelpSearch::Runner::_create_member_item(TreeItem *p_parent, const String &p_class_name, const String &p_icon, const String &p_name, const String &p_type, const String &p_metatype, const String &p_tooltip) { - Ref icon; String text; if (search_flags & SEARCH_SHOW_HIERARCHY) { @@ -585,7 +550,6 @@ TreeItem *EditorHelpSearch::Runner::_create_member_item(TreeItem *p_parent, cons } bool EditorHelpSearch::Runner::work(uint64_t slot) { - // Return true when the search has been completed, otherwise false. const uint64_t until = OS::get_singleton()->get_ticks_usec() + slot; while (!_slice()) -- 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/editor_help_search.cpp | 150 +++++++++++++++++++++++++++--------------- 1 file changed, 97 insertions(+), 53 deletions(-) (limited to 'editor/editor_help_search.cpp') diff --git a/editor/editor_help_search.cpp b/editor/editor_help_search.cpp index 936288b176..5bfcbf06fc 100644 --- a/editor/editor_help_search.cpp +++ b/editor/editor_help_search.cpp @@ -42,18 +42,21 @@ void EditorHelpSearch::_update_icons() { case_sensitive_button->set_icon(results_tree->get_theme_icon("MatchCase", "EditorIcons")); hierarchy_button->set_icon(results_tree->get_theme_icon("ClassList", "EditorIcons")); - if (is_visible()) + if (is_visible()) { _update_results(); + } } void EditorHelpSearch::_update_results() { String term = search_box->get_text(); int search_flags = filter_combo->get_selected_id(); - if (case_sensitive_button->is_pressed()) + if (case_sensitive_button->is_pressed()) { search_flags |= SEARCH_CASE_SENSITIVE; - if (hierarchy_button->is_pressed()) + } + if (hierarchy_button->is_pressed()) { search_flags |= SEARCH_SHOW_HIERARCHY; + } search = Ref(memnew(Runner(results_tree, results_tree, term, search_flags))); set_process(true); @@ -85,8 +88,9 @@ void EditorHelpSearch::_filter_combo_item_selected(int p_option) { void EditorHelpSearch::_confirmed() { TreeItem *item = results_tree->get_selected(); - if (!item) + if (!item) { return; + } // Activate the script editor and emit the signal with the documentation link to display. EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT); @@ -120,10 +124,11 @@ void EditorHelpSearch::_notification(int p_what) { // Search done. // Only point to the perfect match if it's a new search, and not just reopening a old one. - if (!old_search) + if (!old_search) { results_tree->ensure_cursor_is_visible(); - else + } else { old_search = false; + } get_ok()->set_disabled(!results_tree->get_selected()); @@ -148,18 +153,20 @@ void EditorHelpSearch::popup_dialog() { void EditorHelpSearch::popup_dialog(const String &p_term) { // Restore valid window bounds or pop up at default size. Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "search_help", Rect2()); - if (saved_size != Rect2()) + if (saved_size != Rect2()) { popup(saved_size); - else + } else { popup_centered_ratio(0.5F); + } if (p_term == "") { search_box->clear(); } else { - if (old_term == p_term) + if (old_term == p_term) { old_search = true; - else + } else { old_term = p_term; + } search_box->set_text(p_term); search_box->select_all(); @@ -291,8 +298,9 @@ bool EditorHelpSearch::Runner::_slice() { return true; }; - if (phase_done) + if (phase_done) { phase++; + } return false; } @@ -313,41 +321,58 @@ bool EditorHelpSearch::Runner::_phase_match_classes() { match.doc = &class_doc; // Match class name. - if (search_flags & SEARCH_CLASSES) + if (search_flags & SEARCH_CLASSES) { match.name = term == "" || _match_string(term, class_doc.name); + } // Match members if the term is long enough. if (term.length() > 1) { - if (search_flags & SEARCH_METHODS) + if (search_flags & SEARCH_METHODS) { for (int i = 0; i < class_doc.methods.size(); i++) { String method_name = (search_flags & SEARCH_CASE_SENSITIVE) ? class_doc.methods[i].name : class_doc.methods[i].name.to_lower(); String aux_term = (search_flags & SEARCH_CASE_SENSITIVE) ? term : term.to_lower(); - if (aux_term.begins_with(".")) + if (aux_term.begins_with(".")) { aux_term = aux_term.right(1); + } - if (aux_term.ends_with("(")) + if (aux_term.ends_with("(")) { aux_term = aux_term.left(aux_term.length() - 1).strip_edges(); + } - if (aux_term.is_subsequence_of(method_name)) + if (aux_term.is_subsequence_of(method_name)) { match.methods.push_back(const_cast(&class_doc.methods[i])); + } } - if (search_flags & SEARCH_SIGNALS) - for (int i = 0; i < class_doc.signals.size(); i++) - if (_match_string(term, class_doc.signals[i].name)) + } + if (search_flags & SEARCH_SIGNALS) { + for (int i = 0; i < class_doc.signals.size(); i++) { + if (_match_string(term, class_doc.signals[i].name)) { match.signals.push_back(const_cast(&class_doc.signals[i])); - if (search_flags & SEARCH_CONSTANTS) - for (int i = 0; i < class_doc.constants.size(); i++) - if (_match_string(term, class_doc.constants[i].name)) + } + } + } + if (search_flags & SEARCH_CONSTANTS) { + for (int i = 0; i < class_doc.constants.size(); i++) { + if (_match_string(term, class_doc.constants[i].name)) { match.constants.push_back(const_cast(&class_doc.constants[i])); - if (search_flags & SEARCH_PROPERTIES) - for (int i = 0; i < class_doc.properties.size(); i++) - if (_match_string(term, class_doc.properties[i].name) || _match_string(term, class_doc.properties[i].getter) || _match_string(term, class_doc.properties[i].setter)) + } + } + } + if (search_flags & SEARCH_PROPERTIES) { + for (int i = 0; i < class_doc.properties.size(); i++) { + if (_match_string(term, class_doc.properties[i].name) || _match_string(term, class_doc.properties[i].getter) || _match_string(term, class_doc.properties[i].setter)) { match.properties.push_back(const_cast(&class_doc.properties[i])); - if (search_flags & SEARCH_THEME_ITEMS) - for (int i = 0; i < class_doc.theme_properties.size(); i++) - if (_match_string(term, class_doc.theme_properties[i].name)) + } + } + } + if (search_flags & SEARCH_THEME_ITEMS) { + for (int i = 0; i < class_doc.theme_properties.size(); i++) { + if (_match_string(term, class_doc.theme_properties[i].name)) { match.theme_properties.push_back(const_cast(&class_doc.theme_properties[i])); + } + } + } } } @@ -369,11 +394,13 @@ bool EditorHelpSearch::Runner::_phase_class_items() { ClassMatch &match = iterator_match->value(); if (search_flags & SEARCH_SHOW_HIERARCHY) { - if (match.required()) + if (match.required()) { _create_class_hierarchy(match); + } } else { - if (match.name) + if (match.name) { _create_class_item(root_item, match.doc, false); + } } iterator_match = iterator_match->next(); @@ -390,49 +417,59 @@ bool EditorHelpSearch::Runner::_phase_member_items() { ClassMatch &match = iterator_match->value(); TreeItem *parent = (search_flags & SEARCH_SHOW_HIERARCHY) ? class_items[match.doc->name] : root_item; - for (int i = 0; i < match.methods.size(); i++) + for (int i = 0; i < match.methods.size(); i++) { _create_method_item(parent, match.doc, match.methods[i]); - for (int i = 0; i < match.signals.size(); i++) + } + for (int i = 0; i < match.signals.size(); i++) { _create_signal_item(parent, match.doc, match.signals[i]); - for (int i = 0; i < match.constants.size(); i++) + } + for (int i = 0; i < match.constants.size(); i++) { _create_constant_item(parent, match.doc, match.constants[i]); - for (int i = 0; i < match.properties.size(); i++) + } + for (int i = 0; i < match.properties.size(); i++) { _create_property_item(parent, match.doc, match.properties[i]); - for (int i = 0; i < match.theme_properties.size(); i++) + } + for (int i = 0; i < match.theme_properties.size(); i++) { _create_theme_property_item(parent, match.doc, match.theme_properties[i]); + } iterator_match = iterator_match->next(); return !iterator_match; } bool EditorHelpSearch::Runner::_phase_select_match() { - if (matched_item) + if (matched_item) { matched_item->select(0); + } return true; } bool EditorHelpSearch::Runner::_match_string(const String &p_term, const String &p_string) const { - if (search_flags & SEARCH_CASE_SENSITIVE) + if (search_flags & SEARCH_CASE_SENSITIVE) { return p_term.is_subsequence_of(p_string); - else + } else { return p_term.is_subsequence_ofi(p_string); + } } void EditorHelpSearch::Runner::_match_item(TreeItem *p_item, const String &p_text) { if (!matched_item) { if (search_flags & SEARCH_CASE_SENSITIVE) { - if (p_text.casecmp_to(term) == 0) + if (p_text.casecmp_to(term) == 0) { matched_item = p_item; + } } else { - if (p_text.nocasecmp_to(term) == 0) + if (p_text.nocasecmp_to(term) == 0) { matched_item = p_item; + } } } } TreeItem *EditorHelpSearch::Runner::_create_class_hierarchy(const ClassMatch &p_match) { - if (class_items.has(p_match.doc->name)) + if (class_items.has(p_match.doc->name)) { return class_items[p_match.doc->name]; + } // Ensure parent nodes are created first. TreeItem *parent = root_item; @@ -452,10 +489,11 @@ TreeItem *EditorHelpSearch::Runner::_create_class_hierarchy(const ClassMatch &p_ TreeItem *EditorHelpSearch::Runner::_create_class_item(TreeItem *p_parent, const DocData::ClassDoc *p_doc, bool p_gray) { Ref icon = empty_icon; - if (ui_service->has_theme_icon(p_doc->name, "EditorIcons")) + if (ui_service->has_theme_icon(p_doc->name, "EditorIcons")) { icon = ui_service->get_theme_icon(p_doc->name, "EditorIcons"); - else if (ClassDB::class_exists(p_doc->name) && ClassDB::is_parent_class(p_doc->name, "Object")) + } else if (ClassDB::class_exists(p_doc->name) && ClassDB::is_parent_class(p_doc->name, "Object")) { icon = ui_service->get_theme_icon("Object", "EditorIcons"); + } String tooltip = p_doc->brief_description.strip_edges(); TreeItem *item = results_tree->create_item(p_parent); @@ -480,10 +518,12 @@ TreeItem *EditorHelpSearch::Runner::_create_method_item(TreeItem *p_parent, cons for (int i = 0; i < p_doc->arguments.size(); i++) { const DocData::ArgumentDoc &arg = p_doc->arguments[i]; tooltip += arg.type + " " + arg.name; - if (arg.default_value != "") + if (arg.default_value != "") { tooltip += " = " + arg.default_value; - if (i < p_doc->arguments.size() - 1) + } + if (i < p_doc->arguments.size() - 1) { tooltip += ", "; + } } tooltip += ")"; return _create_member_item(p_parent, p_class_doc->name, "MemberMethod", p_doc->name, TTRC("Method"), "method", tooltip); @@ -494,10 +534,12 @@ TreeItem *EditorHelpSearch::Runner::_create_signal_item(TreeItem *p_parent, cons for (int i = 0; i < p_doc->arguments.size(); i++) { const DocData::ArgumentDoc &arg = p_doc->arguments[i]; tooltip += arg.type + " " + arg.name; - if (arg.default_value != "") + if (arg.default_value != "") { tooltip += " = " + arg.default_value; - if (i < p_doc->arguments.size() - 1) + } + if (i < p_doc->arguments.size() - 1) { tooltip += ", "; + } } tooltip += ")"; return _create_member_item(p_parent, p_class_doc->name, "MemberSignal", p_doc->name, TTRC("Signal"), "signal", tooltip); @@ -529,10 +571,10 @@ TreeItem *EditorHelpSearch::Runner::_create_member_item(TreeItem *p_parent, cons } else { icon = ui_service->get_theme_icon(p_icon, "EditorIcons"); /*// In flat mode, show the class icon. - if (ui_service->has_icon(p_class_name, "EditorIcons")) - icon = ui_service->get_icon(p_class_name, "EditorIcons"); - else if (ClassDB::is_parent_class(p_class_name, "Object")) - icon = ui_service->get_icon("Object", "EditorIcons");*/ +if (ui_service->has_icon(p_class_name, "EditorIcons")) +icon = ui_service->get_icon(p_class_name, "EditorIcons"); +else if (ClassDB::is_parent_class(p_class_name, "Object")) +icon = ui_service->get_icon("Object", "EditorIcons");*/ text = p_class_name + "." + p_name; } @@ -552,9 +594,11 @@ TreeItem *EditorHelpSearch::Runner::_create_member_item(TreeItem *p_parent, cons bool EditorHelpSearch::Runner::work(uint64_t slot) { // Return true when the search has been completed, otherwise false. const uint64_t until = OS::get_singleton()->get_ticks_usec() + slot; - while (!_slice()) - if (OS::get_singleton()->get_ticks_usec() > until) + while (!_slice()) { + if (OS::get_singleton()->get_ticks_usec() > until) { return false; + } + } return true; } -- cgit v1.2.3