From f8db8a3faa30b71dca33ced38be16d3f93f43e8a Mon Sep 17 00:00:00 2001 From: Rémi Verschelde Date: Sun, 19 Mar 2017 00:36:26 +0100 Subject: Bring that Whole New World to the Old Continent too Applies the clang-format style to the 2.1 branch as done for master in 5dbf1809c6e3e905b94b8764e99491e608122261. --- editor/plugins/script_editor_plugin.cpp | 1569 +++++++++++++------------------ 1 file changed, 672 insertions(+), 897 deletions(-) (limited to 'editor/plugins/script_editor_plugin.cpp') diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 4709cb843..8d319500d 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -27,33 +27,32 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "script_editor_plugin.h" +#include "editor/editor_node.h" #include "editor/editor_settings.h" +#include "editor/script_editor_debugger.h" +#include "globals.h" #include "io/resource_loader.h" #include "io/resource_saver.h" +#include "os/file_access.h" +#include "os/input.h" +#include "os/keyboard.h" #include "os/keyboard.h" #include "os/os.h" -#include "editor/editor_node.h" -#include "editor/script_editor_debugger.h" -#include "globals.h" -#include "os/file_access.h" #include "scene/main/viewport.h" -#include "os/keyboard.h" -#include "os/input.h" /*** SCRIPT EDITOR ****/ - -static bool _can_open_in_editor(Script* p_script) { +static bool _can_open_in_editor(Script *p_script) { String path = p_script->get_path(); - if (path.find("::")!=-1) { + if (path.find("::") != -1) { //refuse handling this if it can't be edited - bool valid=false; - for(int i=0;iget_editor_data().get_edited_scene_count();i++) { + bool valid = false; + for (int i = 0; i < EditorNode::get_singleton()->get_editor_data().get_edited_scene_count(); i++) { if (path.begins_with(EditorNode::get_singleton()->get_editor_data().get_scene_path(i))) { - valid=true; + valid = true; break; } } @@ -64,68 +63,63 @@ static bool _can_open_in_editor(Script* p_script) { return true; } - class EditorScriptCodeCompletionCache : public ScriptCodeCompletionCache { - struct Cache { uint64_t time_loaded; RES cache; }; - Map cached; - + Map cached; public: - uint64_t max_time_cache; int max_cache_size; void cleanup() { - List< Map::Element * > to_clean; + List::Element *> to_clean; - - Map::Element *I=cached.front(); - while(I) { - if ((OS::get_singleton()->get_ticks_msec()-I->get().time_loaded)>max_time_cache) { + Map::Element *I = cached.front(); + while (I) { + if ((OS::get_singleton()->get_ticks_msec() - I->get().time_loaded) > max_time_cache) { to_clean.push_back(I); } - I=I->next(); + I = I->next(); } - while(to_clean.front()) { + while (to_clean.front()) { cached.erase(to_clean.front()->get()); to_clean.pop_front(); } } - RES get_cached_resource(const String& p_path) { + RES get_cached_resource(const String &p_path) { - Map::Element *E=cached.find(p_path); + Map::Element *E = cached.find(p_path); if (!E) { Cache c; - c.cache=ResourceLoader::load(p_path); - E=cached.insert(p_path,c); + c.cache = ResourceLoader::load(p_path); + E = cached.insert(p_path, c); } - E->get().time_loaded=OS::get_singleton()->get_ticks_msec(); + E->get().time_loaded = OS::get_singleton()->get_ticks_msec(); - if (cached.size()>max_cache_size) { + if (cached.size() > max_cache_size) { uint64_t older; - Map::Element *O=cached.front(); - older=O->get().time_loaded; - Map::Element *I=O; - while(I) { - if (I->get().time_loaded::Element *O = cached.front(); + older = O->get().time_loaded; + Map::Element *I = O; + while (I) { + if (I->get().time_loaded < older) { older = I->get().time_loaded; - O=I; + O = I; } - I=I->next(); + I = I->next(); } - if (O!=E) {//should never heppane.. + if (O != E) { //should never heppane.. cached.erase(O); } } @@ -133,18 +127,16 @@ public: return E->get().cache; } - EditorScriptCodeCompletionCache() { - max_cache_size=128; - max_time_cache=5*60*1000; //minutes, five + max_cache_size = 128; + max_time_cache = 5 * 60 * 1000; //minutes, five } - }; #define SORT_SCRIPT_LIST -void ScriptEditorQuickOpen::popup(const Vector& p_functions, bool p_dontclear) { +void ScriptEditorQuickOpen::popup(const Vector &p_functions, bool p_dontclear) { popup_centered_ratio(0.6); if (p_dontclear) @@ -152,55 +144,45 @@ void ScriptEditorQuickOpen::popup(const Vector& p_functions, bool p_dont else search_box->clear(); search_box->grab_focus(); - functions=p_functions; + functions = p_functions; _update_search(); - - } - -void ScriptEditorQuickOpen::_text_changed(const String& p_newtext) { +void ScriptEditorQuickOpen::_text_changed(const String &p_newtext) { _update_search(); } -void ScriptEditorQuickOpen::_sbox_input(const InputEvent& p_ie) { +void ScriptEditorQuickOpen::_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 ) ) { + 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_options->call("_input_event", p_ie); search_box->accept_event(); } - } - - void ScriptEditorQuickOpen::_update_search() { - search_options->clear(); TreeItem *root = search_options->create_item(); - for(int i=0;iget_text()=="" || file.findn(search_box->get_text())!=-1)) { + if ((search_box->get_text() == "" || file.findn(search_box->get_text()) != -1)) { TreeItem *ti = search_options->create_item(root); - ti->set_text(0,file); - if (root->get_children()==ti) + ti->set_text(0, file); + if (root->get_children() == ti) ti->select(0); - } } - get_ok()->set_disabled(root->get_children()==NULL); - + get_ok()->set_disabled(root->get_children() == NULL); } void ScriptEditorQuickOpen::_confirmed() { @@ -208,80 +190,68 @@ void ScriptEditorQuickOpen::_confirmed() { TreeItem *ti = search_options->get_selected(); if (!ti) return; - int line = ti->get_text(0).get_slice(":",1).to_int(); + int line = ti->get_text(0).get_slice(":", 1).to_int(); - emit_signal("goto_line",line-1); + emit_signal("goto_line", line - 1); hide(); } void ScriptEditorQuickOpen::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_TREE) { - - connect("confirmed",this,"_confirmed"); - + if (p_what == NOTIFICATION_ENTER_TREE) { + connect("confirmed", this, "_confirmed"); } } - - - void ScriptEditorQuickOpen::_bind_methods() { - ObjectTypeDB::bind_method(_MD("_text_changed"),&ScriptEditorQuickOpen::_text_changed); - ObjectTypeDB::bind_method(_MD("_confirmed"),&ScriptEditorQuickOpen::_confirmed); - ObjectTypeDB::bind_method(_MD("_sbox_input"),&ScriptEditorQuickOpen::_sbox_input); - - ADD_SIGNAL(MethodInfo("goto_line",PropertyInfo(Variant::INT,"line"))); + ObjectTypeDB::bind_method(_MD("_text_changed"), &ScriptEditorQuickOpen::_text_changed); + ObjectTypeDB::bind_method(_MD("_confirmed"), &ScriptEditorQuickOpen::_confirmed); + ObjectTypeDB::bind_method(_MD("_sbox_input"), &ScriptEditorQuickOpen::_sbox_input); + ADD_SIGNAL(MethodInfo("goto_line", PropertyInfo(Variant::INT, "line"))); } - ScriptEditorQuickOpen::ScriptEditorQuickOpen() { - - VBoxContainer *vbc = memnew( VBoxContainer ); + VBoxContainer *vbc = memnew(VBoxContainer); add_child(vbc); set_child_rect(vbc); - search_box = memnew( LineEdit ); - vbc->add_margin_child(TTR("Search:"),search_box); - search_box->connect("text_changed",this,"_text_changed"); - search_box->connect("input_event",this,"_sbox_input"); - search_options = memnew( Tree ); - vbc->add_margin_child(TTR("Matches:"),search_options,true); + search_box = memnew(LineEdit); + vbc->add_margin_child(TTR("Search:"), search_box); + search_box->connect("text_changed", this, "_text_changed"); + search_box->connect("input_event", this, "_sbox_input"); + search_options = memnew(Tree); + vbc->add_margin_child(TTR("Matches:"), search_options, true); get_ok()->set_text(TTR("Open")); get_ok()->set_disabled(true); register_text_enter(search_box); set_hide_on_ok(false); - search_options->connect("item_activated",this,"_confirmed"); + search_options->connect("item_activated", this, "_confirmed"); search_options->set_hide_root(true); } - ///////////////////////////////// -ScriptEditor *ScriptEditor::script_editor=NULL; - -Vector ScriptTextEditor::get_functions() { +ScriptEditor *ScriptEditor::script_editor = NULL; +Vector ScriptTextEditor::get_functions() { String errortxt; - int line=-1,col; - TextEdit *te=get_text_edit(); + int line = -1, col; + TextEdit *te = get_text_edit(); String text = te->get_text(); List fnc; - if (script->get_language()->validate(text,line,col,errortxt,script->get_path(),&fnc)) { + if (script->get_language()->validate(text, line, col, errortxt, script->get_path(), &fnc)) { //if valid rewrite functions to latest functions.clear(); - for (List::Element *E=fnc.front();E;E=E->next()) { + for (List::Element *E = fnc.front(); E; E = E->next()) { functions.push_back(E->get()); } - - } return functions; @@ -291,7 +261,7 @@ void ScriptTextEditor::apply_code() { if (script.is_null()) return; -// print_line("applying code"); + // print_line("applying code"); script->set_source_code(get_text_edit()->get_text()); script->update_exports(); } @@ -307,108 +277,105 @@ void ScriptTextEditor::_load_theme_settings() { /* keyword color */ - - get_text_edit()->set_custom_bg_color(EDITOR_DEF("text_editor/background_color",Color(0,0,0,0))); - get_text_edit()->add_color_override("completion_background_color", EDITOR_DEF("text_editor/completion_background_color", Color(0,0,0,0))); + get_text_edit()->set_custom_bg_color(EDITOR_DEF("text_editor/background_color", Color(0, 0, 0, 0))); + get_text_edit()->add_color_override("completion_background_color", EDITOR_DEF("text_editor/completion_background_color", Color(0, 0, 0, 0))); get_text_edit()->add_color_override("completion_selected_color", EDITOR_DEF("text_editor/completion_selected_color", Color::html("434244"))); get_text_edit()->add_color_override("completion_existing_color", EDITOR_DEF("text_editor/completion_existing_color", Color::html("21dfdfdf"))); get_text_edit()->add_color_override("completion_scroll_color", EDITOR_DEF("text_editor/completion_scroll_color", Color::html("ffffff"))); get_text_edit()->add_color_override("completion_font_color", EDITOR_DEF("text_editor/completion_font_color", Color::html("aaaaaa"))); - get_text_edit()->add_color_override("font_color",EDITOR_DEF("text_editor/text_color",Color(0,0,0))); - get_text_edit()->add_color_override("line_number_color",EDITOR_DEF("text_editor/line_number_color",Color(0,0,0))); - get_text_edit()->add_color_override("caret_color",EDITOR_DEF("text_editor/caret_color",Color(0,0,0))); - get_text_edit()->add_color_override("caret_background_color",EDITOR_DEF("text_editor/caret_background_color",Color(0,0,0))); - get_text_edit()->add_color_override("font_selected_color",EDITOR_DEF("text_editor/text_selected_color",Color(1,1,1))); - get_text_edit()->add_color_override("selection_color",EDITOR_DEF("text_editor/selection_color",Color(0.2,0.2,1))); - get_text_edit()->add_color_override("brace_mismatch_color",EDITOR_DEF("text_editor/brace_mismatch_color",Color(1,0.2,0.2))); - get_text_edit()->add_color_override("current_line_color",EDITOR_DEF("text_editor/current_line_color",Color(0.3,0.5,0.8,0.15))); - get_text_edit()->add_color_override("word_highlighted_color",EDITOR_DEF("text_editor/word_highlighted_color",Color(0.8,0.9,0.9,0.15))); - get_text_edit()->add_color_override("number_color",EDITOR_DEF("text_editor/number_color",Color(0.9,0.6,0.0,2))); - get_text_edit()->add_color_override("function_color",EDITOR_DEF("text_editor/function_color",Color(0.4,0.6,0.8))); - get_text_edit()->add_color_override("member_variable_color",EDITOR_DEF("text_editor/member_variable_color",Color(0.9,0.3,0.3))); - get_text_edit()->add_color_override("mark_color", EDITOR_DEF("text_editor/mark_color", Color(1.0,0.4,0.4,0.4))); - get_text_edit()->add_color_override("breakpoint_color", EDITOR_DEF("text_editor/breakpoint_color", Color(0.8,0.8,0.4,0.2))); - get_text_edit()->add_color_override("search_result_color",EDITOR_DEF("text_editor/search_result_color",Color(0.05,0.25,0.05,1))); - get_text_edit()->add_color_override("search_result_border_color",EDITOR_DEF("text_editor/search_result_border_color",Color(0.1,0.45,0.1,1))); - get_text_edit()->add_constant_override("line_spacing", EDITOR_DEF("text_editor/line_spacing",4)); - - Color keyword_color= EDITOR_DEF("text_editor/keyword_color",Color(0.5,0.0,0.2)); + get_text_edit()->add_color_override("font_color", EDITOR_DEF("text_editor/text_color", Color(0, 0, 0))); + get_text_edit()->add_color_override("line_number_color", EDITOR_DEF("text_editor/line_number_color", Color(0, 0, 0))); + get_text_edit()->add_color_override("caret_color", EDITOR_DEF("text_editor/caret_color", Color(0, 0, 0))); + get_text_edit()->add_color_override("caret_background_color", EDITOR_DEF("text_editor/caret_background_color", Color(0, 0, 0))); + get_text_edit()->add_color_override("font_selected_color", EDITOR_DEF("text_editor/text_selected_color", Color(1, 1, 1))); + get_text_edit()->add_color_override("selection_color", EDITOR_DEF("text_editor/selection_color", Color(0.2, 0.2, 1))); + get_text_edit()->add_color_override("brace_mismatch_color", EDITOR_DEF("text_editor/brace_mismatch_color", Color(1, 0.2, 0.2))); + get_text_edit()->add_color_override("current_line_color", EDITOR_DEF("text_editor/current_line_color", Color(0.3, 0.5, 0.8, 0.15))); + get_text_edit()->add_color_override("word_highlighted_color", EDITOR_DEF("text_editor/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15))); + get_text_edit()->add_color_override("number_color", EDITOR_DEF("text_editor/number_color", Color(0.9, 0.6, 0.0, 2))); + get_text_edit()->add_color_override("function_color", EDITOR_DEF("text_editor/function_color", Color(0.4, 0.6, 0.8))); + get_text_edit()->add_color_override("member_variable_color", EDITOR_DEF("text_editor/member_variable_color", Color(0.9, 0.3, 0.3))); + get_text_edit()->add_color_override("mark_color", EDITOR_DEF("text_editor/mark_color", Color(1.0, 0.4, 0.4, 0.4))); + get_text_edit()->add_color_override("breakpoint_color", EDITOR_DEF("text_editor/breakpoint_color", Color(0.8, 0.8, 0.4, 0.2))); + get_text_edit()->add_color_override("search_result_color", EDITOR_DEF("text_editor/search_result_color", Color(0.05, 0.25, 0.05, 1))); + get_text_edit()->add_color_override("search_result_border_color", EDITOR_DEF("text_editor/search_result_border_color", Color(0.1, 0.45, 0.1, 1))); + get_text_edit()->add_constant_override("line_spacing", EDITOR_DEF("text_editor/line_spacing", 4)); + + Color keyword_color = EDITOR_DEF("text_editor/keyword_color", Color(0.5, 0.0, 0.2)); List keywords; script->get_language()->get_reserved_words(&keywords); - for(List::Element *E=keywords.front();E;E=E->next()) { + for (List::Element *E = keywords.front(); E; E = E->next()) { - get_text_edit()->add_keyword_color(E->get(),keyword_color); + get_text_edit()->add_keyword_color(E->get(), keyword_color); } //colorize core types - Color basetype_color= EDITOR_DEF("text_editor/base_type_color",Color(0.3,0.3,0.0)); - - get_text_edit()->add_keyword_color("Vector2",basetype_color); - get_text_edit()->add_keyword_color("Vector3",basetype_color); - get_text_edit()->add_keyword_color("Plane",basetype_color); - get_text_edit()->add_keyword_color("Quat",basetype_color); - get_text_edit()->add_keyword_color("AABB",basetype_color); - get_text_edit()->add_keyword_color("Matrix3",basetype_color); - get_text_edit()->add_keyword_color("Transform",basetype_color); - get_text_edit()->add_keyword_color("Color",basetype_color); - get_text_edit()->add_keyword_color("Image",basetype_color); - get_text_edit()->add_keyword_color("InputEvent",basetype_color); - get_text_edit()->add_keyword_color("Rect2",basetype_color); - get_text_edit()->add_keyword_color("NodePath",basetype_color); + Color basetype_color = EDITOR_DEF("text_editor/base_type_color", Color(0.3, 0.3, 0.0)); + + get_text_edit()->add_keyword_color("Vector2", basetype_color); + get_text_edit()->add_keyword_color("Vector3", basetype_color); + get_text_edit()->add_keyword_color("Plane", basetype_color); + get_text_edit()->add_keyword_color("Quat", basetype_color); + get_text_edit()->add_keyword_color("AABB", basetype_color); + get_text_edit()->add_keyword_color("Matrix3", basetype_color); + get_text_edit()->add_keyword_color("Transform", basetype_color); + get_text_edit()->add_keyword_color("Color", basetype_color); + get_text_edit()->add_keyword_color("Image", basetype_color); + get_text_edit()->add_keyword_color("InputEvent", basetype_color); + get_text_edit()->add_keyword_color("Rect2", basetype_color); + get_text_edit()->add_keyword_color("NodePath", basetype_color); //colorize engine types - Color type_color= EDITOR_DEF("text_editor/engine_type_color",Color(0.0,0.2,0.4)); + Color type_color = EDITOR_DEF("text_editor/engine_type_color", Color(0.0, 0.2, 0.4)); List types; ObjectTypeDB::get_type_list(&types); - for(List::Element *E=types.front();E;E=E->next()) { + for (List::Element *E = types.front(); E; E = E->next()) { String n = E->get(); if (n.begins_with("_")) n = n.substr(1, n.length()); - get_text_edit()->add_keyword_color(n,type_color); + get_text_edit()->add_keyword_color(n, type_color); } //colorize comments - Color comment_color = EDITOR_DEF("text_editor/comment_color",Color::hex(0x797e7eff)); + Color comment_color = EDITOR_DEF("text_editor/comment_color", Color::hex(0x797e7eff)); List comments; script->get_language()->get_comment_delimiters(&comments); - for(List::Element *E=comments.front();E;E=E->next()) { + for (List::Element *E = comments.front(); E; E = E->next()) { String comment = E->get(); - String beg = comment.get_slice(" ",0); - String end = comment.get_slice_count(" ")>1?comment.get_slice(" ",1):String(); + String beg = comment.get_slice(" ", 0); + String end = comment.get_slice_count(" ") > 1 ? comment.get_slice(" ", 1) : String(); - get_text_edit()->add_color_region(beg,end,comment_color,end==""); + get_text_edit()->add_color_region(beg, end, comment_color, end == ""); } //colorize strings - Color string_color = EDITOR_DEF("text_editor/string_color",Color::hex(0x6b6f00ff)); + Color string_color = EDITOR_DEF("text_editor/string_color", Color::hex(0x6b6f00ff)); List strings; script->get_language()->get_string_delimiters(&strings); - for (List::Element *E=strings.front();E;E=E->next()) { + for (List::Element *E = strings.front(); E; E = E->next()) { String string = E->get(); - String beg = string.get_slice(" ",0); - String end = string.get_slice_count(" ")>1?string.get_slice(" ",1):String(); - get_text_edit()->add_color_region(beg,end,string_color,end==""); + String beg = string.get_slice(" ", 0); + String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String(); + get_text_edit()->add_color_region(beg, end, string_color, end == ""); } //colorize symbols - Color symbol_color= EDITOR_DEF("text_editor/symbol_color",Color::hex(0x005291ff)); + Color symbol_color = EDITOR_DEF("text_editor/symbol_color", Color::hex(0x005291ff)); get_text_edit()->set_symbol_color(symbol_color); - } - void ScriptTextEditor::reload_text() { - ERR_FAIL_COND(script.is_null()) ; + ERR_FAIL_COND(script.is_null()); TextEdit *te = get_text_edit(); int column = te->cursor_get_column(); @@ -426,57 +393,51 @@ void ScriptTextEditor::reload_text() { te->tag_saved_version(); _line_col_changed(); - } void ScriptTextEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_READY) { + if (p_what == NOTIFICATION_READY) { //emit_signal("name_changed"); } } +bool ScriptTextEditor::is_unsaved() { -bool ScriptTextEditor::is_unsaved() { - - return get_text_edit()->get_version()!=get_text_edit()->get_saved_version(); + return get_text_edit()->get_version() != get_text_edit()->get_saved_version(); } -String ScriptTextEditor::get_name() { +String ScriptTextEditor::get_name() { String name; - if (script->get_path().find("local://")==-1 && script->get_path().find("::")==-1) { - name=script->get_path().get_file(); - if (get_text_edit()->get_version()!=get_text_edit()->get_saved_version()) { - name+="(*)"; + if (script->get_path().find("local://") == -1 && script->get_path().find("::") == -1) { + name = script->get_path().get_file(); + if (get_text_edit()->get_version() != get_text_edit()->get_saved_version()) { + name += "(*)"; } - } else if (script->get_name()!="") - name=script->get_name(); + } else if (script->get_name() != "") + name = script->get_name(); else - name=script->get_type()+"("+itos(script->get_instance_ID())+")"; + name = script->get_type() + "(" + itos(script->get_instance_ID()) + ")"; return name; - } Ref ScriptTextEditor::get_icon() { - if (get_parent_control() && get_parent_control()->has_icon(script->get_type(),"EditorIcons")) { - return get_parent_control()->get_icon(script->get_type(),"EditorIcons"); + if (get_parent_control() && get_parent_control()->has_icon(script->get_type(), "EditorIcons")) { + return get_parent_control()->get_icon(script->get_type(), "EditorIcons"); } return Ref(); } - - -void ScriptTextEditor::set_edited_script(const Ref