Making bits of docs appear in different dialogues is made easier with EditorHelpBit

This commit is contained in:
Juan Linietsky 2016-08-23 23:15:16 -03:00
parent ad8f208bdb
commit dc7139c90d
7 changed files with 177 additions and 63 deletions

View File

@ -140,7 +140,7 @@ void CreateDialog::_update_search() {
search_options->clear(); search_options->clear();
help_bit->set_text("");
/* /*
TreeItem *root = search_options->create_item(); TreeItem *root = search_options->create_item();
_parse_fs(EditorFileSystem::get_singleton()->get_filesystem()); _parse_fs(EditorFileSystem::get_singleton()->get_filesystem());
@ -336,11 +336,27 @@ String CreateDialog::get_base_type() const {
return base_type; return base_type;
} }
void CreateDialog::_item_selected() {
TreeItem *item = search_options->get_selected();
if (!item)
return;
String name = item->get_text(0);
if (!EditorHelp::get_doc_data()->class_list.has(name))
return;
help_bit->set_text(EditorHelp::get_doc_data()->class_list[name].brief_description);
}
void CreateDialog::_bind_methods() { void CreateDialog::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_text_changed"),&CreateDialog::_text_changed); ObjectTypeDB::bind_method(_MD("_text_changed"),&CreateDialog::_text_changed);
ObjectTypeDB::bind_method(_MD("_confirmed"),&CreateDialog::_confirmed); ObjectTypeDB::bind_method(_MD("_confirmed"),&CreateDialog::_confirmed);
ObjectTypeDB::bind_method(_MD("_sbox_input"),&CreateDialog::_sbox_input); ObjectTypeDB::bind_method(_MD("_sbox_input"),&CreateDialog::_sbox_input);
ObjectTypeDB::bind_method(_MD("_item_selected"),&CreateDialog::_item_selected);
ADD_SIGNAL(MethodInfo("create")); ADD_SIGNAL(MethodInfo("create"));
@ -364,9 +380,14 @@ CreateDialog::CreateDialog() {
register_text_enter(search_box); register_text_enter(search_box);
set_hide_on_ok(false); set_hide_on_ok(false);
search_options->connect("item_activated",this,"_confirmed"); search_options->connect("item_activated",this,"_confirmed");
search_options->connect("cell_selected",this,"_item_selected");
// search_options->set_hide_root(true); // search_options->set_hide_root(true);
base_type="Object"; base_type="Object";
help_bit = memnew( EditorHelpBit );
vbc->add_margin_child(TTR("Description:"),help_bit);
help_bit->connect("request_hide",this,"_closed");
} }

View File

@ -34,6 +34,7 @@
#include "scene/gui/tree.h" #include "scene/gui/tree.h"
#include "scene/gui/line_edit.h" #include "scene/gui/line_edit.h"
#include "scene/gui/label.h" #include "scene/gui/label.h"
#include "editor_help.h"
/** /**
@author Juan Linietsky <reduzio@gmail.com> @author Juan Linietsky <reduzio@gmail.com>
*/ */
@ -49,6 +50,10 @@ class CreateDialog : public ConfirmationDialog {
Tree *search_options; Tree *search_options;
String base_type; String base_type;
EditorHelpBit *help_bit;
void _item_selected();
void _update_search(); void _update_search();
void _sbox_input(const InputEvent& p_ie); void _sbox_input(const InputEvent& p_ie);

View File

@ -31,7 +31,7 @@
#include "editor_settings.h" #include "editor_settings.h"
#include "os/keyboard.h" #include "os/keyboard.h"
#include "doc_data_compressed.h" #include "doc_data_compressed.h"
#include "tools/editor/plugins/script_editor_plugin.h"
#include "os/keyboard.h" #include "os/keyboard.h"
@ -1256,16 +1256,20 @@ void EditorHelp::_help_callback(const String& p_topic) {
} }
void EditorHelp::_add_text(const String& p_bbcode) {
/*class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color")); static void _add_text_to_rt(const String& p_bbcode,RichTextLabel *p_rt) {
class_desc->push_font( get_font("normal","Fonts") );
class_desc->push_indent(1);*/ DocData *doc = EditorHelp::get_doc_data();
String base_path;
/*p_rt->push_color(EditorSettings::get_singleton()->get("text_editor/text_color"));
p_rt->push_font( get_font("normal","Fonts") );
p_rt->push_indent(1);*/
int pos = 0; int pos = 0;
Ref<Font> doc_font = get_font("doc","EditorFonts"); Ref<Font> doc_font = p_rt->get_font("doc","EditorFonts");
Ref<Font> doc_code_font = get_font("doc_source","EditorFonts"); Ref<Font> doc_code_font = p_rt->get_font("doc_source","EditorFonts");
String bbcode=p_bbcode.replace("\t"," ").replace("\r"," ").strip_edges(); String bbcode=p_bbcode.replace("\t"," ").replace("\r"," ").strip_edges();
@ -1333,7 +1337,7 @@ void EditorHelp::_add_text(const String& p_bbcode) {
brk_pos=bbcode.length(); brk_pos=bbcode.length();
if (brk_pos > pos) { if (brk_pos > pos) {
class_desc->add_text(bbcode.substr(pos,brk_pos-pos)); p_rt->add_text(bbcode.substr(pos,brk_pos-pos));
} }
@ -1344,7 +1348,7 @@ void EditorHelp::_add_text(const String& p_bbcode) {
if (brk_end==-1) { if (brk_end==-1) {
//no close, add the rest //no close, add the rest
class_desc->add_text(bbcode.substr(brk_pos,bbcode.length()-brk_pos)); p_rt->add_text(bbcode.substr(brk_pos,bbcode.length()-brk_pos));
break; break;
} }
@ -1362,7 +1366,7 @@ void EditorHelp::_add_text(const String& p_bbcode) {
} }
if (!tag_ok) { if (!tag_ok) {
class_desc->add_text("["); p_rt->add_text("[");
pos++; pos++;
continue; continue;
} }
@ -1370,32 +1374,32 @@ void EditorHelp::_add_text(const String& p_bbcode) {
tag_stack.pop_front(); tag_stack.pop_front();
pos=brk_end+1; pos=brk_end+1;
if (tag!="/img") if (tag!="/img")
class_desc->pop(); p_rt->pop();
} else if (tag.begins_with("method ")) { } else if (tag.begins_with("method ")) {
String m = tag.substr(7,tag.length()); String m = tag.substr(7,tag.length());
class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color")); p_rt->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
class_desc->push_meta("@"+m); p_rt->push_meta("@"+m);
class_desc->add_text(m+"()"); p_rt->add_text(m+"()");
class_desc->pop(); p_rt->pop();
class_desc->pop(); p_rt->pop();
pos=brk_end+1; pos=brk_end+1;
} else if (doc->class_list.has(tag)) { } else if (doc->class_list.has(tag)) {
class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color")); p_rt->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
class_desc->push_meta("#"+tag); p_rt->push_meta("#"+tag);
class_desc->add_text(tag); p_rt->add_text(tag);
class_desc->pop(); p_rt->pop();
class_desc->pop(); p_rt->pop();
pos=brk_end+1; pos=brk_end+1;
} else if (tag=="b") { } else if (tag=="b") {
//use bold font //use bold font
class_desc->push_font(doc_code_font); p_rt->push_font(doc_code_font);
pos=brk_end+1; pos=brk_end+1;
tag_stack.push_front(tag); tag_stack.push_front(tag);
} else if (tag=="i") { } else if (tag=="i") {
@ -1406,37 +1410,37 @@ void EditorHelp::_add_text(const String& p_bbcode) {
text_color.r*=1.1; text_color.r*=1.1;
text_color.g*=1.1; text_color.g*=1.1;
text_color.b*=1.1; text_color.b*=1.1;
class_desc->push_color(text_color); p_rt->push_color(text_color);
//class_desc->push_font(get_font("italic","Fonts")); //p_rt->push_font(get_font("italic","Fonts"));
pos=brk_end+1; pos=brk_end+1;
tag_stack.push_front(tag); tag_stack.push_front(tag);
} else if (tag=="code" || tag=="codeblock") { } else if (tag=="code" || tag=="codeblock") {
//use monospace font //use monospace font
class_desc->push_font(doc_code_font); p_rt->push_font(doc_code_font);
pos=brk_end+1; pos=brk_end+1;
tag_stack.push_front(tag); tag_stack.push_front(tag);
} else if (tag=="center") { } else if (tag=="center") {
//use monospace font //use monospace font
class_desc->push_align(RichTextLabel::ALIGN_CENTER); p_rt->push_align(RichTextLabel::ALIGN_CENTER);
pos=brk_end+1; pos=brk_end+1;
tag_stack.push_front(tag); tag_stack.push_front(tag);
} else if (tag=="br") { } else if (tag=="br") {
//use monospace font //use monospace font
class_desc->add_newline(); p_rt->add_newline();
pos=brk_end+1; pos=brk_end+1;
} else if (tag=="u") { } else if (tag=="u") {
//use underline //use underline
class_desc->push_underline(); p_rt->push_underline();
pos=brk_end+1; pos=brk_end+1;
tag_stack.push_front(tag); tag_stack.push_front(tag);
} else if (tag=="s") { } else if (tag=="s") {
//use strikethrough (not supported underline instead) //use strikethrough (not supported underline instead)
class_desc->push_underline(); p_rt->push_underline();
pos=brk_end+1; pos=brk_end+1;
tag_stack.push_front(tag); tag_stack.push_front(tag);
@ -1447,14 +1451,14 @@ void EditorHelp::_add_text(const String& p_bbcode) {
if (end==-1) if (end==-1)
end=bbcode.length(); end=bbcode.length();
String url = bbcode.substr(brk_end+1,end-brk_end-1); String url = bbcode.substr(brk_end+1,end-brk_end-1);
class_desc->push_meta(url); p_rt->push_meta(url);
pos=brk_end+1; pos=brk_end+1;
tag_stack.push_front(tag); tag_stack.push_front(tag);
} else if (tag.begins_with("url=")) { } else if (tag.begins_with("url=")) {
String url = tag.substr(4,tag.length()); String url = tag.substr(4,tag.length());
class_desc->push_meta(url); p_rt->push_meta(url);
pos=brk_end+1; pos=brk_end+1;
tag_stack.push_front("url"); tag_stack.push_front("url");
} else if (tag=="img") { } else if (tag=="img") {
@ -1467,7 +1471,7 @@ void EditorHelp::_add_text(const String& p_bbcode) {
Ref<Texture> texture = ResourceLoader::load(base_path+"/"+image,"Texture"); Ref<Texture> texture = ResourceLoader::load(base_path+"/"+image,"Texture");
if (texture.is_valid()) if (texture.is_valid())
class_desc->add_image(texture); p_rt->add_image(texture);
pos=end; pos=end;
tag_stack.push_front(tag); tag_stack.push_front(tag);
@ -1515,7 +1519,7 @@ void EditorHelp::_add_text(const String& p_bbcode) {
class_desc->push_color(color); p_rt->push_color(color);
pos=brk_end+1; pos=brk_end+1;
tag_stack.push_front("color"); tag_stack.push_front("color");
@ -1526,9 +1530,9 @@ void EditorHelp::_add_text(const String& p_bbcode) {
Ref<Font> font = ResourceLoader::load(base_path+"/"+fnt,"Font"); Ref<Font> font = ResourceLoader::load(base_path+"/"+fnt,"Font");
if (font.is_valid()) if (font.is_valid())
class_desc->push_font(font); p_rt->push_font(font);
else { else {
class_desc->push_font(doc_font); p_rt->push_font(doc_font);
} }
pos=brk_end+1; pos=brk_end+1;
@ -1537,15 +1541,23 @@ void EditorHelp::_add_text(const String& p_bbcode) {
} else { } else {
class_desc->add_text("["); //ignore p_rt->add_text("["); //ignore
pos=brk_pos+1; pos=brk_pos+1;
} }
} }
/*class_desc->pop(); /*p_rt->pop();
class_desc->pop(); p_rt->pop();
class_desc->pop();*/ p_rt->pop();*/
}
void EditorHelp::_add_text(const String& p_bbcode) {
_add_text_to_rt(p_bbcode,class_desc);
} }
@ -1703,3 +1715,71 @@ EditorHelp::~EditorHelp() {
} }
/////////////
void EditorHelpBit::_go_to_help(String p_what) {
EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
ScriptEditor::get_singleton()->goto_help(p_what);
emit_signal("request_hide");
}
void EditorHelpBit::_meta_clicked(String p_select) {
// print_line("LINK: "+p_select);
if (p_select.begins_with("#")) {
//_goto_desc(p_select.substr(1,p_select.length()));
_go_to_help("class_name:"+p_select.substr(1,p_select.length()));
return;
} else if (p_select.begins_with("@")) {
String m = p_select.substr(1,p_select.length());
if (m.find(".")!=-1) {
//must go somewhere else
_go_to_help("class_method:"+m.get_slice(".",0)+":"+m.get_slice(".",0));
} else {
//
// if (!method_line.has(m))
// return;
//class_desc->scroll_to_line(method_line[m]);
}
}
}
void EditorHelpBit::_bind_methods() {
ObjectTypeDB::bind_method("_meta_clicked",&EditorHelpBit::_meta_clicked);
ADD_SIGNAL(MethodInfo("request_hide"));
}
void EditorHelpBit::_notification(int p_what){
if (p_what==NOTIFICATION_ENTER_TREE) {
add_style_override("panel",get_stylebox("normal","TextEdit"));
}
}
void EditorHelpBit::set_text(const String& p_text) {
rich_text->clear();
_add_text_to_rt(p_text,rich_text);
}
EditorHelpBit::EditorHelpBit() {
rich_text = memnew( RichTextLabel );
add_child(rich_text);
rich_text->set_area_as_parent_rect(8*EDSCALE);
rich_text->connect("meta_clicked",this,"_meta_clicked");
set_custom_minimum_size(Size2(0,70*EDSCALE));
}

View File

@ -200,6 +200,23 @@ public:
class EditorHelpBit : public Panel {
OBJ_TYPE( EditorHelpBit, Panel);
RichTextLabel *rich_text;
void _go_to_help(String p_what);
void _meta_clicked(String p_what);
protected:
static void _bind_methods();
void _notification(int p_what);
public:
void set_text(const String& p_text);
EditorHelpBit();
};
#endif // EDITOR_HELP_H #endif // EDITOR_HELP_H

View File

@ -320,6 +320,8 @@ public:
void close_builtin_scripts_from_scene(const String& p_scene); void close_builtin_scripts_from_scene(const String& p_scene);
void goto_help(const String& p_desc) { _help_class_goto(p_desc); }
ScriptEditorDebugger *get_debugger() { return debugger; } ScriptEditorDebugger *get_debugger() { return debugger; }
void set_live_auto_reload_running_scripts(bool p_enabled); void set_live_auto_reload_running_scripts(bool p_enabled);

View File

@ -2,7 +2,6 @@
#include "editor_scale.h" #include "editor_scale.h"
#include "os/keyboard.h" #include "os/keyboard.h"
#include "editor_help.h"
void PropertySelector::_text_changed(const String& p_newtext) { void PropertySelector::_text_changed(const String& p_newtext) {
@ -51,7 +50,7 @@ void PropertySelector::_update_search() {
set_title(TTR("Select Method")); set_title(TTR("Select Method"));
search_options->clear(); search_options->clear();
rich_text->clear(); help_bit->set_text("");
TreeItem *root = search_options->create_item(); TreeItem *root = search_options->create_item();
@ -307,14 +306,13 @@ void PropertySelector::_confirmed() {
void PropertySelector::_item_selected() { void PropertySelector::_item_selected() {
rich_text->clear(); help_bit->set_text("");
TreeItem *item=search_options->get_selected(); TreeItem *item=search_options->get_selected();
if (!item) if (!item)
return; return;
String name = item->get_metadata(0); String name = item->get_metadata(0);
print_line("NAME: "+name);
String class_type; String class_type;
if (properties && type==Variant::INPUT_EVENT) { if (properties && type==Variant::INPUT_EVENT) {
@ -350,12 +348,11 @@ void PropertySelector::_item_selected() {
while(at_class!=String()) { while(at_class!=String()) {
print_line("AT CLASS: "+at_class);
Map<String,DocData::ClassDoc>::Element *E=dd->class_list.find(at_class); Map<String,DocData::ClassDoc>::Element *E=dd->class_list.find(at_class);
if (E) { if (E) {
for(int i=0;i<E->get().properties.size();i++) { for(int i=0;i<E->get().properties.size();i++) {
if (E->get().properties[i].name==name) { if (E->get().properties[i].name==name) {
print_line("FOUND PROP");
text=E->get().properties[i].description; text=E->get().properties[i].description;
} }
} }
@ -368,14 +365,11 @@ void PropertySelector::_item_selected() {
StringName setter; StringName setter;
StringName type; StringName type;
print_line("AT SETGET: ");
if (ObjectTypeDB::get_setter_and_type_for_property(class_type,name,type,setter)) { if (ObjectTypeDB::get_setter_and_type_for_property(class_type,name,type,setter)) {
print_line("GOT: "+String(type));
Map<String,DocData::ClassDoc>::Element *E=dd->class_list.find(type); Map<String,DocData::ClassDoc>::Element *E=dd->class_list.find(type);
if (E) { if (E) {
for(int i=0;i<E->get().methods.size();i++) { for(int i=0;i<E->get().methods.size();i++) {
if (E->get().methods[i].name==setter.operator String()) { if (E->get().methods[i].name==setter.operator String()) {
print_line("FOUND");
text=E->get().methods[i].description; text=E->get().methods[i].description;
} }
} }
@ -392,12 +386,10 @@ void PropertySelector::_item_selected() {
while(at_class!=String()) { while(at_class!=String()) {
print_line("AT CLASS: "+at_class);
Map<String,DocData::ClassDoc>::Element *E=dd->class_list.find(at_class); Map<String,DocData::ClassDoc>::Element *E=dd->class_list.find(at_class);
if (E) { if (E) {
for(int i=0;i<E->get().methods.size();i++) { for(int i=0;i<E->get().methods.size();i++) {
if (E->get().methods[i].name==name) { if (E->get().methods[i].name==name) {
print_line("FOUND");
text=E->get().methods[i].description; text=E->get().methods[i].description;
} }
} }
@ -411,9 +403,7 @@ void PropertySelector::_item_selected() {
if (text==String()) if (text==String())
return; return;
rich_text->parse_bbcode(text); help_bit->set_text(text);
} }
@ -423,7 +413,7 @@ void PropertySelector::_notification(int p_what) {
if (p_what==NOTIFICATION_ENTER_TREE) { if (p_what==NOTIFICATION_ENTER_TREE) {
connect("confirmed",this,"_confirmed"); connect("confirmed",this,"_confirmed");
description->add_style_override("bg",get_stylebox("normal","TextEdit"));
} }
} }
@ -599,11 +589,9 @@ PropertySelector::PropertySelector() {
search_options->set_hide_root(true); search_options->set_hide_root(true);
search_options->set_hide_folding(true); search_options->set_hide_folding(true);
description = memnew( Panel ); help_bit = memnew( EditorHelpBit );
description->set_custom_minimum_size(Size2(0,80*EDSCALE)); vbc->add_margin_child(TTR("Description:"),help_bit);
vbc->add_margin_child(TTR("Description:"),description); help_bit->connect("request_hide",this,"_closed");
rich_text = memnew( RichTextLabel );
description->add_child(rich_text);
rich_text->set_area_as_parent_rect(8*EDSCALE);
} }

View File

@ -3,6 +3,8 @@
#include "tools/editor/property_editor.h" #include "tools/editor/property_editor.h"
#include "scene/gui/rich_text_label.h" #include "scene/gui/rich_text_label.h"
#include "editor_help.h"
class PropertySelector : public ConfirmationDialog { class PropertySelector : public ConfirmationDialog {
OBJ_TYPE(PropertySelector,ConfirmationDialog ) OBJ_TYPE(PropertySelector,ConfirmationDialog )
@ -17,8 +19,7 @@ class PropertySelector : public ConfirmationDialog {
void _confirmed(); void _confirmed();
void _text_changed(const String& p_newtext); void _text_changed(const String& p_newtext);
Panel *description; EditorHelpBit *help_bit;
RichTextLabel *rich_text;
bool properties; bool properties;
String selected; String selected;