From f2a068984c36de1f77940ae9d5dc0d017b8e642d Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 20 Feb 2014 23:01:44 -0300 Subject: -run script in editor -add search docs dialog that returns places string was found -added flash --- tools/editor/create_dialog.cpp | 2 + tools/editor/editor_help.cpp | 353 +++++++++++++++++++++++++++- tools/editor/editor_help.h | 43 ++++ tools/editor/editor_node.cpp | 38 +++ tools/editor/editor_node.h | 4 +- tools/editor/editor_run_script.cpp | 72 ++++++ tools/editor/editor_run_script.h | 27 +++ tools/editor/plugins/script_editor_plugin.h | 1 + 8 files changed, 536 insertions(+), 4 deletions(-) create mode 100644 tools/editor/editor_run_script.cpp create mode 100644 tools/editor/editor_run_script.h (limited to 'tools') diff --git a/tools/editor/create_dialog.cpp b/tools/editor/create_dialog.cpp index 8d577909ef..3a6b856247 100644 --- a/tools/editor/create_dialog.cpp +++ b/tools/editor/create_dialog.cpp @@ -245,6 +245,7 @@ void CreateDialog::_notification(int p_what) { void CreateDialog::set_base_type(const String& p_base) { base_type=p_base; + set_title("Create New "+p_base); _update_search(); } @@ -295,6 +296,7 @@ CreateDialog::CreateDialog() { search_options->connect("item_activated",this,"_confirmed"); // search_options->set_hide_root(true); base_type="Object"; + } diff --git a/tools/editor/editor_help.cpp b/tools/editor/editor_help.cpp index 1f281a0feb..75b902dc64 100644 --- a/tools/editor/editor_help.cpp +++ b/tools/editor/editor_help.cpp @@ -32,6 +32,288 @@ #include "os/keyboard.h" #include "doc_data_compressed.h" + + +#include "os/keyboard.h" + + +void EditorHelpSearch::popup(const String& p_term) { + + popup_centered_ratio(0.6); + if (p_term!="") { + search_box->set_text(p_term); + search_box->select_all(); + } else + search_box->clear(); + search_box->grab_focus(); +} + + +void EditorHelpSearch::_text_changed(const String& p_newtext) { + + _update_search(); +} + +void EditorHelpSearch::_sbox_input(const InputEvent& p_ie) { + + if (p_ie.type==InputEvent::KEY && ( + p_ie.key.scancode == KEY_UP || + p_ie.key.scancode == KEY_DOWN || + p_ie.key.scancode == KEY_PAGEUP || + p_ie.key.scancode == KEY_PAGEDOWN ) ) { + + search_options->call("_input_event",p_ie); + search_box->accept_event(); + } + +} + +void EditorHelpSearch::_update_search() { + + + search_options->clear(); + search_options->set_hide_root(true); + + /* + TreeItem *root = search_options->create_item(); + _parse_fs(EditorFileSystem::get_singleton()->get_filesystem()); +*/ + + List type_list; + ObjectTypeDB::get_type_list(&type_list); + + DocData *doc=EditorHelp::get_doc_data(); + String term = search_box->get_text(); + if (term.length()<3) + return; + + TreeItem *root = search_options->create_item(); + + + + Ref def_icon = get_icon("Node","EditorIcons"); + //classes first + for (Map::Element *E=doc->class_list.front();E;E=E->next()) { + + if (E->key().findn(term)!=-1) { + + TreeItem *item = search_options->create_item(root); + item->set_metadata(0,"class_name:"+E->key()); + item->set_text(0,E->key()+" (Class)"); + if (has_icon(E->key(),"EditorIcons")) + item->set_icon(0,get_icon(E->key(),"EditorIcons")); + else + item->set_icon(0,def_icon); + + + } + + } + + //class methods, etc second + for (Map::Element *E=doc->class_list.front();E;E=E->next()) { + + + DocData::ClassDoc & c = E->get(); + + Ref cicon; + if (has_icon(E->key(),"EditorIcons")) + cicon=get_icon(E->key(),"EditorIcons"); + else + cicon=def_icon; + + for(int i=0;icreate_item(root); + item->set_metadata(0,"class_method:"+E->key()+":"+c.methods[i].name); + item->set_text(0,E->key()+"."+c.methods[i].name+" (Method)"); + item->set_icon(0,cicon); + } + } + + for(int i=0;icreate_item(root); + item->set_metadata(0,"class_signal:"+E->key()+":"+c.signals[i].name); + item->set_text(0,E->key()+"."+c.signals[i].name+" (Signal)"); + item->set_icon(0,cicon); + } + } + + for(int i=0;icreate_item(root); + item->set_metadata(0,"class_constant:"+E->key()+":"+c.constants[i].name); + item->set_text(0,E->key()+"."+c.constants[i].name+" (Constant)"); + item->set_icon(0,cicon); + } + } + + for(int i=0;icreate_item(root); + item->set_metadata(0,"class_property:"+E->key()+":"+c.properties[i].name); + item->set_text(0,E->key()+"."+c.properties[i].name+" (Property)"); + item->set_icon(0,cicon); + } + } + + } + + //same but descriptions + + for (Map::Element *E=doc->class_list.front();E;E=E->next()) { + + + DocData::ClassDoc & c = E->get(); + + Ref cicon; + if (has_icon(E->key(),"EditorIcons")) + cicon=get_icon(E->key(),"EditorIcons"); + else + cicon=def_icon; + + if (c.description.findn(term)!=-1) { + + + TreeItem *item = search_options->create_item(root); + item->set_metadata(0,"class_desc:"+E->key()); + item->set_text(0,E->key()+" (Class Description)"); + item->set_icon(0,cicon); + + } + + for(int i=0;icreate_item(root); + item->set_metadata(0,"class_method_desc:"+E->key()+":"+c.methods[i].name); + item->set_text(0,E->key()+"."+c.methods[i].name+" (Method Description)"); + item->set_icon(0,cicon); + } + } + + for(int i=0;icreate_item(root); + item->set_metadata(0,"class_signal:"+E->key()+":"+c.signals[i].name); + item->set_text(0,E->key()+"."+c.signals[i].name+" (Signal Description)"); + item->set_icon(0,cicon); + } + } + + for(int i=0;icreate_item(root); + item->set_metadata(0,"class_constant:"+E->key()+":"+c.constants[i].name); + item->set_text(0,E->key()+"."+c.constants[i].name+" (Constant Description)"); + item->set_icon(0,cicon); + } + } + + for(int i=0;icreate_item(root); + item->set_metadata(0,"class_property_desc:"+E->key()+":"+c.properties[i].name); + item->set_text(0,E->key()+"."+c.properties[i].name+" (Property Description)"); + item->set_icon(0,cicon); + } + } + + } + + get_ok()->set_disabled(root->get_children()==NULL); + +} + +void EditorHelpSearch::_confirmed() { + + TreeItem *ti = search_options->get_selected(); + if (!ti) + return; + + String mdata=ti->get_metadata(0); + emit_signal("go_to_help",mdata); + // go to that + hide(); +} + +void EditorHelpSearch::_notification(int p_what) { + + if (p_what==NOTIFICATION_ENTER_SCENE) { + + connect("confirmed",this,"_confirmed"); + _update_search(); + } + + if (p_what==NOTIFICATION_VISIBILITY_CHANGED) { + + if (is_visible()) { + + search_box->call_deferred("grab_focus"); // still not visible + search_box->select_all(); + } + } + +} + + +void EditorHelpSearch::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("_text_changed"),&EditorHelpSearch::_text_changed); + ObjectTypeDB::bind_method(_MD("_confirmed"),&EditorHelpSearch::_confirmed); + ObjectTypeDB::bind_method(_MD("_sbox_input"),&EditorHelpSearch::_sbox_input); + ObjectTypeDB::bind_method(_MD("_update_search"),&EditorHelpSearch::_sbox_input); + + ADD_SIGNAL(MethodInfo("go_to_help")); + +} + + +EditorHelpSearch::EditorHelpSearch(EditorNode *p_editor) { + + editor=p_editor; + VBoxContainer *vbc = memnew( VBoxContainer ); + add_child(vbc); + set_child_rect(vbc); + HBoxContainer *sb_hb = memnew( HBoxContainer); + search_box = memnew( LineEdit ); + sb_hb->add_child(search_box); + search_box->set_h_size_flags(SIZE_EXPAND_FILL); + Button *sb = memnew( Button("Search")); + sb->connect("pressed",this,"_update_search"); + sb_hb->add_child(sb); + vbc->add_margin_child("Search:",sb_hb); + search_box->connect("text_changed",this,"_text_changed"); + search_box->connect("input_event",this,"_sbox_input"); + search_options = memnew( Tree ); + vbc->add_margin_child("Matches:",search_options,true); + get_ok()->set_text("View"); + get_ok()->set_disabled(true); + register_text_enter(search_box); + set_hide_on_ok(false); + search_options->connect("item_activated",this,"_confirmed"); + set_title("Search Classes"); +// search_options->set_hide_root(true); + +} + + DocData *EditorHelp::doc=NULL; void EditorHelp::_unhandled_key_input(const InputEvent& p_ev) { @@ -98,8 +380,12 @@ void EditorHelp::_button_pressed(int p_idx) { } else if (p_idx==PAGE_SEARCH) { _search(""); + } else if (p_idx==CLASS_SEARCH) { + + class_search->popup(); } + } @@ -181,6 +467,7 @@ void EditorHelp::_goto_desc(const String& p_class,bool p_update_history,int p_vs //tabs->set_current_tab(PAGE_CLASS_DESC); edited_class->set_pressed(true); class_list_button->set_pressed(false); + description_line=0; if (p_class==edited_class->get_text()) return; //already there @@ -203,7 +490,7 @@ void EditorHelp::_goto_desc(const String& p_class,bool p_update_history,int p_vs method_line.clear(); edited_class->set_text(p_class); - edited_class->show(); + //edited_class->show(); DocData::ClassDoc &cd=doc->class_list[p_class]; @@ -217,6 +504,16 @@ void EditorHelp::_goto_desc(const String& p_class,bool p_update_history,int p_vs h_color=Color(1,1,1,1); + class_desc->push_font(doc_title_font); + class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color")); + class_desc->add_text("Class: "); + class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/base_type_color")); + class_desc->add_text(p_class); + class_desc->pop(); + class_desc->pop(); + class_desc->pop(); + class_desc->add_newline(); + if (cd.inherits!="") { class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color")); @@ -264,6 +561,7 @@ void EditorHelp::_goto_desc(const String& p_class,bool p_update_history,int p_vs for(int i=0;iget_line_count()-2; //gets overriden if description class_desc->push_font(doc_code_font); _add_type(cd.methods[i].return_type); class_desc->add_text(" "); @@ -332,6 +630,7 @@ void EditorHelp::_goto_desc(const String& p_class,bool p_update_history,int p_vs for(int i=0;iget_line_count()-2; //gets overriden if description class_desc->push_font(doc_code_font); _add_type(cd.properties[i].type); class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/text_color")); @@ -374,6 +673,7 @@ void EditorHelp::_goto_desc(const String& p_class,bool p_update_history,int p_vs for(int i=0;iget_line_count()-2; //gets overriden if description class_desc->push_font(doc_code_font); //_add_type("void"); //class_desc->add_text(" "); @@ -435,6 +735,7 @@ void EditorHelp::_goto_desc(const String& p_class,bool p_update_history,int p_vs for(int i=0;iget_line_count()-2; class_desc->push_font(doc_code_font); class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/base_type_color")); class_desc->add_text(cd.constants[i].name); @@ -466,6 +767,7 @@ void EditorHelp::_goto_desc(const String& p_class,bool p_update_history,int p_vs if (cd.description!="") { + description_line=class_desc->get_line_count()-2; class_desc->push_color(EditorSettings::get_singleton()->get("text_editor/keyword_color")); class_desc->push_font(doc_title_font); class_desc->add_text("Description:"); @@ -560,12 +862,46 @@ void EditorHelp::_goto_desc(const String& p_class,bool p_update_history,int p_vs void EditorHelp::_request_help(const String& p_string) { + _goto_desc(p_string); - _goto_desc(p_string); + //100 palabras } +void EditorHelp::_help_callback(const String& p_topic) { + + String what = p_topic.get_slice(":",0); + String clss = p_topic.get_slice(":",1); + String name; + if (p_topic.get_slice_count(":")==3) + name=p_topic.get_slice(":",2); + + _request_help(clss); //first go to class + + int line=0; + + if (what=="class_desc") { + line=description_line; + } else if (what=="class_signal") { + if (signal_line.has(name)) + line=signal_line[name]; + } else if (what=="class_method" || what=="class_method_desc") { + 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_constant") { + + if (constant_line.has(name)) + line=constant_line[name]; + } + + class_desc->scroll_to_line(line); + +} void EditorHelp::_add_text(const String& p_bbcode) { @@ -903,6 +1239,7 @@ void EditorHelp::_bind_methods() { ObjectTypeDB::bind_method("_unhandled_key_input",&EditorHelp::_unhandled_key_input); ObjectTypeDB::bind_method("_search",&EditorHelp::_search); ObjectTypeDB::bind_method("_tree_item_selected",&EditorHelp::_tree_item_selected); + ObjectTypeDB::bind_method("_help_callback",&EditorHelp::_help_callback); } @@ -933,6 +1270,10 @@ EditorHelp::EditorHelp(EditorNode *p_editor) { b->connect("pressed",this,"_button_pressed",make_binds(PAGE_CLASS_DESC)); edited_class->hide(); + b = memnew( Button ); + b->set_text("Search in Classes"); + panel_hb->add_child(b); + b->connect("pressed",this,"_button_pressed",make_binds(CLASS_SEARCH)); Control *expand = memnew( Control ); expand->set_h_size_flags(SIZE_EXPAND_FILL); @@ -959,10 +1300,13 @@ EditorHelp::EditorHelp(EditorNode *p_editor) { search->connect("text_entered",this,"_search"); b = memnew( Button ); - b->set_text("Search"); + b->set_text("Find"); panel_hb->add_child(b); b->connect("pressed",this,"_button_pressed",make_binds(PAGE_SEARCH)); + hs = memnew( VSeparator ); + panel_hb->add_child(hs); + h_split = memnew( HSplitContainer ); h_split->set_v_size_flags(SIZE_EXPAND_FILL); @@ -994,6 +1338,9 @@ EditorHelp::EditorHelp(EditorNode *p_editor) { class_list->connect("cell_selected",this,"_tree_item_selected"); class_desc->hide(); + class_search = memnew( EditorHelpSearch(editor) ); + editor->get_gui_base()->add_child(class_search); + class_search->connect("go_to_help",this,"_help_callback"); // prev_search_page=-1; } diff --git a/tools/editor/editor_help.h b/tools/editor/editor_help.h index d626304b4a..eac33e5e16 100644 --- a/tools/editor/editor_help.h +++ b/tools/editor/editor_help.h @@ -45,6 +45,36 @@ class EditorNode; +class EditorHelpSearch : public ConfirmationDialog { + + OBJ_TYPE(EditorHelpSearch,ConfirmationDialog ) + + EditorNode *editor; + LineEdit *search_box; + Tree *search_options; + String base_type; + + void _update_search(); + + void _sbox_input(const InputEvent& p_ie); + + void _confirmed(); + void _text_changed(const String& p_newtext); + + +protected: + + void _notification(int p_what); + static void _bind_methods(); +public: + + void popup(const String& p_term=""); + + EditorHelpSearch(EditorNode *p_editor); +}; + + + class EditorHelp : public VBoxContainer { OBJ_TYPE( EditorHelp, VBoxContainer ); @@ -56,6 +86,7 @@ class EditorHelp : public VBoxContainer { PAGE_CLASS_PREV, PAGE_CLASS_NEXT, PAGE_SEARCH, + CLASS_SEARCH, }; @@ -74,6 +105,10 @@ class EditorHelp : public VBoxContainer { EditorNode *editor; Map method_line; + Map signal_line; + Map property_line; + Map constant_line; + int description_line; Tree *class_list; @@ -91,6 +126,9 @@ class EditorHelp : public VBoxContainer { HashMap tree_item_map; + + void _help_callback(const String& p_topic); + void _add_text(const String& p_text); bool scroll_locked; @@ -112,6 +150,8 @@ class EditorHelp : public VBoxContainer { void add_type(const String& p_type,HashMap& p_types,TreeItem *p_root); void _tree_item_selected(); + EditorHelpSearch *class_search; + protected: @@ -120,12 +160,14 @@ protected: public: static void generate_doc(); + static DocData *get_doc_data() { return doc; } EditorHelp(EditorNode *p_editor=NULL); ~EditorHelp(); }; + class EditorHelpPlugin : public EditorPlugin { OBJ_TYPE( EditorHelpPlugin, EditorPlugin ); @@ -156,4 +198,5 @@ public: }; + #endif // EDITOR_HELP_H diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 35809e653e..ed932396db 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -938,7 +938,27 @@ void EditorNode::_dialog_action(String p_file) { } break; + case FILE_RUN_SCRIPT: { + print_line("RUN: "+p_file); + Ref