Allow run/edit multiple projects from project manager

This commit is contained in:
marynate 2014-05-11 09:45:52 +08:00
parent 78fd9ada45
commit e94f875788
2 changed files with 100 additions and 57 deletions

View File

@ -345,6 +345,7 @@ struct ProjectItem {
_FORCE_INLINE_ bool operator <(const ProjectItem& l) const { return last_modified > l.last_modified; } _FORCE_INLINE_ bool operator <(const ProjectItem& l) const { return last_modified > l.last_modified; }
}; };
void ProjectManager::_panel_draw(Node *p_hb) { void ProjectManager::_panel_draw(Node *p_hb) {
HBoxContainer *hb = p_hb->cast_to<HBoxContainer>(); HBoxContainer *hb = p_hb->cast_to<HBoxContainer>();
@ -361,6 +362,7 @@ void ProjectManager::_panel_input(const InputEvent& p_ev,Node *p_hb) {
if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.pressed && p_ev.mouse_button.button_index==BUTTON_LEFT) { if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.pressed && p_ev.mouse_button.button_index==BUTTON_LEFT) {
String clicked = p_hb->get_meta("name"); String clicked = p_hb->get_meta("name");
String clicked_main_scene = p_hb->get_meta("main_scene");
if (p_ev.key.mod.shift && selected_list.size()>0 && last_clicked!="" && clicked != last_clicked) { if (p_ev.key.mod.shift && selected_list.size()>0 && last_clicked!="" && clicked != last_clicked) {
@ -382,7 +384,7 @@ void ProjectManager::_panel_input(const InputEvent& p_ev,Node *p_hb) {
if (i!=clicked_id && (i<min || i>max) && !p_ev.key.mod.control) { if (i!=clicked_id && (i<min || i>max) && !p_ev.key.mod.control) {
selected_list.erase(hb->get_meta("name")); selected_list.erase(hb->get_meta("name"));
} else if (i>=min && i<=max) { } else if (i>=min && i<=max) {
selected_list.insert(hb->get_meta("name")); selected_list.insert(hb->get_meta("name"), hb->get_meta("main_scene"));
} }
} }
} }
@ -395,30 +397,30 @@ void ProjectManager::_panel_input(const InputEvent& p_ev,Node *p_hb) {
last_clicked = clicked; last_clicked = clicked;
if (p_ev.key.mod.control || selected_list.size()==0) { if (p_ev.key.mod.control || selected_list.size()==0) {
selected_list.insert(clicked); selected_list.insert(clicked, clicked_main_scene);
} else { } else {
selected_list.clear(); selected_list.clear();
selected_list.insert(clicked); selected_list.insert(clicked, clicked_main_scene);
} }
} }
String selected = ""; String single_selected = "";
if (selected_list.size() == 1) { if (selected_list.size() == 1) {
selected = selected_list.front()->get(); single_selected = selected_list.front()->key();
} }
selected_main = ""; single_selected_main = "";
for(int i=0;i<scroll_childs->get_child_count();i++) { for(int i=0;i<scroll_childs->get_child_count();i++) {
CanvasItem *item = scroll_childs->get_child(i)->cast_to<CanvasItem>(); CanvasItem *item = scroll_childs->get_child(i)->cast_to<CanvasItem>();
item->update(); item->update();
if (selected!="" && selected == item->get_meta("name")) if (single_selected!="" && single_selected == item->get_meta("name"))
selected_main = item->get_meta("main_scene"); single_selected_main = item->get_meta("main_scene");
} }
erase_btn->set_disabled(selected_list.size()<1); erase_btn->set_disabled(selected_list.size()<1);
open_btn->set_disabled(selected_list.size()!=1); open_btn->set_disabled(selected_list.size()<1);
run_btn->set_disabled(selected_main==""); run_btn->set_disabled(selected_list.size()<1 || (selected_list.size()==1 && single_selected_main==""));
if (p_ev.mouse_button.doubleclick) if (p_ev.mouse_button.doubleclick)
_open_project(); //open if doubleclicked _open_project(); //open if doubleclicked
@ -535,68 +537,91 @@ void ProjectManager::_load_recent_projects() {
} }
erase_btn->set_disabled(selected_list.size()<1); erase_btn->set_disabled(selected_list.size()<1);
open_btn->set_disabled(selected_list.size()!=1); open_btn->set_disabled(selected_list.size()<1);
run_btn->set_disabled(selected_main == ""); run_btn->set_disabled(selected_list.size()<1 || (selected_list.size()==1 && single_selected_main==""));
}
void ProjectManager::_open_project_confirm() {
for (Map<String,String>::Element *E=selected_list.front(); E; E=E->next()) {
const String &selected = E->key();
String path = EditorSettings::get_singleton()->get("projects/"+selected);
print_line("OPENING: "+path+" ("+selected+")");
List<String> args;
args.push_back("-path");
args.push_back(path);
args.push_back("-editor");
const String &selected_main = E->get();
if (selected_main!="") {
args.push_back(selected_main);
}
String exec = OS::get_singleton()->get_executable_path();
OS::ProcessID pid=0;
Error err = OS::get_singleton()->execute(exec,args,false,&pid);
ERR_FAIL_COND(err);
}
get_scene()->quit();
} }
void ProjectManager::_open_project() { void ProjectManager::_open_project() {
if (selected_list.size()<1) {
if (selected_list.size()!=1) {
return; return;
} }
const String &selected = selected_list.front()->get(); if (selected_list.size()>1) {
String path = EditorSettings::get_singleton()->get("projects/"+selected); multi_open_ask->set_text("Are you sure to open more than one projects?");
print_line("OPENING: "+path+" ("+selected+")"); multi_open_ask->popup_centered(Size2(300,100));
} else {
List<String> args; _open_project_confirm();
args.push_back("-path");
args.push_back(path);
args.push_back("-editor");
if (selected_main!="") {
args.push_back(selected_main);
} }
}
String exec = OS::get_singleton()->get_executable_path(); void ProjectManager::_run_project_confirm() {
OS::ProcessID pid=0; for (Map<String,String>::Element *E=selected_list.front(); E; E=E->next()) {
Error err = OS::get_singleton()->execute(exec,args,false,&pid);
ERR_FAIL_COND(err);
get_scene()->quit(); const String &selected_main = E->get();
if (selected_main == "") continue;
const String &selected = E->key();
String path = EditorSettings::get_singleton()->get("projects/"+selected);
print_line("OPENING: "+path+" ("+selected+")");
List<String> args;
args.push_back("-path");
args.push_back(path);
String exec = OS::get_singleton()->get_executable_path();
OS::ProcessID pid=0;
Error err = OS::get_singleton()->execute(exec,args,false,&pid);
ERR_FAIL_COND(err);
}
// get_scene()->quit(); do not quit
} }
void ProjectManager::_run_project() { void ProjectManager::_run_project() {
if (selected_list.size()!=1) { if (selected_list.size()<1) {
return; return;
} }
const String &selected = selected_list.front()->get(); if (selected_list.size()>1) {
String path = EditorSettings::get_singleton()->get("projects/"+selected); multi_run_ask->set_text("Are you sure to run more than one projects?");
print_line("OPENING: "+path+" ("+selected+")"); multi_run_ask->popup_centered(Size2(300,100));
} else {
List<String> args; _run_project_confirm();
}
args.push_back("-path");
args.push_back(path);
String exec = OS::get_singleton()->get_executable_path();
OS::ProcessID pid=0;
Error err = OS::get_singleton()->execute(exec,args,false,&pid);
ERR_FAIL_COND(err);
// get_scene()->quit(); do not quit
} }
void ProjectManager::_scan_dir(DirAccess *da,float pos, float total,List<String> *r_projects) { void ProjectManager::_scan_dir(DirAccess *da,float pos, float total,List<String> *r_projects) {
@ -674,13 +699,13 @@ void ProjectManager::_erase_project_confirm() {
if (selected_list.size()==0) { if (selected_list.size()==0) {
return; return;
} }
for (Set<String>::Element *E=selected_list.front(); E; E=E->next()) { for (Map<String,String>::Element *E=selected_list.front(); E; E=E->next()) {
EditorSettings::get_singleton()->erase("projects/"+E->get()); EditorSettings::get_singleton()->erase("projects/"+E->key());
} }
EditorSettings::get_singleton()->save(); EditorSettings::get_singleton()->save();
selected_list.clear(); selected_list.clear();
last_clicked = ""; last_clicked = "";
selected_main=""; single_selected_main="";
_load_recent_projects(); _load_recent_projects();
} }
@ -705,7 +730,9 @@ void ProjectManager::_exit_dialog() {
void ProjectManager::_bind_methods() { void ProjectManager::_bind_methods() {
ObjectTypeDB::bind_method("_open_project",&ProjectManager::_open_project); ObjectTypeDB::bind_method("_open_project",&ProjectManager::_open_project);
ObjectTypeDB::bind_method("_open_project_confirm",&ProjectManager::_open_project_confirm);
ObjectTypeDB::bind_method("_run_project",&ProjectManager::_run_project); ObjectTypeDB::bind_method("_run_project",&ProjectManager::_run_project);
ObjectTypeDB::bind_method("_run_project_confirm",&ProjectManager::_run_project_confirm);
ObjectTypeDB::bind_method("_scan_projects",&ProjectManager::_scan_projects); ObjectTypeDB::bind_method("_scan_projects",&ProjectManager::_scan_projects);
ObjectTypeDB::bind_method("_scan_begin",&ProjectManager::_scan_begin); ObjectTypeDB::bind_method("_scan_begin",&ProjectManager::_scan_begin);
ObjectTypeDB::bind_method("_import_project",&ProjectManager::_import_project); ObjectTypeDB::bind_method("_import_project",&ProjectManager::_import_project);
@ -846,6 +873,18 @@ ProjectManager::ProjectManager() {
add_child(erase_ask); add_child(erase_ask);
multi_open_ask = memnew( ConfirmationDialog );
multi_open_ask->get_ok()->set_text("Edit");
multi_open_ask->get_ok()->connect("pressed", this, "_open_project_confirm");
add_child(multi_open_ask);
multi_run_ask = memnew( ConfirmationDialog );
multi_run_ask->get_ok()->set_text("Run");
multi_run_ask->get_ok()->connect("pressed", this, "_run_project_confirm");
add_child(multi_run_ask);
OS::get_singleton()->set_low_processor_usage_mode(true); OS::get_singleton()->set_low_processor_usage_mode(true);
npdialog = memnew( NewProjectDialog ); npdialog = memnew( NewProjectDialog );

View File

@ -46,12 +46,14 @@ class ProjectManager : public Control {
FileDialog *scan_dir; FileDialog *scan_dir;
ConfirmationDialog *erase_ask; ConfirmationDialog *erase_ask;
ConfirmationDialog *multi_open_ask;
ConfirmationDialog *multi_run_ask;
NewProjectDialog *npdialog; NewProjectDialog *npdialog;
ScrollContainer *scroll; ScrollContainer *scroll;
VBoxContainer *scroll_childs; VBoxContainer *scroll_childs;
Set<String> selected_list; Map<String, String> selected_list; // name -> main_scene
String last_clicked; String last_clicked;
String selected_main; String single_selected_main;
bool importing; bool importing;
void _item_doubleclicked(); void _item_doubleclicked();
@ -60,7 +62,9 @@ class ProjectManager : public Control {
void _scan_projects(); void _scan_projects();
void _run_project(); void _run_project();
void _run_project_confirm();
void _open_project(); void _open_project();
void _open_project_confirm();
void _import_project(); void _import_project();
void _new_project(); void _new_project();
void _erase_project(); void _erase_project();