You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-11 13:10:58 +00:00
-Fixed EditorDirDialog, which was really old and needed to use EditorFileSystem
-Fixed refactoring tools to work with imported scenes (properly move .import files)
This commit is contained in:
@@ -1117,6 +1117,9 @@ Error ResourceFormatLoaderBinary::rename_dependencies(const String &p_path, cons
|
|||||||
memdelete(f);
|
memdelete(f);
|
||||||
}
|
}
|
||||||
ERR_FAIL_COND_V(!fw, ERR_CANT_CREATE);
|
ERR_FAIL_COND_V(!fw, ERR_CANT_CREATE);
|
||||||
|
|
||||||
|
uint8_t magic[4] = { 'R', 'S', 'R', 'C' };
|
||||||
|
fw->store_buffer(magic, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool big_endian = f->get_32();
|
bool big_endian = f->get_32();
|
||||||
|
|||||||
@@ -31,50 +31,40 @@
|
|||||||
|
|
||||||
#include "editor/editor_file_system.h"
|
#include "editor/editor_file_system.h"
|
||||||
#include "editor/editor_settings.h"
|
#include "editor/editor_settings.h"
|
||||||
|
#include "editor_scale.h"
|
||||||
#include "os/keyboard.h"
|
#include "os/keyboard.h"
|
||||||
#include "os/os.h"
|
#include "os/os.h"
|
||||||
|
void EditorDirDialog::_update_dir(TreeItem *p_item, EditorFileSystemDirectory *p_dir, const String &p_select_path) {
|
||||||
void EditorDirDialog::_update_dir(TreeItem *p_item) {
|
|
||||||
|
|
||||||
updating = true;
|
updating = true;
|
||||||
p_item->clear_children();
|
|
||||||
DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
|
||||||
String cdir = p_item->get_metadata(0);
|
|
||||||
|
|
||||||
da->change_dir(cdir);
|
String path = p_dir->get_path();
|
||||||
da->list_dir_begin();
|
|
||||||
String p = da->get_next();
|
|
||||||
|
|
||||||
List<String> dirs;
|
p_item->set_metadata(0, p_dir->get_path());
|
||||||
bool ishidden;
|
p_item->set_icon(0, get_icon("Folder", "EditorIcons"));
|
||||||
bool show_hidden = EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files");
|
|
||||||
|
|
||||||
while (p != "") {
|
if (!p_item->get_parent()) {
|
||||||
|
p_item->set_text(0, "res://");
|
||||||
|
} else {
|
||||||
|
|
||||||
ishidden = da->current_is_hidden();
|
if (!opened_paths.has(path) && (p_select_path == String() || !p_select_path.begins_with(path))) {
|
||||||
|
p_item->set_collapsed(true);
|
||||||
if (show_hidden || !ishidden) {
|
|
||||||
if (da->current_is_dir() && !p.begins_with(".")) {
|
|
||||||
dirs.push_back(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
p = da->get_next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dirs.sort();
|
p_item->set_text(0, p_dir->get_name());
|
||||||
|
|
||||||
for (List<String>::Element *E = dirs.front(); E; E = E->next()) {
|
|
||||||
TreeItem *ti = tree->create_item(p_item);
|
|
||||||
ti->set_text(0, E->get());
|
|
||||||
ti->set_icon(0, get_icon("Folder", "EditorIcons"));
|
|
||||||
ti->set_collapsed(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memdelete(da);
|
//this should be handled by EditorFileSystem already
|
||||||
|
//bool show_hidden = EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files");
|
||||||
updating = false;
|
updating = false;
|
||||||
|
for (int i = 0; i < p_dir->get_subdir_count(); i++) {
|
||||||
|
|
||||||
|
TreeItem *ti = tree->create_item(p_item);
|
||||||
|
_update_dir(ti, p_dir->get_subdir(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorDirDialog::reload() {
|
void EditorDirDialog::reload(const String &p_with_path) {
|
||||||
|
|
||||||
if (!is_visible_in_tree()) {
|
if (!is_visible_in_tree()) {
|
||||||
must_reload = true;
|
must_reload = true;
|
||||||
@@ -83,10 +73,7 @@ void EditorDirDialog::reload() {
|
|||||||
|
|
||||||
tree->clear();
|
tree->clear();
|
||||||
TreeItem *root = tree->create_item();
|
TreeItem *root = tree->create_item();
|
||||||
root->set_metadata(0, "res://");
|
_update_dir(root, EditorFileSystem::get_singleton()->get_filesystem(), p_with_path);
|
||||||
root->set_icon(0, get_icon("Folder", "EditorIcons"));
|
|
||||||
root->set_text(0, "/");
|
|
||||||
_update_dir(root);
|
|
||||||
_item_collapsed(root);
|
_item_collapsed(root);
|
||||||
must_reload = false;
|
must_reload = false;
|
||||||
}
|
}
|
||||||
@@ -94,6 +81,7 @@ void EditorDirDialog::reload() {
|
|||||||
void EditorDirDialog::_notification(int p_what) {
|
void EditorDirDialog::_notification(int p_what) {
|
||||||
|
|
||||||
if (p_what == NOTIFICATION_ENTER_TREE) {
|
if (p_what == NOTIFICATION_ENTER_TREE) {
|
||||||
|
EditorFileSystem::get_singleton()->connect("filesystem_changed", this, "reload");
|
||||||
reload();
|
reload();
|
||||||
|
|
||||||
if (!tree->is_connected("item_collapsed", this, "_item_collapsed")) {
|
if (!tree->is_connected("item_collapsed", this, "_item_collapsed")) {
|
||||||
@@ -105,6 +93,10 @@ void EditorDirDialog::_notification(int p_what) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (p_what == NOTIFICATION_EXIT_TREE) {
|
||||||
|
EditorFileSystem::get_singleton()->disconnect("filesystem_changed", this, "reload");
|
||||||
|
}
|
||||||
|
|
||||||
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
|
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
|
||||||
if (must_reload && is_visible_in_tree()) {
|
if (must_reload && is_visible_in_tree()) {
|
||||||
reload();
|
reload();
|
||||||
@@ -116,57 +108,13 @@ void EditorDirDialog::_item_collapsed(Object *p_item) {
|
|||||||
|
|
||||||
TreeItem *item = Object::cast_to<TreeItem>(p_item);
|
TreeItem *item = Object::cast_to<TreeItem>(p_item);
|
||||||
|
|
||||||
if (updating || item->is_collapsed())
|
if (updating)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TreeItem *ci = item->get_children();
|
if (item->is_collapsed())
|
||||||
while (ci) {
|
opened_paths.erase(item->get_metadata(0));
|
||||||
|
else
|
||||||
String p = ci->get_metadata(0);
|
opened_paths.insert(item->get_metadata(0));
|
||||||
if (p == "") {
|
|
||||||
String pp = item->get_metadata(0);
|
|
||||||
ci->set_metadata(0, pp.plus_file(ci->get_text(0)));
|
|
||||||
_update_dir(ci);
|
|
||||||
}
|
|
||||||
ci = ci->get_next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void EditorDirDialog::set_current_path(const String &p_path) {
|
|
||||||
|
|
||||||
reload();
|
|
||||||
String p = p_path;
|
|
||||||
if (p.begins_with("res://"))
|
|
||||||
p = p.replace_first("res://", "");
|
|
||||||
|
|
||||||
Vector<String> dirs = p.split("/", false);
|
|
||||||
|
|
||||||
TreeItem *r = tree->get_root();
|
|
||||||
for (int i = 0; i < dirs.size(); i++) {
|
|
||||||
|
|
||||||
String d = dirs[i];
|
|
||||||
TreeItem *p = r->get_children();
|
|
||||||
while (p) {
|
|
||||||
|
|
||||||
if (p->get_text(0) == d)
|
|
||||||
break;
|
|
||||||
p = p->get_next();
|
|
||||||
}
|
|
||||||
|
|
||||||
ERR_FAIL_COND(!p);
|
|
||||||
String pp = p->get_metadata(0);
|
|
||||||
if (pp == "") {
|
|
||||||
p->set_metadata(0, String(r->get_metadata(0)).plus_file(d));
|
|
||||||
_update_dir(p);
|
|
||||||
}
|
|
||||||
updating = true;
|
|
||||||
p->set_collapsed(false);
|
|
||||||
updating = false;
|
|
||||||
_item_collapsed(p);
|
|
||||||
r = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
r->select(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorDirDialog::ok_pressed() {
|
void EditorDirDialog::ok_pressed() {
|
||||||
@@ -201,14 +149,16 @@ void EditorDirDialog::_make_dir_confirm() {
|
|||||||
|
|
||||||
String dir = ti->get_metadata(0);
|
String dir = ti->get_metadata(0);
|
||||||
|
|
||||||
DirAccess *d = DirAccess::open(dir);
|
DirAccessRef d = DirAccess::open(dir);
|
||||||
ERR_FAIL_COND(!d);
|
ERR_FAIL_COND(!d);
|
||||||
Error err = d->make_dir(makedirname->get_text());
|
Error err = d->make_dir(makedirname->get_text());
|
||||||
|
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
mkdirerr->popup_centered_minsize(Size2(250, 80));
|
mkdirerr->popup_centered_minsize(Size2(250, 80) * EDSCALE);
|
||||||
} else {
|
} else {
|
||||||
set_current_path(dir.plus_file(makedirname->get_text()));
|
opened_paths.insert(dir);
|
||||||
|
//reload(dir.plus_file(makedirname->get_text()));
|
||||||
|
EditorFileSystem::get_singleton()->scan_changes(); //we created a dir, so rescan changes
|
||||||
}
|
}
|
||||||
makedirname->set_text(""); // reset label
|
makedirname->set_text(""); // reset label
|
||||||
}
|
}
|
||||||
@@ -218,7 +168,7 @@ void EditorDirDialog::_bind_methods() {
|
|||||||
ClassDB::bind_method(D_METHOD("_item_collapsed"), &EditorDirDialog::_item_collapsed);
|
ClassDB::bind_method(D_METHOD("_item_collapsed"), &EditorDirDialog::_item_collapsed);
|
||||||
ClassDB::bind_method(D_METHOD("_make_dir"), &EditorDirDialog::_make_dir);
|
ClassDB::bind_method(D_METHOD("_make_dir"), &EditorDirDialog::_make_dir);
|
||||||
ClassDB::bind_method(D_METHOD("_make_dir_confirm"), &EditorDirDialog::_make_dir_confirm);
|
ClassDB::bind_method(D_METHOD("_make_dir_confirm"), &EditorDirDialog::_make_dir_confirm);
|
||||||
ClassDB::bind_method(D_METHOD("reload"), &EditorDirDialog::reload);
|
ClassDB::bind_method(D_METHOD("reload"), &EditorDirDialog::reload, DEFVAL(""));
|
||||||
|
|
||||||
ADD_SIGNAL(MethodInfo("dir_selected", PropertyInfo(Variant::STRING, "dir")));
|
ADD_SIGNAL(MethodInfo("dir_selected", PropertyInfo(Variant::STRING, "dir")));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#ifndef EDITOR_DIR_DIALOG_H
|
#ifndef EDITOR_DIR_DIALOG_H
|
||||||
#define EDITOR_DIR_DIALOG_H
|
#define EDITOR_DIR_DIALOG_H
|
||||||
|
|
||||||
|
#include "editor/editor_file_system.h"
|
||||||
#include "os/dir_access.h"
|
#include "os/dir_access.h"
|
||||||
#include "scene/gui/dialogs.h"
|
#include "scene/gui/dialogs.h"
|
||||||
#include "scene/gui/tree.h"
|
#include "scene/gui/tree.h"
|
||||||
@@ -42,12 +43,13 @@ class EditorDirDialog : public ConfirmationDialog {
|
|||||||
AcceptDialog *mkdirerr;
|
AcceptDialog *mkdirerr;
|
||||||
|
|
||||||
Button *makedir;
|
Button *makedir;
|
||||||
|
Set<String> opened_paths;
|
||||||
|
|
||||||
Tree *tree;
|
Tree *tree;
|
||||||
bool updating;
|
bool updating;
|
||||||
|
|
||||||
void _item_collapsed(Object *p_item);
|
void _item_collapsed(Object *p_item);
|
||||||
void _update_dir(TreeItem *p_item);
|
void _update_dir(TreeItem *p_item, EditorFileSystemDirectory *p_dir, const String &p_select_path = String());
|
||||||
|
|
||||||
void _make_dir();
|
void _make_dir();
|
||||||
void _make_dir_confirm();
|
void _make_dir_confirm();
|
||||||
@@ -61,8 +63,7 @@ protected:
|
|||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void set_current_path(const String &p_path);
|
void reload(const String &p_path = "");
|
||||||
void reload();
|
|
||||||
EditorDirDialog();
|
EditorDirDialog();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -828,7 +828,12 @@ void FileSystemDock::_move_operation(const String &p_to_path) {
|
|||||||
//make list of remaps
|
//make list of remaps
|
||||||
Map<String, String> renames;
|
Map<String, String> renames;
|
||||||
String repfrom = path == "res://" ? path : String(path + "/");
|
String repfrom = path == "res://" ? path : String(path + "/");
|
||||||
String repto = p_to_path == "res://" ? p_to_path : String(p_to_path + "/");
|
String repto = p_to_path;
|
||||||
|
if (!repto.ends_with("/")) {
|
||||||
|
repto += "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
print_line("reprfrom: " + repfrom + " repto " + repto);
|
||||||
|
|
||||||
for (int i = 0; i < move_files.size(); i++) {
|
for (int i = 0; i < move_files.size(); i++) {
|
||||||
renames[move_files[i]] = move_files[i].replace_first(repfrom, repto);
|
renames[move_files[i]] = move_files[i].replace_first(repfrom, repto);
|
||||||
@@ -868,6 +873,13 @@ void FileSystemDock::_move_operation(const String &p_to_path) {
|
|||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
EditorNode::get_singleton()->add_io_error(TTR("Error moving file:\n") + move_files[i] + "\n");
|
EditorNode::get_singleton()->add_io_error(TTR("Error moving file:\n") + move_files[i] + "\n");
|
||||||
}
|
}
|
||||||
|
if (FileAccess::exists(move_files[i] + ".import")) { //move imported files too
|
||||||
|
//@todo should remove the files in .import folder
|
||||||
|
err = da->rename(move_files[i] + ".import", to + ".import");
|
||||||
|
if (err != OK) {
|
||||||
|
EditorNode::get_singleton()->add_io_error(TTR("Error moving file:\n") + move_files[i] + ".import\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < move_dirs.size(); i++) {
|
for (int i = 0; i < move_dirs.size(); i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user