2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* project_manager.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:11:42 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "project_manager.h"
|
2017-01-16 07:04:19 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "editor_initialize_ssl.h"
|
|
|
|
#include "editor_scale.h"
|
|
|
|
#include "editor_settings.h"
|
|
|
|
#include "editor_themes.h"
|
|
|
|
#include "io/config_file.h"
|
|
|
|
#include "io/resource_saver.h"
|
|
|
|
#include "io/stream_peer_ssl.h"
|
|
|
|
#include "io/zip_io.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "os/dir_access.h"
|
|
|
|
#include "os/file_access.h"
|
2016-07-23 19:37:25 +00:00
|
|
|
#include "os/keyboard.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "os/os.h"
|
|
|
|
#include "scene/gui/center_container.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "scene/gui/line_edit.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "scene/gui/margin_container.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "scene/gui/panel_container.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "scene/gui/separator.h"
|
2017-01-14 09:52:54 +00:00
|
|
|
#include "scene/gui/texture_rect.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "scene/gui/tool_button.h"
|
|
|
|
#include "version.h"
|
2016-07-12 00:34:02 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
class NewProjectDialog : public ConfirmationDialog {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GDCLASS(NewProjectDialog, ConfirmationDialog);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-07-12 00:34:02 +00:00
|
|
|
public:
|
|
|
|
enum Mode {
|
|
|
|
MODE_NEW,
|
|
|
|
MODE_IMPORT,
|
|
|
|
MODE_INSTALL
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
private:
|
2016-07-12 00:34:02 +00:00
|
|
|
Mode mode;
|
2017-03-05 15:44:50 +00:00
|
|
|
Label *pp, *pn;
|
2014-02-10 01:10:30 +00:00
|
|
|
Label *error;
|
|
|
|
LineEdit *project_path;
|
|
|
|
LineEdit *project_name;
|
|
|
|
FileDialog *fdialog;
|
2016-07-12 00:34:02 +00:00
|
|
|
String zip_path;
|
|
|
|
String zip_title;
|
|
|
|
AcceptDialog *dialog_error;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-11-14 12:40:05 +00:00
|
|
|
String _test_path() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
error->set_text("");
|
|
|
|
get_ok()->set_disabled(true);
|
|
|
|
DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
2016-11-14 12:40:05 +00:00
|
|
|
String valid_path;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (d->change_dir(project_path->get_text()) == OK) {
|
|
|
|
valid_path = project_path->get_text();
|
|
|
|
} else if (d->change_dir(project_path->get_text().strip_edges()) == OK) {
|
|
|
|
valid_path = project_path->get_text().strip_edges();
|
2016-11-14 12:40:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (valid_path == "") {
|
2016-05-18 22:08:12 +00:00
|
|
|
error->set_text(TTR("Invalid project path, the path must exist!"));
|
2014-02-10 01:10:30 +00:00
|
|
|
memdelete(d);
|
2016-11-14 12:40:05 +00:00
|
|
|
return "";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mode != MODE_IMPORT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-01 15:44:52 +00:00
|
|
|
if (d->file_exists("project.godot")) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-01 15:44:52 +00:00
|
|
|
error->set_text(TTR("Invalid project path, project.godot must not exist."));
|
2014-02-10 01:10:30 +00:00
|
|
|
memdelete(d);
|
2016-11-14 12:40:05 +00:00
|
|
|
return "";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2017-05-01 15:44:52 +00:00
|
|
|
if (valid_path != "" && !d->file_exists("project.godot")) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-01 15:44:52 +00:00
|
|
|
error->set_text(TTR("Invalid project path, project.godot must exist."));
|
2014-02-10 01:10:30 +00:00
|
|
|
memdelete(d);
|
2016-11-14 12:40:05 +00:00
|
|
|
return "";
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memdelete(d);
|
|
|
|
get_ok()->set_disabled(false);
|
2016-11-14 12:40:05 +00:00
|
|
|
return valid_path;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void _path_text_changed(const String &p_path) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String sp = _test_path();
|
|
|
|
if (sp != "") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
sp = sp.replace("\\", "/");
|
|
|
|
int lidx = sp.find_last("/");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (lidx != -1) {
|
|
|
|
sp = sp.substr(lidx + 1, sp.length());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
if (sp == "" && mode == MODE_IMPORT)
|
|
|
|
sp = TTR("Imported Project");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
project_name->set_text(sp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void _file_selected(const String &p_path) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String p = p_path;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mode == MODE_IMPORT) {
|
2017-05-01 15:44:52 +00:00
|
|
|
if (p.ends_with("project.godot")) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
p = p.get_base_dir();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
String sp = p.simplify_path();
|
|
|
|
project_path->set_text(sp);
|
2016-11-08 12:39:28 +00:00
|
|
|
_path_text_changed(sp);
|
2016-10-06 10:41:38 +00:00
|
|
|
get_ok()->call_deferred("grab_focus");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void _path_selected(const String &p_path) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String p = p_path;
|
|
|
|
String sp = p.simplify_path();
|
|
|
|
project_path->set_text(sp);
|
2016-11-08 12:39:28 +00:00
|
|
|
_path_text_changed(sp);
|
2016-10-06 10:41:38 +00:00
|
|
|
get_ok()->call_deferred("grab_focus");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _browse_path() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mode == MODE_IMPORT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
fdialog->set_mode(FileDialog::MODE_OPEN_FILE);
|
|
|
|
fdialog->clear_filters();
|
2017-05-01 15:44:52 +00:00
|
|
|
fdialog->add_filter("project.godot ; " _MKSTR(VERSION_NAME) " Project");
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
fdialog->set_mode(FileDialog::MODE_OPEN_DIR);
|
|
|
|
}
|
|
|
|
fdialog->popup_centered_ratio();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void _text_changed(const String &p_text) {
|
2014-02-10 01:10:30 +00:00
|
|
|
_test_path();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ok_pressed() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String dir = _test_path();
|
|
|
|
if (dir == "") {
|
2016-11-14 12:40:05 +00:00
|
|
|
error->set_text(TTR("Invalid project path (changed anything?)."));
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2016-11-14 12:40:05 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mode == MODE_IMPORT) {
|
2016-11-14 12:40:05 +00:00
|
|
|
// nothing to do
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mode == MODE_NEW) {
|
2016-07-12 00:34:02 +00:00
|
|
|
|
2017-05-01 15:44:52 +00:00
|
|
|
FileAccess *f = FileAccess::open(dir.plus_file("/project.godot"), FileAccess::WRITE);
|
2016-07-12 00:34:02 +00:00
|
|
|
if (!f) {
|
2017-05-01 15:44:52 +00:00
|
|
|
error->set_text(TTR("Couldn't create project.godot in project path."));
|
2016-07-12 00:34:02 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
f->store_line("; Engine configuration file.");
|
2016-07-19 19:35:14 +00:00
|
|
|
f->store_line("; It's best edited using the editor UI and not directly,");
|
|
|
|
f->store_line("; since the parameters that go here are not all obvious.");
|
2016-07-12 00:34:02 +00:00
|
|
|
f->store_line("; ");
|
|
|
|
f->store_line("; Format: ");
|
|
|
|
f->store_line("; [section] ; section goes between []");
|
|
|
|
f->store_line("; param=value ; assign values to parameters");
|
|
|
|
f->store_line("\n");
|
|
|
|
f->store_line("[application]");
|
2016-07-19 19:35:14 +00:00
|
|
|
f->store_line("\n");
|
2017-03-05 15:44:50 +00:00
|
|
|
f->store_line("name=\"" + project_name->get_text() + "\"");
|
2016-07-12 00:34:02 +00:00
|
|
|
f->store_line("icon=\"res://icon.png\"");
|
|
|
|
|
|
|
|
memdelete(f);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ResourceSaver::save(dir.plus_file("/icon.png"), get_icon("DefaultProjectIcon", "EditorIcons"));
|
2016-07-12 00:34:02 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (mode == MODE_INSTALL) {
|
2016-07-12 00:34:02 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
FileAccess *src_f = NULL;
|
2016-07-12 00:34:02 +00:00
|
|
|
zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
|
|
|
|
|
|
|
|
unzFile pkg = unzOpen2(zip_path.utf8().get_data(), &io);
|
|
|
|
if (!pkg) {
|
|
|
|
|
|
|
|
dialog_error->set_text("Error opening package file, not in zip format.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ret = unzGoToFirstFile(pkg);
|
|
|
|
|
|
|
|
Vector<String> failed_files;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int idx = 0;
|
|
|
|
while (ret == UNZ_OK) {
|
2016-07-12 00:34:02 +00:00
|
|
|
|
|
|
|
//get filename
|
|
|
|
unz_file_info info;
|
|
|
|
char fname[16384];
|
2017-03-05 15:44:50 +00:00
|
|
|
ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0);
|
2016-07-12 00:34:02 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String path = fname;
|
2016-07-12 00:34:02 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
int depth = 1; //stuff from github comes with tag
|
|
|
|
bool skip = false;
|
|
|
|
while (depth > 0) {
|
2016-07-12 00:34:02 +00:00
|
|
|
int pp = path.find("/");
|
2017-03-05 15:44:50 +00:00
|
|
|
if (pp == -1) {
|
|
|
|
skip = true;
|
2016-07-12 00:34:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
path = path.substr(pp + 1, path.length());
|
2016-07-12 00:34:02 +00:00
|
|
|
depth--;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (skip || path == String()) {
|
2016-07-12 00:34:02 +00:00
|
|
|
//
|
|
|
|
} else if (path.ends_with("/")) { // a dir
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
path = path.substr(0, path.length() - 1);
|
2016-07-12 00:34:02 +00:00
|
|
|
|
|
|
|
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
|
|
|
da->make_dir(dir.plus_file(path));
|
|
|
|
memdelete(da);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Vector<uint8_t> data;
|
|
|
|
data.resize(info.uncompressed_size);
|
|
|
|
|
|
|
|
//read
|
|
|
|
unzOpenCurrentFile(pkg);
|
2017-03-05 15:44:50 +00:00
|
|
|
unzReadCurrentFile(pkg, data.ptr(), data.size());
|
2016-07-12 00:34:02 +00:00
|
|
|
unzCloseCurrentFile(pkg);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
FileAccess *f = FileAccess::open(dir.plus_file(path), FileAccess::WRITE);
|
2016-07-12 00:34:02 +00:00
|
|
|
|
|
|
|
if (f) {
|
2017-03-05 15:44:50 +00:00
|
|
|
f->store_buffer(data.ptr(), data.size());
|
2016-07-12 00:34:02 +00:00
|
|
|
memdelete(f);
|
|
|
|
} else {
|
|
|
|
failed_files.push_back(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
ret = unzGoToNextFile(pkg);
|
|
|
|
}
|
|
|
|
|
|
|
|
unzClose(pkg);
|
|
|
|
|
|
|
|
if (failed_files.size()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
String msg = TTR("The following files failed extraction from package:") + "\n\n";
|
|
|
|
for (int i = 0; i < failed_files.size(); i++) {
|
2016-07-12 00:34:02 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (i > 15) {
|
|
|
|
msg += "\nAnd " + itos(failed_files.size() - i) + " more files.";
|
2016-07-12 00:34:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
msg += failed_files[i] + "\n";
|
2016-07-12 00:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dialog_error->set_text(msg);
|
|
|
|
dialog_error->popup_centered_minsize();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
dialog_error->set_text(TTR("Package Installed Successfully!"));
|
|
|
|
dialog_error->popup_centered_minsize();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
dir = dir.replace("\\", "/");
|
2014-02-10 01:10:30 +00:00
|
|
|
if (dir.ends_with("/"))
|
2017-03-05 15:44:50 +00:00
|
|
|
dir = dir.substr(0, dir.length() - 1);
|
|
|
|
String proj = dir.replace("/", "::");
|
|
|
|
EditorSettings::get_singleton()->set("projects/" + proj, dir);
|
2014-02-10 01:10:30 +00:00
|
|
|
EditorSettings::get_singleton()->save();
|
|
|
|
|
|
|
|
hide();
|
2016-11-07 18:39:05 +00:00
|
|
|
emit_signal("project_created", dir);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method("_browse_path", &NewProjectDialog::_browse_path);
|
|
|
|
ClassDB::bind_method("_text_changed", &NewProjectDialog::_text_changed);
|
|
|
|
ClassDB::bind_method("_path_text_changed", &NewProjectDialog::_path_text_changed);
|
|
|
|
ClassDB::bind_method("_path_selected", &NewProjectDialog::_path_selected);
|
|
|
|
ClassDB::bind_method("_file_selected", &NewProjectDialog::_file_selected);
|
|
|
|
ADD_SIGNAL(MethodInfo("project_created"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_zip_path(const String &p_path) {
|
|
|
|
zip_path = p_path;
|
2016-07-12 00:34:02 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_zip_title(const String &p_title) {
|
|
|
|
zip_title = p_title;
|
2016-07-12 00:34:02 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-07-12 00:34:02 +00:00
|
|
|
void set_mode(Mode p_mode) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
mode = p_mode;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void show_dialog() {
|
|
|
|
|
|
|
|
project_path->clear();
|
|
|
|
project_name->clear();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (mode == MODE_IMPORT) {
|
2016-05-04 01:25:37 +00:00
|
|
|
set_title(TTR("Import Existing Project"));
|
|
|
|
get_ok()->set_text(TTR("Import"));
|
2016-05-18 22:08:12 +00:00
|
|
|
pp->set_text(TTR("Project Path (Must Exist):"));
|
2016-05-04 01:25:37 +00:00
|
|
|
pn->set_text(TTR("Project Name:"));
|
2014-02-10 01:10:30 +00:00
|
|
|
pn->hide();
|
|
|
|
project_name->hide();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
popup_centered(Size2(500, 125) * EDSCALE);
|
2016-07-12 00:34:02 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (mode == MODE_NEW) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
set_title(TTR("Create New Project"));
|
|
|
|
get_ok()->set_text(TTR("Create"));
|
|
|
|
pp->set_text(TTR("Project Path:"));
|
|
|
|
pn->set_text(TTR("Project Name:"));
|
2014-02-10 01:10:30 +00:00
|
|
|
pn->show();
|
|
|
|
project_name->show();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
popup_centered(Size2(500, 145) * EDSCALE);
|
|
|
|
} else if (mode == MODE_INSTALL) {
|
2016-07-12 00:34:02 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
set_title(TTR("Install Project:") + " " + zip_title);
|
2016-07-12 00:34:02 +00:00
|
|
|
get_ok()->set_text(TTR("Install"));
|
|
|
|
pp->set_text(TTR("Project Path:"));
|
|
|
|
pn->hide();
|
|
|
|
project_name->hide();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
popup_centered(Size2(500, 125) * EDSCALE);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2016-11-14 12:40:05 +00:00
|
|
|
project_path->grab_focus();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
_test_path();
|
|
|
|
}
|
|
|
|
|
|
|
|
NewProjectDialog() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
VBoxContainer *vb = memnew(VBoxContainer);
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(vb);
|
2017-01-14 11:26:56 +00:00
|
|
|
//set_child_rect(vb);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Label *l = memnew(Label);
|
2016-05-04 01:25:37 +00:00
|
|
|
l->set_text(TTR("Project Path:"));
|
2014-02-10 01:10:30 +00:00
|
|
|
vb->add_child(l);
|
2017-03-05 15:44:50 +00:00
|
|
|
pp = l;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
project_path = memnew(LineEdit);
|
|
|
|
MarginContainer *mc = memnew(MarginContainer);
|
2014-02-10 01:10:30 +00:00
|
|
|
vb->add_child(mc);
|
2017-03-05 15:44:50 +00:00
|
|
|
HBoxContainer *pphb = memnew(HBoxContainer);
|
2014-02-10 01:10:30 +00:00
|
|
|
mc->add_child(pphb);
|
|
|
|
pphb->add_child(project_path);
|
|
|
|
project_path->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Button *browse = memnew(Button);
|
2014-02-10 01:10:30 +00:00
|
|
|
pphb->add_child(browse);
|
2016-05-04 01:25:37 +00:00
|
|
|
browse->set_text(TTR("Browse"));
|
2017-03-05 15:44:50 +00:00
|
|
|
browse->connect("pressed", this, "_browse_path");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
l = memnew(Label);
|
2016-05-04 01:25:37 +00:00
|
|
|
l->set_text(TTR("Project Name:"));
|
2017-03-29 15:29:38 +00:00
|
|
|
l->set_position(Point2(5, 50));
|
2014-02-10 01:10:30 +00:00
|
|
|
vb->add_child(l);
|
2017-03-05 15:44:50 +00:00
|
|
|
pn = l;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
project_name = memnew(LineEdit);
|
|
|
|
mc = memnew(MarginContainer);
|
2014-02-10 01:10:30 +00:00
|
|
|
vb->add_child(mc);
|
|
|
|
mc->add_child(project_name);
|
2016-05-04 01:25:37 +00:00
|
|
|
project_name->set_text(TTR("New Game Project"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
l = memnew(Label);
|
2016-05-04 01:25:37 +00:00
|
|
|
l->set_text(TTR("That's a BINGO!"));
|
2014-02-10 01:10:30 +00:00
|
|
|
vb->add_child(l);
|
2017-03-05 15:44:50 +00:00
|
|
|
error = l;
|
|
|
|
l->add_color_override("font_color", Color(1, 0.4, 0.3, 0.8));
|
2014-02-10 01:10:30 +00:00
|
|
|
l->set_align(Label::ALIGN_CENTER);
|
|
|
|
|
|
|
|
DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
|
|
|
project_path->set_text(d->get_current_dir());
|
|
|
|
memdelete(d);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
fdialog = memnew(FileDialog);
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(fdialog);
|
|
|
|
fdialog->set_access(FileDialog::ACCESS_FILESYSTEM);
|
2017-03-05 15:44:50 +00:00
|
|
|
fdialog->set_current_dir(EditorSettings::get_singleton()->get("filesystem/directories/default_project_path"));
|
|
|
|
project_name->connect("text_changed", this, "_text_changed");
|
|
|
|
project_path->connect("text_changed", this, "_path_text_changed");
|
|
|
|
fdialog->connect("dir_selected", this, "_path_selected");
|
|
|
|
fdialog->connect("file_selected", this, "_file_selected");
|
2014-02-10 01:10:30 +00:00
|
|
|
set_hide_on_ok(false);
|
2017-03-05 15:44:50 +00:00
|
|
|
mode = MODE_NEW;
|
2016-07-12 00:34:02 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
dialog_error = memnew(AcceptDialog);
|
2016-07-12 00:34:02 +00:00
|
|
|
add_child(dialog_error);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-05-01 11:30:10 +00:00
|
|
|
struct ProjectItem {
|
|
|
|
String project;
|
|
|
|
String path;
|
|
|
|
String conf;
|
|
|
|
uint64_t last_modified;
|
2014-05-20 08:38:18 +00:00
|
|
|
bool favorite;
|
2014-05-01 11:30:10 +00:00
|
|
|
ProjectItem() {}
|
2017-03-05 15:44:50 +00:00
|
|
|
ProjectItem(const String &p_project, const String &p_path, const String &p_conf, uint64_t p_last_modified, bool p_favorite = false) {
|
|
|
|
project = p_project;
|
|
|
|
path = p_path;
|
|
|
|
conf = p_conf;
|
|
|
|
last_modified = p_last_modified;
|
|
|
|
favorite = p_favorite;
|
2014-05-01 11:30:10 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
_FORCE_INLINE_ bool operator<(const ProjectItem &l) const { return last_modified > l.last_modified; }
|
|
|
|
_FORCE_INLINE_ bool operator==(const ProjectItem &l) const { return project == l.project; }
|
2014-05-01 11:30:10 +00:00
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-12-14 19:31:37 +00:00
|
|
|
void ProjectManager::_notification(int p_what) {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_what == NOTIFICATION_ENTER_TREE) {
|
2015-12-14 19:31:37 +00:00
|
|
|
|
|
|
|
get_tree()->set_editor_hint(true);
|
2016-07-23 19:37:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
|
2016-07-23 19:37:25 +00:00
|
|
|
|
2017-01-13 13:45:50 +00:00
|
|
|
set_process_unhandled_input(is_visible_in_tree());
|
2015-12-14 19:31:37 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-11 01:45:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void ProjectManager::_panel_draw(Node *p_hb) {
|
|
|
|
|
|
|
|
HBoxContainer *hb = p_hb->cast_to<HBoxContainer>();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
hb->draw_line(Point2(0, hb->get_size().y + 1), Point2(hb->get_size().x - 10, hb->get_size().y + 1), get_color("guide_color", "Tree"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-05-01 13:47:45 +00:00
|
|
|
if (selected_list.has(hb->get_meta("name"))) {
|
2017-03-05 15:44:50 +00:00
|
|
|
hb->draw_style_box(gui_base->get_stylebox("selected", "Tree"), Rect2(Point2(), hb->get_size() - Size2(10, 0)));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void ProjectManager::_update_project_buttons() {
|
|
|
|
for (int i = 0; i < scroll_childs->get_child_count(); i++) {
|
2016-08-05 14:06:16 +00:00
|
|
|
|
2016-07-29 00:33:59 +00:00
|
|
|
CanvasItem *item = scroll_childs->get_child(i)->cast_to<CanvasItem>();
|
|
|
|
item->update();
|
2016-07-30 22:04:16 +00:00
|
|
|
}
|
2016-08-05 14:06:16 +00:00
|
|
|
|
2016-07-30 22:04:16 +00:00
|
|
|
bool has_runnable_scene = false;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<String, String>::Element *E = selected_list.front(); E; E = E->next()) {
|
2016-07-30 22:04:16 +00:00
|
|
|
const String &selected_main = E->get();
|
|
|
|
if (selected_main == "") continue;
|
|
|
|
has_runnable_scene = true;
|
|
|
|
break;
|
2016-07-29 00:33:59 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
erase_btn->set_disabled(selected_list.size() < 1);
|
|
|
|
open_btn->set_disabled(selected_list.size() < 1);
|
2016-08-05 14:06:16 +00:00
|
|
|
run_btn->set_disabled(!has_runnable_scene);
|
2016-07-29 00:33:59 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void ProjectManager::_panel_input(const InputEvent &p_ev, Node *p_hb) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_ev.type == InputEvent::MOUSE_BUTTON && p_ev.mouse_button.pressed && p_ev.mouse_button.button_index == BUTTON_LEFT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-05-01 13:47:45 +00:00
|
|
|
String clicked = p_hb->get_meta("name");
|
2014-05-11 01:45:52 +00:00
|
|
|
String clicked_main_scene = p_hb->get_meta("main_scene");
|
2014-05-01 13:47:45 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_ev.key.mod.shift && selected_list.size() > 0 && last_clicked != "" && clicked != last_clicked) {
|
2014-05-01 13:47:45 +00:00
|
|
|
|
|
|
|
int clicked_id = -1;
|
|
|
|
int last_clicked_id = -1;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < scroll_childs->get_child_count(); i++) {
|
2014-05-01 13:47:45 +00:00
|
|
|
HBoxContainer *hb = scroll_childs->get_child(i)->cast_to<HBoxContainer>();
|
|
|
|
if (!hb) continue;
|
|
|
|
if (hb->get_meta("name") == clicked) clicked_id = i;
|
|
|
|
if (hb->get_meta("name") == last_clicked) last_clicked_id = i;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (last_clicked_id != -1 && clicked_id != -1) {
|
|
|
|
int min = clicked_id < last_clicked_id ? clicked_id : last_clicked_id;
|
|
|
|
int max = clicked_id > last_clicked_id ? clicked_id : last_clicked_id;
|
|
|
|
for (int i = 0; i < scroll_childs->get_child_count(); ++i) {
|
2014-05-01 13:47:45 +00:00
|
|
|
HBoxContainer *hb = scroll_childs->get_child(i)->cast_to<HBoxContainer>();
|
|
|
|
if (!hb) continue;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (i != clicked_id && (i < min || i > max) && !p_ev.key.mod.control) {
|
2014-05-01 13:47:45 +00:00
|
|
|
selected_list.erase(hb->get_meta("name"));
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (i >= min && i <= max) {
|
2014-05-11 01:45:52 +00:00
|
|
|
selected_list.insert(hb->get_meta("name"), hb->get_meta("main_scene"));
|
2014-05-01 13:47:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (selected_list.has(clicked) && p_ev.key.mod.control) {
|
|
|
|
|
|
|
|
selected_list.erase(clicked);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
last_clicked = clicked;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_ev.key.mod.control || selected_list.size() == 0) {
|
2014-05-11 01:45:52 +00:00
|
|
|
selected_list.insert(clicked, clicked_main_scene);
|
2014-05-01 13:47:45 +00:00
|
|
|
} else {
|
|
|
|
selected_list.clear();
|
2014-05-11 01:45:52 +00:00
|
|
|
selected_list.insert(clicked, clicked_main_scene);
|
2014-05-01 13:47:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-29 00:33:59 +00:00
|
|
|
_update_project_buttons();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (p_ev.mouse_button.doubleclick)
|
|
|
|
_open_project(); //open if doubleclicked
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void ProjectManager::_unhandled_input(const InputEvent &p_ev) {
|
2016-07-23 19:37:25 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_ev.type == InputEvent::KEY) {
|
2016-07-23 19:37:25 +00:00
|
|
|
|
|
|
|
const InputEventKey &k = p_ev.key;
|
|
|
|
|
|
|
|
if (!k.pressed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool scancode_handled = true;
|
|
|
|
|
|
|
|
switch (k.scancode) {
|
|
|
|
|
2016-08-05 14:06:16 +00:00
|
|
|
case KEY_RETURN: {
|
|
|
|
|
|
|
|
_open_project();
|
|
|
|
} break;
|
2016-07-23 19:37:25 +00:00
|
|
|
case KEY_HOME: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < scroll_childs->get_child_count(); i++) {
|
2016-07-23 19:37:25 +00:00
|
|
|
|
|
|
|
HBoxContainer *hb = scroll_childs->get_child(i)->cast_to<HBoxContainer>();
|
|
|
|
if (hb) {
|
|
|
|
selected_list.clear();
|
|
|
|
selected_list.insert(hb->get_meta("name"), hb->get_meta("main_scene"));
|
|
|
|
scroll->set_v_scroll(0);
|
2016-08-05 14:06:16 +00:00
|
|
|
_update_project_buttons();
|
2016-07-23 19:37:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case KEY_END: {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = scroll_childs->get_child_count() - 1; i >= 0; i--) {
|
2016-07-23 19:37:25 +00:00
|
|
|
|
|
|
|
HBoxContainer *hb = scroll_childs->get_child(i)->cast_to<HBoxContainer>();
|
|
|
|
if (hb) {
|
|
|
|
selected_list.clear();
|
|
|
|
selected_list.insert(hb->get_meta("name"), hb->get_meta("main_scene"));
|
|
|
|
scroll->set_v_scroll(scroll_childs->get_size().y);
|
2016-08-05 14:06:16 +00:00
|
|
|
_update_project_buttons();
|
2016-07-23 19:37:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case KEY_UP: {
|
|
|
|
|
|
|
|
if (k.mod.shift)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (selected_list.size()) {
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = scroll_childs->get_child_count() - 1; i >= 0; i--) {
|
2016-07-23 19:37:25 +00:00
|
|
|
|
|
|
|
HBoxContainer *hb = scroll_childs->get_child(i)->cast_to<HBoxContainer>();
|
|
|
|
if (!hb) continue;
|
|
|
|
|
|
|
|
String current = hb->get_meta("name");
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
selected_list.clear();
|
|
|
|
selected_list.insert(current, hb->get_meta("main_scene"));
|
|
|
|
|
2017-03-29 15:29:38 +00:00
|
|
|
int offset_diff = scroll->get_v_scroll() - hb->get_position().y;
|
2016-07-23 19:37:25 +00:00
|
|
|
|
|
|
|
if (offset_diff > 0)
|
|
|
|
scroll->set_v_scroll(scroll->get_v_scroll() - offset_diff);
|
|
|
|
|
2016-08-05 14:06:16 +00:00
|
|
|
_update_project_buttons();
|
|
|
|
|
2016-07-23 19:37:25 +00:00
|
|
|
break;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (current == selected_list.back()->key()) {
|
2016-07-23 19:37:25 +00:00
|
|
|
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// else fallthrough to key_down
|
|
|
|
}
|
|
|
|
case KEY_DOWN: {
|
|
|
|
|
|
|
|
if (k.mod.shift)
|
|
|
|
break;
|
|
|
|
|
|
|
|
bool found = selected_list.empty();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < scroll_childs->get_child_count(); i++) {
|
2016-07-23 19:37:25 +00:00
|
|
|
|
|
|
|
HBoxContainer *hb = scroll_childs->get_child(i)->cast_to<HBoxContainer>();
|
|
|
|
if (!hb) continue;
|
|
|
|
|
|
|
|
String current = hb->get_meta("name");
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
selected_list.clear();
|
|
|
|
selected_list.insert(current, hb->get_meta("main_scene"));
|
|
|
|
|
|
|
|
int last_y_visible = scroll->get_v_scroll() + scroll->get_size().y;
|
2017-03-29 15:29:38 +00:00
|
|
|
int offset_diff = (hb->get_position().y + hb->get_size().y) - last_y_visible;
|
2016-07-23 19:37:25 +00:00
|
|
|
|
|
|
|
if (offset_diff > 0)
|
|
|
|
scroll->set_v_scroll(scroll->get_v_scroll() + offset_diff);
|
|
|
|
|
2016-08-05 14:06:16 +00:00
|
|
|
_update_project_buttons();
|
|
|
|
|
2016-07-23 19:37:25 +00:00
|
|
|
break;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (current == selected_list.back()->key()) {
|
2016-07-23 19:37:25 +00:00
|
|
|
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2016-07-26 19:17:41 +00:00
|
|
|
case KEY_F: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (k.mod.command)
|
|
|
|
this->project_filter->search_box->grab_focus();
|
|
|
|
else
|
|
|
|
scancode_handled = false;
|
2016-07-26 19:17:41 +00:00
|
|
|
} break;
|
2016-07-23 19:37:25 +00:00
|
|
|
default: {
|
|
|
|
scancode_handled = false;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scancode_handled) {
|
|
|
|
accept_event();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-20 08:38:18 +00:00
|
|
|
void ProjectManager::_favorite_pressed(Node *p_hb) {
|
|
|
|
|
|
|
|
String clicked = p_hb->get_meta("name");
|
|
|
|
bool favorite = !p_hb->get_meta("favorite");
|
2017-03-05 15:44:50 +00:00
|
|
|
String proj = clicked.replace(":::", ":/");
|
|
|
|
proj = proj.replace("::", "/");
|
2014-05-20 08:38:18 +00:00
|
|
|
|
|
|
|
if (favorite) {
|
2017-03-05 15:44:50 +00:00
|
|
|
EditorSettings::get_singleton()->set("favorite_projects/" + clicked, proj);
|
2014-05-20 08:38:18 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
EditorSettings::get_singleton()->erase("favorite_projects/" + clicked);
|
2014-05-20 08:38:18 +00:00
|
|
|
}
|
|
|
|
EditorSettings::get_singleton()->save();
|
2014-06-25 03:43:45 +00:00
|
|
|
call_deferred("_load_recent_projects");
|
2014-05-20 08:38:18 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void ProjectManager::_load_recent_projects() {
|
|
|
|
|
2014-06-11 09:57:13 +00:00
|
|
|
ProjectListFilter::FilterOption filter_option = project_filter->get_filter_option();
|
|
|
|
String search_term = project_filter->get_search_term();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (scroll_childs->get_child_count() > 0) {
|
|
|
|
memdelete(scroll_childs->get_child(0));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 00:33:59 +00:00
|
|
|
Map<String, String> selected_list_copy = selected_list;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
List<PropertyInfo> properties;
|
|
|
|
EditorSettings::get_singleton()->get_property_list(&properties);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Color font_color = gui_base->get_color("font_color", "Tree");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-05-01 11:30:10 +00:00
|
|
|
List<ProjectItem> projects;
|
2014-05-20 08:38:18 +00:00
|
|
|
List<ProjectItem> favorite_projects;
|
2014-05-01 11:30:10 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String _name = E->get().name;
|
2014-05-20 08:38:18 +00:00
|
|
|
if (!_name.begins_with("projects/") && !_name.begins_with("favorite_projects/"))
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
String path = EditorSettings::get_singleton()->get(_name);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (filter_option == ProjectListFilter::FILTER_PATH && search_term != "" && path.findn(search_term) == -1)
|
2014-06-11 09:57:13 +00:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String project = _name.get_slice("/", 1);
|
2017-05-01 15:44:52 +00:00
|
|
|
String conf = path.plus_file("project.godot");
|
2017-03-05 15:44:50 +00:00
|
|
|
bool favorite = (_name.begins_with("favorite_projects/")) ? true : false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-05-01 11:30:10 +00:00
|
|
|
uint64_t last_modified = 0;
|
2015-10-20 04:14:02 +00:00
|
|
|
if (FileAccess::exists(conf)) {
|
2014-05-01 11:30:10 +00:00
|
|
|
last_modified = FileAccess::get_modified_time(conf);
|
|
|
|
|
2015-10-20 04:14:02 +00:00
|
|
|
String fscache = path.plus_file(".fscache");
|
|
|
|
if (FileAccess::exists(fscache)) {
|
|
|
|
uint64_t cache_modified = FileAccess::get_modified_time(fscache);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (cache_modified > last_modified)
|
2015-10-20 04:14:02 +00:00
|
|
|
last_modified = cache_modified;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectItem item(project, path, conf, last_modified, favorite);
|
|
|
|
if (favorite)
|
|
|
|
favorite_projects.push_back(item);
|
|
|
|
else
|
|
|
|
projects.push_back(item);
|
|
|
|
} else {
|
|
|
|
//project doesn't exist on disk but it's in the XML settings file
|
|
|
|
EditorSettings::get_singleton()->erase(_name); //remove it
|
|
|
|
}
|
2014-05-01 11:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
projects.sort();
|
2014-05-20 08:38:18 +00:00
|
|
|
favorite_projects.sort();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<ProjectItem>::Element *E = projects.front(); E;) {
|
2014-05-20 08:38:18 +00:00
|
|
|
List<ProjectItem>::Element *next = E->next();
|
|
|
|
if (favorite_projects.find(E->get()) != NULL)
|
|
|
|
projects.erase(E->get());
|
2017-03-05 15:44:50 +00:00
|
|
|
E = next;
|
2014-05-20 08:38:18 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<ProjectItem>::Element *E = favorite_projects.back(); E; E = E->prev()) {
|
2014-05-20 08:38:18 +00:00
|
|
|
projects.push_front(E->get());
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<Texture> favorite_icon = get_icon("Favorites", "EditorIcons");
|
2014-05-01 11:30:10 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<ProjectItem>::Element *E = projects.front(); E; E = E->next()) {
|
2014-05-01 11:30:10 +00:00
|
|
|
|
|
|
|
ProjectItem &item = E->get();
|
|
|
|
String project = item.project;
|
|
|
|
String path = item.path;
|
|
|
|
String conf = item.conf;
|
2014-05-20 08:38:18 +00:00
|
|
|
bool is_favorite = item.favorite;
|
2014-05-01 11:30:10 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<ConfigFile> cf = memnew(ConfigFile);
|
2014-02-10 01:10:30 +00:00
|
|
|
Error err = cf->load(conf);
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_CONTINUE(err != OK);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
String project_name = TTR("Unnamed Project");
|
2014-06-11 09:57:13 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (cf->has_section_key("application", "name")) {
|
|
|
|
project_name = static_cast<String>(cf->get_value("application", "name")).xml_unescape();
|
2014-06-11 09:57:13 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (filter_option == ProjectListFilter::FILTER_NAME && search_term != "" && project_name.findn(search_term) == -1)
|
2014-06-11 09:57:13 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Ref<Texture> icon;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (cf->has_section_key("application", "icon")) {
|
|
|
|
String appicon = cf->get_value("application", "icon");
|
|
|
|
if (appicon != "") {
|
2017-05-17 10:36:47 +00:00
|
|
|
Ref<Image> img;
|
|
|
|
img.instance();
|
|
|
|
Error err = img->load(appicon.replace_first("res://", path + "/"));
|
2017-03-05 15:44:50 +00:00
|
|
|
if (err == OK) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-17 10:36:47 +00:00
|
|
|
img->resize(64, 64);
|
2017-03-05 15:44:50 +00:00
|
|
|
Ref<ImageTexture> it = memnew(ImageTexture);
|
2014-02-10 01:10:30 +00:00
|
|
|
it->create_from_image(img);
|
2017-03-05 15:44:50 +00:00
|
|
|
icon = it;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (icon.is_null()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
icon = get_icon("DefaultProjectIcon", "EditorIcons");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String main_scene;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (cf->has_section_key("application", "main_scene")) {
|
|
|
|
main_scene = cf->get_value("application", "main_scene");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 00:33:59 +00:00
|
|
|
selected_list_copy.erase(project);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
HBoxContainer *hb = memnew(HBoxContainer);
|
|
|
|
hb->set_meta("name", project);
|
|
|
|
hb->set_meta("main_scene", main_scene);
|
|
|
|
hb->set_meta("favorite", is_favorite);
|
|
|
|
hb->connect("draw", this, "_panel_draw", varray(hb));
|
|
|
|
hb->connect("gui_input", this, "_panel_input", varray(hb));
|
|
|
|
hb->add_constant_override("separation", 10 * EDSCALE);
|
2014-05-20 08:38:18 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
VBoxContainer *favorite_box = memnew(VBoxContainer);
|
|
|
|
TextureButton *favorite = memnew(TextureButton);
|
2014-05-20 08:38:18 +00:00
|
|
|
favorite->set_normal_texture(favorite_icon);
|
|
|
|
if (!is_favorite)
|
2017-03-05 15:44:50 +00:00
|
|
|
favorite->set_modulate(Color(1, 1, 1, 0.2));
|
2014-05-20 08:38:18 +00:00
|
|
|
favorite->set_v_size_flags(SIZE_EXPAND);
|
2017-03-05 15:44:50 +00:00
|
|
|
favorite->connect("pressed", this, "_favorite_pressed", varray(hb));
|
2014-05-20 08:38:18 +00:00
|
|
|
favorite_box->add_child(favorite);
|
|
|
|
hb->add_child(favorite_box);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
TextureRect *tf = memnew(TextureRect);
|
2014-02-10 01:10:30 +00:00
|
|
|
tf->set_texture(icon);
|
|
|
|
hb->add_child(tf);
|
2014-05-20 08:38:18 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
VBoxContainer *vb = memnew(VBoxContainer);
|
2016-11-07 18:39:05 +00:00
|
|
|
vb->set_name("project");
|
2014-02-10 01:10:30 +00:00
|
|
|
hb->add_child(vb);
|
2017-03-05 15:44:50 +00:00
|
|
|
Control *ec = memnew(Control);
|
|
|
|
ec->set_custom_minimum_size(Size2(0, 1));
|
2014-02-10 01:10:30 +00:00
|
|
|
vb->add_child(ec);
|
2017-03-05 15:44:50 +00:00
|
|
|
Label *title = memnew(Label(project_name));
|
|
|
|
title->add_font_override("font", gui_base->get_font("large", "Fonts"));
|
|
|
|
title->add_color_override("font_color", font_color);
|
2014-02-10 01:10:30 +00:00
|
|
|
vb->add_child(title);
|
2017-03-05 15:44:50 +00:00
|
|
|
Label *fpath = memnew(Label(path));
|
2016-11-07 18:39:05 +00:00
|
|
|
fpath->set_name("path");
|
2014-02-10 01:10:30 +00:00
|
|
|
vb->add_child(fpath);
|
2017-03-05 15:44:50 +00:00
|
|
|
fpath->set_modulate(Color(1, 1, 1, 0.5));
|
|
|
|
fpath->add_color_override("font_color", font_color);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
scroll_childs->add_child(hb);
|
|
|
|
}
|
2016-08-05 14:06:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<String, String>::Element *E = selected_list_copy.front(); E; E = E->next()) {
|
2016-07-29 00:33:59 +00:00
|
|
|
String key = E->key();
|
|
|
|
selected_list.erase(key);
|
|
|
|
}
|
2016-08-05 14:06:16 +00:00
|
|
|
|
2014-06-11 09:57:13 +00:00
|
|
|
scroll->set_v_scroll(0);
|
2016-08-05 14:06:16 +00:00
|
|
|
|
2016-07-29 00:33:59 +00:00
|
|
|
_update_project_buttons();
|
2015-10-20 04:14:02 +00:00
|
|
|
|
|
|
|
EditorSettings::get_singleton()->save();
|
2016-07-12 00:34:02 +00:00
|
|
|
|
|
|
|
tabs->set_current_tab(0);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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;
|
2016-11-07 18:39:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (has_already) {
|
|
|
|
_update_scroll_pos(dir);
|
|
|
|
} else {
|
|
|
|
_load_recent_projects();
|
|
|
|
scroll->connect("draw", this, "_update_scroll_pos", varray(dir), CONNECT_ONESHOT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
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");
|
2016-11-07 18:39:05 +00:00
|
|
|
selected_list.clear();
|
|
|
|
selected_list.insert(hb->get_meta("name"), hb->get_meta("main_scene"));
|
|
|
|
_update_project_buttons();
|
2017-03-05 15:44:50 +00:00
|
|
|
int last_y_visible = scroll->get_v_scroll() + scroll->get_size().y;
|
2017-03-29 15:29:38 +00:00
|
|
|
int offset_diff = (hb->get_position().y + hb->get_size().y) - last_y_visible;
|
2016-11-07 18:39:05 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (offset_diff > 0)
|
|
|
|
scroll->set_v_scroll(scroll->get_v_scroll() + offset_diff);
|
2016-11-07 18:39:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-11 01:45:52 +00:00
|
|
|
void ProjectManager::_open_project_confirm() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<String, String>::Element *E = selected_list.front(); E; E = E->next()) {
|
2014-05-11 01:45:52 +00:00
|
|
|
const String &selected = E->key();
|
2017-03-05 15:44:50 +00:00
|
|
|
String path = EditorSettings::get_singleton()->get("projects/" + selected);
|
|
|
|
print_line("OPENING: " + path + " (" + selected + ")");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-05-11 01:45:52 +00:00
|
|
|
List<String> args;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-05-11 01:45:52 +00:00
|
|
|
args.push_back("-path");
|
|
|
|
args.push_back(path);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-05-11 01:45:52 +00:00
|
|
|
args.push_back("-editor");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-05-11 01:45:52 +00:00
|
|
|
String exec = OS::get_singleton()->get_executable_path();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
OS::ProcessID pid = 0;
|
|
|
|
Error err = OS::get_singleton()->execute(exec, args, false, &pid);
|
2014-05-11 01:45:52 +00:00
|
|
|
ERR_FAIL_COND(err);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2014-11-06 00:20:42 +00:00
|
|
|
get_tree()->quit();
|
2014-05-11 01:45:52 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-05-11 01:45:52 +00:00
|
|
|
void ProjectManager::_open_project() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (selected_list.size() < 1) {
|
2014-05-11 01:45:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (selected_list.size() > 1) {
|
2016-08-05 14:06:16 +00:00
|
|
|
multi_open_ask->set_text(TTR("Are you sure to open more than one project?"));
|
2015-04-22 00:30:00 +00:00
|
|
|
multi_open_ask->popup_centered_minsize();
|
2014-05-11 01:45:52 +00:00
|
|
|
} else {
|
|
|
|
_open_project_confirm();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2014-05-11 01:45:52 +00:00
|
|
|
void ProjectManager::_run_project_confirm() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<String, String>::Element *E = selected_list.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-05-11 01:45:52 +00:00
|
|
|
const String &selected_main = E->get();
|
|
|
|
if (selected_main == "") continue;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-05-11 01:45:52 +00:00
|
|
|
const String &selected = E->key();
|
2017-03-05 15:44:50 +00:00
|
|
|
String path = EditorSettings::get_singleton()->get("projects/" + selected);
|
|
|
|
print_line("OPENING: " + path + " (" + selected + ")");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-05-11 01:45:52 +00:00
|
|
|
List<String> args;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-05-11 01:45:52 +00:00
|
|
|
args.push_back("-path");
|
|
|
|
args.push_back(path);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-05-11 01:45:52 +00:00
|
|
|
String exec = OS::get_singleton()->get_executable_path();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
OS::ProcessID pid = 0;
|
|
|
|
Error err = OS::get_singleton()->execute(exec, args, false, &pid);
|
2014-05-11 01:45:52 +00:00
|
|
|
ERR_FAIL_COND(err);
|
|
|
|
}
|
2017-01-14 11:26:56 +00:00
|
|
|
//get_scene()->quit(); do not quit
|
2014-05-11 01:45:52 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-05-11 01:45:52 +00:00
|
|
|
void ProjectManager::_run_project() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (selected_list.size() < 1) {
|
2014-05-11 01:45:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (selected_list.size() > 1) {
|
2016-08-05 14:06:16 +00:00
|
|
|
multi_run_ask->set_text(TTR("Are you sure to run more than one project?"));
|
2015-04-22 00:30:00 +00:00
|
|
|
multi_run_ask->popup_centered_minsize();
|
2014-05-11 01:45:52 +00:00
|
|
|
} else {
|
|
|
|
_run_project_confirm();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void ProjectManager::_scan_dir(DirAccess *da, float pos, float total, List<String> *r_projects) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
List<String> subdirs;
|
|
|
|
da->list_dir_begin();
|
|
|
|
String n = da->get_next();
|
2017-03-05 15:44:50 +00:00
|
|
|
while (n != String()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
if (da->current_is_dir() && !n.begins_with(".")) {
|
|
|
|
subdirs.push_front(n);
|
2017-05-01 15:44:52 +00:00
|
|
|
} else if (n == "project.godot") {
|
2014-02-10 01:10:30 +00:00
|
|
|
r_projects->push_back(da->get_current_dir());
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
n = da->get_next();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
da->list_dir_end();
|
2017-03-05 15:44:50 +00:00
|
|
|
int m = 0;
|
|
|
|
for (List<String>::Element *E = subdirs.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
da->change_dir(E->get());
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
float slice = total / subdirs.size();
|
|
|
|
_scan_dir(da, pos + slice * m, slice, r_projects);
|
2014-02-10 01:10:30 +00:00
|
|
|
da->change_dir("..");
|
|
|
|
m++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void ProjectManager::_scan_begin(const String &p_base) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
print_line("SCAN PROJECTS AT: " + p_base);
|
2014-02-10 01:10:30 +00:00
|
|
|
List<String> projects;
|
|
|
|
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
|
|
|
da->change_dir(p_base);
|
2017-03-05 15:44:50 +00:00
|
|
|
_scan_dir(da, 0, 1, &projects);
|
2014-02-10 01:10:30 +00:00
|
|
|
memdelete(da);
|
2017-03-05 15:44:50 +00:00
|
|
|
print_line("found: " + itos(projects.size()) + " projects.");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<String>::Element *E = projects.front(); E; E = E->next()) {
|
|
|
|
String proj = E->get().replace("/", "::");
|
|
|
|
EditorSettings::get_singleton()->set("projects/" + proj, E->get());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
EditorSettings::get_singleton()->save();
|
|
|
|
_load_recent_projects();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectManager::_scan_projects() {
|
|
|
|
|
|
|
|
scan_dir->popup_centered_ratio();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void ProjectManager::_new_project() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-07-12 00:34:02 +00:00
|
|
|
npdialog->set_mode(NewProjectDialog::MODE_NEW);
|
2014-02-10 01:10:30 +00:00
|
|
|
npdialog->show_dialog();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void ProjectManager::_import_project() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-07-12 00:34:02 +00:00
|
|
|
npdialog->set_mode(NewProjectDialog::MODE_IMPORT);
|
2014-02-10 01:10:30 +00:00
|
|
|
npdialog->show_dialog();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void ProjectManager::_erase_project_confirm() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (selected_list.size() == 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Map<String, String>::Element *E = selected_list.front(); E; E = E->next()) {
|
|
|
|
EditorSettings::get_singleton()->erase("projects/" + E->key());
|
|
|
|
EditorSettings::get_singleton()->erase("favorite_projects/" + E->key());
|
2014-05-01 13:47:45 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
EditorSettings::get_singleton()->save();
|
2014-05-01 13:47:45 +00:00
|
|
|
selected_list.clear();
|
|
|
|
last_clicked = "";
|
2014-02-10 01:10:30 +00:00
|
|
|
_load_recent_projects();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void ProjectManager::_erase_project() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (selected_list.size() == 0)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2016-05-18 22:08:12 +00:00
|
|
|
erase_ask->set_text(TTR("Remove project from the list? (Folder contents will not be modified)"));
|
2015-04-22 00:30:00 +00:00
|
|
|
erase_ask->popup_centered_minsize();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void ProjectManager::_exit_dialog() {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-11-06 00:20:42 +00:00
|
|
|
get_tree()->quit();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void ProjectManager::_install_project(const String &p_zip_path, const String &p_title) {
|
2016-07-12 00:34:02 +00:00
|
|
|
|
|
|
|
npdialog->set_mode(NewProjectDialog::MODE_INSTALL);
|
|
|
|
npdialog->set_zip_path(p_zip_path);
|
|
|
|
npdialog->set_zip_title(p_title);
|
|
|
|
npdialog->show_dialog();
|
|
|
|
}
|
|
|
|
|
2017-01-11 03:52:51 +00:00
|
|
|
void ProjectManager::_files_dropped(PoolStringArray p_files, int p_screen) {
|
2016-07-31 22:59:31 +00:00
|
|
|
Set<String> folders_set;
|
|
|
|
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
2016-07-29 15:06:37 +00:00
|
|
|
for (int i = 0; i < p_files.size(); i++) {
|
2016-07-31 22:59:31 +00:00
|
|
|
String file = p_files[i];
|
|
|
|
folders_set.insert(da->dir_exists(file) ? file : file.get_base_dir());
|
|
|
|
}
|
|
|
|
memdelete(da);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (folders_set.size() > 0) {
|
2017-01-11 03:52:51 +00:00
|
|
|
PoolStringArray folders;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (Set<String>::Element *E = folders_set.front(); E; E = E->next()) {
|
2016-07-31 22:59:31 +00:00
|
|
|
folders.append(E->get());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool confirm = true;
|
2017-03-05 15:44:50 +00:00
|
|
|
if (folders.size() == 1) {
|
2016-07-31 22:59:31 +00:00
|
|
|
DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
2017-03-05 15:44:50 +00:00
|
|
|
if (dir->change_dir(folders[0]) == OK) {
|
2016-07-31 22:59:31 +00:00
|
|
|
dir->list_dir_begin();
|
|
|
|
String file = dir->get_next();
|
2017-03-05 15:44:50 +00:00
|
|
|
while (confirm && file != String()) {
|
2017-05-01 15:44:52 +00:00
|
|
|
if (!dir->current_is_dir() && file.ends_with("project.godot")) {
|
2016-07-31 22:59:31 +00:00
|
|
|
confirm = false;
|
|
|
|
}
|
|
|
|
file = dir->get_next();
|
|
|
|
}
|
|
|
|
dir->list_dir_end();
|
|
|
|
}
|
|
|
|
memdelete(dir);
|
|
|
|
}
|
|
|
|
if (confirm) {
|
|
|
|
multi_scan_ask->get_ok()->disconnect("pressed", this, "_scan_multiple_folders");
|
|
|
|
multi_scan_ask->get_ok()->connect("pressed", this, "_scan_multiple_folders", varray(folders));
|
|
|
|
multi_scan_ask->set_text(vformat(TTR("You are about the scan %s folders for existing Godot projects. Do you confirm?"), folders.size()));
|
|
|
|
multi_scan_ask->popup_centered_minsize();
|
|
|
|
} else {
|
|
|
|
_scan_multiple_folders(folders);
|
2016-07-29 15:06:37 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-31 22:59:31 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void ProjectManager::_scan_multiple_folders(PoolStringArray p_files) {
|
2016-07-31 22:59:31 +00:00
|
|
|
for (int i = 0; i < p_files.size(); i++) {
|
|
|
|
_scan_begin(p_files.get(i));
|
2016-07-30 22:10:13 +00:00
|
|
|
}
|
2016-07-29 15:06:37 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void ProjectManager::_bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method("_open_project", &ProjectManager::_open_project);
|
|
|
|
ClassDB::bind_method("_open_project_confirm", &ProjectManager::_open_project_confirm);
|
|
|
|
ClassDB::bind_method("_run_project", &ProjectManager::_run_project);
|
|
|
|
ClassDB::bind_method("_run_project_confirm", &ProjectManager::_run_project_confirm);
|
|
|
|
ClassDB::bind_method("_scan_projects", &ProjectManager::_scan_projects);
|
|
|
|
ClassDB::bind_method("_scan_begin", &ProjectManager::_scan_begin);
|
|
|
|
ClassDB::bind_method("_import_project", &ProjectManager::_import_project);
|
|
|
|
ClassDB::bind_method("_new_project", &ProjectManager::_new_project);
|
|
|
|
ClassDB::bind_method("_erase_project", &ProjectManager::_erase_project);
|
|
|
|
ClassDB::bind_method("_erase_project_confirm", &ProjectManager::_erase_project_confirm);
|
|
|
|
ClassDB::bind_method("_exit_dialog", &ProjectManager::_exit_dialog);
|
|
|
|
ClassDB::bind_method("_load_recent_projects", &ProjectManager::_load_recent_projects);
|
|
|
|
ClassDB::bind_method("_on_project_created", &ProjectManager::_on_project_created);
|
|
|
|
ClassDB::bind_method("_update_scroll_pos", &ProjectManager::_update_scroll_pos);
|
|
|
|
ClassDB::bind_method("_panel_draw", &ProjectManager::_panel_draw);
|
|
|
|
ClassDB::bind_method("_panel_input", &ProjectManager::_panel_input);
|
|
|
|
ClassDB::bind_method("_unhandled_input", &ProjectManager::_unhandled_input);
|
|
|
|
ClassDB::bind_method("_favorite_pressed", &ProjectManager::_favorite_pressed);
|
|
|
|
ClassDB::bind_method("_install_project", &ProjectManager::_install_project);
|
|
|
|
ClassDB::bind_method("_files_dropped", &ProjectManager::_files_dropped);
|
|
|
|
ClassDB::bind_method(D_METHOD("_scan_multiple_folders", "files"), &ProjectManager::_scan_multiple_folders);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ProjectManager::ProjectManager() {
|
|
|
|
|
|
|
|
// load settings
|
|
|
|
if (!EditorSettings::get_singleton())
|
|
|
|
EditorSettings::create();
|
|
|
|
|
2016-07-03 22:13:45 +00:00
|
|
|
EditorSettings::get_singleton()->set_optimize_save(false); //just write settings as they came
|
|
|
|
|
2016-06-05 21:43:45 +00:00
|
|
|
{
|
2017-01-05 22:41:36 +00:00
|
|
|
int dpi_mode = EditorSettings::get_singleton()->get("interface/hidpi_mode");
|
2017-03-05 15:44:50 +00:00
|
|
|
if (dpi_mode == 0) {
|
2017-03-24 16:39:16 +00:00
|
|
|
editor_set_scale(OS::get_singleton()->get_screen_dpi(0) >= 192 && OS::get_singleton()->get_screen_size(OS::get_singleton()->get_current_screen()).x > 2000 ? 2.0 : 1.0);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (dpi_mode == 1) {
|
2016-09-13 14:05:47 +00:00
|
|
|
editor_set_scale(0.75);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (dpi_mode == 2) {
|
2016-09-13 14:05:47 +00:00
|
|
|
editor_set_scale(1.0);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (dpi_mode == 3) {
|
2016-09-13 14:05:47 +00:00
|
|
|
editor_set_scale(1.5);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (dpi_mode == 4) {
|
2016-09-13 14:05:47 +00:00
|
|
|
editor_set_scale(2.0);
|
2016-06-05 21:43:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-23 08:32:52 +00:00
|
|
|
FileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
set_area_as_parent_rect();
|
2016-09-11 13:01:52 +00:00
|
|
|
set_theme(create_editor_theme());
|
2015-12-09 15:35:20 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
gui_base = memnew(Control);
|
2016-06-18 05:32:03 +00:00
|
|
|
add_child(gui_base);
|
|
|
|
gui_base->set_area_as_parent_rect();
|
2016-09-20 12:41:57 +00:00
|
|
|
gui_base->set_theme(create_custom_theme());
|
2015-12-09 15:35:20 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Panel *panel = memnew(Panel);
|
2016-06-18 05:32:03 +00:00
|
|
|
gui_base->add_child(panel);
|
2014-02-10 01:10:30 +00:00
|
|
|
panel->set_area_as_parent_rect();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
VBoxContainer *vb = memnew(VBoxContainer);
|
2014-02-10 01:10:30 +00:00
|
|
|
panel->add_child(vb);
|
2017-03-05 15:44:50 +00:00
|
|
|
vb->set_area_as_parent_rect(20 * EDSCALE);
|
|
|
|
vb->set_margin(MARGIN_TOP, 4 * EDSCALE);
|
|
|
|
vb->set_margin(MARGIN_BOTTOM, 4 * EDSCALE);
|
|
|
|
vb->add_constant_override("separation", 15 * EDSCALE);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-08 12:25:47 +00:00
|
|
|
String cp;
|
|
|
|
cp.push_back(0xA9);
|
|
|
|
cp.push_back(0);
|
2017-03-05 15:44:50 +00:00
|
|
|
OS::get_singleton()->set_window_title(_MKSTR(VERSION_NAME) + String(" - ") + TTR("Project Manager") + " - " + cp + " 2008-2017 Juan Linietsky, Ariel Manzur.");
|
2016-06-08 12:25:47 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
HBoxContainer *top_hb = memnew(HBoxContainer);
|
2016-06-08 12:25:47 +00:00
|
|
|
vb->add_child(top_hb);
|
2017-03-05 15:44:50 +00:00
|
|
|
CenterContainer *ccl = memnew(CenterContainer);
|
|
|
|
Label *l = memnew(Label);
|
|
|
|
l->set_text(_MKSTR(VERSION_NAME) + String(" - ") + TTR("Project Manager"));
|
|
|
|
l->add_font_override("font", gui_base->get_font("doc", "EditorFonts"));
|
2016-06-08 12:25:47 +00:00
|
|
|
ccl->add_child(l);
|
|
|
|
top_hb->add_child(ccl);
|
|
|
|
top_hb->add_spacer();
|
2017-03-05 15:44:50 +00:00
|
|
|
l = memnew(Label);
|
2015-10-29 13:27:19 +00:00
|
|
|
l->set_text("v" VERSION_MKSTRING);
|
2014-02-10 01:10:30 +00:00
|
|
|
//l->add_font_override("font",get_font("bold","Fonts"));
|
|
|
|
l->set_align(Label::ALIGN_CENTER);
|
2016-06-08 12:25:47 +00:00
|
|
|
top_hb->add_child(l);
|
|
|
|
//vb->add_child(memnew(HSeparator));
|
|
|
|
//vb->add_margin_child("\n",memnew(Control));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
tabs = memnew(TabContainer);
|
2016-06-08 12:25:47 +00:00
|
|
|
vb->add_child(tabs);
|
|
|
|
tabs->set_v_size_flags(SIZE_EXPAND_FILL);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
HBoxContainer *tree_hb = memnew(HBoxContainer);
|
2016-06-08 12:25:47 +00:00
|
|
|
projects_hb = tree_hb;
|
|
|
|
|
|
|
|
projects_hb->set_name(TTR("Project List"));
|
|
|
|
|
|
|
|
tabs->add_child(tree_hb);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-06-11 09:57:13 +00:00
|
|
|
VBoxContainer *search_tree_vb = memnew(VBoxContainer);
|
|
|
|
search_tree_vb->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
tree_hb->add_child(search_tree_vb);
|
|
|
|
|
|
|
|
HBoxContainer *search_box = memnew(HBoxContainer);
|
|
|
|
search_box->add_spacer(true);
|
|
|
|
project_filter = memnew(ProjectListFilter);
|
|
|
|
search_box->add_child(project_filter);
|
|
|
|
project_filter->connect("filter_changed", this, "_load_recent_projects");
|
2017-03-05 15:44:50 +00:00
|
|
|
project_filter->set_custom_minimum_size(Size2(250, 10));
|
2014-06-11 09:57:13 +00:00
|
|
|
search_tree_vb->add_child(search_box);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
PanelContainer *pc = memnew(PanelContainer);
|
|
|
|
pc->add_style_override("panel", gui_base->get_stylebox("bg", "Tree"));
|
2014-06-11 09:57:13 +00:00
|
|
|
search_tree_vb->add_child(pc);
|
|
|
|
pc->set_v_size_flags(SIZE_EXPAND_FILL);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
scroll = memnew(ScrollContainer);
|
2014-02-10 01:10:30 +00:00
|
|
|
pc->add_child(scroll);
|
|
|
|
scroll->set_enable_h_scroll(false);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
VBoxContainer *tree_vb = memnew(VBoxContainer);
|
2014-06-04 21:15:37 +00:00
|
|
|
tree_hb->add_child(tree_vb);
|
2017-03-05 15:44:50 +00:00
|
|
|
scroll_childs = memnew(VBoxContainer);
|
2014-02-10 01:10:30 +00:00
|
|
|
scroll_childs->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
scroll->add_child(scroll_childs);
|
|
|
|
|
|
|
|
//HBoxContainer *hb = memnew( HBoxContainer );
|
|
|
|
//vb->add_child(hb);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Button *open = memnew(Button);
|
2016-05-04 01:25:37 +00:00
|
|
|
open->set_text(TTR("Edit"));
|
2014-02-10 01:10:30 +00:00
|
|
|
tree_vb->add_child(open);
|
2017-03-05 15:44:50 +00:00
|
|
|
open->connect("pressed", this, "_open_project");
|
|
|
|
open_btn = open;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Button *run = memnew(Button);
|
2016-05-04 01:25:37 +00:00
|
|
|
run->set_text(TTR("Run"));
|
2014-02-10 01:10:30 +00:00
|
|
|
tree_vb->add_child(run);
|
2017-03-05 15:44:50 +00:00
|
|
|
run->connect("pressed", this, "_run_project");
|
|
|
|
run_btn = run;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
tree_vb->add_child(memnew(HSeparator));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Button *scan = memnew(Button);
|
2016-05-04 01:25:37 +00:00
|
|
|
scan->set_text(TTR("Scan"));
|
2014-02-10 01:10:30 +00:00
|
|
|
tree_vb->add_child(scan);
|
2017-03-05 15:44:50 +00:00
|
|
|
scan->connect("pressed", this, "_scan_projects");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
tree_vb->add_child(memnew(HSeparator));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
scan_dir = memnew(FileDialog);
|
2014-02-10 01:10:30 +00:00
|
|
|
scan_dir->set_access(FileDialog::ACCESS_FILESYSTEM);
|
|
|
|
scan_dir->set_mode(FileDialog::MODE_OPEN_DIR);
|
2016-07-31 18:46:00 +00:00
|
|
|
scan_dir->set_title(TTR("Select a Folder to Scan")); // must be after mode or it's overridden
|
2017-03-05 15:44:50 +00:00
|
|
|
scan_dir->set_current_dir(EditorSettings::get_singleton()->get("filesystem/directories/default_project_path"));
|
2016-06-18 05:32:03 +00:00
|
|
|
gui_base->add_child(scan_dir);
|
2017-03-05 15:44:50 +00:00
|
|
|
scan_dir->connect("dir_selected", this, "_scan_begin");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Button *create = memnew(Button);
|
2016-05-04 01:25:37 +00:00
|
|
|
create->set_text(TTR("New Project"));
|
2014-02-10 01:10:30 +00:00
|
|
|
tree_vb->add_child(create);
|
2017-03-05 15:44:50 +00:00
|
|
|
create->connect("pressed", this, "_new_project");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Button *import = memnew(Button);
|
2016-05-04 01:25:37 +00:00
|
|
|
import->set_text(TTR("Import"));
|
2014-02-10 01:10:30 +00:00
|
|
|
tree_vb->add_child(import);
|
2017-03-05 15:44:50 +00:00
|
|
|
import->connect("pressed", this, "_import_project");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Button *erase = memnew(Button);
|
2016-05-04 01:25:37 +00:00
|
|
|
erase->set_text(TTR("Remove"));
|
2014-02-10 01:10:30 +00:00
|
|
|
tree_vb->add_child(erase);
|
2017-03-05 15:44:50 +00:00
|
|
|
erase->connect("pressed", this, "_erase_project");
|
|
|
|
erase_btn = erase;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
tree_vb->add_spacer();
|
|
|
|
|
2016-06-10 01:47:43 +00:00
|
|
|
if (StreamPeerSSL::is_available()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
asset_library = memnew(EditorAssetLibrary(true));
|
2017-04-20 12:42:35 +00:00
|
|
|
asset_library->set_name(TTR("Templates"));
|
2016-06-10 01:47:43 +00:00
|
|
|
tabs->add_child(asset_library);
|
2017-03-05 15:44:50 +00:00
|
|
|
asset_library->connect("install_asset", this, "_install_project");
|
2016-06-10 01:47:43 +00:00
|
|
|
} else {
|
|
|
|
WARN_PRINT("Asset Library not available, as it requires SSL to work.");
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
CenterContainer *cc = memnew(CenterContainer);
|
|
|
|
Button *cancel = memnew(Button);
|
2016-06-08 12:25:47 +00:00
|
|
|
cancel->set_text(TTR("Exit"));
|
2017-03-05 15:44:50 +00:00
|
|
|
cancel->set_custom_minimum_size(Size2(100, 1) * EDSCALE);
|
2016-06-08 12:25:47 +00:00
|
|
|
cc->add_child(cancel);
|
2017-03-05 15:44:50 +00:00
|
|
|
cancel->connect("pressed", this, "_exit_dialog");
|
2016-06-08 12:25:47 +00:00
|
|
|
vb->add_child(cc);
|
|
|
|
|
|
|
|
//
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
erase_ask = memnew(ConfirmationDialog);
|
2016-05-04 01:25:37 +00:00
|
|
|
erase_ask->get_ok()->set_text(TTR("Remove"));
|
2017-03-05 15:44:50 +00:00
|
|
|
erase_ask->get_ok()->connect("pressed", this, "_erase_project_confirm");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-18 05:32:03 +00:00
|
|
|
gui_base->add_child(erase_ask);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
multi_open_ask = memnew(ConfirmationDialog);
|
2016-05-04 01:25:37 +00:00
|
|
|
multi_open_ask->get_ok()->set_text(TTR("Edit"));
|
2014-05-11 01:45:52 +00:00
|
|
|
multi_open_ask->get_ok()->connect("pressed", this, "_open_project_confirm");
|
|
|
|
|
2016-06-18 05:32:03 +00:00
|
|
|
gui_base->add_child(multi_open_ask);
|
2014-05-11 01:45:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
multi_run_ask = memnew(ConfirmationDialog);
|
2016-05-04 01:25:37 +00:00
|
|
|
multi_run_ask->get_ok()->set_text(TTR("Run"));
|
2014-05-11 01:45:52 +00:00
|
|
|
multi_run_ask->get_ok()->connect("pressed", this, "_run_project_confirm");
|
2016-08-05 14:06:16 +00:00
|
|
|
|
2016-06-18 05:32:03 +00:00
|
|
|
gui_base->add_child(multi_run_ask);
|
2016-08-05 14:06:16 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
multi_scan_ask = memnew(ConfirmationDialog);
|
2016-07-31 22:59:31 +00:00
|
|
|
multi_scan_ask->get_ok()->set_text(TTR("Scan"));
|
|
|
|
|
|
|
|
gui_base->add_child(multi_scan_ask);
|
2014-05-11 01:45:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
OS::get_singleton()->set_low_processor_usage_mode(true);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
npdialog = memnew(NewProjectDialog);
|
2016-06-18 05:32:03 +00:00
|
|
|
gui_base->add_child(npdialog);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
npdialog->connect("project_created", this, "_on_project_created");
|
2014-02-10 01:10:30 +00:00
|
|
|
_load_recent_projects();
|
2014-11-01 06:06:29 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (EditorSettings::get_singleton()->get("filesystem/directories/autoscan_project_path")) {
|
|
|
|
_scan_begin(EditorSettings::get_singleton()->get("filesystem/directories/autoscan_project_path"));
|
2014-11-01 06:06:29 +00:00
|
|
|
}
|
|
|
|
|
2016-05-20 23:18:35 +00:00
|
|
|
//get_ok()->set_text("Open");
|
|
|
|
//get_ok()->set_text("Exit");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2014-05-01 13:47:45 +00:00
|
|
|
last_clicked = "";
|
2016-07-29 15:06:37 +00:00
|
|
|
|
|
|
|
SceneTree::get_singleton()->connect("files_dropped", this, "_files_dropped");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ProjectManager::~ProjectManager() {
|
|
|
|
|
|
|
|
if (EditorSettings::get_singleton())
|
|
|
|
EditorSettings::destroy();
|
|
|
|
}
|
2014-06-11 09:57:13 +00:00
|
|
|
|
|
|
|
void ProjectListFilter::_setup_filters() {
|
|
|
|
|
|
|
|
filter_option->clear();
|
2016-05-04 01:25:37 +00:00
|
|
|
filter_option->add_item(TTR("Name"));
|
2016-05-29 08:10:23 +00:00
|
|
|
filter_option->add_item(TTR("Path"));
|
2014-06-11 09:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectListFilter::_command(int p_command) {
|
|
|
|
switch (p_command) {
|
|
|
|
|
|
|
|
case CMD_CLEAR_FILTER: {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (search_box->get_text() != "") {
|
2014-06-11 09:57:13 +00:00
|
|
|
search_box->clear();
|
|
|
|
emit_signal("filter_changed");
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
} break;
|
2014-06-11 09:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectListFilter::_search_text_changed(const String &p_newtext) {
|
|
|
|
emit_signal("filter_changed");
|
|
|
|
}
|
|
|
|
|
|
|
|
String ProjectListFilter::get_search_term() {
|
|
|
|
return search_box->get_text().strip_edges();
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectListFilter::FilterOption ProjectListFilter::get_filter_option() {
|
|
|
|
return _current_filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectListFilter::_filter_option_selected(int p_idx) {
|
|
|
|
FilterOption selected = (FilterOption)(filter_option->get_selected());
|
2017-03-05 15:44:50 +00:00
|
|
|
if (_current_filter != selected) {
|
2014-06-11 09:57:13 +00:00
|
|
|
_current_filter = selected;
|
|
|
|
emit_signal("filter_changed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-17 05:38:27 +00:00
|
|
|
void ProjectListFilter::_notification(int p_what) {
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_what) {
|
2014-11-06 00:20:42 +00:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2017-03-05 15:44:50 +00:00
|
|
|
clear_search_button->set_icon(get_icon("CloseHover", "EditorIcons"));
|
2014-06-17 05:38:27 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-11 09:57:13 +00:00
|
|
|
void ProjectListFilter::_bind_methods() {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("_command"), &ProjectListFilter::_command);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("_search_text_changed"), &ProjectListFilter::_search_text_changed);
|
|
|
|
ClassDB::bind_method(D_METHOD("_filter_option_selected"), &ProjectListFilter::_filter_option_selected);
|
2014-06-11 09:57:13 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("filter_changed"));
|
2014-06-11 09:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ProjectListFilter::ProjectListFilter() {
|
|
|
|
|
2016-07-06 18:50:02 +00:00
|
|
|
editor_initialize_certificates(); //for asset sharing
|
|
|
|
|
2014-06-11 09:57:13 +00:00
|
|
|
_current_filter = FILTER_NAME;
|
|
|
|
|
|
|
|
filter_option = memnew(OptionButton);
|
2017-03-05 15:44:50 +00:00
|
|
|
filter_option->set_custom_minimum_size(Size2(80, 10));
|
2014-06-11 09:57:13 +00:00
|
|
|
filter_option->set_clip_text(true);
|
|
|
|
filter_option->connect("item_selected", this, "_filter_option_selected");
|
|
|
|
add_child(filter_option);
|
|
|
|
|
|
|
|
_setup_filters();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
search_box = memnew(LineEdit);
|
|
|
|
search_box->connect("text_changed", this, "_search_text_changed");
|
2014-06-11 09:57:13 +00:00
|
|
|
search_box->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
add_child(search_box);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
clear_search_button = memnew(ToolButton);
|
|
|
|
clear_search_button->connect("pressed", this, "_command", make_binds(CMD_CLEAR_FILTER));
|
2014-06-11 09:57:13 +00:00
|
|
|
add_child(clear_search_button);
|
|
|
|
}
|