Show documentation for properties on hover.
This works if the property has been documented (about half are at this point)
This commit is contained in:
parent
04cb3c9eb1
commit
d50921b550
7 changed files with 117 additions and 1 deletions
|
@ -746,6 +746,25 @@ bool ObjectTypeDB::has_method(StringName p_type,StringName p_method,bool p_no_in
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ObjectTypeDB::get_setter_and_type_for_property(const StringName& p_class, const StringName& p_prop, StringName& r_class, StringName& r_setter) {
|
||||||
|
|
||||||
|
TypeInfo *type=types.getptr(p_class);
|
||||||
|
TypeInfo *check=type;
|
||||||
|
while(check) {
|
||||||
|
|
||||||
|
if (check->property_setget.has(p_prop)) {
|
||||||
|
r_class=check->name;
|
||||||
|
r_setter=check->property_setget[p_prop].setter;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
check=check->inherits_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_METHODS_ENABLED
|
#ifdef DEBUG_METHODS_ENABLED
|
||||||
MethodBind* ObjectTypeDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind , const MethodDefinition &method_name, const Variant **p_defs, int p_defcount) {
|
MethodBind* ObjectTypeDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind , const MethodDefinition &method_name, const Variant **p_defs, int p_defcount) {
|
||||||
StringName mdname=method_name.name;
|
StringName mdname=method_name.name;
|
||||||
|
|
|
@ -475,7 +475,9 @@ public:
|
||||||
static void get_integer_constant_list(const StringName& p_type, List<String> *p_constants, bool p_no_inheritance=false);
|
static void get_integer_constant_list(const StringName& p_type, List<String> *p_constants, bool p_no_inheritance=false);
|
||||||
static int get_integer_constant(const StringName& p_type, const StringName &p_name, bool *p_success=NULL);
|
static int get_integer_constant(const StringName& p_type, const StringName &p_name, bool *p_success=NULL);
|
||||||
static StringName get_category(const StringName& p_node);
|
static StringName get_category(const StringName& p_node);
|
||||||
|
|
||||||
|
static bool get_setter_and_type_for_property(const StringName& p_class, const StringName& p_prop, StringName& r_class, StringName& r_setter);
|
||||||
|
|
||||||
static void set_type_enabled(StringName p_type,bool p_enable);
|
static void set_type_enabled(StringName p_type,bool p_enable);
|
||||||
static bool is_type_enabled(StringName p_type);
|
static bool is_type_enabled(StringName p_type);
|
||||||
|
|
||||||
|
|
|
@ -3048,6 +3048,38 @@ bool String::is_valid_identifier() const {
|
||||||
|
|
||||||
//kind of poor should be rewritten properly
|
//kind of poor should be rewritten properly
|
||||||
|
|
||||||
|
String String::world_wrap(int p_chars_per_line) const {
|
||||||
|
|
||||||
|
int from=0;
|
||||||
|
int last_space=0;
|
||||||
|
String ret;
|
||||||
|
for(int i=0;i<length();i++) {
|
||||||
|
if (i-from>=p_chars_per_line) {
|
||||||
|
if (last_space==-1) {
|
||||||
|
ret+=substr(from,i-from+1)+"\n";
|
||||||
|
from=i+1;
|
||||||
|
} else {
|
||||||
|
ret+=substr(from,last_space-from)+"\n";
|
||||||
|
i=last_space;
|
||||||
|
from=i+1;
|
||||||
|
}
|
||||||
|
last_space=-1;
|
||||||
|
} else if (operator[](i)==' ' || operator[](i)=='\t') {
|
||||||
|
last_space=i;
|
||||||
|
} else if (operator[](i)=='\n') {
|
||||||
|
ret+=substr(from,i-from);
|
||||||
|
from=i+1;
|
||||||
|
last_space=-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (from<length()) {
|
||||||
|
ret+=substr(from,length());
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
String String::c_unescape() const {
|
String String::c_unescape() const {
|
||||||
|
|
||||||
String escaped=*this;
|
String escaped=*this;
|
||||||
|
|
|
@ -209,6 +209,7 @@ public:
|
||||||
String xml_unescape() const;
|
String xml_unescape() const;
|
||||||
String c_escape() const;
|
String c_escape() const;
|
||||||
String c_unescape() const;
|
String c_unescape() const;
|
||||||
|
String world_wrap(int p_chars_per_line) const;
|
||||||
|
|
||||||
String percent_encode() const;
|
String percent_encode() const;
|
||||||
String percent_decode() const;
|
String percent_decode() const;
|
||||||
|
|
|
@ -4835,6 +4835,7 @@ EditorNode::EditorNode() {
|
||||||
property_editor->set_autoclear(true);
|
property_editor->set_autoclear(true);
|
||||||
property_editor->set_show_categories(true);
|
property_editor->set_show_categories(true);
|
||||||
property_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
property_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL);
|
||||||
|
property_editor->set_use_doc_hints(true);
|
||||||
|
|
||||||
property_editor->hide_top_label();
|
property_editor->hide_top_label();
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include "editor_node.h"
|
#include "editor_node.h"
|
||||||
#include "multi_node_edit.h"
|
#include "multi_node_edit.h"
|
||||||
#include "array_property_edit.h"
|
#include "array_property_edit.h"
|
||||||
|
#include "editor_help.h"
|
||||||
|
|
||||||
void CustomPropertyEditor::_notification(int p_what) {
|
void CustomPropertyEditor::_notification(int p_what) {
|
||||||
|
|
||||||
|
@ -2214,6 +2215,23 @@ void PropertyEditor::update_tree() {
|
||||||
sep->set_selectable(1,false);
|
sep->set_selectable(1,false);
|
||||||
sep->set_custom_bg_color(0,get_color("prop_category","Editor"));
|
sep->set_custom_bg_color(0,get_color("prop_category","Editor"));
|
||||||
sep->set_custom_bg_color(1,get_color("prop_category","Editor"));
|
sep->set_custom_bg_color(1,get_color("prop_category","Editor"));
|
||||||
|
|
||||||
|
if (use_doc_hints) {
|
||||||
|
StringName type=p.name;
|
||||||
|
if (!class_descr_cache.has(type)) {
|
||||||
|
|
||||||
|
String descr;
|
||||||
|
DocData *dd=EditorHelp::get_doc_data();
|
||||||
|
Map<String,DocData::ClassDoc>::Element *E=dd->class_list.find(type);
|
||||||
|
if (E) {
|
||||||
|
descr=E->get().brief_description;
|
||||||
|
}
|
||||||
|
class_descr_cache[type]=descr.world_wrap(80);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sep->set_tooltip(0,"Class: "+p.name+":\n\n"+class_descr_cache[type]);
|
||||||
|
}
|
||||||
//sep->set_custom_color(0,Color(1,1,1));
|
//sep->set_custom_color(0,Color(1,1,1));
|
||||||
|
|
||||||
|
|
||||||
|
@ -2267,6 +2285,42 @@ void PropertyEditor::update_tree() {
|
||||||
|
|
||||||
item->set_tooltip(0, p.name);
|
item->set_tooltip(0, p.name);
|
||||||
|
|
||||||
|
if (use_doc_hints) {
|
||||||
|
StringName setter;
|
||||||
|
StringName type;
|
||||||
|
if (ObjectTypeDB::get_setter_and_type_for_property(obj->get_type_name(),p.name,type,setter)) {
|
||||||
|
|
||||||
|
String descr;
|
||||||
|
bool found=false;
|
||||||
|
Map<StringName,Map<StringName,String> >::Element *E=descr_cache.find(type);
|
||||||
|
if (E) {
|
||||||
|
|
||||||
|
Map<StringName,String>::Element *F=E->get().find(setter);
|
||||||
|
if (F) {
|
||||||
|
found=true;
|
||||||
|
descr=F->get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
|
||||||
|
DocData *dd=EditorHelp::get_doc_data();
|
||||||
|
Map<String,DocData::ClassDoc>::Element *E=dd->class_list.find(type);
|
||||||
|
if (E) {
|
||||||
|
for(int i=0;i<E->get().methods.size();i++) {
|
||||||
|
if (E->get().methods[i].name==setter.operator String()) {
|
||||||
|
descr=E->get().methods[i].description.strip_edges().world_wrap(80);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
descr_cache[type][setter]=descr;
|
||||||
|
}
|
||||||
|
|
||||||
|
item->set_tooltip(0, "Property: "+p.name+"\n\n"+descr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//EditorHelp::get_doc_data();
|
||||||
|
|
||||||
Dictionary d;
|
Dictionary d;
|
||||||
d["name"]=p.name;
|
d["name"]=p.name;
|
||||||
d["type"]=(int)p.type;
|
d["type"]=(int)p.type;
|
||||||
|
@ -3277,6 +3331,7 @@ PropertyEditor::PropertyEditor() {
|
||||||
read_only=false;
|
read_only=false;
|
||||||
show_categories=false;
|
show_categories=false;
|
||||||
refresh_countdown=0;
|
refresh_countdown=0;
|
||||||
|
use_doc_hints=false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,7 @@ class CustomPropertyEditor : public Popup {
|
||||||
Button *checks20[20];
|
Button *checks20[20];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Control *easing_draw;
|
Control *easing_draw;
|
||||||
|
|
||||||
Object* owner;
|
Object* owner;
|
||||||
|
@ -157,9 +158,13 @@ class PropertyEditor : public Control {
|
||||||
bool read_only;
|
bool read_only;
|
||||||
bool show_categories;
|
bool show_categories;
|
||||||
float refresh_countdown;
|
float refresh_countdown;
|
||||||
|
bool use_doc_hints;
|
||||||
|
|
||||||
HashMap<String,String> pending;
|
HashMap<String,String> pending;
|
||||||
String selected_property;
|
String selected_property;
|
||||||
|
|
||||||
|
Map<StringName,Map<StringName,String> > descr_cache;
|
||||||
|
Map<StringName,String > class_descr_cache;
|
||||||
|
|
||||||
CustomPropertyEditor *custom_editor;
|
CustomPropertyEditor *custom_editor;
|
||||||
|
|
||||||
|
@ -217,6 +222,7 @@ public:
|
||||||
void set_autoclear(bool p_enable);
|
void set_autoclear(bool p_enable);
|
||||||
|
|
||||||
void set_show_categories(bool p_show);
|
void set_show_categories(bool p_show);
|
||||||
|
void set_use_doc_hints(bool p_enable) { use_doc_hints=p_enable; }
|
||||||
|
|
||||||
PropertyEditor();
|
PropertyEditor();
|
||||||
~PropertyEditor();
|
~PropertyEditor();
|
||||||
|
|
Loading…
Reference in a new issue