diff options
Diffstat (limited to 'modules/gdscript/gd_editor.cpp')
-rw-r--r-- | modules/gdscript/gd_editor.cpp | 171 |
1 files changed, 86 insertions, 85 deletions
diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp index 1499f167c4..f8b45af85a 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gd_editor.cpp @@ -6,6 +6,7 @@ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -26,10 +27,15 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#include "editor/editor_settings.h" #include "gd_compiler.h" #include "gd_script.h" -#include "global_config.h" #include "os/file_access.h" +#include "project_settings.h" +#ifdef TOOLS_ENABLED +#include "editor/editor_file_system.h" +#include "editor/editor_settings.h" +#endif void GDScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const { @@ -49,11 +55,12 @@ Ref<Script> GDScriptLanguage::get_template(const String &p_class_name, const Str "# var a = 2\n" + "# var b = \"textvar\"\n\n" + "func _ready():\n" + - "\t# Called every time the node is added to the scene.\n" + - "\t# Initialization here\n" + - "\tpass\n"; + "%TS%# Called every time the node is added to the scene.\n" + + "%TS%# Initialization here\n" + + "%TS%pass\n"; _template = _template.replace("%BASE%", p_base_class_name); + _template = _template.replace("%TS%", _get_indentation()); Ref<GDScript> script; script.instance(); @@ -62,6 +69,19 @@ Ref<Script> GDScriptLanguage::get_template(const String &p_class_name, const Str return script; } +bool GDScriptLanguage::is_using_templates() { + + return true; +} + +void GDScriptLanguage::make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script) { + + String src = p_script->get_source_code(); + src = src.replace("%BASE%", p_base_class_name); + src = src.replace("%TS%", _get_indentation()); + p_script->set_source_code(src); +} + bool GDScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions) const { GDParser parser; @@ -137,7 +157,7 @@ Script *GDScriptLanguage::create_script() const { bool GDScriptLanguage::debug_break_parse(const String &p_file, int p_line, const String &p_error) { //break because of parse error - if (ScriptDebugger::get_singleton() && Thread::get_caller_ID() == Thread::get_main_ID()) { + if (ScriptDebugger::get_singleton() && Thread::get_caller_id() == Thread::get_main_id()) { _debug_parse_err_line = p_line; _debug_parse_err_file = p_file; @@ -151,7 +171,7 @@ bool GDScriptLanguage::debug_break_parse(const String &p_file, int p_line, const bool GDScriptLanguage::debug_break(const String &p_error, bool p_allow_continue) { - if (ScriptDebugger::get_singleton() && Thread::get_caller_ID() == Thread::get_main_ID()) { + if (ScriptDebugger::get_singleton() && Thread::get_caller_id() == Thread::get_main_id()) { _debug_parse_err_line = -1; _debug_parse_err_file = ""; @@ -618,7 +638,7 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: String which = arg1.get_slice("/", 2); if (which != "") { List<PropertyInfo> props; - GlobalConfig::get_singleton()->get_property_list(&props); + ProjectSettings::get_singleton()->get_property_list(&props); //print_line("find singleton"); for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { @@ -630,7 +650,7 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: String name = s.get_slice("/", 1); //print_line("name: "+name+", which: "+which); if (name == which) { - String script = GlobalConfig::get_singleton()->get(s); + String script = ProjectSettings::get_singleton()->get(s); if (!script.begins_with("res://")) { script = "res://" + script; @@ -1085,7 +1105,7 @@ static bool _guess_identifier_type(GDCompletionContext &context, int p_line, con //autoloads as singletons List<PropertyInfo> props; - GlobalConfig::get_singleton()->get_property_list(&props); + ProjectSettings::get_singleton()->get_property_list(&props); for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { @@ -1095,7 +1115,7 @@ static bool _guess_identifier_type(GDCompletionContext &context, int p_line, con String name = s.get_slice("/", 1); if (name == String(p_identifier)) { - String path = GlobalConfig::get_singleton()->get(s); + String path = ProjectSettings::get_singleton()->get(s); if (path.begins_with("*")) { String script = path.substr(1, path.length()); @@ -1256,7 +1276,7 @@ static void _find_identifiers_in_class(GDCompletionContext &context, bool p_stat } } List<MethodInfo> methods; - ClassDB::get_method_list(type, &methods); + ClassDB::get_method_list(type, &methods, false, true); for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) { if (E->get().name.begins_with("_")) continue; @@ -1314,8 +1334,8 @@ static void _find_identifiers(GDCompletionContext &context, int p_line, bool p_o static const char *_type_names[Variant::VARIANT_MAX] = { "null", "bool", "int", "float", "String", "Vector2", "Rect2", "Vector3", "Transform2D", "Plane", "Quat", "AABB", "Basis", "Transform", - "Color", "Image", "NodePath", "RID", "Object", "InputEvent", "Dictionary", "Array", "RawArray", "IntArray", "FloatArray", "StringArray", - "Vector2Array", "Vector3Array", "ColorArray" + "Color", "NodePath", "RID", "Object", "Dictionary", "Array", "PoolByteArray", "PoolIntArray", "PoolRealArray", "PoolStringArray", + "PoolVector2Array", "PoolVector3Array", "PoolColorArray" }; for (int i = 0; i < Variant::VARIANT_MAX; i++) { @@ -1324,7 +1344,7 @@ static void _find_identifiers(GDCompletionContext &context, int p_line, bool p_o //autoload singletons List<PropertyInfo> props; - GlobalConfig::get_singleton()->get_property_list(&props); + ProjectSettings::get_singleton()->get_property_list(&props); for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { @@ -1332,7 +1352,7 @@ static void _find_identifiers(GDCompletionContext &context, int p_line, bool p_o if (!s.begins_with("autoload/")) continue; String name = s.get_slice("/", 1); - String path = GlobalConfig::get_singleton()->get(s); + String path = ProjectSettings::get_singleton()->get(s); if (path.begins_with("*")) { result.insert(name); } @@ -1404,25 +1424,21 @@ static void _make_function_hint(const GDParser::FunctionNode *p_func, int p_argi arghint += ")"; } -static void _find_type_arguments(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, const StringName &p_method, const GDCompletionIdentifier &id, int p_argidx, Set<String> &result, String &arghint) { - - //print_line("find type arguments?"); - if (id.type == Variant::INPUT_EVENT && String(p_method) == "is_action" && p_argidx == 0) { - - List<PropertyInfo> pinfo; - GlobalConfig::get_singleton()->get_property_list(&pinfo); +void get_directory_contents(EditorFileSystemDirectory *p_dir, Set<String> &r_list) { - for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - const PropertyInfo &pi = E->get(); + for (int i = 0; i < p_dir->get_subdir_count(); i++) { + get_directory_contents(p_dir->get_subdir(i), r_list); + } - if (!pi.name.begins_with("input/")) - continue; + for (int i = 0; i < p_dir->get_file_count(); i++) { + r_list.insert("\"" + p_dir->get_file_path(i) + "\""); + } +} - String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length()); - result.insert("\"" + name + "\""); - } +static void _find_type_arguments(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, const StringName &p_method, const GDCompletionIdentifier &id, int p_argidx, Set<String> &result, String &arghint) { - } else if (id.type == Variant::OBJECT && id.obj_type != StringName()) { + //print_line("find type arguments?"); + if (id.type == Variant::OBJECT && id.obj_type != StringName()) { MethodBind *m = ClassDB::get_method(id.obj_type, p_method); if (!m) { @@ -1627,7 +1643,7 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N } else { //regular method - if (p_method.operator String() == "connect") { + if (p_method.operator String() == "connect" || (p_method.operator String() == "emit_signal" && p_argidx == 0)) { if (p_argidx == 0) { List<MethodInfo> sigs; @@ -1669,7 +1685,7 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N if (p_argidx == 0 && (String(p_method) == "get_node" || String(p_method) == "has_node") && ClassDB::is_parent_class(id.obj_type, "Node")) { List<PropertyInfo> props; - GlobalConfig::get_singleton()->get_property_list(&props); + ProjectSettings::get_singleton()->get_property_list(&props); for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { @@ -1752,6 +1768,10 @@ static void _find_call_arguments(GDCompletionContext &context, const GDParser::N const GDParser::BuiltInFunctionNode *fn = static_cast<const GDParser::BuiltInFunctionNode *>(op->arguments[0]); MethodInfo mi = GDFunctions::get_info(fn->function); + if (mi.name == "load" && bool(EditorSettings::get_singleton()->get("text_editor/completion/complete_file_paths"))) { + get_directory_contents(EditorFileSystem::get_singleton()->get_filesystem(), result); + } + arghint = _get_visual_datatype(mi.return_val, false) + " " + GDFunctions::get_func_name(fn->function) + String("("); for (int i = 0; i < mi.arguments.size(); i++) { if (i > 0) @@ -2231,7 +2251,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base } List<MethodInfo> mi; - ClassDB::get_method_list(t.obj_type, &mi); + ClassDB::get_method_list(t.obj_type, &mi, false, true); for (List<MethodInfo>::Element *E = mi.front(); E; E = E->next()) { if (E->get().name.begins_with("_")) @@ -2244,54 +2264,8 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base } } else { - if (t.type == Variant::INPUT_EVENT) { - - //this is hardcoded otherwise it's not obvious - Set<String> exclude; - - for (int i = 0; i < InputEvent::TYPE_MAX; i++) { - - InputEvent ie; - ie.type = InputEvent::Type(i); - static const char *evnames[] = { - "# Common", - "# Key", - "# MouseMotion", - "# MouseButton", - "# JoypadMotion", - "# JoypadButton", - "# ScreenTouch", - "# ScreenDrag", - "# Action" - }; - - r_options->push_back(evnames[i]); - - Variant v = ie; - - if (i == 0) { - List<MethodInfo> mi; - v.get_method_list(&mi); - for (List<MethodInfo>::Element *E = mi.front(); E; E = E->next()) { - r_options->push_back(E->get().name + "("); - } - } - - List<PropertyInfo> pi; - v.get_property_list(&pi); - - for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) { - - if (i == 0) - exclude.insert(E->get().name); - else if (exclude.has(E->get().name)) - continue; - - r_options->push_back(E->get().name); - } - } - return OK; - } else { + //check InputEvent hint + { if (t.value.get_type() == Variant::NIL) { Variant::CallError ce; t.value = Variant::construct(t.type, NULL, 0, ce); @@ -2373,6 +2347,11 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base } } break; + case GDParser::COMPLETION_RESOURCE_PATH: { + + if (EditorSettings::get_singleton()->get("text_editor/completion/complete_file_paths")) + get_directory_contents(EditorFileSystem::get_singleton()->get_filesystem(), options); + } break; } for (Set<String>::Element *E = options.front(); E; E = E->next()) { @@ -2390,8 +2369,29 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base #endif +String GDScriptLanguage::_get_indentation() const { +#ifdef TOOLS_ENABLED + if (SceneTree::get_singleton()->is_editor_hint()) { + bool use_space_indentation = EDITOR_DEF("text_editor/indent/type", 0); + + if (use_space_indentation) { + int indent_size = EDITOR_DEF("text_editor/indent/size", 4); + + String space_indent = ""; + for (int i = 0; i < indent_size; i++) { + space_indent += " "; + } + return space_indent; + } + } +#endif + return "\t"; +} + void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_to_line) const { + String indent = _get_indentation(); + Vector<String> lines = p_code.split("\n"); List<int> indent_stack; @@ -2431,8 +2431,9 @@ void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_t if (i >= p_from_line) { l = ""; - for (int j = 0; j < indent_stack.size(); j++) - l += "\t"; + for (int j = 0; j < indent_stack.size(); j++) { + l += indent; + } l += st; } else if (i > p_to_line) { @@ -2659,7 +2660,7 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol //guess in autoloads as singletons List<PropertyInfo> props; - GlobalConfig::get_singleton()->get_property_list(&props); + ProjectSettings::get_singleton()->get_property_list(&props); for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { @@ -2669,7 +2670,7 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol String name = s.get_slice("/", 1); if (name == String(p_symbol)) { - String path = GlobalConfig::get_singleton()->get(s); + String path = ProjectSettings::get_singleton()->get(s); if (path.begins_with("*")) { String script = path.substr(1, path.length()); |