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/create_dialog.cpp | 502 ++++++++++++++++++++--------------------------- 1 file changed, 215 insertions(+), 287 deletions(-) (limited to 'editor/create_dialog.cpp') diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 2be867ce8..b70c56ed6 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -28,40 +28,39 @@ /*************************************************************************/ #include "create_dialog.h" +#include "editor_node.h" #include "object_type_db.h" #include "print_string.h" #include "scene/gui/box_container.h" -#include "editor_node.h" #if 1 -#include "os/keyboard.h" -#include "editor_settings.h" #include "editor_help.h" - +#include "editor_settings.h" +#include "os/keyboard.h" void CreateDialog::popup(bool p_dontclear) { recent->clear(); - FileAccess *f = FileAccess::open( EditorSettings::get_singleton()->get_project_settings_path().plus_file("create_recent."+base_type), FileAccess::READ ); + FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_path().plus_file("create_recent." + base_type), FileAccess::READ); if (f) { TreeItem *root = recent->create_item(); - while(!f->eof_reached()) { + while (!f->eof_reached()) { String l = f->get_line().strip_edges(); - if (l!=String()) { + if (l != String()) { TreeItem *ti = recent->create_item(root); - ti->set_text(0,l); - if (has_icon(l,"EditorIcons")) { + ti->set_text(0, l); + if (has_icon(l, "EditorIcons")) { - ti->set_icon(0,get_icon(l,"EditorIcons")); + ti->set_icon(0, get_icon(l, "EditorIcons")); } else { - ti->set_icon(0,get_icon("Object","EditorIcons")); + ti->set_icon(0, get_icon("Object", "EditorIcons")); } } } @@ -71,17 +70,16 @@ void CreateDialog::popup(bool p_dontclear) { favorites->clear(); - f = FileAccess::open( EditorSettings::get_singleton()->get_project_settings_path().plus_file("favorites."+base_type), FileAccess::READ ); + f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_path().plus_file("favorites." + base_type), FileAccess::READ); favorite_list.clear(); if (f) { - - while(!f->eof_reached()) { + while (!f->eof_reached()) { String l = f->get_line().strip_edges(); - if (l!=String()) { + if (l != String()) { favorite_list.push_back(l); } } @@ -123,64 +121,57 @@ void CreateDialog::popup(bool p_dontclear) { search_box->grab_focus(); _update_search(); - - } - -void CreateDialog::_text_changed(const String& p_newtext) { +void CreateDialog::_text_changed(const String &p_newtext) { _update_search(); } -void CreateDialog::_sbox_input(const InputEvent& p_ie) { +void CreateDialog::_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 CreateDialog::add_type(const String& p_type,HashMap& p_types,TreeItem *p_root,TreeItem **to_select) { +void CreateDialog::add_type(const String &p_type, HashMap &p_types, TreeItem *p_root, TreeItem **to_select) { if (p_types.has(p_type)) return; - if (!ObjectTypeDB::is_type(p_type,base_type) || p_type==base_type) + if (!ObjectTypeDB::is_type(p_type, base_type) || p_type == base_type) return; - String inherits=ObjectTypeDB::type_inherits_from(p_type); - - TreeItem *parent=p_root; + String inherits = ObjectTypeDB::type_inherits_from(p_type); + TreeItem *parent = p_root; if (inherits.length()) { if (!p_types.has(inherits)) { - add_type(inherits,p_types,p_root,to_select); + add_type(inherits, p_types, p_root, to_select); } - if (p_types.has(inherits) ) - parent=p_types[inherits]; + if (p_types.has(inherits)) + parent = p_types[inherits]; } TreeItem *item = search_options->create_item(parent); - item->set_text(0,p_type); + item->set_text(0, p_type); if (!ObjectTypeDB::can_instance(p_type)) { - item->set_custom_color(0, Color(0.5,0.5,0.5) ); - item->set_selectable(0,false); + item->set_custom_color(0, Color(0.5, 0.5, 0.5)); + item->set_selectable(0, false); } else { - if ((!*to_select && (search_box->get_text().is_subsequence_ofi(p_type))) || search_box->get_text()==p_type) { - *to_select=item; + if ((!*to_select && (search_box->get_text().is_subsequence_ofi(p_type))) || search_box->get_text() == p_type) { + *to_select = item; } - } if (bool(EditorSettings::get_singleton()->get("scenetree_editor/start_create_dialog_fully_expanded"))) { @@ -195,23 +186,19 @@ void CreateDialog::add_type(const String& p_type,HashMap& p_ty item->set_collapsed(collapse); } - const String& description = EditorHelp::get_doc_data()->class_list[p_type].brief_description; - item->set_tooltip(0,description); - + const String &description = EditorHelp::get_doc_data()->class_list[p_type].brief_description; + item->set_tooltip(0, description); - if (has_icon(p_type,"EditorIcons")) { + if (has_icon(p_type, "EditorIcons")) { - item->set_icon(0, get_icon(p_type,"EditorIcons")); + item->set_icon(0, get_icon(p_type, "EditorIcons")); } - - - p_types[p_type]=item; + p_types[p_type] = item; } void CreateDialog::_update_search() { - search_options->clear(); favorite->set_disabled(true); @@ -224,58 +211,54 @@ void CreateDialog::_update_search() { List type_list; ObjectTypeDB::get_type_list(&type_list); - HashMap types; + HashMap types; TreeItem *root = search_options->create_item(); - root->set_text(0,base_type); - if (has_icon(base_type,"EditorIcons")) { - root->set_icon(0,get_icon(base_type,"EditorIcons")); + root->set_text(0, base_type); + if (has_icon(base_type, "EditorIcons")) { + root->set_icon(0, get_icon(base_type, "EditorIcons")); } - List::Element *I=type_list.front(); - TreeItem *to_select=NULL; - - for(;I;I=I->next()) { - + List::Element *I = type_list.front(); + TreeItem *to_select = NULL; + for (; I; I = I->next()) { - String type=I->get(); + String type = I->get(); - if (base_type=="Node" && type.begins_with("Editor")) + if (base_type == "Node" && type.begins_with("Editor")) continue; // do not show editor nodes if (!ObjectTypeDB::can_instance(type)) continue; // cant create what can't be instanced - if (search_box->get_text()=="") { - add_type(type,types,root,&to_select); + if (search_box->get_text() == "") { + add_type(type, types, root, &to_select); } else { - bool found=false; - String type=I->get(); - while(type!="" && ObjectTypeDB::is_type(type,base_type) && type!=base_type) { + bool found = false; + String type = I->get(); + while (type != "" && ObjectTypeDB::is_type(type, base_type) && type != base_type) { if (search_box->get_text().is_subsequence_ofi(type)) { - found=true; + found = true; break; } - type=ObjectTypeDB::type_inherits_from(type); + type = ObjectTypeDB::type_inherits_from(type); } - if (found) - add_type(I->get(),types,root,&to_select); + add_type(I->get(), types, root, &to_select); } if (EditorNode::get_editor_data().get_custom_types().has(type) && ObjectTypeDB::is_type(type, base_type)) { //there are custom types based on this... cool. //print_line("there are custom types"); - const Vector &ct = EditorNode::get_editor_data().get_custom_types()[type]; - for(int i=0;iget_text().is_subsequence_ofi(ct[i].name); @@ -283,40 +266,35 @@ void CreateDialog::_update_search() { continue; if (!types.has(type)) - add_type(type,types,root,&to_select); + add_type(type, types, root, &to_select); TreeItem *ti; - if (types.has(type) ) - ti=types[type]; + if (types.has(type)) + ti = types[type]; else - ti=search_options->get_root(); - + ti = search_options->get_root(); TreeItem *item = search_options->create_item(ti); - item->set_metadata(0,type); - item->set_text(0,ct[i].name); + item->set_metadata(0, type); + item->set_text(0, ct[i].name); if (ct[i].icon.is_valid()) { - item->set_icon(0,ct[i].icon); - + item->set_icon(0, ct[i].icon); } - if (!to_select || ct[i].name==search_box->get_text()) { - to_select=item; + if (!to_select || ct[i].name == search_box->get_text()) { + to_select = item; } - } - } } if (to_select) { to_select->select(0); favorite->set_disabled(false); - favorite->set_pressed(favorite_list.find(to_select->get_text(0))!=-1); + favorite->set_pressed(favorite_list.find(to_select->get_text(0)) != -1); } - get_ok()->set_disabled(root->get_children()==NULL); - + get_ok()->set_disabled(root->get_children() == NULL); } void CreateDialog::_confirmed() { @@ -325,25 +303,25 @@ void CreateDialog::_confirmed() { if (!ti) return; - FileAccess *f = FileAccess::open( EditorSettings::get_singleton()->get_project_settings_path().plus_file("create_recent."+base_type), FileAccess::WRITE ); + FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_path().plus_file("create_recent." + base_type), FileAccess::WRITE); if (f) { f->store_line(get_selected_type()); TreeItem *t = recent->get_root(); if (t) - t=t->get_children(); - int count=0; - while(t) { - if (t->get_text(0)!=get_selected_type()) { + t = t->get_children(); + int count = 0; + while (t) { + if (t->get_text(0) != get_selected_type()) { f->store_line(t->get_text(0)); } - if (count>32) { + if (count > 32) { //limit it to 32 entries.. break; } - t=t->get_next(); + t = t->get_next(); count++; } @@ -356,18 +334,17 @@ void CreateDialog::_confirmed() { void CreateDialog::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_TREE) { + if (p_what == NOTIFICATION_ENTER_TREE) { - connect("confirmed",this,"_confirmed"); - favorite->set_icon(get_icon("Favorites","EditorIcons")); + connect("confirmed", this, "_confirmed"); + favorite->set_icon(get_icon("Favorites", "EditorIcons")); } - if (p_what==NOTIFICATION_EXIT_TREE) { - - disconnect("confirmed",this,"_confirmed"); + if (p_what == NOTIFICATION_EXIT_TREE) { + disconnect("confirmed", this, "_confirmed"); } - if (p_what==NOTIFICATION_VISIBILITY_CHANGED) { + if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { if (is_visible()) { @@ -375,13 +352,12 @@ void CreateDialog::_notification(int p_what) { search_box->select_all(); } } - } -void CreateDialog::set_base_type(const String& p_base) { +void CreateDialog::set_base_type(const String &p_base) { - base_type=p_base; - set_title(TTR("Create New")+" "+p_base); + base_type = p_base; + set_title(TTR("Create New") + " " + p_base); _update_search(); } @@ -400,28 +376,26 @@ Object *CreateDialog::instance_selected() { if (selected) { String custom = selected->get_metadata(0); - if (custom!=String()) { + if (custom != String()) { if (EditorNode::get_editor_data().get_custom_types().has(custom)) { - for(int i=0;iget_text(0)) { + for (int i = 0; i < EditorNode::get_editor_data().get_custom_types()[custom].size(); i++) { + if (EditorNode::get_editor_data().get_custom_types()[custom][i].name == selected->get_text(0)) { Ref icon = EditorNode::get_editor_data().get_custom_types()[custom][i].icon; Ref