Merge pull request #24437 from mateusfccp/single_quotes_option

Add settings for single-quotes on completion
This commit is contained in:
Rémi Verschelde 2019-04-30 14:58:33 +02:00 committed by GitHub
commit 9dc9434b1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 67 additions and 17 deletions

View file

@ -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() {
@ -123,6 +127,8 @@ void Input::_bind_methods() {
void Input::get_argument_options(const StringName &p_function, int p_idx, List<String> *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")) {
@ -136,7 +142,7 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S
continue;
String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
r_options->push_back("\"" + name + "\"");
r_options->push_back(quote_style + name + quote_style);
}
}
#endif

View file

@ -466,6 +466,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> 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);

View file

@ -511,8 +511,10 @@ struct GDScriptCompletionIdentifier {
static void _get_directory_contents(EditorFileSystemDirectory *p_dir, Set<String> &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++) {
@ -2178,6 +2180,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: {
@ -2198,7 +2202,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);
}
}
@ -2211,7 +2215,7 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con
List<MethodInfo> signals;
gds->get_script_signal_list(&signals);
for (List<MethodInfo>::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<GDScript> base_script = gds->get_base_script();
@ -2270,7 +2274,7 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con
List<MethodInfo> signals;
ClassDB::get_signal_list(class_name, &signals);
for (List<MethodInfo>::Element *E = signals.front(); E; E = E->next()) {
r_result.insert("\"" + E->get().name + "\"");
r_result.insert(quote_style + E->get().name + quote_style);
}
}
@ -2285,7 +2289,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);
}
}
@ -2299,7 +2303,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);
}
}
@ -2334,6 +2338,8 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con
static void _find_call_arguments(GDScriptCompletionContext &p_context, const GDScriptParser::Node *p_node, int p_argidx, Set<String> &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;
}
@ -2451,7 +2457,7 @@ static void _find_call_arguments(GDScriptCompletionContext &p_context, const GDS
Set<String> methods;
_find_identifiers_in_base(p_context, connect_base, true, methods);
for (Set<String>::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);
}
}
@ -2460,6 +2466,8 @@ static void _find_call_arguments(GDScriptCompletionContext &p_context, const GDS
Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *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);
@ -2526,7 +2534,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;
@ -2666,7 +2674,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;
@ -2677,7 +2685,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base
List<MethodInfo> signals;
scr->get_script_signal_list(&signals);
for (List<MethodInfo>::Element *E = signals.front(); E; E = E->next()) {
options.insert("\"" + E->get().name + "\"");
options.insert(quote_style + E->get().name + quote_style);
}
Ref<Script> base_script = scr->get_base_script();
if (base_script.is_valid()) {
@ -2704,7 +2712,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base
List<MethodInfo> signals;
ClassDB::get_signal_list(class_name, &signals);
for (List<MethodInfo>::Element *E = signals.front(); E; E = E->next()) {
options.insert("\"" + E->get().name + "\"");
options.insert(quote_style + E->get().name + quote_style);
}
} break;
default: {
@ -2890,7 +2898,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base
String GDScriptLanguage::_get_indentation() const {
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
bool use_space_indentation = EDITOR_DEF("text_editor/indent/type", 0);
bool use_space_indentation = EDITOR_DEF("text_editor/indent/type", false);
if (use_space_indentation) {
int indent_size = EDITOR_DEF("text_editor/indent/size", 4);

View file

@ -34,7 +34,10 @@
#include "core/message_queue.h"
#include "scene/scene_string_names.h"
#include "servers/audio/audio_stream.h"
#ifdef TOOLS_ENABLED
#include "editor/editor_settings.h"
void AnimatedValuesBackup::update_skeletons() {
for (int i = 0; i < entries.size(); i++) {
@ -1510,13 +1513,19 @@ NodePath AnimationPlayer::get_root() const {
void AnimationPlayer::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
#ifdef TOOLS_ENABLED
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\"";
#else
const String quote_style = "\"";
#endif
String pf = p_function;
if (p_function == "play" || p_function == "play_backwards" || p_function == "remove_animation" || p_function == "has_animation" || p_function == "queue") {
List<StringName> al;
get_animation_list(&al);
for (List<StringName>::Element *E = al.front(); E; E = E->next()) {
r_options->push_back("\"" + String(E->get()) + "\"");
r_options->push_back(quote_style + String(E->get()) + quote_style);
}
}
Node::get_argument_options(p_function, p_idx, r_options);

View file

@ -2634,6 +2634,12 @@ bool Control::is_visibility_clip_disabled() const {
void Control::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
#ifdef TOOLS_ENABLED
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\"";
#else
const String quote_style = "\"";
#endif
Node::get_argument_options(p_function, p_idx, r_options);
if (p_idx == 0) {
@ -2651,7 +2657,7 @@ void Control::get_argument_options(const StringName &p_function, int p_idx, List
sn.sort_custom<StringName::AlphCompare>();
for (List<StringName>::Element *E = sn.front(); E; E = E->next()) {
r_options->push_back("\"" + E->get() + "\"");
r_options->push_back(quote_style + E->get() + quote_style);
}
}
}

View file

@ -39,6 +39,10 @@
#include "scene/scene_string_names.h"
#include "viewport.h"
#ifdef TOOLS_ENABLED
#include "editor/editor_settings.h"
#endif
VARIANT_ENUM_CAST(Node::PauseMode);
int Node::orphan_node_count = 0;
@ -2637,10 +2641,16 @@ NodePath Node::get_import_path() const {
static void _add_nodes_to_options(const Node *p_base, const Node *p_node, List<String> *r_options) {
#ifdef TOOLS_ENABLED
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\"";
#else
const String quote_style = "\"";
#endif
if (p_node != p_base && !p_node->get_owner())
return;
String n = p_base->get_path_to(p_node);
r_options->push_back("\"" + n + "\"");
r_options->push_back(quote_style + n + quote_style);
for (int i = 0; i < p_node->get_child_count(); i++) {
_add_nodes_to_options(p_base, p_node->get_child(i), r_options);
}

View file

@ -30,6 +30,10 @@
#include "material.h"
#ifdef TOOLS_ENABLED
#include "editor/editor_settings.h"
#endif
#include "scene/scene_string_names.h"
void Material::set_next_pass(const Ref<Material> &p_pass) {
@ -236,6 +240,12 @@ void ShaderMaterial::_bind_methods() {
void ShaderMaterial::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
#ifdef TOOLS_ENABLED
const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\"";
#else
const String quote_style = "\"";
#endif
String f = p_function.operator String();
if ((f == "get_shader_param" || f == "set_shader_param") && p_idx == 0) {
@ -243,7 +253,7 @@ void ShaderMaterial::get_argument_options(const StringName &p_function, int p_id
List<PropertyInfo> pl;
shader->get_param_list(&pl);
for (List<PropertyInfo>::Element *E = pl.front(); E; E = E->next()) {
r_options->push_back("\"" + E->get().name.replace_first("shader_param/", "") + "\"");
r_options->push_back(quote_style + E->get().name.replace_first("shader_param/", "") + quote_style);
}
}
}