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();
help_bit->set_text("");
/*
TreeItem *root = search_options->create_item();
_parse_fs(EditorFileSystem::get_singleton()->get_filesystem());
@ -336,11 +336,27 @@ String CreateDialog::get_base_type() const {
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() {
ObjectTypeDB::bind_method(_MD("_text_changed"),&CreateDialog::_text_changed);
ObjectTypeDB::bind_method(_MD("_confirmed"),&CreateDialog::_confirmed);
ObjectTypeDB::bind_method(_MD("_sbox_input"),&CreateDialog::_sbox_input);
ObjectTypeDB::bind_method(_MD("_item_selected"),&CreateDialog::_item_selected);
ADD_SIGNAL(MethodInfo("create"));
@ -364,9 +380,14 @@ CreateDialog::CreateDialog() {
register_text_enter(search_box);
set_hide_on_ok(false);
search_options->connect("item_activated",this,"_confirmed");
search_options->connect("cell_selected",this,"_item_selected");
// search_options->set_hide_root(true);
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/line_edit.h"
#include "scene/gui/label.h"
#include "editor_help.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
@ -49,6 +50,10 @@ class CreateDialog : public ConfirmationDialog {
Tree *search_options;
String base_type;
EditorHelpBit *help_bit;
void _item_selected();
void _update_search();
void _sbox_input(const InputEvent& p_ie);

View File

@ -31,7 +31,7 @@
#include "editor_settings.h"
#include "os/keyboard.h"
#include "doc_data_compressed.h"
#include "tools/editor/plugins/script_editor_plugin.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"));
class_desc->push_font( get_font("normal","Fonts") );
class_desc->push_indent(1);*/
static void _add_text_to_rt(const String& p_bbcode,RichTextLabel *p_rt) {
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;
Ref<Font> doc_font = get_font("doc","EditorFonts");
Ref<Font> doc_code_font = get_font("doc_source","EditorFonts");
Ref<Font> doc_font = p_rt->get_font("doc","EditorFonts");
Ref<Font> doc_code_font = p_rt->get_font("doc_source","EditorFonts");
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();
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) {
//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;
}
@ -1362,7 +1366,7 @@ void EditorHelp::_add_text(const String& p_bbcode) {
}
if (!tag_ok) {
class_desc->add_text("[");
p_rt->add_text("[");
pos++;
continue;
}
@ -1370,32 +1374,32 @@ void EditorHelp::_add_text(const String& p_bbcode) {
tag_stack.pop_front();
pos=brk_end+1;
if (tag!="/img")
class_desc->pop();
p_rt->pop();
} else if (tag.begins_with("method ")) {
String m = tag.substr(7,tag.length());
class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
class_desc->push_meta("@"+m);
class_desc->add_text(m+"()");
class_desc->pop();
class_desc->pop();
p_rt->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
p_rt->push_meta("@"+m);
p_rt->add_text(m+"()");
p_rt->pop();
p_rt->pop();
pos=brk_end+1;
} else if (doc->class_list.has(tag)) {
class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
class_desc->push_meta("#"+tag);
class_desc->add_text(tag);
class_desc->pop();
class_desc->pop();
p_rt->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color"));
p_rt->push_meta("#"+tag);
p_rt->add_text(tag);
p_rt->pop();
p_rt->pop();
pos=brk_end+1;
} else if (tag=="b") {
//use bold font
class_desc->push_font(doc_code_font);
p_rt->push_font(doc_code_font);
pos=brk_end+1;
tag_stack.push_front(tag);
} else if (tag=="i") {
@ -1406,37 +1410,37 @@ void EditorHelp::_add_text(const String& p_bbcode) {
text_color.r*=1.1;
text_color.g*=1.1;
text_color.b*=1.1;
class_desc->push_color(text_color);
//class_desc->push_font(get_font("italic","Fonts"));
p_rt->push_color(text_color);
//p_rt->push_font(get_font("italic","Fonts"));
pos=brk_end+1;
tag_stack.push_front(tag);
} else if (tag=="code" || tag=="codeblock") {
//use monospace font
class_desc->push_font(doc_code_font);
p_rt->push_font(doc_code_font);
pos=brk_end+1;
tag_stack.push_front(tag);
} else if (tag=="center") {
//use monospace font
class_desc->push_align(RichTextLabel::ALIGN_CENTER);
p_rt->push_align(RichTextLabel::ALIGN_CENTER);
pos=brk_end+1;
tag_stack.push_front(tag);
} else if (tag=="br") {
//use monospace font
class_desc->add_newline();
p_rt->add_newline();
pos=brk_end+1;
} else if (tag=="u") {
//use underline
class_desc->push_underline();
p_rt->push_underline();
pos=brk_end+1;
tag_stack.push_front(tag);
} else if (tag=="s") {
//use strikethrough (not supported underline instead)
class_desc->push_underline();
p_rt->push_underline();
pos=brk_end+1;
tag_stack.push_front(tag);
@ -1447,14 +1451,14 @@ void EditorHelp::_add_text(const String& p_bbcode) {
if (end==-1)
end=bbcode.length();
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;
tag_stack.push_front(tag);
} else if (tag.begins_with("url=")) {
String url = tag.substr(4,tag.length());
class_desc->push_meta(url);
p_rt->push_meta(url);
pos=brk_end+1;
tag_stack.push_front("url");
} 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");
if (texture.is_valid())
class_desc->add_image(texture);
p_rt->add_image(texture);
pos=end;
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;
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");
if (font.is_valid())
class_desc->push_font(font);
p_rt->push_font(font);
else {
class_desc->push_font(doc_font);
p_rt->push_font(doc_font);
}
pos=brk_end+1;
@ -1537,15 +1541,23 @@ void EditorHelp::_add_text(const String& p_bbcode) {
} else {
class_desc->add_text("["); //ignore
p_rt->add_text("["); //ignore
pos=brk_pos+1;
}
}
/*class_desc->pop();
class_desc->pop();
class_desc->pop();*/
/*p_rt->pop();
p_rt->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

View File

@ -320,6 +320,8 @@ public:
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; }
void set_live_auto_reload_running_scripts(bool p_enabled);

View File

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

View File

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