1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-20 14:45:44 +00:00

Enhanced 'open' in filesystemdock and fixed some non clang-format code

This commit is contained in:
sersoong
2017-11-25 13:54:53 +08:00
parent 517f520f64
commit 97c80f84ca
2 changed files with 101 additions and 108 deletions

View File

@@ -259,8 +259,7 @@ void FileSystemDock::_make_dir_confirm() {
if (dir_name.length() == 0) { if (dir_name.length() == 0) {
EditorNode::get_singleton()->show_warning(TTR("No name provided")); EditorNode::get_singleton()->show_warning(TTR("No name provided"));
return; return;
} } else if (dir_name.find("/") != -1 || dir_name.find("\\") != -1 || dir_name.find(":") != -1) {
else if (dir_name.find("/") != -1 || dir_name.find("\\") != -1 || dir_name.find(":") != -1) {
EditorNode::get_singleton()->show_warning(TTR("Provided name contains invalid characters")); EditorNode::get_singleton()->show_warning(TTR("Provided name contains invalid characters"));
return; return;
} }
@@ -276,8 +275,7 @@ void FileSystemDock::_make_dir_confirm() {
if (err == OK) { if (err == OK) {
print_line("call rescan!"); print_line("call rescan!");
_rescan(); _rescan();
} } else {
else {
EditorNode::get_singleton()->show_warning(TTR("Could not create folder.")); EditorNode::get_singleton()->show_warning(TTR("Could not create folder."));
} }
} }
@@ -288,8 +286,7 @@ void FileSystemDock::_rename_operation_confirm() {
if (new_name.length() == 0) { if (new_name.length() == 0) {
EditorNode::get_singleton()->show_warning(TTR("No name provided.")); EditorNode::get_singleton()->show_warning(TTR("No name provided."));
return; return;
} } else if (new_name.find("/") != -1 || new_name.find("\\") != -1 || new_name.find(":") != -1) {
else if (new_name.find("/") != -1 || new_name.find("\\") != -1 || new_name.find(":") != -1) {
EditorNode::get_singleton()->show_warning(TTR("Name contains invalid characters.")); EditorNode::get_singleton()->show_warning(TTR("Name contains invalid characters."));
return; return;
} }
@@ -339,12 +336,10 @@ void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_
if (new_path == old_path) { if (new_path == old_path) {
return; return;
} } else if (old_path == "res://") {
else if (old_path == "res://") {
EditorNode::get_singleton()->add_io_error(TTR("Cannot move/rename resources root.")); EditorNode::get_singleton()->add_io_error(TTR("Cannot move/rename resources root."));
return; return;
} } else if (!p_item.is_file && new_path.begins_with(old_path)) {
else if (!p_item.is_file && new_path.begins_with(old_path)) {
//This check doesn't erroneously catch renaming to a longer name as folder paths always end with "/" //This check doesn't erroneously catch renaming to a longer name as folder paths always end with "/"
EditorNode::get_singleton()->add_io_error(TTR("Cannot move a folder into itself.\n") + old_path + "\n"); EditorNode::get_singleton()->add_io_error(TTR("Cannot move a folder into itself.\n") + old_path + "\n");
return; return;
@@ -354,8 +349,7 @@ void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_
Vector<String> changed_paths; Vector<String> changed_paths;
if (p_item.is_file) { if (p_item.is_file) {
changed_paths.push_back(old_path); changed_paths.push_back(old_path);
} } else {
else {
_get_all_files_in_dir(EditorFileSystem::get_singleton()->get_path(old_path), changed_paths); _get_all_files_in_dir(EditorFileSystem::get_singleton()->get_path(old_path), changed_paths);
} }
@@ -368,8 +362,7 @@ void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_
p_renames[changed_paths[i]] = changed_paths[i].replace_first(old_path, new_path); p_renames[changed_paths[i]] = changed_paths[i].replace_first(old_path, new_path);
print_line(" Remap: " + changed_paths[i] + " -> " + p_renames[changed_paths[i]]); print_line(" Remap: " + changed_paths[i] + " -> " + p_renames[changed_paths[i]]);
} }
} } else {
else {
EditorNode::get_singleton()->add_io_error(TTR("Error moving:\n") + old_path + "\n"); EditorNode::get_singleton()->add_io_error(TTR("Error moving:\n") + old_path + "\n");
} }
memdelete(da); memdelete(da);
@@ -1041,40 +1034,40 @@ void FileSystemDock::_file_option(int p_option) {
case FILE_SHOW_IN_EXPLORER: case FILE_SHOW_IN_EXPLORER:
case FILE_OPEN: { case FILE_OPEN: {
int idx = -1; int idx = -1;
int selectcount = files->get_selected_items().size();
for (int i = 0; i < files->get_item_count(); i++) { for (int i = 0; i < files->get_item_count(); i++) {
if (files->is_selected(i)) { if (files->is_selected(i)) {
idx = i; String path = files->get_item_metadata(i);
break; if (selectcount == 1) {
} if (p_option == FILE_SHOW_IN_EXPLORER) {
} String dir = Globals::get_singleton()->globalize_path(path);
dir = dir.substr(0, dir.find_last("/"));
OS::get_singleton()->shell_open(String("file://") + dir);
return;
}
if (path.ends_with("/")) {
if (path != "res://") {
path = path.substr(0, path.length() - 1);
}
this->path = path;
_update_files(false);
current_path->set_text(path);
_push_to_history();
} else {
if (idx < 0) if (ResourceLoader::get_resource_type(path) == "PackedScene") {
return;
String path = files->get_item_metadata(idx); editor->open_request(path);
if (p_option == FILE_SHOW_IN_EXPLORER) { } else {
String dir = Globals::get_singleton()->globalize_path(path);
dir = dir.substr(0, dir.find_last("/"));
OS::get_singleton()->shell_open(String("file://") + dir);
return;
}
if (path.ends_with("/")) { editor->load_resource(path);
if (path != "res://") { }
path = path.substr(0, path.length() - 1); }
} } else if (selectcount > 1) {
this->path = path; if (ResourceLoader::get_resource_type(path) == "PackedScene") {
_update_files(false); editor->open_request(path);
current_path->set_text(path); }
_push_to_history(); }
} else {
if (ResourceLoader::get_resource_type(path) == "PackedScene") {
editor->open_request(path);
} else {
editor->load_resource(path);
} }
} }
} break; } break;
@@ -1221,69 +1214,69 @@ void FileSystemDock::_folder_option(int p_option) {
TreeItem *selected = tree->get_selected(); TreeItem *selected = tree->get_selected();
switch (p_option) { switch (p_option) {
case FOLDER_EXPAND_ALL: case FOLDER_EXPAND_ALL:
case FOLDER_COLLAPSE_ALL: { case FOLDER_COLLAPSE_ALL: {
bool is_collapsed = (p_option == FOLDER_COLLAPSE_ALL); bool is_collapsed = (p_option == FOLDER_COLLAPSE_ALL);
Vector<TreeItem *> needs_check; Vector<TreeItem *> needs_check;
needs_check.push_back(selected); needs_check.push_back(selected);
while (needs_check.size()) { while (needs_check.size()) {
needs_check[0]->set_collapsed(is_collapsed); needs_check[0]->set_collapsed(is_collapsed);
TreeItem *child = needs_check[0]->get_children(); TreeItem *child = needs_check[0]->get_children();
while (child) { while (child) {
needs_check.push_back(child); needs_check.push_back(child);
child = child->get_next(); child = child->get_next();
}
needs_check.remove(0);
} }
} break;
needs_check.remove(0); case FOLDER_MOVE: {
} to_move.clear();
} break; String fpath = selected->get_metadata(tree->get_selected_column());
case FOLDER_MOVE: { if (fpath != "res://") {
to_move.clear(); fpath = fpath.ends_with("/") ? fpath.substr(0, fpath.length() - 1) : fpath;
String fpath = selected->get_metadata(tree->get_selected_column()); to_move.push_back(FileOrFolder(fpath, false));
if (fpath != "res://") { move_dir_dialog->popup_centered_ratio();
fpath = fpath.ends_with("/") ? fpath.substr(0, fpath.length() - 1) : fpath; }
to_move.push_back(FileOrFolder(fpath, false)); } break;
move_dir_dialog->popup_centered_ratio(); case FOLDER_RENAME: {
} to_rename.path = selected->get_metadata(tree->get_selected_column());
} break; to_rename.is_file = false;
case FOLDER_RENAME: { if (to_rename.path != "res://") {
to_rename.path = selected->get_metadata(tree->get_selected_column()); String name = to_rename.path.ends_with("/") ? to_rename.path.substr(0, to_rename.path.length() - 1).get_file() : to_rename.path.get_file();
to_rename.is_file = false; rename_dir_dialog->set_title(TTR("Renaming folder:") + " " + name);
if (to_rename.path != "res://") { rename_dialog_text->set_text(name);
String name = to_rename.path.ends_with("/") ? to_rename.path.substr(0, to_rename.path.length() - 1).get_file() : to_rename.path.get_file(); rename_dialog_text->select(0, name.length());
rename_dir_dialog->set_title(TTR("Renaming folder:") + " " + name); rename_dir_dialog->popup_centered_minsize(Size2(250, 80) * EDSCALE);
rename_dialog_text->set_text(name); rename_dialog_text->grab_focus();
rename_dialog_text->select(0, name.length()); }
rename_dir_dialog->popup_centered_minsize(Size2(250, 80) * EDSCALE); } break;
rename_dialog_text->grab_focus(); case FOLDER_REMOVE: {
} Vector<String> remove_folders;
} break; Vector<String> remove_files;
case FOLDER_REMOVE: { String fpath = selected->get_metadata(tree->get_selected_column());
Vector<String> remove_folders; if (fpath != "res://") {
Vector<String> remove_files; remove_folders.push_back(fpath);
String fpath = selected->get_metadata(tree->get_selected_column()); remove_dialog->show(remove_folders);
if (fpath != "res://") { }
remove_folders.push_back(fpath); } break;
remove_dialog->show(remove_folders); case FOLDER_NEW_FOLDER: {
} make_dir_dialog_text->set_text("new folder");
} break; make_dir_dialog_text->select_all();
case FOLDER_NEW_FOLDER: { make_dir_dialog->popup_centered_minsize(Size2(250, 80) * EDSCALE);
make_dir_dialog_text->set_text("new folder"); make_dir_dialog_text->grab_focus();
make_dir_dialog_text->select_all(); } break;
make_dir_dialog->popup_centered_minsize(Size2(250, 80) * EDSCALE); case FOLDER_COPY_PATH: {
make_dir_dialog_text->grab_focus(); String fpath = selected->get_metadata(tree->get_selected_column());
} break; OS::get_singleton()->set_clipboard(fpath);
case FOLDER_COPY_PATH: { } break;
String fpath = selected->get_metadata(tree->get_selected_column()); case FOLDER_SHOW_IN_EXPLORER: {
OS::get_singleton()->set_clipboard(fpath); String fpath = selected->get_metadata(tree->get_selected_column());
} break; String dir = Globals::get_singleton()->globalize_path(fpath);
case FOLDER_SHOW_IN_EXPLORER: { OS::get_singleton()->shell_open(String("file://") + dir);
String fpath = selected->get_metadata(tree->get_selected_column()); } break;
String dir = Globals::get_singleton()->globalize_path(fpath);
OS::get_singleton()->shell_open(String("file://") + dir);
} break;
} }
} }
@@ -1885,7 +1878,7 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) {
make_dir_dialog_text = memnew(LineEdit); make_dir_dialog_text = memnew(LineEdit);
make_folder_dialog_vb->add_margin_child(TTR("Name:"), make_dir_dialog_text); make_folder_dialog_vb->add_margin_child(TTR("Name:"), make_dir_dialog_text);
add_child(make_dir_dialog); add_child(make_dir_dialog);
make_dir_dialog->add_child(make_folder_dialog_vb); make_dir_dialog->add_child(make_folder_dialog_vb);
make_dir_dialog->set_child_rect(make_folder_dialog_vb); make_dir_dialog->set_child_rect(make_folder_dialog_vb);
make_dir_dialog->register_text_enter(make_dir_dialog_text); make_dir_dialog->register_text_enter(make_dir_dialog_text);

View File

@@ -173,12 +173,12 @@ private:
void _push_to_history(); void _push_to_history();
void _dir_selected(); void _dir_selected();
void _dir_rmb_pressed(const Vector2 & p_pos); void _dir_rmb_pressed(const Vector2 &p_pos);
void _make_dir_confirm(); void _make_dir_confirm();
void _rename_operation_confirm(); void _rename_operation_confirm();
void _move_operation_confirm(const String & p_to_path); void _move_operation_confirm(const String &p_to_path);
void _try_move_item(const FileOrFolder & p_item, const String & p_new_path, Map<String, String>& p_renames); void _try_move_item(const FileOrFolder &p_item, const String &p_new_path, Map<String, String> &p_renames);
void _get_all_files_in_dir(EditorFileSystemDirectory * efsd, Vector<String>& files); void _get_all_files_in_dir(EditorFileSystemDirectory *efsd, Vector<String> &files);
void _update_dependencies_after_move(Map<String, String> &p_renames); void _update_dependencies_after_move(Map<String, String> &p_renames);
void _update_tree(); void _update_tree();
void _rescan(); void _rescan();