2016-06-18 14:46:12 +02:00
|
|
|
/**************************************************************************/
|
|
|
|
|
/* editor_file_dialog.cpp */
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
/* This file is part of: */
|
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
|
/* https://godotengine.org */
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
|
/* */
|
|
|
|
|
/* 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. */
|
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2015-05-31 01:59:42 -03:00
|
|
|
#include "editor_file_dialog.h"
|
2019-07-25 11:09:57 +02:00
|
|
|
|
2025-06-10 16:47:26 +02:00
|
|
|
#include "editor/docks/filesystem_dock.h"
|
|
|
|
|
#include "editor/file_system/dependency_editor.h"
|
|
|
|
|
#include "editor/settings/editor_settings.h"
|
2015-05-31 01:59:42 -03:00
|
|
|
|
2025-12-02 12:30:51 +01:00
|
|
|
void EditorFileDialog::_item_menu_id_pressed(int p_option) {
|
|
|
|
|
// Use dependency dialog to delete the entry in the editor, but only for project files.
|
|
|
|
|
if (p_option == ITEM_MENU_DELETE && get_access() == ACCESS_RESOURCES) {
|
|
|
|
|
const PackedInt32Array selected = get_file_item_list()->get_selected_items();
|
|
|
|
|
if (selected.is_empty()) {
|
|
|
|
|
return;
|
2024-03-21 10:42:38 +02:00
|
|
|
}
|
|
|
|
|
|
2025-12-02 12:30:51 +01:00
|
|
|
if (!dependency_remove_dialog) {
|
|
|
|
|
dependency_remove_dialog = memnew(DependencyRemoveDialog);
|
|
|
|
|
add_child(dependency_remove_dialog);
|
2024-03-21 10:42:38 +02:00
|
|
|
}
|
2024-11-24 23:49:46 +02:00
|
|
|
|
2025-12-02 12:30:51 +01:00
|
|
|
const Dictionary meta = get_file_item_list()->get_item_metadata(selected[0]);
|
|
|
|
|
const String delete_path = dir_access->get_current_dir().path_join(meta["name"]);
|
2025-02-13 09:26:07 +02:00
|
|
|
|
2025-12-02 12:30:51 +01:00
|
|
|
if (meta["dir"]) {
|
|
|
|
|
dependency_remove_dialog->show(Vector<String>{ delete_path }, Vector<String>());
|
|
|
|
|
} else {
|
|
|
|
|
dependency_remove_dialog->show(Vector<String>(), Vector<String>{ delete_path });
|
2024-03-21 10:42:38 +02:00
|
|
|
}
|
2025-12-02 12:30:51 +01:00
|
|
|
return;
|
2024-03-21 10:42:38 +02:00
|
|
|
}
|
2025-12-02 12:30:51 +01:00
|
|
|
FileDialog::_item_menu_id_pressed(p_option);
|
2024-03-21 10:42:38 +02:00
|
|
|
}
|
|
|
|
|
|
2025-12-02 12:30:51 +01:00
|
|
|
bool EditorFileDialog::_should_use_native_popup() const {
|
|
|
|
|
return _can_use_native_popup() && (OS::get_singleton()->is_sandboxed() || EDITOR_GET("interface/editor/use_native_file_dialogs").operator bool());
|
2022-01-03 17:08:03 +08:00
|
|
|
}
|
|
|
|
|
|
2025-12-02 12:30:51 +01:00
|
|
|
bool EditorFileDialog::_should_hide_file(const String &p_file) const {
|
|
|
|
|
if (Engine::get_singleton()->is_project_manager_hint()) {
|
|
|
|
|
return false;
|
2022-01-03 17:08:03 +08:00
|
|
|
}
|
2025-12-02 12:30:51 +01:00
|
|
|
const String full_path = dir_access->get_current_dir().path_join(p_file);
|
|
|
|
|
return EditorFileSystem::_should_skip_directory(full_path);
|
2020-07-11 18:45:19 +02:00
|
|
|
}
|
|
|
|
|
|
2025-12-02 12:30:51 +01:00
|
|
|
Color EditorFileDialog::_get_folder_color(const String &p_path) const {
|
|
|
|
|
return FileSystemDock::get_dir_icon_color(p_path, FileDialog::_get_folder_color(p_path));
|
2015-05-31 01:59:42 -03:00
|
|
|
}
|
|
|
|
|
|
2025-12-02 12:30:51 +01:00
|
|
|
void EditorFileDialog::_bind_methods() {
|
|
|
|
|
#ifndef DISABLE_DEPRECATED
|
|
|
|
|
ClassDB::bind_method(D_METHOD("add_side_menu", "menu", "title"), &EditorFileDialog::add_side_menu, DEFVAL(""));
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_disable_overwrite_warning", "disable"), &EditorFileDialog::set_disable_overwrite_warning);
|
|
|
|
|
ClassDB::bind_method(D_METHOD("is_overwrite_warning_disabled"), &EditorFileDialog::is_overwrite_warning_disabled);
|
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disable_overwrite_warning", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_disable_overwrite_warning", "is_overwrite_warning_disabled");
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2023-08-13 02:33:39 +02:00
|
|
|
|
2025-12-02 12:30:51 +01:00
|
|
|
void EditorFileDialog::_validate_property(PropertyInfo &p_property) const {
|
|
|
|
|
// Hide properties controlled by editor settings.
|
|
|
|
|
if (p_property.name == "use_native_dialog" || p_property.name == "show_hidden_files" || p_property.name == "display_mode") {
|
|
|
|
|
p_property.usage = PROPERTY_USAGE_NONE;
|
|
|
|
|
}
|
2022-09-01 18:52:49 +03:00
|
|
|
}
|
|
|
|
|
|
2015-05-31 01:59:42 -03:00
|
|
|
void EditorFileDialog::_notification(int p_what) {
|
2022-02-16 00:52:32 +01:00
|
|
|
switch (p_what) {
|
2025-12-02 12:30:51 +01:00
|
|
|
case NOTIFICATION_VISIBILITY_CHANGED: {
|
|
|
|
|
if (!is_visible()) {
|
|
|
|
|
// Synchronize back favorites and recent directories, in case they have changed.
|
|
|
|
|
EditorSettings::get_singleton()->set_favorites(get_favorite_list(), false);
|
|
|
|
|
EditorSettings::get_singleton()->set_recent_dirs(get_recent_list(), false);
|
2015-05-31 01:59:42 -03:00
|
|
|
}
|
2022-02-16 00:52:32 +01:00
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
|
2022-11-23 00:14:08 +01:00
|
|
|
if (!EditorSettings::get_singleton()->check_changed_settings_in_group("filesystem/file_dialog")) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2025-12-02 12:30:51 +01:00
|
|
|
set_show_hidden_files(EDITOR_GET("filesystem/file_dialog/show_hidden_files"));
|
2022-10-18 16:43:37 +02:00
|
|
|
set_display_mode((DisplayMode)EDITOR_GET("filesystem/file_dialog/display_mode").operator int());
|
2022-02-16 00:52:32 +01:00
|
|
|
} break;
|
2015-05-31 01:59:42 -03:00
|
|
|
}
|
|
|
|
|
}
|