diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/code_editor.cpp | 98 | ||||
-rw-r--r-- | editor/code_editor.h | 6 | ||||
-rw-r--r-- | editor/editor_about.cpp | 1 | ||||
-rw-r--r-- | editor/editor_inspector.cpp | 21 | ||||
-rw-r--r-- | editor/editor_node.cpp | 5 | ||||
-rw-r--r-- | editor/editor_properties.cpp | 2 | ||||
-rw-r--r-- | editor/icons/ExternalLink.svg | 2 | ||||
-rw-r--r-- | editor/plugins/script_text_editor.cpp | 37 |
8 files changed, 136 insertions, 36 deletions
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index b6da21bc79..c9868bc3c2 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -151,6 +151,8 @@ bool FindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col) text_editor->set_caret_column(pos.x + text.length(), false); text_editor->center_viewport_to_caret(); text_editor->select(pos.y, pos.x, pos.y, pos.x + text.length()); + + line_col_changed_for_result = true; } text_editor->set_search_text(text); @@ -209,6 +211,8 @@ void FindReplaceBar::_replace() { } text_editor->end_complex_operation(); results_count = -1; + results_count_to_current = -1; + needs_to_count_results = true; if (selection_enabled && is_selection_only()) { // Reselect in order to keep 'Replace' restricted to selection @@ -305,6 +309,8 @@ void FindReplaceBar::_replace_all() { text_editor->call_deferred(SNAME("connect"), "text_changed", callable_mp(this, &FindReplaceBar::_editor_text_changed)); results_count = -1; + results_count_to_current = -1; + needs_to_count_results = true; } void FindReplaceBar::_get_search_from(int &r_line, int &r_col) { @@ -321,40 +327,57 @@ void FindReplaceBar::_get_search_from(int &r_line, int &r_col) { } void FindReplaceBar::_update_results_count() { - if (results_count != -1) { + if (!needs_to_count_results && (result_line != -1)) { + results_count_to_current += (flags & TextEdit::SEARCH_BACKWARDS) ? -1 : 1; + + if (results_count_to_current > results_count) { + results_count_to_current = results_count_to_current - results_count; + } else if (results_count_to_current == 0) { + results_count_to_current = results_count; + } + return; } results_count = 0; + results_count_to_current = 0; String searched = get_search_text(); if (searched.is_empty()) { return; } - String full_text = text_editor->get_text(); + needs_to_count_results = false; - int from_pos = 0; + for (int i = 0; i < text_editor->get_line_count(); i++) { + String line_text = text_editor->get_line(i); - while (true) { - int pos = is_case_sensitive() ? full_text.find(searched, from_pos) : full_text.findn(searched, from_pos); - if (pos == -1) { - break; - } + int col_pos = 0; + + while (true) { + col_pos = is_case_sensitive() ? line_text.find(searched, col_pos) : line_text.findn(searched, col_pos); - int pos_subsequent = pos + searched.length(); - if (is_whole_words()) { - from_pos = pos + 1; // Making sure we won't hit the same match next time, if we get out via a continue. - if (pos > 0 && !(is_symbol(full_text[pos - 1]) || full_text[pos - 1] == '\n')) { - continue; + if (col_pos == -1) { + break; } - if (pos_subsequent < full_text.length() && !(is_symbol(full_text[pos_subsequent]) || full_text[pos_subsequent] == '\n')) { - continue; + + if (is_whole_words()) { + if (col_pos > 0 && !is_symbol(line_text[col_pos - 1])) { + break; + } + if (col_pos + line_text.length() < line_text.length() && !is_symbol(line_text[col_pos + searched.length()])) { + break; + } } - } - results_count++; - from_pos = pos_subsequent; + results_count++; + + if (i == result_line && col_pos == result_col) { + results_count_to_current = results_count; + } + + col_pos += searched.length(); + } } } @@ -365,12 +388,19 @@ void FindReplaceBar::_update_matches_label() { matches_label->show(); matches_label->add_theme_color_override("font_color", results_count > 0 ? get_theme_color(SNAME("font_color"), SNAME("Label")) : get_theme_color(SNAME("error_color"), SNAME("Editor"))); - matches_label->set_text(vformat(results_count == 1 ? TTR("%d match.") : TTR("%d matches."), results_count)); + + if (results_count == 0) { + matches_label->set_text("No match"); + } else if (results_count == 1) { + matches_label->set_text(vformat(TTR("%d match"), results_count)); + } else { + matches_label->set_text(vformat(TTR("%d of %d matches"), results_count_to_current, results_count)); + } } } bool FindReplaceBar::search_current() { - uint32_t flags = 0; + flags = 0; if (is_whole_words()) { flags |= TextEdit::SEARCH_WHOLE_WORDS; @@ -390,7 +420,7 @@ bool FindReplaceBar::search_prev() { popup_search(true); } - uint32_t flags = 0; + flags = 0; String text = get_search_text(); if (is_whole_words()) { @@ -425,7 +455,7 @@ bool FindReplaceBar::search_next() { popup_search(true); } - uint32_t flags = 0; + flags = 0; String text; if (replace_all_mode) { text = get_replace_text(); @@ -496,6 +526,8 @@ void FindReplaceBar::_show_search(bool p_focus_replace, bool p_show_only) { } results_count = -1; + results_count_to_current = -1; + needs_to_count_results = true; _update_results_count(); _update_matches_label(); } @@ -523,11 +555,15 @@ void FindReplaceBar::popup_replace() { void FindReplaceBar::_search_options_changed(bool p_pressed) { results_count = -1; + results_count_to_current = -1; + needs_to_count_results = true; search_current(); } void FindReplaceBar::_editor_text_changed() { results_count = -1; + results_count_to_current = -1; + needs_to_count_results = true; if (is_visible_in_tree()) { preserve_cursor = true; search_current(); @@ -537,6 +573,8 @@ void FindReplaceBar::_editor_text_changed() { void FindReplaceBar::_search_text_changed(const String &p_text) { results_count = -1; + results_count_to_current = -1; + needs_to_count_results = true; search_current(); } @@ -601,6 +639,8 @@ void FindReplaceBar::set_text_edit(CodeTextEditor *p_text_editor) { } results_count = -1; + results_count_to_current = -1; + needs_to_count_results = true; base_text_editor = p_text_editor; text_editor = base_text_editor->get_text_editor(); text_editor->connect("text_changed", callable_mp(this, &FindReplaceBar::_editor_text_changed)); @@ -618,6 +658,8 @@ void FindReplaceBar::_bind_methods() { FindReplaceBar::FindReplaceBar() { results_count = -1; + results_count_to_current = -1; + needs_to_count_results = true; vbc_lineedit = memnew(VBoxContainer); add_child(vbc_lineedit); @@ -836,6 +878,14 @@ void CodeTextEditor::_line_col_changed() { sb.append(itos(positional_column + 1).lpad(3)); line_and_col_txt->set_text(sb.as_string()); + + if (find_replace_bar) { + if (!find_replace_bar->line_col_changed_for_result) { + find_replace_bar->needs_to_count_results = true; + } + + find_replace_bar->line_col_changed_for_result = false; + } } void CodeTextEditor::_text_changed() { @@ -844,6 +894,10 @@ void CodeTextEditor::_text_changed() { } idle->start(); + + if (find_replace_bar) { + find_replace_bar->needs_to_count_results = true; + } } void CodeTextEditor::_code_complete_timer_timeout() { diff --git a/editor/code_editor.h b/editor/code_editor.h index d52f57860c..bb1791940e 100644 --- a/editor/code_editor.h +++ b/editor/code_editor.h @@ -82,9 +82,12 @@ class FindReplaceBar : public HBoxContainer { CodeTextEditor *base_text_editor = nullptr; CodeEdit *text_editor = nullptr; + uint32_t flags = 0; + int result_line; int result_col; int results_count; + int results_count_to_current; bool replace_all_mode = false; bool preserve_cursor = false; @@ -131,6 +134,9 @@ public: bool search_prev(); bool search_next(); + bool needs_to_count_results = true; + bool line_col_changed_for_result = false; + FindReplaceBar(); }; diff --git a/editor/editor_about.cpp b/editor/editor_about.cpp index 877af41160..cd5a4f16e4 100644 --- a/editor/editor_about.cpp +++ b/editor/editor_about.cpp @@ -129,6 +129,7 @@ EditorAbout::EditorAbout() { vbc->add_child(hbc); _logo = memnew(TextureRect); + _logo->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED); hbc->add_child(_logo); VBoxContainer *version_info_vbc = memnew(VBoxContainer); diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 5d47b87fbf..9a30c6a1e3 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -2456,8 +2456,6 @@ void EditorInspector::update_tree() { _parse_added_editors(main_vbox, ped); } - bool in_script_variables = false; - // Get the lists of editors for properties. for (List<PropertyInfo>::Element *E_property = plist.front(); E_property; E_property = E_property->next()) { PropertyInfo &p = E_property->get(); @@ -2549,9 +2547,6 @@ void EditorInspector::update_tree() { if (category->icon.is_null() && has_theme_icon(base_type, SNAME("EditorIcons"))) { category->icon = get_theme_icon(base_type, SNAME("EditorIcons")); } - in_script_variables = true; - } else { - in_script_variables = false; } if (category->icon.is_null()) { if (!type.is_empty()) { // Can happen for built-in scripts. @@ -2687,9 +2682,9 @@ void EditorInspector::update_tree() { } } - // Don't localize properties in Script Variables category. + // Don't localize script variables. EditorPropertyNameProcessor::Style name_style = property_name_style; - if (in_script_variables && name_style == EditorPropertyNameProcessor::STYLE_LOCALIZED) { + if ((p.usage & PROPERTY_USAGE_SCRIPT_VARIABLE) && name_style == EditorPropertyNameProcessor::STYLE_LOCALIZED) { name_style = EditorPropertyNameProcessor::STYLE_CAPITALIZED; } const String property_label_string = EditorPropertyNameProcessor::get_singleton()->process_name(name_override, name_style) + feature_tag; @@ -2745,9 +2740,15 @@ void EditorInspector::update_tree() { String label; String tooltip; + // Don't localize groups for script variables. + EditorPropertyNameProcessor::Style section_name_style = property_name_style; + if ((p.usage & PROPERTY_USAGE_SCRIPT_VARIABLE) && section_name_style == EditorPropertyNameProcessor::STYLE_LOCALIZED) { + section_name_style = EditorPropertyNameProcessor::STYLE_CAPITALIZED; + } + // Only process group label if this is not the group or subgroup. if ((i == 0 && component == group) || (i == 1 && component == subgroup)) { - if (property_name_style == EditorPropertyNameProcessor::STYLE_LOCALIZED) { + if (section_name_style == EditorPropertyNameProcessor::STYLE_LOCALIZED) { label = TTRGET(component); tooltip = component; } else { @@ -2755,8 +2756,8 @@ void EditorInspector::update_tree() { tooltip = TTRGET(component); } } else { - label = EditorPropertyNameProcessor::get_singleton()->process_name(component, property_name_style); - tooltip = EditorPropertyNameProcessor::get_singleton()->process_name(component, EditorPropertyNameProcessor::get_tooltip_style(property_name_style)); + label = EditorPropertyNameProcessor::get_singleton()->process_name(component, section_name_style); + tooltip = EditorPropertyNameProcessor::get_singleton()->process_name(component, EditorPropertyNameProcessor::get_tooltip_style(section_name_style)); } Color c = sscolor; diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 113f01caae..3d52686378 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -4128,7 +4128,10 @@ Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p // We've reached a native class, use its icon. String base_type; script->get_language()->get_global_class_name(script->get_path(), &base_type); - return gui_base->get_theme_icon(base_type, "EditorIcons"); + if (gui_base->has_theme_icon(base_type, "EditorIcons")) { + return gui_base->get_theme_icon(base_type, "EditorIcons"); + } + return gui_base->get_theme_icon(p_fallback, "EditorIcons"); } script = base_script; class_name = EditorNode::get_editor_data().script_class_get_name(script->get_path()); diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 581a807e27..d8fe545b25 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -2980,7 +2980,7 @@ void EditorPropertyResource::_resource_selected(const RES &p_resource, bool p_ed List<String> extensions; ResourceLoader::get_recognized_extensions_for_type("PackedScene", &extensions); - if (extensions.find(parent.get_extension()) && (!EditorNode::get_singleton()->get_edited_scene() || EditorNode::get_singleton()->get_edited_scene()->get_scene_file_path() == parent)) { + if (extensions.find(parent.get_extension()) && (!EditorNode::get_singleton()->get_edited_scene() || EditorNode::get_singleton()->get_edited_scene()->get_scene_file_path() != parent)) { // If the resource belongs to another scene, edit it in that scene instead. EditorNode::get_singleton()->call_deferred("edit_foreign_resource", p_resource); return; diff --git a/editor/icons/ExternalLink.svg b/editor/icons/ExternalLink.svg index 7fd78ae009..94148b2798 100644 --- a/editor/icons/ExternalLink.svg +++ b/editor/icons/ExternalLink.svg @@ -1 +1 @@ -<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><clipPath id="a"><path d="m0 0h16v16h-16z"/></clipPath><g clip-path="url(#a)" fill="#e0e0e0"><path d="m-1940-64.061 5.5-5.5-2.44-2.439h7v7l-2.439-2.439-5.5 5.5z" transform="translate(1944.939 73)"/><path d="m12 15h-8a3.079 3.079 0 0 1 -3-3v-8a3.04 3.04 0 0 1 3-3h2a1 1 0 0 1 0 2h-2a1.04 1.04 0 0 0 -1 1v8a1.083 1.083 0 0 0 1 1h8a1.068 1.068 0 0 0 1-1v-2a1 1 0 0 1 2 0v2a3.063 3.063 0 0 1 -3 3z"/></g></svg> +<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g fill="#e0e0e0"><path d="m-1940-64.061 5.5-5.5-2.44-2.439h7v7l-2.439-2.439-5.5 5.5z" transform="translate(1944.939 73)"/><path d="m12 15h-8a3.079 3.079 0 0 1 -3-3v-8a3.04 3.04 0 0 1 3-3h2a1 1 0 0 1 0 2h-2a1.04 1.04 0 0 0 -1 1v8a1.083 1.083 0 0 0 1 1h8a1.068 1.068 0 0 0 1-1v-2a1 1 0 0 1 2 0v2a3.063 3.063 0 0 1 -3 3z"/></g></svg> diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 4626f10b8d..f581d6c928 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -239,6 +239,29 @@ void ScriptTextEditor::_show_warnings_panel(bool p_show) { void ScriptTextEditor::_warning_clicked(Variant p_line) { if (p_line.get_type() == Variant::INT) { goto_line_centered(p_line.operator int64_t()); + } else if (p_line.get_type() == Variant::DICTIONARY) { + Dictionary meta = p_line.operator Dictionary(); + const int line = meta["line"].operator int64_t() - 1; + + CodeEdit *text_editor = code_editor->get_text_editor(); + String prev_line = line > 0 ? text_editor->get_line(line - 1) : ""; + if (prev_line.contains("@warning_ignore")) { + const int closing_bracket_idx = prev_line.find(")"); + const String text_to_insert = ", " + meta["code"].operator String(); + prev_line = prev_line.insert(closing_bracket_idx, text_to_insert); + text_editor->set_line(line - 1, prev_line); + } else { + const int indent = text_editor->get_indent_level(line) / text_editor->get_indent_size(); + String annotation_indent; + if (!text_editor->is_indent_using_spaces()) { + annotation_indent = String("\t").repeat(indent); + } else { + annotation_indent = String(" ").repeat(text_editor->get_indent_size() * indent); + } + text_editor->insert_line_at(line, annotation_indent + "@warning_ignore(" + meta["code"].operator String() + ")"); + } + + _validate_script(); } } @@ -482,8 +505,20 @@ void ScriptTextEditor::_update_warnings() { } // Add script warnings. - warnings_panel->push_table(2); + warnings_panel->push_table(3); for (const ScriptLanguage::Warning &w : warnings) { + Dictionary ignore_meta; + ignore_meta["line"] = w.start_line; + ignore_meta["code"] = w.string_code.to_lower(); + warnings_panel->push_cell(); + warnings_panel->push_meta(ignore_meta); + warnings_panel->push_color( + warnings_panel->get_theme_color(SNAME("accent_color"), SNAME("Editor")).lerp(warnings_panel->get_theme_color(SNAME("mono_color"), SNAME("Editor")), 0.5f)); + warnings_panel->add_text(TTR("[Ignore]")); + warnings_panel->pop(); // Color. + warnings_panel->pop(); // Meta ignore. + warnings_panel->pop(); // Cell. + warnings_panel->push_cell(); warnings_panel->push_meta(w.start_line - 1); warnings_panel->push_color(warnings_panel->get_theme_color(SNAME("warning_color"), SNAME("Editor"))); |