Ctrl+Clicking a enum now scrolls down to it in the docs.

This commit is contained in:
Felix Yang 2018-03-30 16:20:24 +02:00
parent b61021d34f
commit 7d5a40c3e6
7 changed files with 75 additions and 12 deletions

View file

@ -651,7 +651,6 @@ void ClassDB::bind_integer_constant(const StringName &p_class, const StringName
}
type->constant_map[p_name] = p_constant;
#ifdef DEBUG_METHODS_ENABLED
String enum_name = p_enum;
if (enum_name != String()) {
@ -670,6 +669,7 @@ void ClassDB::bind_integer_constant(const StringName &p_class, const StringName
}
}
#ifdef DEBUG_METHODS_ENABLED
type->constant_order.push_back(p_name);
#endif
}
@ -725,7 +725,6 @@ int ClassDB::get_integer_constant(const StringName &p_class, const StringName &p
return 0;
}
#ifdef DEBUG_METHODS_ENABLED
StringName ClassDB::get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) {
OBJTYPE_RLOCK;
@ -794,7 +793,6 @@ void ClassDB::get_enum_constants(const StringName &p_class, const StringName &p_
type = type->inherits_ptr;
}
}
#endif
void ClassDB::add_signal(StringName p_class, const MethodInfo &p_signal) {

View file

@ -116,10 +116,10 @@ public:
ClassInfo *inherits_ptr;
HashMap<StringName, MethodBind *, StringNameHasher> method_map;
HashMap<StringName, int, StringNameHasher> constant_map;
HashMap<StringName, List<StringName> > enum_map;
HashMap<StringName, MethodInfo, StringNameHasher> signal_map;
List<PropertyInfo> property_list;
#ifdef DEBUG_METHODS_ENABLED
HashMap<StringName, List<StringName> > enum_map;
List<StringName> constant_order;
List<StringName> method_order;
Set<StringName> methods_in_properties;
@ -344,11 +344,9 @@ public:
static void get_integer_constant_list(const StringName &p_class, List<String> *p_constants, bool p_no_inheritance = false);
static int get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success = NULL);
#ifdef DEBUG_METHODS_ENABLED
static StringName get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
static void get_enum_list(const StringName &p_class, List<StringName> *p_enums, bool p_no_inheritance = false);
static void get_enum_constants(const StringName &p_class, const StringName &p_enum, List<StringName> *p_constants, bool p_no_inheritance = false);
#endif
static StringName get_category(const StringName &p_node);

View file

@ -221,7 +221,9 @@ public:
RESULT_CLASS,
RESULT_CLASS_CONSTANT,
RESULT_CLASS_PROPERTY,
RESULT_CLASS_METHOD
RESULT_CLASS_METHOD,
RESULT_CLASS_ENUM,
RESULT_CLASS_TBD_GLOBALSCOPE
};
Type type;
Ref<Script> script;

View file

@ -1172,7 +1172,12 @@ Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) {
class_desc->push_indent(1);
Vector<DocData::ConstantDoc> enum_list = E->get();
Map<String, int> enumValuesContainer;
int enumStartingLine = enum_line[E->key()];
for (int i = 0; i < enum_list.size(); i++) {
if (cd.name == "@GlobalScope")
enumValuesContainer[enum_list[i].name] = enumStartingLine;
class_desc->push_font(doc_code_font);
class_desc->push_color(headline_color);
@ -1200,6 +1205,9 @@ Error EditorHelp::_goto_desc(const String &p_class, int p_vscr) {
class_desc->add_newline();
}
if (cd.name == "@GlobalScope")
enum_values_line[E->key()] = enumValuesContainer;
class_desc->pop();
class_desc->add_newline();
@ -1485,21 +1493,32 @@ void EditorHelp::_help_callback(const String &p_topic) {
if (method_line.has(name))
line = method_line[name];
} else if (what == "class_property") {
if (property_line.has(name))
line = property_line[name];
} else if (what == "class_enum") {
if (enum_line.has(name))
line = enum_line[name];
} else if (what == "class_theme_item") {
if (theme_property_line.has(name))
line = theme_property_line[name];
} else if (what == "class_constant") {
if (constant_line.has(name))
line = constant_line[name];
} else if (what == "class_global") {
if (constant_line.has(name))
line = constant_line[name];
else {
Map<String, Map<String, int> >::Element *iter = enum_values_line.front();
while (true) {
if (iter->value().has(name)) {
line = iter->value()[name];
break;
} else if (iter == enum_values_line.back())
break;
else
iter = iter->next();
}
}
}
class_desc->call_deferred("scroll_to_line", line);

View file

@ -152,6 +152,7 @@ class EditorHelp : public VBoxContainer {
Map<String, int> theme_property_line;
Map<String, int> constant_line;
Map<String, int> enum_line;
Map<String, Map<String, int> > enum_values_line;
int description_line;
RichTextLabel *class_desc;

View file

@ -789,6 +789,26 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c
emit_signal("go_to_help", "class_method:" + result.class_name + ":" + result.class_member);
} break;
case ScriptLanguage::LookupResult::RESULT_CLASS_ENUM: {
StringName cname = result.class_name;
StringName success;
while (true) {
success = ClassDB::get_integer_constant_enum(cname, result.class_member, true);
if (success != StringName()) {
result.class_name = cname;
cname = ClassDB::get_parent_class(cname);
} else {
break;
}
}
emit_signal("go_to_help", "class_enum:" + result.class_name + ":" + result.class_member);
} break;
case ScriptLanguage::LookupResult::RESULT_CLASS_TBD_GLOBALSCOPE: {
emit_signal("go_to_help", "class_global:" + result.class_name + ":" + result.class_member);
} break;
}
}
}

View file

@ -2850,7 +2850,24 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol
return OK;
}
} else {
r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT;
/*
// Because get_integer_constant_enum and get_integer_constant dont work on @GlobalScope
// We cannot determine the exact nature of the identifier here
// Otherwise these codes would work
StringName enumName = ClassDB::get_integer_constant_enum("@GlobalScope", p_symbol, true);
if (enumName != NULL) {
r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_ENUM;
r_result.class_name = "@GlobalScope";
r_result.class_member = enumName;
return OK;
}
else {
r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT;
r_result.class_name = "@GlobalScope";
r_result.class_member = p_symbol;
return OK;
}*/
r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_TBD_GLOBALSCOPE;
r_result.class_name = "@GlobalScope";
r_result.class_member = p_symbol;
return OK;
@ -2913,6 +2930,14 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol
return OK;
}
StringName enumName = ClassDB::get_integer_constant_enum(t.obj_type, p_symbol, true);
if (enumName != StringName()) {
r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_ENUM;
r_result.class_name = t.obj_type;
r_result.class_member = enumName;
return OK;
}
bool success;
ClassDB::get_integer_constant(t.obj_type, p_symbol, &success);
if (success) {