Merge pull request #7063 from volzhs/pm-auto-select

Select newly created or imported project automatically
This commit is contained in:
Rémi Verschelde 2016-11-09 11:49:28 +01:00 committed by GitHub
commit 9a504b650e
2 changed files with 45 additions and 2 deletions

View File

@ -335,7 +335,7 @@ private:
hide();
emit_signal("project_created");
emit_signal("project_created", dir);
}
@ -882,6 +882,7 @@ void ProjectManager::_load_recent_projects() {
hb->add_child(tf);
VBoxContainer *vb = memnew(VBoxContainer);
vb->set_name("project");
hb->add_child(vb);
Control *ec = memnew( Control );
ec->set_custom_minimum_size(Size2(0,1));
@ -891,6 +892,7 @@ void ProjectManager::_load_recent_projects() {
title->add_color_override("font_color",font_color);
vb->add_child(title);
Label *fpath = memnew( Label(path) );
fpath->set_name("path");
vb->add_child(fpath);
fpath->set_opacity(0.5);
fpath->add_color_override("font_color",font_color);
@ -912,6 +914,43 @@ void ProjectManager::_load_recent_projects() {
tabs->set_current_tab(0);
}
void ProjectManager::_on_project_created(const String& dir) {
bool has_already=false;
for (int i=0;i<scroll_childs->get_child_count();i++) {
HBoxContainer *hb=scroll_childs->get_child(i)->cast_to<HBoxContainer>();
Label *fpath=hb->get_node(NodePath("project/path"))->cast_to<Label>();
if (fpath->get_text()==dir) {
has_already=true;
break;
}
}
if (has_already) {
_update_scroll_pos(dir);
} else {
_load_recent_projects();
scroll->connect("draw", this, "_update_scroll_pos", varray(dir), CONNECT_ONESHOT);
}
}
void ProjectManager::_update_scroll_pos(const String& dir) {
for (int i=0;i<scroll_childs->get_child_count();i++) {
HBoxContainer *hb=scroll_childs->get_child(i)->cast_to<HBoxContainer>();
Label *fpath=hb->get_node(NodePath("project/path"))->cast_to<Label>();
if (fpath->get_text()==dir) {
last_clicked=hb->get_meta("name");
selected_list.clear();
selected_list.insert(hb->get_meta("name"), hb->get_meta("main_scene"));
_update_project_buttons();
int last_y_visible=scroll->get_v_scroll()+scroll->get_size().y;
int offset_diff=(hb->get_pos().y + hb->get_size().y)-last_y_visible;
if (offset_diff>0)
scroll->set_v_scroll(scroll->get_v_scroll()+offset_diff);
break;
}
}
}
void ProjectManager::_open_project_confirm() {
for (Map<String,String>::Element *E=selected_list.front(); E; E=E->next()) {
@ -1164,6 +1203,8 @@ void ProjectManager::_bind_methods() {
ObjectTypeDB::bind_method("_erase_project_confirm",&ProjectManager::_erase_project_confirm);
ObjectTypeDB::bind_method("_exit_dialog",&ProjectManager::_exit_dialog);
ObjectTypeDB::bind_method("_load_recent_projects",&ProjectManager::_load_recent_projects);
ObjectTypeDB::bind_method("_on_project_created",&ProjectManager::_on_project_created);
ObjectTypeDB::bind_method("_update_scroll_pos",&ProjectManager::_update_scroll_pos);
ObjectTypeDB::bind_method("_panel_draw",&ProjectManager::_panel_draw);
ObjectTypeDB::bind_method("_panel_input",&ProjectManager::_panel_input);
ObjectTypeDB::bind_method("_unhandled_input",&ProjectManager::_unhandled_input);
@ -1382,7 +1423,7 @@ ProjectManager::ProjectManager() {
npdialog = memnew( NewProjectDialog );
gui_base->add_child(npdialog);
npdialog->connect("project_created", this,"_load_recent_projects");
npdialog->connect("project_created", this,"_on_project_created");
_load_recent_projects();
if ( EditorSettings::get_singleton()->get("global/autoscan_project_path") ) {

View File

@ -85,6 +85,8 @@ class ProjectManager : public Control {
void _scan_begin(const String& p_base);
void _load_recent_projects();
void _on_project_created(const String& dir);
void _update_scroll_pos(const String& dir);
void _scan_dir(DirAccess *da,float pos, float total,List<String> *r_projects);
void _install_project(const String& p_zip_path,const String& p_title);