From ca1935d6f776a789dda9e046e5624ba0715e2671 Mon Sep 17 00:00:00 2001 From: "Mateus Felipe C. C. Pinto" Date: Mon, 17 Dec 2018 23:53:54 -0200 Subject: [PATCH] Add settings for single-quotes on completion --- core/os/input.cpp | 8 ++++++- editor/editor_settings.cpp | 1 + modules/gdscript/gdscript_editor.cpp | 32 +++++++++++++++++----------- scene/animation/animation_player.cpp | 11 +++++++++- scene/gui/control.cpp | 8 ++++++- scene/main/node.cpp | 12 ++++++++++- scene/resources/material.cpp | 12 ++++++++++- 7 files changed, 67 insertions(+), 17 deletions(-) diff --git a/core/os/input.cpp b/core/os/input.cpp index 3b895b16b46..6b4c15b85d8 100644 --- a/core/os/input.cpp +++ b/core/os/input.cpp @@ -34,6 +34,10 @@ #include "core/os/os.h" #include "core/project_settings.h" +#ifdef TOOLS_ENABLED +#include "editor/editor_settings.h" +#endif + Input *Input::singleton = NULL; Input *Input::get_singleton() { @@ -121,6 +125,8 @@ void Input::_bind_methods() { void Input::get_argument_options(const StringName &p_function, int p_idx, List *r_options) const { #ifdef TOOLS_ENABLED + const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\""; + String pf = p_function; if (p_idx == 0 && (pf == "is_action_pressed" || pf == "action_press" || pf == "action_release" || pf == "is_action_just_pressed" || pf == "is_action_just_released" || pf == "get_action_strength")) { @@ -134,7 +140,7 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, Listpush_back("\"" + name + "\""); + r_options->push_back(quote_style + name + quote_style); } } #endif diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index fbcab3cbb67..984bfd34c91 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -464,6 +464,7 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { _initial_set("text_editor/completion/callhint_tooltip_offset", Vector2()); _initial_set("text_editor/completion/complete_file_paths", true); _initial_set("text_editor/completion/add_type_hints", false); + _initial_set("text_editor/completion/use_single_quotes", false); // Help _initial_set("text_editor/help/show_help_index", true); diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 068e8d2d928..3ed78ffc602 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -499,8 +499,10 @@ struct GDScriptCompletionIdentifier { static void _get_directory_contents(EditorFileSystemDirectory *p_dir, Set &r_list) { + const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\""; + for (int i = 0; i < p_dir->get_file_count(); i++) { - r_list.insert("\"" + p_dir->get_file_path(i) + "\""); + r_list.insert(quote_style + p_dir->get_file_path(i) + quote_style); } for (int i = 0; i < p_dir->get_subdir_count(); i++) { @@ -2151,6 +2153,8 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con GDScriptParser::DataType base_type = p_base.type; bool _static = false; + const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\""; + while (base_type.has_type) { switch (base_type.kind) { case GDScriptParser::DataType::CLASS: { @@ -2171,7 +2175,7 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con if ((p_method == "connect" || p_method == "emit_signal") && p_argidx == 0) { for (int i = 0; i < base_type.class_type->_signals.size(); i++) { - r_result.insert("\"" + base_type.class_type->_signals[i].name.operator String() + "\""); + r_result.insert(quote_style + base_type.class_type->_signals[i].name.operator String() + quote_style); } } @@ -2184,7 +2188,7 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con List signals; gds->get_script_signal_list(&signals); for (List::Element *E = signals.front(); E; E = E->next()) { - r_result.insert("\"" + E->get().name + "\""); + r_result.insert(quote_style + E->get().name + quote_style); } } Ref base_script = gds->get_base_script(); @@ -2243,7 +2247,7 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con List signals; ClassDB::get_signal_list(class_name, &signals); for (List::Element *E = signals.front(); E; E = E->next()) { - r_result.insert("\"" + E->get().name + "\""); + r_result.insert(quote_style + E->get().name + quote_style); } } @@ -2258,7 +2262,7 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con continue; } String name = s.get_slice("/", 1); - r_result.insert("\"/root/" + name + "\""); + r_result.insert(quote_style + "/root/" + name + quote_style); } } @@ -2272,7 +2276,7 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con continue; } String name = s.get_slice("/", 1); - r_result.insert("\"" + name + "\""); + r_result.insert(quote_style + name + quote_style); } } @@ -2307,6 +2311,8 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con static void _find_call_arguments(const GDScriptCompletionContext &p_context, const GDScriptParser::Node *p_node, int p_argidx, Set &r_result, bool &r_forced, String &r_arghint) { + const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\""; + if (!p_node || p_node->type != GDScriptParser::Node::TYPE_OPERATOR) { return; } @@ -2424,7 +2430,7 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con Set methods; _find_identifiers_in_base(p_context, connect_base, true, methods); for (Set::Element *E = methods.front(); E; E = E->next()) { - r_result.insert("\"" + E->get().replace("(", "").replace(")", "") + "\""); + r_result.insert(quote_style + E->get().replace("(", "").replace(")", "") + quote_style); } } @@ -2433,6 +2439,8 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List *r_options, bool &r_forced, String &r_call_hint) { + const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\""; + GDScriptParser parser; parser.parse(p_code, p_base_path, false, "", true); @@ -2495,7 +2503,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base continue; } String name = s.get_slice("/", 1); - options.insert("\"/root/" + name + "\""); + options.insert(quote_style + "/root/" + name + quote_style); } } } break; @@ -2635,7 +2643,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base switch (base_type.kind) { case GDScriptParser::DataType::CLASS: { for (int i = 0; i < base_type.class_type->_signals.size(); i++) { - options.insert("\"" + base_type.class_type->_signals[i].name.operator String() + "\""); + options.insert(quote_style + base_type.class_type->_signals[i].name.operator String() + quote_style); } base_type = base_type.class_type->base_type; } break; @@ -2646,7 +2654,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base List signals; scr->get_script_signal_list(&signals); for (List::Element *E = signals.front(); E; E = E->next()) { - options.insert("\"" + E->get().name + "\""); + options.insert(quote_style + E->get().name + quote_style); } Ref