2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* editor_file_dialog.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:11:45 +02:00
|
|
|
/* https://godotengine.org */
|
2016-06-18 14:46:12 +02:00
|
|
|
/*************************************************************************/
|
2018-01-02 11:27:24 +01:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
2016-06-18 14:46:12 +02: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. */
|
|
|
|
/*************************************************************************/
|
2015-05-31 06:59:42 +02:00
|
|
|
#include "editor_file_dialog.h"
|
|
|
|
#include "editor_resource_preview.h"
|
2017-03-19 00:36:26 +01:00
|
|
|
#include "editor_scale.h"
|
2015-06-06 14:44:38 +02:00
|
|
|
#include "editor_settings.h"
|
2015-12-12 23:21:43 +01:00
|
|
|
#include "os/file_access.h"
|
2017-03-19 00:36:26 +01:00
|
|
|
#include "os/keyboard.h"
|
|
|
|
#include "print_string.h"
|
|
|
|
#include "scene/gui/center_container.h"
|
|
|
|
#include "scene/gui/label.h"
|
|
|
|
#include "scene/gui/margin_container.h"
|
|
|
|
EditorFileDialog::GetIconFunc EditorFileDialog::get_icon_func = NULL;
|
|
|
|
EditorFileDialog::GetIconFunc EditorFileDialog::get_large_icon_func = NULL;
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
EditorFileDialog::RegisterFunc EditorFileDialog::register_func = NULL;
|
|
|
|
EditorFileDialog::RegisterFunc EditorFileDialog::unregister_func = NULL;
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
VBoxContainer *EditorFileDialog::get_vbox() {
|
|
|
|
return vbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::_notification(int p_what) {
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (p_what == NOTIFICATION_ENTER_TREE) {
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
mode_thumbnails->set_icon(get_icon("FileThumbnail", "EditorIcons"));
|
|
|
|
mode_list->set_icon(get_icon("FileList", "EditorIcons"));
|
|
|
|
dir_prev->set_icon(get_icon("ArrowLeft", "EditorIcons"));
|
|
|
|
dir_next->set_icon(get_icon("ArrowRight", "EditorIcons"));
|
|
|
|
dir_up->set_icon(get_icon("ArrowUp", "EditorIcons"));
|
|
|
|
refresh->set_icon(get_icon("Reload", "EditorIcons"));
|
|
|
|
favorite->set_icon(get_icon("Favorites", "EditorIcons"));
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
fav_up->set_icon(get_icon("MoveUp", "EditorIcons"));
|
|
|
|
fav_down->set_icon(get_icon("MoveDown", "EditorIcons"));
|
|
|
|
fav_rm->set_icon(get_icon("RemoveSmall", "EditorIcons"));
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
} else if (p_what == NOTIFICATION_PROCESS) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
if (preview_waiting) {
|
2017-03-19 00:36:26 +01:00
|
|
|
preview_wheel_timeout -= get_process_delta_time();
|
|
|
|
if (preview_wheel_timeout <= 0) {
|
2015-05-31 06:59:42 +02:00
|
|
|
preview_wheel_index++;
|
2017-03-19 00:36:26 +01:00
|
|
|
if (preview_wheel_index >= 8)
|
|
|
|
preview_wheel_index = 0;
|
|
|
|
Ref<Texture> frame = get_icon("WaitPreview" + itos(preview_wheel_index + 1), "EditorIcons");
|
2015-05-31 06:59:42 +02:00
|
|
|
preview->set_texture(frame);
|
2017-03-19 00:36:26 +01:00
|
|
|
preview_wheel_timeout = 0.1;
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
} else if (p_what == NOTIFICATION_DRAW) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
//RID ci = get_canvas_item();
|
|
|
|
//get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));
|
2017-03-19 00:36:26 +01:00
|
|
|
} else if (p_what == NOTIFICATION_POPUP_HIDE) {
|
2015-12-29 00:36:48 +01:00
|
|
|
|
|
|
|
set_process_unhandled_input(false);
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
} else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
|
2015-12-06 23:35:31 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool show_hidden = EditorSettings::get_singleton()->get("file_dialog/show_hidden_files");
|
|
|
|
if (show_hidden_files != show_hidden)
|
2015-12-29 00:36:48 +01:00
|
|
|
set_show_hidden_files(show_hidden);
|
2015-12-15 17:39:13 +01:00
|
|
|
set_display_mode((DisplayMode)EditorSettings::get_singleton()->get("file_dialog/display_mode").operator int());
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void EditorFileDialog::_unhandled_input(const InputEvent &p_event) {
|
2015-12-29 00:36:48 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (p_event.type == InputEvent::KEY && is_window_modal_on_top()) {
|
2015-12-29 00:36:48 +01:00
|
|
|
|
2016-06-18 19:32:04 +02:00
|
|
|
if (p_event.key.pressed) {
|
2015-12-29 00:36:48 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool handled = false;
|
2015-12-29 00:36:48 +01:00
|
|
|
|
2016-06-18 19:32:04 +02:00
|
|
|
if (ED_IS_SHORTCUT("file_dialog/go_back", p_event)) {
|
|
|
|
_go_back();
|
2017-03-19 00:36:26 +01:00
|
|
|
handled = true;
|
2016-06-18 19:32:04 +02:00
|
|
|
}
|
|
|
|
if (ED_IS_SHORTCUT("file_dialog/go_forward", p_event)) {
|
|
|
|
_go_forward();
|
2017-03-19 00:36:26 +01:00
|
|
|
handled = true;
|
2016-06-18 19:32:04 +02:00
|
|
|
}
|
|
|
|
if (ED_IS_SHORTCUT("file_dialog/go_up", p_event)) {
|
|
|
|
_go_up();
|
2017-03-19 00:36:26 +01:00
|
|
|
handled = true;
|
2016-06-18 19:32:04 +02:00
|
|
|
}
|
|
|
|
if (ED_IS_SHORTCUT("file_dialog/refresh", p_event)) {
|
|
|
|
invalidate();
|
2017-03-19 00:36:26 +01:00
|
|
|
handled = true;
|
2016-06-18 19:32:04 +02:00
|
|
|
}
|
|
|
|
if (ED_IS_SHORTCUT("file_dialog/toggle_hidden_files", p_event)) {
|
2017-03-19 00:36:26 +01:00
|
|
|
bool show = !show_hidden_files;
|
2016-06-18 19:32:04 +02:00
|
|
|
set_show_hidden_files(show);
|
2017-03-19 00:36:26 +01:00
|
|
|
EditorSettings::get_singleton()->set("file_dialog/show_hidden_files", show);
|
|
|
|
handled = true;
|
2016-06-18 19:32:04 +02:00
|
|
|
}
|
|
|
|
if (ED_IS_SHORTCUT("file_dialog/toggle_favorite", p_event)) {
|
|
|
|
_favorite_toggled(favorite->is_pressed());
|
2017-03-19 00:36:26 +01:00
|
|
|
handled = true;
|
2016-06-18 19:32:04 +02:00
|
|
|
}
|
|
|
|
if (ED_IS_SHORTCUT("file_dialog/toggle_mode", p_event)) {
|
|
|
|
if (mode_thumbnails->is_pressed()) {
|
|
|
|
set_display_mode(DISPLAY_LIST);
|
|
|
|
} else {
|
|
|
|
set_display_mode(DISPLAY_THUMBNAILS);
|
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
handled = true;
|
2016-06-18 19:32:04 +02:00
|
|
|
}
|
|
|
|
if (ED_IS_SHORTCUT("file_dialog/create_folder", p_event)) {
|
|
|
|
_make_dir();
|
2017-03-19 00:36:26 +01:00
|
|
|
handled = true;
|
2016-06-18 19:32:04 +02:00
|
|
|
}
|
|
|
|
if (ED_IS_SHORTCUT("file_dialog/focus_path", p_event)) {
|
|
|
|
dir->grab_focus();
|
2017-03-19 00:36:26 +01:00
|
|
|
handled = true;
|
2016-06-18 19:32:04 +02:00
|
|
|
}
|
2016-06-28 16:12:07 +02:00
|
|
|
if (ED_IS_SHORTCUT("file_dialog/move_favorite_up", p_event)) {
|
2016-06-18 19:32:04 +02:00
|
|
|
_favorite_move_up();
|
2017-03-19 00:36:26 +01:00
|
|
|
handled = true;
|
2016-06-18 19:32:04 +02:00
|
|
|
}
|
2016-06-28 16:12:07 +02:00
|
|
|
if (ED_IS_SHORTCUT("file_dialog/move_favorite_down", p_event)) {
|
2016-06-18 19:32:04 +02:00
|
|
|
_favorite_move_down();
|
2017-03-19 00:36:26 +01:00
|
|
|
handled = true;
|
2015-12-29 00:36:48 +01:00
|
|
|
}
|
|
|
|
|
2016-06-18 19:32:04 +02:00
|
|
|
if (handled) {
|
2015-12-29 00:36:48 +01:00
|
|
|
accept_event();
|
2016-06-18 19:32:04 +02:00
|
|
|
}
|
2015-12-29 00:36:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-31 06:59:42 +02:00
|
|
|
void EditorFileDialog::set_enable_multiple_selection(bool p_enable) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
item_list->set_select_mode(p_enable ? ItemList::SELECT_MULTI : ItemList::SELECT_SINGLE);
|
2015-05-31 06:59:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Vector<String> EditorFileDialog::get_selected_files() const {
|
|
|
|
|
|
|
|
Vector<String> list;
|
2017-03-19 00:36:26 +01:00
|
|
|
for (int i = 0; i < item_list->get_item_count(); i++) {
|
2015-06-06 14:44:38 +02:00
|
|
|
if (item_list->is_selected(i))
|
|
|
|
list.push_back(item_list->get_item_text(i));
|
|
|
|
}
|
2015-05-31 06:59:42 +02:00
|
|
|
return list;
|
|
|
|
};
|
|
|
|
|
|
|
|
void EditorFileDialog::update_dir() {
|
|
|
|
|
|
|
|
dir->set_text(dir_access->get_current_dir());
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::_dir_entered(String p_dir) {
|
|
|
|
|
|
|
|
dir_access->change_dir(p_dir);
|
|
|
|
file->set_text("");
|
|
|
|
invalidate();
|
|
|
|
update_dir();
|
2015-06-06 14:44:38 +02:00
|
|
|
_push_history();
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void EditorFileDialog::_file_entered(const String &p_file) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
_action_pressed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::_save_confirm_pressed() {
|
2017-03-19 00:36:26 +01:00
|
|
|
String f = dir_access->get_current_dir().plus_file(file->get_text());
|
2015-06-06 14:44:38 +02:00
|
|
|
_save_to_recent();
|
2017-03-19 00:36:26 +01:00
|
|
|
emit_signal("file_selected", f);
|
2015-05-31 06:59:42 +02:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::_post_popup() {
|
|
|
|
|
|
|
|
ConfirmationDialog::_post_popup();
|
|
|
|
if (invalidated) {
|
|
|
|
update_file_list();
|
2017-03-19 00:36:26 +01:00
|
|
|
invalidated = false;
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
if (mode == MODE_SAVE_FILE)
|
2015-05-31 06:59:42 +02:00
|
|
|
file->grab_focus();
|
|
|
|
else
|
2015-06-06 14:44:38 +02:00
|
|
|
item_list->grab_focus();
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (is_visible() && get_current_file() != "")
|
2015-05-31 06:59:42 +02:00
|
|
|
_request_single_thumbnail(get_current_dir().plus_file(get_current_file()));
|
|
|
|
|
2015-06-06 14:44:38 +02:00
|
|
|
if (is_visible()) {
|
2017-03-19 00:36:26 +01:00
|
|
|
Ref<Texture> folder = get_icon("folder", "FileDialog");
|
2015-06-06 14:44:38 +02:00
|
|
|
recent->clear();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool res = access == ACCESS_RESOURCES;
|
2015-06-06 14:44:38 +02:00
|
|
|
Vector<String> recentd = EditorSettings::get_singleton()->get_recent_dirs();
|
2017-03-19 00:36:26 +01:00
|
|
|
for (int i = 0; i < recentd.size(); i++) {
|
2015-06-06 14:44:38 +02:00
|
|
|
bool cres = recentd[i].begins_with("res://");
|
2017-03-19 00:36:26 +01:00
|
|
|
if (cres != res)
|
2015-06-06 14:44:38 +02:00
|
|
|
continue;
|
|
|
|
String name = recentd[i];
|
2017-03-19 00:36:26 +01:00
|
|
|
if (res && name == "res://") {
|
|
|
|
name = "/";
|
2015-06-06 14:44:38 +02:00
|
|
|
} else {
|
2017-03-19 00:36:26 +01:00
|
|
|
name = name.get_file() + "/";
|
2015-06-06 14:44:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//print_line("file: "+name);
|
2017-03-19 00:36:26 +01:00
|
|
|
recent->add_item(name, folder);
|
|
|
|
recent->set_item_metadata(recent->get_item_count() - 1, recentd[i]);
|
2015-06-06 14:44:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
local_history.clear();
|
2017-03-19 00:36:26 +01:00
|
|
|
local_history_pos = -1;
|
2015-06-06 14:44:38 +02:00
|
|
|
_push_history();
|
|
|
|
|
|
|
|
_update_favorites();
|
|
|
|
}
|
|
|
|
|
2015-12-29 00:36:48 +01:00
|
|
|
set_process_unhandled_input(true);
|
2015-06-06 14:44:38 +02:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void EditorFileDialog::_thumbnail_result(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata) {
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (display_mode == DISPLAY_LIST || p_preview.is_null())
|
2015-06-06 14:44:38 +02:00
|
|
|
return;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
for (int i = 0; i < item_list->get_item_count(); i++) {
|
2015-06-06 14:44:38 +02:00
|
|
|
Dictionary d = item_list->get_item_metadata(i);
|
|
|
|
String pname = d["path"];
|
2017-03-19 00:36:26 +01:00
|
|
|
if (pname == p_path) {
|
|
|
|
item_list->set_item_icon(i, p_preview);
|
|
|
|
item_list->set_item_tag_icon(i, Ref<Texture>());
|
2015-06-06 14:44:38 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void EditorFileDialog::_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
set_process(false);
|
2017-03-19 00:36:26 +01:00
|
|
|
preview_waiting = false;
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (p_preview.is_valid() && get_current_path() == p_path) {
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2015-05-31 06:59:42 +02:00
|
|
|
preview->set_texture(p_preview);
|
2017-03-19 00:36:26 +01:00
|
|
|
if (display_mode == DISPLAY_THUMBNAILS) {
|
2015-06-06 14:44:38 +02:00
|
|
|
preview_vb->hide();
|
|
|
|
} else {
|
|
|
|
preview_vb->show();
|
|
|
|
}
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
preview_vb->hide();
|
|
|
|
preview->set_texture(Ref<Texture>());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void EditorFileDialog::_request_single_thumbnail(const String &p_path) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2015-12-12 23:21:43 +01:00
|
|
|
if (!FileAccess::exists(p_path))
|
|
|
|
return;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
EditorResourcePreview::get_singleton()->queue_resource_preview(p_path, this, "_thumbnail_done", p_path);
|
2015-08-24 01:15:56 +02:00
|
|
|
//print_line("want file "+p_path);
|
2015-05-31 06:59:42 +02:00
|
|
|
set_process(true);
|
2017-03-19 00:36:26 +01:00
|
|
|
preview_waiting = true;
|
|
|
|
preview_wheel_timeout = 0;
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::_action_pressed() {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (mode == MODE_OPEN_FILES) {
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
String fbase = dir_access->get_current_dir();
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
DVector<String> files;
|
2017-03-19 00:36:26 +01:00
|
|
|
for (int i = 0; i < item_list->get_item_count(); i++) {
|
2015-06-06 14:44:38 +02:00
|
|
|
if (item_list->is_selected(i))
|
2017-03-19 00:36:26 +01:00
|
|
|
files.push_back(fbase.plus_file(item_list->get_item_text(i)));
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (files.size()) {
|
2015-06-06 14:44:38 +02:00
|
|
|
_save_to_recent();
|
2017-03-19 00:36:26 +01:00
|
|
|
emit_signal("files_selected", files);
|
2015-05-31 06:59:42 +02:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
String f = dir_access->get_current_dir().plus_file(file->get_text());
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if ((mode == MODE_OPEN_ANY || mode == MODE_OPEN_FILE) && dir_access->file_exists(f)) {
|
2015-06-06 14:44:38 +02:00
|
|
|
_save_to_recent();
|
2017-03-19 00:36:26 +01:00
|
|
|
emit_signal("file_selected", f);
|
2015-05-31 06:59:42 +02:00
|
|
|
hide();
|
2017-03-19 00:36:26 +01:00
|
|
|
} else if (mode == MODE_OPEN_ANY || mode == MODE_OPEN_DIR) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
String path = dir_access->get_current_dir();
|
2015-05-31 06:59:42 +02:00
|
|
|
/*if (tree->get_selected()) {
|
|
|
|
Dictionary d = tree->get_selected()->get_metadata(0);
|
|
|
|
if (d["dir"]) {
|
|
|
|
path=path+"/"+String(d["name"]);
|
|
|
|
}
|
|
|
|
}*/
|
2017-03-19 00:36:26 +01:00
|
|
|
path = path.replace("\\", "/");
|
2015-06-06 14:44:38 +02:00
|
|
|
_save_to_recent();
|
2017-03-19 00:36:26 +01:00
|
|
|
emit_signal("dir_selected", path);
|
2015-05-31 06:59:42 +02:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (mode == MODE_SAVE_FILE) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool valid = false;
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (filter->get_selected() == filter->get_item_count() - 1) {
|
|
|
|
valid = true; //match none
|
|
|
|
} else if (filters.size() > 1 && filter->get_selected() == 0) {
|
2015-05-31 06:59:42 +02:00
|
|
|
// match all filters
|
2017-03-19 00:36:26 +01:00
|
|
|
for (int i = 0; i < filters.size(); i++) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
String flt = filters[i].get_slice(";", 0);
|
|
|
|
for (int j = 0; j < flt.get_slice_count(","); j++) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
String str = flt.get_slice(",", j).strip_edges();
|
2015-05-31 06:59:42 +02:00
|
|
|
if (f.match(str)) {
|
2017-03-19 00:36:26 +01:00
|
|
|
valid = true;
|
2015-05-31 06:59:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (valid)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2017-03-19 00:36:26 +01:00
|
|
|
int idx = filter->get_selected();
|
|
|
|
if (filters.size() > 1)
|
2015-05-31 06:59:42 +02:00
|
|
|
idx--;
|
2017-03-19 00:36:26 +01:00
|
|
|
if (idx >= 0 && idx < filters.size()) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
String flt = filters[idx].get_slice(";", 0);
|
|
|
|
int filterSliceCount = flt.get_slice_count(",");
|
|
|
|
for (int j = 0; j < filterSliceCount; j++) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
String str = (flt.get_slice(",", j).strip_edges());
|
2015-05-31 06:59:42 +02:00
|
|
|
if (f.match(str)) {
|
2017-03-19 00:36:26 +01:00
|
|
|
valid = true;
|
2015-05-31 06:59:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (!valid && filterSliceCount > 0) {
|
|
|
|
String str = (flt.get_slice(",", 0).strip_edges());
|
|
|
|
f += str.substr(1, str.length() - 1);
|
2015-05-31 06:59:42 +02:00
|
|
|
_request_single_thumbnail(get_current_dir().plus_file(f.get_file()));
|
|
|
|
file->set_text(f.get_file());
|
2017-03-19 00:36:26 +01:00
|
|
|
valid = true;
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
} else {
|
2017-03-19 00:36:26 +01:00
|
|
|
valid = true;
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!valid) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
exterr->popup_centered_minsize(Size2(250, 80) * EDSCALE);
|
2015-05-31 06:59:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-20 05:38:13 +02:00
|
|
|
if (dir_access->file_exists(f) && !disable_overwrite_warning) {
|
2016-05-04 03:25:37 +02:00
|
|
|
confirm_save->set_text(TTR("File Exists, Overwrite?"));
|
2017-03-19 00:36:26 +01:00
|
|
|
confirm_save->popup_centered(Size2(200, 80));
|
2015-05-31 06:59:42 +02:00
|
|
|
} else {
|
|
|
|
|
2015-06-06 14:44:38 +02:00
|
|
|
_save_to_recent();
|
2017-03-19 00:36:26 +01:00
|
|
|
emit_signal("file_selected", f);
|
2015-05-31 06:59:42 +02:00
|
|
|
hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::_cancel_pressed() {
|
|
|
|
|
|
|
|
file->set_text("");
|
|
|
|
invalidate();
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
2015-06-06 14:44:38 +02:00
|
|
|
void EditorFileDialog::_item_selected(int p_item) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2015-06-06 14:44:38 +02:00
|
|
|
int current = p_item;
|
2017-03-19 00:36:26 +01:00
|
|
|
if (current < 0 || current >= item_list->get_item_count())
|
2015-05-31 06:59:42 +02:00
|
|
|
return;
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Dictionary d = item_list->get_item_metadata(current);
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
if (!d["dir"]) {
|
|
|
|
|
|
|
|
file->set_text(d["name"]);
|
|
|
|
_request_single_thumbnail(get_current_dir().plus_file(get_current_file()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-06 14:44:38 +02:00
|
|
|
void EditorFileDialog::_push_history() {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
local_history.resize(local_history_pos + 1);
|
2015-06-06 14:44:38 +02:00
|
|
|
String new_path = dir_access->get_current_dir();
|
2017-03-19 00:36:26 +01:00
|
|
|
if (local_history.size() == 0 || new_path != local_history[local_history_pos]) {
|
2015-06-06 14:44:38 +02:00
|
|
|
local_history.push_back(new_path);
|
|
|
|
local_history_pos++;
|
2017-03-19 00:36:26 +01:00
|
|
|
dir_prev->set_disabled(local_history_pos == 0);
|
2015-06-06 14:44:38 +02:00
|
|
|
dir_next->set_disabled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void EditorFileDialog::_item_dc_selected(int p_item) {
|
|
|
|
|
|
|
|
int current = p_item;
|
2017-03-19 00:36:26 +01:00
|
|
|
if (current < 0 || current >= item_list->get_item_count())
|
2015-05-31 06:59:42 +02:00
|
|
|
return;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Dictionary d = item_list->get_item_metadata(current);
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
if (d["dir"]) {
|
|
|
|
|
|
|
|
dir_access->change_dir(d["name"]);
|
|
|
|
call_deferred("_update_file_list");
|
|
|
|
call_deferred("_update_dir");
|
2015-06-06 14:44:38 +02:00
|
|
|
|
|
|
|
_push_history();
|
|
|
|
|
2015-05-31 06:59:42 +02:00
|
|
|
} else {
|
|
|
|
|
|
|
|
_action_pressed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::update_file_list() {
|
|
|
|
|
2015-06-06 14:44:38 +02:00
|
|
|
int thumbnail_size = EditorSettings::get_singleton()->get("file_dialog/thumbnail_size");
|
2017-03-19 00:36:26 +01:00
|
|
|
thumbnail_size *= EDSCALE;
|
2015-06-06 14:44:38 +02:00
|
|
|
Ref<Texture> folder_thumbnail;
|
|
|
|
Ref<Texture> file_thumbnail;
|
|
|
|
|
|
|
|
item_list->clear();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (display_mode == DISPLAY_THUMBNAILS) {
|
2015-06-06 14:44:38 +02:00
|
|
|
|
|
|
|
item_list->set_max_columns(0);
|
|
|
|
item_list->set_icon_mode(ItemList::ICON_MODE_TOP);
|
2017-03-19 00:36:26 +01:00
|
|
|
item_list->set_fixed_column_width(thumbnail_size * 3 / 2);
|
2015-06-06 14:44:38 +02:00
|
|
|
item_list->set_max_text_lines(2);
|
2017-03-19 00:36:26 +01:00
|
|
|
item_list->set_fixed_icon_size(Size2(thumbnail_size, thumbnail_size));
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (!has_icon("ResizedFolder", "EditorIcons")) {
|
|
|
|
Ref<ImageTexture> folder = get_icon("FolderBig", "EditorIcons");
|
2015-06-06 14:44:38 +02:00
|
|
|
Image img = folder->get_data();
|
2017-03-19 00:36:26 +01:00
|
|
|
img.resize(thumbnail_size, thumbnail_size);
|
|
|
|
Ref<ImageTexture> resized_folder = Ref<ImageTexture>(memnew(ImageTexture));
|
|
|
|
resized_folder->create_from_image(img, 0);
|
|
|
|
Theme::get_default()->set_icon("ResizedFolder", "EditorIcons", resized_folder);
|
2015-06-06 14:44:38 +02:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
folder_thumbnail = get_icon("ResizedFolder", "EditorIcons");
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (!has_icon("ResizedFile", "EditorIcons")) {
|
|
|
|
Ref<ImageTexture> file = get_icon("FileBig", "EditorIcons");
|
2015-06-06 14:44:38 +02:00
|
|
|
Image img = file->get_data();
|
2017-03-19 00:36:26 +01:00
|
|
|
img.resize(thumbnail_size, thumbnail_size);
|
|
|
|
Ref<ImageTexture> resized_file = Ref<ImageTexture>(memnew(ImageTexture));
|
|
|
|
resized_file->create_from_image(img, 0);
|
|
|
|
Theme::get_default()->set_icon("ResizedFile", "EditorIcons", resized_file);
|
2015-06-06 14:44:38 +02:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
file_thumbnail = get_icon("ResizedFile", "EditorIcons");
|
2015-06-06 14:44:38 +02:00
|
|
|
|
|
|
|
preview_vb->hide();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
item_list->set_icon_mode(ItemList::ICON_MODE_LEFT);
|
|
|
|
item_list->set_max_columns(1);
|
|
|
|
item_list->set_max_text_lines(1);
|
|
|
|
item_list->set_fixed_column_width(0);
|
2016-06-12 21:51:27 +02:00
|
|
|
item_list->set_fixed_icon_size(Size2());
|
2015-06-06 14:44:38 +02:00
|
|
|
if (preview->get_texture().is_valid())
|
|
|
|
preview_vb->show();
|
|
|
|
}
|
|
|
|
|
2015-12-11 13:37:34 +01:00
|
|
|
String cdir = dir_access->get_current_dir();
|
2017-03-19 00:36:26 +01:00
|
|
|
bool skip_pp = access == ACCESS_RESOURCES && cdir == "res://";
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2015-05-31 06:59:42 +02:00
|
|
|
dir_access->list_dir_begin();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Ref<Texture> folder = get_icon("folder", "FileDialog");
|
2015-05-31 06:59:42 +02:00
|
|
|
List<String> files;
|
|
|
|
List<String> dirs;
|
|
|
|
|
|
|
|
bool isdir;
|
|
|
|
bool ishidden;
|
|
|
|
bool show_hidden = show_hidden_files;
|
|
|
|
String item;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
while ((item = dir_access->get_next(&isdir)) != "") {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
ishidden = dir_access->current_is_hidden();
|
|
|
|
|
|
|
|
if (show_hidden || !ishidden) {
|
|
|
|
if (!isdir)
|
|
|
|
files.push_back(item);
|
2017-03-19 00:36:26 +01:00
|
|
|
else if (item != ".." || !skip_pp)
|
2015-05-31 06:59:42 +02:00
|
|
|
dirs.push_back(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (dirs.find("..") == NULL) {
|
2016-06-18 17:49:58 +02:00
|
|
|
//may happen if lacking permissions
|
|
|
|
dirs.push_back("..");
|
|
|
|
}
|
|
|
|
|
2015-05-31 06:59:42 +02:00
|
|
|
dirs.sort_custom<NoCaseComparator>();
|
|
|
|
files.sort_custom<NoCaseComparator>();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
while (!dirs.empty()) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (dirs.front()->get() != ".") {
|
|
|
|
item_list->add_item(dirs.front()->get() + "/");
|
|
|
|
if (display_mode == DISPLAY_THUMBNAILS) {
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
item_list->set_item_icon(item_list->get_item_count() - 1, folder_thumbnail);
|
2015-06-06 14:44:38 +02:00
|
|
|
} else {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
item_list->set_item_icon(item_list->get_item_count() - 1, folder);
|
2015-06-06 14:44:38 +02:00
|
|
|
}
|
|
|
|
|
2015-05-31 06:59:42 +02:00
|
|
|
Dictionary d;
|
2017-03-19 00:36:26 +01:00
|
|
|
d["name"] = dirs.front()->get();
|
|
|
|
d["path"] = String();
|
|
|
|
d["dir"] = true;
|
|
|
|
item_list->set_item_metadata(item_list->get_item_count() - 1, d);
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
dirs.pop_front();
|
|
|
|
}
|
|
|
|
|
|
|
|
dirs.clear();
|
|
|
|
|
|
|
|
List<String> patterns;
|
|
|
|
// build filter
|
2017-03-19 00:36:26 +01:00
|
|
|
if (filter->get_selected() == filter->get_item_count() - 1) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
// match all
|
2017-03-19 00:36:26 +01:00
|
|
|
} else if (filters.size() > 1 && filter->get_selected() == 0) {
|
2015-05-31 06:59:42 +02:00
|
|
|
// match all filters
|
2017-03-19 00:36:26 +01:00
|
|
|
for (int i = 0; i < filters.size(); i++) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
String f = filters[i].get_slice(";", 0);
|
|
|
|
for (int j = 0; j < f.get_slice_count(","); j++) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
patterns.push_back(f.get_slice(",", j).strip_edges());
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2017-03-19 00:36:26 +01:00
|
|
|
int idx = filter->get_selected();
|
|
|
|
if (filters.size() > 1)
|
2015-05-31 06:59:42 +02:00
|
|
|
idx--;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (idx >= 0 && idx < filters.size()) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
String f = filters[idx].get_slice(";", 0);
|
|
|
|
for (int j = 0; j < f.get_slice_count(","); j++) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
patterns.push_back(f.get_slice(",", j).strip_edges());
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String base_dir = dir_access->get_current_dir();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
while (!files.empty()) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool match = patterns.empty();
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
for (List<String>::Element *E = patterns.front(); E; E = E->next()) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
if (files.front()->get().matchn(E->get())) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
match = true;
|
2015-05-31 06:59:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (match) {
|
2015-06-06 14:44:38 +02:00
|
|
|
//TreeItem *ti=tree->create_item(root);
|
|
|
|
//ti->set_text(0,files.front()->get());
|
|
|
|
item_list->add_item(files.front()->get());
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
if (get_icon_func) {
|
|
|
|
|
|
|
|
Ref<Texture> icon = get_icon_func(base_dir.plus_file(files.front()->get()));
|
2015-06-06 14:44:38 +02:00
|
|
|
//ti->set_icon(0,icon);
|
2017-03-19 00:36:26 +01:00
|
|
|
if (display_mode == DISPLAY_THUMBNAILS) {
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
item_list->set_item_icon(item_list->get_item_count() - 1, file_thumbnail);
|
|
|
|
item_list->set_item_tag_icon(item_list->get_item_count() - 1, icon);
|
2015-06-06 14:44:38 +02:00
|
|
|
} else {
|
2017-03-19 00:36:26 +01:00
|
|
|
item_list->set_item_icon(item_list->get_item_count() - 1, icon);
|
2015-06-06 14:44:38 +02:00
|
|
|
}
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (mode == MODE_OPEN_DIR) {
|
2015-06-06 14:44:38 +02:00
|
|
|
//disabled mode?
|
|
|
|
//ti->set_custom_color(0,get_color("files_disabled"));
|
|
|
|
//ti->set_selectable(0,false);
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
Dictionary d;
|
2017-03-19 00:36:26 +01:00
|
|
|
d["name"] = files.front()->get();
|
|
|
|
d["dir"] = false;
|
2015-06-06 14:44:38 +02:00
|
|
|
String fullpath = base_dir.plus_file(files.front()->get());
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (display_mode == DISPLAY_THUMBNAILS) {
|
|
|
|
EditorResourcePreview::get_singleton()->queue_resource_preview(fullpath, this, "_thumbnail_result", fullpath);
|
2015-06-06 14:44:38 +02:00
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
d["path"] = base_dir.plus_file(files.front()->get());
|
2015-06-06 14:44:38 +02:00
|
|
|
//ti->set_metadata(0,d);
|
2017-03-19 00:36:26 +01:00
|
|
|
item_list->set_item_metadata(item_list->get_item_count() - 1, d);
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (file->get_text() == files.front()->get())
|
|
|
|
item_list->set_current(item_list->get_item_count() - 1);
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
files.pop_front();
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (favorites->get_current() >= 0) {
|
2015-06-06 14:44:38 +02:00
|
|
|
favorites->unselect(favorites->get_current());
|
|
|
|
}
|
|
|
|
|
|
|
|
favorite->set_pressed(false);
|
|
|
|
fav_up->set_disabled(true);
|
|
|
|
fav_down->set_disabled(true);
|
2017-03-19 00:36:26 +01:00
|
|
|
for (int i = 0; i < favorites->get_item_count(); i++) {
|
|
|
|
if (favorites->get_item_metadata(i) == base_dir) {
|
2015-06-06 14:44:38 +02:00
|
|
|
favorites->select(i);
|
|
|
|
favorite->set_pressed(true);
|
2017-03-19 00:36:26 +01:00
|
|
|
if (i > 0) {
|
2015-06-06 14:44:38 +02:00
|
|
|
fav_up->set_disabled(false);
|
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
if (i < favorites->get_item_count() - 1) {
|
2015-06-06 14:44:38 +02:00
|
|
|
fav_down->set_disabled(false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// ??
|
|
|
|
//if (tree->get_root() && tree->get_root()->get_children())
|
|
|
|
// tree->get_root()->get_children()->select(0);
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
files.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::_filter_selected(int) {
|
|
|
|
|
|
|
|
update_file_list();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::update_filters() {
|
|
|
|
|
|
|
|
filter->clear();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (filters.size() > 1) {
|
2015-05-31 06:59:42 +02:00
|
|
|
String all_filters;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
const int max_filters = 5;
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
for (int i = 0; i < MIN(max_filters, filters.size()); i++) {
|
|
|
|
String flt = filters[i].get_slice(";", 0);
|
|
|
|
if (i > 0)
|
|
|
|
all_filters += ",";
|
|
|
|
all_filters += flt;
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (max_filters < filters.size())
|
|
|
|
all_filters += ", ...";
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
filter->add_item(TTR("All Recognized") + " ( " + all_filters + " )");
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
for (int i = 0; i < filters.size(); i++) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
String flt = filters[i].get_slice(";", 0).strip_edges();
|
|
|
|
String desc = filters[i].get_slice(";", 1).strip_edges();
|
2015-05-31 06:59:42 +02:00
|
|
|
if (desc.length())
|
2017-03-19 00:36:26 +01:00
|
|
|
filter->add_item(desc + " ( " + flt + " )");
|
2015-05-31 06:59:42 +02:00
|
|
|
else
|
2017-03-19 00:36:26 +01:00
|
|
|
filter->add_item("( " + flt + " )");
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
filter->add_item(TTR("All Files (*)"));
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::clear_filters() {
|
|
|
|
|
|
|
|
filters.clear();
|
|
|
|
update_filters();
|
|
|
|
invalidate();
|
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
void EditorFileDialog::add_filter(const String &p_filter) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
filters.push_back(p_filter);
|
|
|
|
update_filters();
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
String EditorFileDialog::get_current_dir() const {
|
|
|
|
|
|
|
|
return dir->get_text();
|
|
|
|
}
|
|
|
|
String EditorFileDialog::get_current_file() const {
|
|
|
|
|
|
|
|
return file->get_text();
|
|
|
|
}
|
|
|
|
String EditorFileDialog::get_current_path() const {
|
|
|
|
|
|
|
|
return dir->get_text().plus_file(file->get_text());
|
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
void EditorFileDialog::set_current_dir(const String &p_dir) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
dir_access->change_dir(p_dir);
|
|
|
|
update_dir();
|
|
|
|
invalidate();
|
2015-06-07 03:06:58 +02:00
|
|
|
//_push_history();
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
void EditorFileDialog::set_current_file(const String &p_file) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
file->set_text(p_file);
|
|
|
|
update_dir();
|
|
|
|
invalidate();
|
|
|
|
int lp = p_file.find_last(".");
|
2017-03-19 00:36:26 +01:00
|
|
|
if (lp != -1) {
|
|
|
|
file->select(0, lp);
|
2015-05-31 06:59:42 +02:00
|
|
|
file->grab_focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_visible())
|
|
|
|
_request_single_thumbnail(get_current_dir().plus_file(get_current_file()));
|
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
void EditorFileDialog::set_current_path(const String &p_path) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
if (!p_path.size())
|
|
|
|
return;
|
2017-03-19 00:36:26 +01:00
|
|
|
int pos = MAX(p_path.find_last("/"), p_path.find_last("\\"));
|
|
|
|
if (pos == -1) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
set_current_file(p_path);
|
|
|
|
} else {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
String dir = p_path.substr(0, pos);
|
|
|
|
String file = p_path.substr(pos + 1, p_path.length());
|
2015-05-31 06:59:42 +02:00
|
|
|
set_current_dir(dir);
|
|
|
|
set_current_file(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::set_mode(Mode p_mode) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
mode = p_mode;
|
|
|
|
switch (mode) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
case MODE_OPEN_FILE:
|
|
|
|
get_ok()->set_text(TTR("Open"));
|
|
|
|
set_title("Open a File");
|
|
|
|
makedir->hide();
|
|
|
|
break;
|
|
|
|
case MODE_OPEN_FILES:
|
|
|
|
get_ok()->set_text(TTR("Open"));
|
|
|
|
set_title("Open File(s)");
|
|
|
|
makedir->hide();
|
|
|
|
break;
|
|
|
|
case MODE_OPEN_DIR:
|
|
|
|
get_ok()->set_text(TTR("Open"));
|
|
|
|
set_title("Open a Directory");
|
|
|
|
makedir->show();
|
|
|
|
break;
|
|
|
|
case MODE_OPEN_ANY:
|
|
|
|
get_ok()->set_text(TTR("Open"));
|
|
|
|
set_title("Open a File or Directory");
|
|
|
|
makedir->show();
|
|
|
|
break;
|
|
|
|
case MODE_SAVE_FILE:
|
|
|
|
get_ok()->set_text(TTR("Save"));
|
|
|
|
set_title("Save a File");
|
|
|
|
makedir->show();
|
|
|
|
break;
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (mode == MODE_OPEN_FILES) {
|
2015-06-06 14:44:38 +02:00
|
|
|
item_list->set_select_mode(ItemList::SELECT_MULTI);
|
2015-05-31 06:59:42 +02:00
|
|
|
} else {
|
2015-06-06 14:44:38 +02:00
|
|
|
item_list->set_select_mode(ItemList::SELECT_SINGLE);
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorFileDialog::Mode EditorFileDialog::get_mode() const {
|
|
|
|
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::set_access(Access p_access) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ERR_FAIL_INDEX(p_access, 3);
|
|
|
|
if (access == p_access)
|
2015-05-31 06:59:42 +02:00
|
|
|
return;
|
2017-03-19 00:36:26 +01:00
|
|
|
memdelete(dir_access);
|
|
|
|
switch (p_access) {
|
2015-05-31 06:59:42 +02:00
|
|
|
case ACCESS_FILESYSTEM: {
|
|
|
|
|
|
|
|
dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
|
|
|
|
} break;
|
|
|
|
case ACCESS_RESOURCES: {
|
|
|
|
|
|
|
|
dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
|
|
|
} break;
|
|
|
|
case ACCESS_USERDATA: {
|
|
|
|
|
|
|
|
dir_access = DirAccess::create(DirAccess::ACCESS_USERDATA);
|
|
|
|
} break;
|
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
access = p_access;
|
2015-05-31 06:59:42 +02:00
|
|
|
_update_drives();
|
|
|
|
invalidate();
|
|
|
|
update_filters();
|
|
|
|
update_dir();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::invalidate() {
|
|
|
|
|
|
|
|
if (is_visible()) {
|
|
|
|
update_file_list();
|
2017-03-19 00:36:26 +01:00
|
|
|
invalidated = false;
|
2015-05-31 06:59:42 +02:00
|
|
|
} else {
|
2017-03-19 00:36:26 +01:00
|
|
|
invalidated = true;
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
EditorFileDialog::Access EditorFileDialog::get_access() const {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
return access;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::_make_dir_confirm() {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
Error err = dir_access->make_dir(makedirname->get_text());
|
|
|
|
if (err == OK) {
|
2015-05-31 06:59:42 +02:00
|
|
|
dir_access->change_dir(makedirname->get_text());
|
|
|
|
invalidate();
|
|
|
|
update_filters();
|
|
|
|
update_dir();
|
2015-06-06 14:44:38 +02:00
|
|
|
_push_history();
|
|
|
|
|
2015-05-31 06:59:42 +02:00
|
|
|
} else {
|
2017-03-19 00:36:26 +01:00
|
|
|
mkdirerr->popup_centered_minsize(Size2(250, 50) * EDSCALE);
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
2016-05-01 11:38:24 +02:00
|
|
|
makedirname->set_text(""); // reset label
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::_make_dir() {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
makedialog->popup_centered_minsize(Size2(250, 80) * EDSCALE);
|
2015-05-31 06:59:42 +02:00
|
|
|
makedirname->grab_focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::_select_drive(int p_idx) {
|
|
|
|
|
|
|
|
String d = drives->get_item_text(p_idx);
|
|
|
|
dir_access->change_dir(d);
|
|
|
|
file->set_text("");
|
|
|
|
invalidate();
|
|
|
|
update_dir();
|
2015-06-06 14:44:38 +02:00
|
|
|
_push_history();
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::_update_drives() {
|
|
|
|
|
|
|
|
int dc = dir_access->get_drive_count();
|
2017-03-19 00:36:26 +01:00
|
|
|
if (dc == 0 || access != ACCESS_FILESYSTEM) {
|
2015-05-31 06:59:42 +02:00
|
|
|
drives->hide();
|
|
|
|
} else {
|
|
|
|
drives->clear();
|
|
|
|
drives->show();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
for (int i = 0; i < dir_access->get_drive_count(); i++) {
|
2015-05-31 06:59:42 +02:00
|
|
|
String d = dir_access->get_drive(i);
|
|
|
|
drives->add_item(dir_access->get_drive(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
drives->select(dir_access->get_current_drive());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-06 14:44:38 +02:00
|
|
|
void EditorFileDialog::_favorite_selected(int p_idx) {
|
|
|
|
|
|
|
|
Vector<String> favorited = EditorSettings::get_singleton()->get_favorite_dirs();
|
2017-03-19 00:36:26 +01:00
|
|
|
ERR_FAIL_INDEX(p_idx, favorited.size());
|
2015-06-06 14:44:38 +02:00
|
|
|
|
|
|
|
dir_access->change_dir(favorited[p_idx]);
|
|
|
|
file->set_text("");
|
|
|
|
invalidate();
|
|
|
|
update_dir();
|
|
|
|
_push_history();
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void EditorFileDialog::_favorite_move_up() {
|
2015-06-06 14:44:38 +02:00
|
|
|
|
|
|
|
int current = favorites->get_current();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (current > 0 && current < favorites->get_item_count()) {
|
2015-06-06 14:44:38 +02:00
|
|
|
Vector<String> favorited = EditorSettings::get_singleton()->get_favorite_dirs();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
int a_idx = favorited.find(String(favorites->get_item_metadata(current - 1)));
|
|
|
|
int b_idx = favorited.find(String(favorites->get_item_metadata(current)));
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (a_idx == -1 || b_idx == -1)
|
2015-06-06 14:44:38 +02:00
|
|
|
return;
|
2017-03-19 00:36:26 +01:00
|
|
|
SWAP(favorited[a_idx], favorited[b_idx]);
|
2015-06-06 14:44:38 +02:00
|
|
|
|
|
|
|
EditorSettings::get_singleton()->set_favorite_dirs(favorited);
|
|
|
|
|
|
|
|
_update_favorites();
|
|
|
|
update_file_list();
|
|
|
|
}
|
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
void EditorFileDialog::_favorite_move_down() {
|
2015-06-06 14:44:38 +02:00
|
|
|
|
|
|
|
int current = favorites->get_current();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (current >= 0 && current < favorites->get_item_count() - 1) {
|
2015-06-06 14:44:38 +02:00
|
|
|
Vector<String> favorited = EditorSettings::get_singleton()->get_favorite_dirs();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
int a_idx = favorited.find(String(favorites->get_item_metadata(current + 1)));
|
|
|
|
int b_idx = favorited.find(String(favorites->get_item_metadata(current)));
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (a_idx == -1 || b_idx == -1)
|
2015-06-06 14:44:38 +02:00
|
|
|
return;
|
2017-03-19 00:36:26 +01:00
|
|
|
SWAP(favorited[a_idx], favorited[b_idx]);
|
2015-06-06 14:44:38 +02:00
|
|
|
|
|
|
|
EditorSettings::get_singleton()->set_favorite_dirs(favorited);
|
|
|
|
|
|
|
|
_update_favorites();
|
|
|
|
update_file_list();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::_update_favorites() {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool res = access == ACCESS_RESOURCES;
|
2015-06-06 14:44:38 +02:00
|
|
|
|
|
|
|
String current = get_current_dir();
|
2017-03-19 00:36:26 +01:00
|
|
|
Ref<Texture> star = get_icon("Favorites", "EditorIcons");
|
2015-06-06 14:44:38 +02:00
|
|
|
favorites->clear();
|
|
|
|
|
|
|
|
favorite->set_pressed(false);
|
|
|
|
|
|
|
|
Vector<String> favorited = EditorSettings::get_singleton()->get_favorite_dirs();
|
2017-03-19 00:36:26 +01:00
|
|
|
for (int i = 0; i < favorited.size(); i++) {
|
2015-06-06 14:44:38 +02:00
|
|
|
bool cres = favorited[i].begins_with("res://");
|
2017-03-19 00:36:26 +01:00
|
|
|
if (cres != res)
|
2015-06-06 14:44:38 +02:00
|
|
|
continue;
|
|
|
|
String name = favorited[i];
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool setthis = name == current;
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (res && name == "res://") {
|
|
|
|
name = "/";
|
2015-06-06 14:44:38 +02:00
|
|
|
} else {
|
2017-03-19 00:36:26 +01:00
|
|
|
name = name.get_file() + "/";
|
2015-06-06 14:44:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//print_line("file: "+name);
|
2017-03-19 00:36:26 +01:00
|
|
|
favorites->add_item(name, star);
|
|
|
|
favorites->set_item_metadata(favorites->get_item_count() - 1, favorited[i]);
|
2015-06-06 14:44:38 +02:00
|
|
|
|
|
|
|
if (setthis) {
|
|
|
|
favorite->set_pressed(true);
|
2017-03-19 00:36:26 +01:00
|
|
|
favorites->set_current(favorites->get_item_count() - 1);
|
2015-06-06 14:44:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::_favorite_toggled(bool p_toggle) {
|
2017-03-19 00:36:26 +01:00
|
|
|
bool res = access == ACCESS_RESOURCES;
|
2015-06-06 14:44:38 +02:00
|
|
|
|
|
|
|
String cd = get_current_dir();
|
|
|
|
|
|
|
|
Vector<String> favorited = EditorSettings::get_singleton()->get_favorite_dirs();
|
|
|
|
|
|
|
|
bool found = false;
|
2017-03-19 00:36:26 +01:00
|
|
|
for (int i = 0; i < favorited.size(); i++) {
|
2015-06-06 14:44:38 +02:00
|
|
|
bool cres = favorited[i].begins_with("res://");
|
2017-03-19 00:36:26 +01:00
|
|
|
if (cres != res)
|
2015-06-06 14:44:38 +02:00
|
|
|
continue;
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (favorited[i] == cd) {
|
|
|
|
found = true;
|
2015-06-06 14:44:38 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) {
|
|
|
|
favorited.erase(cd);
|
|
|
|
favorite->set_pressed(false);
|
|
|
|
} else {
|
|
|
|
favorited.push_back(cd);
|
|
|
|
favorite->set_pressed(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorSettings::get_singleton()->set_favorite_dirs(favorited);
|
|
|
|
|
|
|
|
_update_favorites();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::_recent_selected(int p_idx) {
|
|
|
|
|
|
|
|
Vector<String> recentd = EditorSettings::get_singleton()->get_recent_dirs();
|
2017-03-19 00:36:26 +01:00
|
|
|
ERR_FAIL_INDEX(p_idx, recentd.size());
|
2015-06-06 14:44:38 +02:00
|
|
|
|
|
|
|
dir_access->change_dir(recent->get_item_metadata(p_idx));
|
|
|
|
update_file_list();
|
|
|
|
update_dir();
|
|
|
|
_push_history();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::_go_up() {
|
|
|
|
|
|
|
|
dir_access->change_dir("..");
|
|
|
|
update_file_list();
|
|
|
|
update_dir();
|
|
|
|
_push_history();
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void EditorFileDialog::_go_back() {
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (local_history_pos <= 0) {
|
2015-06-06 14:44:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
local_history_pos--;
|
|
|
|
dir_access->change_dir(local_history[local_history_pos]);
|
|
|
|
update_file_list();
|
|
|
|
update_dir();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
dir_prev->set_disabled(local_history_pos == 0);
|
|
|
|
dir_next->set_disabled(local_history_pos == local_history.size() - 1);
|
2015-06-06 14:44:38 +02:00
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
void EditorFileDialog::_go_forward() {
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (local_history_pos == local_history.size() - 1) {
|
2015-06-06 14:44:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
local_history_pos++;
|
|
|
|
dir_access->change_dir(local_history[local_history_pos]);
|
|
|
|
update_file_list();
|
|
|
|
update_dir();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
dir_prev->set_disabled(local_history_pos == 0);
|
|
|
|
dir_next->set_disabled(local_history_pos == local_history.size() - 1);
|
2015-06-06 14:44:38 +02:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool EditorFileDialog::default_show_hidden_files = false;
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
EditorFileDialog::DisplayMode EditorFileDialog::default_display_mode = DISPLAY_THUMBNAILS;
|
2015-12-15 17:39:13 +01:00
|
|
|
|
2015-06-06 14:44:38 +02:00
|
|
|
void EditorFileDialog::set_display_mode(DisplayMode p_mode) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
if (display_mode == p_mode)
|
2015-06-06 14:44:38 +02:00
|
|
|
return;
|
2017-03-19 00:36:26 +01:00
|
|
|
if (p_mode == DISPLAY_THUMBNAILS) {
|
2015-06-06 14:44:38 +02:00
|
|
|
mode_list->set_pressed(false);
|
|
|
|
mode_thumbnails->set_pressed(true);
|
|
|
|
} else {
|
|
|
|
mode_thumbnails->set_pressed(false);
|
|
|
|
mode_list->set_pressed(true);
|
|
|
|
}
|
2017-03-19 00:36:26 +01:00
|
|
|
display_mode = p_mode;
|
2017-01-14 18:03:38 +01:00
|
|
|
invalidate();
|
2015-06-06 14:44:38 +02:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
EditorFileDialog::DisplayMode EditorFileDialog::get_display_mode() const {
|
2015-06-06 14:44:38 +02:00
|
|
|
|
|
|
|
return display_mode;
|
|
|
|
}
|
|
|
|
|
2015-05-31 06:59:42 +02:00
|
|
|
void EditorFileDialog::_bind_methods() {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("_unhandled_input"), &EditorFileDialog::_unhandled_input);
|
|
|
|
|
|
|
|
ObjectTypeDB::bind_method(_MD("_item_selected"), &EditorFileDialog::_item_selected);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_item_db_selected"), &EditorFileDialog::_item_dc_selected);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_dir_entered"), &EditorFileDialog::_dir_entered);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_file_entered"), &EditorFileDialog::_file_entered);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_action_pressed"), &EditorFileDialog::_action_pressed);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_cancel_pressed"), &EditorFileDialog::_cancel_pressed);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_filter_selected"), &EditorFileDialog::_filter_selected);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_save_confirm_pressed"), &EditorFileDialog::_save_confirm_pressed);
|
|
|
|
|
|
|
|
ObjectTypeDB::bind_method(_MD("clear_filters"), &EditorFileDialog::clear_filters);
|
|
|
|
ObjectTypeDB::bind_method(_MD("add_filter", "filter"), &EditorFileDialog::add_filter);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_current_dir"), &EditorFileDialog::get_current_dir);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_current_file"), &EditorFileDialog::get_current_file);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_current_path"), &EditorFileDialog::get_current_path);
|
|
|
|
ObjectTypeDB::bind_method(_MD("set_current_dir", "dir"), &EditorFileDialog::set_current_dir);
|
|
|
|
ObjectTypeDB::bind_method(_MD("set_current_file", "file"), &EditorFileDialog::set_current_file);
|
|
|
|
ObjectTypeDB::bind_method(_MD("set_current_path", "path"), &EditorFileDialog::set_current_path);
|
|
|
|
ObjectTypeDB::bind_method(_MD("set_mode", "mode"), &EditorFileDialog::set_mode);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_mode"), &EditorFileDialog::get_mode);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_vbox:VBoxContainer"), &EditorFileDialog::get_vbox);
|
|
|
|
ObjectTypeDB::bind_method(_MD("set_access", "access"), &EditorFileDialog::set_access);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_access"), &EditorFileDialog::get_access);
|
|
|
|
ObjectTypeDB::bind_method(_MD("set_show_hidden_files", "show"), &EditorFileDialog::set_show_hidden_files);
|
|
|
|
ObjectTypeDB::bind_method(_MD("is_showing_hidden_files"), &EditorFileDialog::is_showing_hidden_files);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_select_drive"), &EditorFileDialog::_select_drive);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_make_dir"), &EditorFileDialog::_make_dir);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_make_dir_confirm"), &EditorFileDialog::_make_dir_confirm);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_update_file_list"), &EditorFileDialog::update_file_list);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_update_dir"), &EditorFileDialog::update_dir);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_thumbnail_done"), &EditorFileDialog::_thumbnail_done);
|
|
|
|
ObjectTypeDB::bind_method(_MD("set_display_mode", "mode"), &EditorFileDialog::set_display_mode);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_display_mode"), &EditorFileDialog::get_display_mode);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_thumbnail_result"), &EditorFileDialog::_thumbnail_result);
|
|
|
|
ObjectTypeDB::bind_method(_MD("set_disable_overwrite_warning", "disable"), &EditorFileDialog::set_disable_overwrite_warning);
|
|
|
|
ObjectTypeDB::bind_method(_MD("is_overwrite_warning_disabled"), &EditorFileDialog::is_overwrite_warning_disabled);
|
|
|
|
|
|
|
|
ObjectTypeDB::bind_method(_MD("_recent_selected"), &EditorFileDialog::_recent_selected);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_go_back"), &EditorFileDialog::_go_back);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_go_forward"), &EditorFileDialog::_go_forward);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_go_up"), &EditorFileDialog::_go_up);
|
|
|
|
|
|
|
|
ObjectTypeDB::bind_method(_MD("_favorite_toggled"), &EditorFileDialog::_favorite_toggled);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_favorite_selected"), &EditorFileDialog::_favorite_selected);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_favorite_move_up"), &EditorFileDialog::_favorite_move_up);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_favorite_move_down"), &EditorFileDialog::_favorite_move_down);
|
|
|
|
|
|
|
|
ObjectTypeDB::bind_method(_MD("invalidate"), &EditorFileDialog::invalidate);
|
|
|
|
|
|
|
|
ADD_SIGNAL(MethodInfo("file_selected", PropertyInfo(Variant::STRING, "path")));
|
|
|
|
ADD_SIGNAL(MethodInfo("files_selected", PropertyInfo(Variant::STRING_ARRAY, "paths")));
|
|
|
|
ADD_SIGNAL(MethodInfo("dir_selected", PropertyInfo(Variant::STRING, "dir")));
|
|
|
|
|
|
|
|
BIND_CONSTANT(MODE_OPEN_FILE);
|
|
|
|
BIND_CONSTANT(MODE_OPEN_FILES);
|
|
|
|
BIND_CONSTANT(MODE_OPEN_DIR);
|
|
|
|
BIND_CONSTANT(MODE_OPEN_ANY);
|
|
|
|
BIND_CONSTANT(MODE_SAVE_FILE);
|
|
|
|
|
|
|
|
BIND_CONSTANT(ACCESS_RESOURCES);
|
|
|
|
BIND_CONSTANT(ACCESS_USERDATA);
|
|
|
|
BIND_CONSTANT(ACCESS_FILESYSTEM);
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::set_show_hidden_files(bool p_show) {
|
2017-03-19 00:36:26 +01:00
|
|
|
show_hidden_files = p_show;
|
2015-05-31 06:59:42 +02:00
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EditorFileDialog::is_showing_hidden_files() const {
|
|
|
|
return show_hidden_files;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorFileDialog::set_default_show_hidden_files(bool p_show) {
|
2017-03-19 00:36:26 +01:00
|
|
|
default_show_hidden_files = p_show;
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
|
2015-12-15 17:39:13 +01:00
|
|
|
void EditorFileDialog::set_default_display_mode(DisplayMode p_mode) {
|
2017-03-19 00:36:26 +01:00
|
|
|
default_display_mode = p_mode;
|
2015-12-15 17:39:13 +01:00
|
|
|
}
|
|
|
|
|
2015-06-06 14:44:38 +02:00
|
|
|
void EditorFileDialog::_save_to_recent() {
|
|
|
|
|
|
|
|
String dir = get_current_dir();
|
|
|
|
Vector<String> recent = EditorSettings::get_singleton()->get_recent_dirs();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
const int max = 20;
|
|
|
|
int count = 0;
|
|
|
|
bool res = dir.begins_with("res://");
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
for (int i = 0; i < recent.size(); i++) {
|
|
|
|
bool cres = recent[i].begins_with("res://");
|
|
|
|
if (recent[i] == dir || (res == cres && count > max)) {
|
2015-06-06 14:44:38 +02:00
|
|
|
recent.remove(i);
|
|
|
|
i--;
|
|
|
|
} else {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
recent.insert(0, dir);
|
2015-06-06 14:44:38 +02:00
|
|
|
|
|
|
|
EditorSettings::get_singleton()->set_recent_dirs(recent);
|
|
|
|
}
|
|
|
|
|
2016-06-20 05:38:13 +02:00
|
|
|
void EditorFileDialog::set_disable_overwrite_warning(bool p_disable) {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
disable_overwrite_warning = p_disable;
|
2016-06-20 05:38:13 +02:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
bool EditorFileDialog::is_overwrite_warning_disabled() const {
|
2016-06-20 05:38:13 +02:00
|
|
|
|
|
|
|
return disable_overwrite_warning;
|
|
|
|
}
|
|
|
|
|
2015-05-31 06:59:42 +02:00
|
|
|
EditorFileDialog::EditorFileDialog() {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
show_hidden_files = default_show_hidden_files;
|
|
|
|
display_mode = default_display_mode;
|
|
|
|
local_history_pos = 0;
|
|
|
|
disable_overwrite_warning = false;
|
|
|
|
VBoxContainer *vbc = memnew(VBoxContainer);
|
2015-05-31 06:59:42 +02:00
|
|
|
add_child(vbc);
|
|
|
|
set_child_rect(vbc);
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
mode = MODE_SAVE_FILE;
|
2016-05-04 03:25:37 +02:00
|
|
|
set_title(TTR("Save a File"));
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ED_SHORTCUT("file_dialog/go_back", TTR("Go Back"), KEY_MASK_ALT | KEY_LEFT);
|
|
|
|
ED_SHORTCUT("file_dialog/go_forward", TTR("Go Forward"), KEY_MASK_ALT | KEY_RIGHT);
|
|
|
|
ED_SHORTCUT("file_dialog/go_up", TTR("Go Up"), KEY_MASK_ALT | KEY_UP);
|
2016-06-28 16:12:07 +02:00
|
|
|
ED_SHORTCUT("file_dialog/refresh", TTR("Refresh"), KEY_F5);
|
2017-03-19 00:36:26 +01:00
|
|
|
ED_SHORTCUT("file_dialog/toggle_hidden_files", TTR("Toggle Hidden Files"), KEY_MASK_CMD | KEY_H);
|
|
|
|
ED_SHORTCUT("file_dialog/toggle_favorite", TTR("Toggle Favorite"), KEY_MASK_ALT | KEY_F);
|
|
|
|
ED_SHORTCUT("file_dialog/toggle_mode", TTR("Toggle Mode"), KEY_MASK_ALT | KEY_V);
|
|
|
|
ED_SHORTCUT("file_dialog/create_folder", TTR("Create Folder"), KEY_MASK_CMD | KEY_N);
|
|
|
|
ED_SHORTCUT("file_dialog/focus_path", TTR("Focus Path"), KEY_MASK_CMD | KEY_D);
|
|
|
|
ED_SHORTCUT("file_dialog/move_favorite_up", TTR("Move Favorite Up"), KEY_MASK_CMD | KEY_UP);
|
|
|
|
ED_SHORTCUT("file_dialog/move_favorite_down", TTR("Move Favorite Down"), KEY_MASK_CMD | KEY_DOWN);
|
2016-06-18 19:32:04 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
HBoxContainer *pathhb = memnew(HBoxContainer);
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
dir_prev = memnew(ToolButton);
|
|
|
|
dir_next = memnew(ToolButton);
|
|
|
|
dir_up = memnew(ToolButton);
|
2015-06-06 14:44:38 +02:00
|
|
|
|
|
|
|
pathhb->add_child(dir_prev);
|
|
|
|
pathhb->add_child(dir_next);
|
|
|
|
pathhb->add_child(dir_up);
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
dir_prev->connect("pressed", this, "_go_back");
|
|
|
|
dir_next->connect("pressed", this, "_go_forward");
|
|
|
|
dir_up->connect("pressed", this, "_go_up");
|
2015-06-06 14:44:38 +02:00
|
|
|
|
|
|
|
dir = memnew(LineEdit);
|
2015-05-31 06:59:42 +02:00
|
|
|
pathhb->add_child(dir);
|
|
|
|
dir->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
refresh = memnew(ToolButton);
|
|
|
|
refresh->connect("pressed", this, "_update_file_list");
|
2015-12-04 19:33:30 +01:00
|
|
|
pathhb->add_child(refresh);
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
favorite = memnew(ToolButton);
|
2015-06-06 14:44:38 +02:00
|
|
|
favorite->set_toggle_mode(true);
|
2017-03-19 00:36:26 +01:00
|
|
|
favorite->connect("toggled", this, "_favorite_toggled");
|
2015-06-06 14:44:38 +02:00
|
|
|
pathhb->add_child(favorite);
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
mode_thumbnails = memnew(ToolButton);
|
|
|
|
mode_thumbnails->connect("pressed", this, "set_display_mode", varray(DISPLAY_THUMBNAILS));
|
2015-06-06 14:44:38 +02:00
|
|
|
mode_thumbnails->set_toggle_mode(true);
|
2017-03-19 00:36:26 +01:00
|
|
|
mode_thumbnails->set_pressed(display_mode == DISPLAY_THUMBNAILS);
|
2015-06-06 14:44:38 +02:00
|
|
|
pathhb->add_child(mode_thumbnails);
|
2015-12-15 17:39:13 +01:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
mode_list = memnew(ToolButton);
|
|
|
|
mode_list->connect("pressed", this, "set_display_mode", varray(DISPLAY_LIST));
|
2015-06-06 14:44:38 +02:00
|
|
|
mode_list->set_toggle_mode(true);
|
2017-03-19 00:36:26 +01:00
|
|
|
mode_list->set_pressed(display_mode == DISPLAY_LIST);
|
2015-06-06 14:44:38 +02:00
|
|
|
pathhb->add_child(mode_list);
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
drives = memnew(OptionButton);
|
2015-05-31 06:59:42 +02:00
|
|
|
pathhb->add_child(drives);
|
2017-03-19 00:36:26 +01:00
|
|
|
drives->connect("item_selected", this, "_select_drive");
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
makedir = memnew(Button);
|
2016-05-04 03:25:37 +02:00
|
|
|
makedir->set_text(TTR("Create Folder"));
|
2017-03-19 00:36:26 +01:00
|
|
|
makedir->connect("pressed", this, "_make_dir");
|
2015-05-31 06:59:42 +02:00
|
|
|
pathhb->add_child(makedir);
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
list_hb = memnew(HBoxContainer);
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
vbc->add_margin_child(TTR("Path:"), pathhb);
|
2015-06-06 14:44:38 +02:00
|
|
|
vbc->add_child(list_hb);
|
|
|
|
list_hb->set_v_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
VBoxContainer *fav_vb = memnew(VBoxContainer);
|
2015-06-06 14:44:38 +02:00
|
|
|
list_hb->add_child(fav_vb);
|
2017-03-19 00:36:26 +01:00
|
|
|
HBoxContainer *fav_hb = memnew(HBoxContainer);
|
2015-06-06 14:44:38 +02:00
|
|
|
fav_vb->add_child(fav_hb);
|
2016-05-04 03:25:37 +02:00
|
|
|
fav_hb->add_child(memnew(Label(TTR("Favorites:"))));
|
2015-06-06 14:44:38 +02:00
|
|
|
fav_hb->add_spacer();
|
2017-03-19 00:36:26 +01:00
|
|
|
fav_up = memnew(ToolButton);
|
2015-06-06 14:44:38 +02:00
|
|
|
fav_hb->add_child(fav_up);
|
2017-03-19 00:36:26 +01:00
|
|
|
fav_up->connect("pressed", this, "_favorite_move_up");
|
|
|
|
fav_down = memnew(ToolButton);
|
2015-06-06 14:44:38 +02:00
|
|
|
fav_hb->add_child(fav_down);
|
2017-03-19 00:36:26 +01:00
|
|
|
fav_down->connect("pressed", this, "_favorite_move_down");
|
|
|
|
fav_rm = memnew(ToolButton);
|
2015-06-06 14:44:38 +02:00
|
|
|
fav_hb->add_child(fav_rm);
|
|
|
|
fav_rm->hide(); // redundant
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
MarginContainer *fav_mv = memnew(MarginContainer);
|
2015-06-06 14:44:38 +02:00
|
|
|
fav_vb->add_child(fav_mv);
|
|
|
|
fav_mv->set_v_size_flags(SIZE_EXPAND_FILL);
|
2017-03-19 00:36:26 +01:00
|
|
|
favorites = memnew(ItemList);
|
2015-06-06 14:44:38 +02:00
|
|
|
fav_mv->add_child(favorites);
|
2017-03-19 00:36:26 +01:00
|
|
|
favorites->connect("item_selected", this, "_favorite_selected");
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
recent = memnew(ItemList);
|
|
|
|
fav_vb->add_margin_child(TTR("Recent:"), recent, true);
|
|
|
|
recent->connect("item_selected", this, "_recent_selected");
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
VBoxContainer *item_vb = memnew(VBoxContainer);
|
2015-06-06 14:44:38 +02:00
|
|
|
list_hb->add_child(item_vb);
|
|
|
|
item_vb->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
item_list = memnew(ItemList);
|
2015-06-06 14:44:38 +02:00
|
|
|
item_list->set_v_size_flags(SIZE_EXPAND_FILL);
|
2017-03-19 00:36:26 +01:00
|
|
|
item_vb->add_margin_child(TTR("Directories & Files:"), item_list, true);
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
HBoxContainer *filter_hb = memnew(HBoxContainer);
|
2015-06-06 14:44:38 +02:00
|
|
|
item_vb->add_child(filter_hb);
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
VBoxContainer *filter_vb = memnew(VBoxContainer);
|
2015-05-31 06:59:42 +02:00
|
|
|
filter_hb->add_child(filter_vb);
|
|
|
|
filter_vb->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
preview_vb = memnew(VBoxContainer);
|
2015-05-31 06:59:42 +02:00
|
|
|
filter_hb->add_child(preview_vb);
|
2017-03-19 00:36:26 +01:00
|
|
|
CenterContainer *prev_cc = memnew(CenterContainer);
|
|
|
|
preview_vb->add_margin_child(TTR("Preview:"), prev_cc);
|
|
|
|
preview = memnew(TextureFrame);
|
2015-05-31 06:59:42 +02:00
|
|
|
prev_cc->add_child(preview);
|
|
|
|
preview_vb->hide();
|
|
|
|
|
|
|
|
file = memnew(LineEdit);
|
|
|
|
//add_child(file);
|
2017-03-19 00:36:26 +01:00
|
|
|
filter_vb->add_margin_child(TTR("File:"), file);
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
filter = memnew(OptionButton);
|
2015-05-31 06:59:42 +02:00
|
|
|
//add_child(filter);
|
2017-03-19 00:36:26 +01:00
|
|
|
filter_vb->add_margin_child(TTR("Filter:"), filter);
|
|
|
|
filter->set_clip_text(true); //too many extensions overflow it
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
2017-03-19 00:36:26 +01:00
|
|
|
access = ACCESS_RESOURCES;
|
2015-05-31 06:59:42 +02:00
|
|
|
_update_drives();
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
connect("confirmed", this, "_action_pressed");
|
2015-05-31 06:59:42 +02:00
|
|
|
//cancel->connect("pressed", this,"_cancel_pressed");
|
2017-03-19 00:36:26 +01:00
|
|
|
item_list->connect("item_selected", this, "_item_selected", varray(), CONNECT_DEFERRED);
|
|
|
|
item_list->connect("item_activated", this, "_item_db_selected", varray());
|
|
|
|
dir->connect("text_entered", this, "_dir_entered");
|
|
|
|
file->connect("text_entered", this, "_file_entered");
|
|
|
|
filter->connect("item_selected", this, "_filter_selected");
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
confirm_save = memnew(ConfirmationDialog);
|
2015-05-31 06:59:42 +02:00
|
|
|
confirm_save->set_as_toplevel(true);
|
|
|
|
add_child(confirm_save);
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
confirm_save->connect("confirmed", this, "_save_confirm_pressed");
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
makedialog = memnew(ConfirmationDialog);
|
2016-05-04 03:25:37 +02:00
|
|
|
makedialog->set_title(TTR("Create Folder"));
|
2017-03-19 00:36:26 +01:00
|
|
|
VBoxContainer *makevb = memnew(VBoxContainer);
|
2015-05-31 06:59:42 +02:00
|
|
|
makedialog->add_child(makevb);
|
|
|
|
makedialog->set_child_rect(makevb);
|
2017-03-19 00:36:26 +01:00
|
|
|
makedirname = memnew(LineEdit);
|
|
|
|
makevb->add_margin_child(TTR("Name:"), makedirname);
|
2015-05-31 06:59:42 +02:00
|
|
|
add_child(makedialog);
|
|
|
|
makedialog->register_text_enter(makedirname);
|
2017-03-19 00:36:26 +01:00
|
|
|
makedialog->connect("confirmed", this, "_make_dir_confirm");
|
|
|
|
mkdirerr = memnew(AcceptDialog);
|
2016-05-04 03:25:37 +02:00
|
|
|
mkdirerr->set_text(TTR("Could not create folder."));
|
2015-05-31 06:59:42 +02:00
|
|
|
add_child(mkdirerr);
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
exterr = memnew(AcceptDialog);
|
2016-05-04 03:25:37 +02:00
|
|
|
exterr->set_text(TTR("Must use a valid extension."));
|
2015-05-31 06:59:42 +02:00
|
|
|
add_child(exterr);
|
|
|
|
|
|
|
|
//update_file_list();
|
|
|
|
update_filters();
|
|
|
|
update_dir();
|
|
|
|
|
|
|
|
set_hide_on_ok(false);
|
2017-03-19 00:36:26 +01:00
|
|
|
vbox = vbc;
|
2015-05-31 06:59:42 +02:00
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
invalidated = true;
|
2015-05-31 06:59:42 +02:00
|
|
|
if (register_func)
|
|
|
|
register_func(this);
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
preview_wheel_timeout = 0;
|
|
|
|
preview_wheel_index = 0;
|
|
|
|
preview_waiting = false;
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
EditorFileDialog::~EditorFileDialog() {
|
|
|
|
|
|
|
|
if (unregister_func)
|
|
|
|
unregister_func(this);
|
|
|
|
memdelete(dir_access);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditorLineEditFileChooser::_bind_methods() {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
ObjectTypeDB::bind_method(_MD("_browse"), &EditorLineEditFileChooser::_browse);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_chosen"), &EditorLineEditFileChooser::_chosen);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_button:Button"), &EditorLineEditFileChooser::get_button);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_line_edit:LineEdit"), &EditorLineEditFileChooser::get_line_edit);
|
|
|
|
ObjectTypeDB::bind_method(_MD("get_file_dialog:EditorFileDialog"), &EditorLineEditFileChooser::get_file_dialog);
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
void EditorLineEditFileChooser::_chosen(const String &p_text) {
|
2015-05-31 06:59:42 +02:00
|
|
|
|
|
|
|
line_edit->set_text(p_text);
|
2017-03-19 00:36:26 +01:00
|
|
|
line_edit->emit_signal("text_entered", p_text);
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditorLineEditFileChooser::_browse() {
|
|
|
|
|
|
|
|
dialog->popup_centered_ratio();
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorLineEditFileChooser::EditorLineEditFileChooser() {
|
|
|
|
|
2017-03-19 00:36:26 +01:00
|
|
|
line_edit = memnew(LineEdit);
|
2015-05-31 06:59:42 +02:00
|
|
|
add_child(line_edit);
|
|
|
|
line_edit->set_h_size_flags(SIZE_EXPAND_FILL);
|
2017-03-19 00:36:26 +01:00
|
|
|
button = memnew(Button);
|
2015-05-31 06:59:42 +02:00
|
|
|
button->set_text(" .. ");
|
|
|
|
add_child(button);
|
2017-03-19 00:36:26 +01:00
|
|
|
button->connect("pressed", this, "_browse");
|
|
|
|
dialog = memnew(EditorFileDialog);
|
2015-05-31 06:59:42 +02:00
|
|
|
add_child(dialog);
|
2017-03-19 00:36:26 +01:00
|
|
|
dialog->connect("file_selected", this, "_chosen");
|
|
|
|
dialog->connect("dir_selected", this, "_chosen");
|
|
|
|
dialog->connect("files_selected", this, "_chosen");
|
2015-05-31 06:59:42 +02:00
|
|
|
}
|