Enhance editor file dialog
1. show valid directory path when opening editor file dialog
2. keep file name when changing path by entering path
3. add first extension in filter automatically if not given
4. remove directory in recent list if it's not valid anymore
(cherry picked from commit 1f4b1e1488
)
This commit is contained in:
parent
650f7c6f35
commit
bd3c2e96c3
3 changed files with 28 additions and 18 deletions
|
@ -222,7 +222,6 @@ void EditorFileDialog::update_dir() {
|
|||
void EditorFileDialog::_dir_entered(String p_dir) {
|
||||
|
||||
dir_access->change_dir(p_dir);
|
||||
file->set_text("");
|
||||
invalidate();
|
||||
update_dir();
|
||||
_push_history();
|
||||
|
@ -244,6 +243,14 @@ void EditorFileDialog::_save_confirm_pressed() {
|
|||
void EditorFileDialog::_post_popup() {
|
||||
|
||||
ConfirmationDialog::_post_popup();
|
||||
|
||||
// Check if the current path doesn't exist and correct it.
|
||||
String current = dir_access->get_current_dir();
|
||||
while (!dir_access->dir_exists(current)) {
|
||||
current = current.get_base_dir();
|
||||
}
|
||||
set_current_dir(current);
|
||||
|
||||
if (invalidated) {
|
||||
update_file_list();
|
||||
invalidated = false;
|
||||
|
@ -279,11 +286,17 @@ void EditorFileDialog::_post_popup() {
|
|||
} else {
|
||||
name = name.get_file() + "/";
|
||||
}
|
||||
|
||||
recent->add_item(name, folder);
|
||||
recent->set_item_metadata(recent->get_item_count() - 1, recentd[i]);
|
||||
recent->set_item_icon_modulate(recent->get_item_count() - 1, folder_color);
|
||||
bool exists = dir_access->dir_exists(recentd[i]);
|
||||
if (!exists) {
|
||||
// Remove invalid directory from the list of Recent directories.
|
||||
recentd.remove(i--);
|
||||
} else {
|
||||
recent->add_item(name, folder);
|
||||
recent->set_item_metadata(recent->get_item_count() - 1, recentd[i]);
|
||||
recent->set_item_icon_modulate(recent->get_item_count() - 1, folder_color);
|
||||
}
|
||||
}
|
||||
EditorSettings::get_singleton()->set_recent_dirs(recentd);
|
||||
|
||||
local_history.clear();
|
||||
local_history_pos = -1;
|
||||
|
@ -441,10 +454,12 @@ void EditorFileDialog::_action_pressed() {
|
|||
}
|
||||
}
|
||||
|
||||
// Add first extension of filter if no valid extension is found.
|
||||
if (!valid) {
|
||||
|
||||
exterr->popup_centered_minsize(Size2(250, 80) * EDSCALE);
|
||||
return;
|
||||
int idx = filter->get_selected();
|
||||
String flt = filters[idx].get_slice(";", 0);
|
||||
String ext = flt.get_slice(",", 0).strip_edges().get_extension();
|
||||
f += "." + ext;
|
||||
}
|
||||
|
||||
if (dir_access->file_exists(f) && !disable_overwrite_warning) {
|
||||
|
@ -1735,10 +1750,6 @@ EditorFileDialog::EditorFileDialog() {
|
|||
mkdirerr->set_text(TTR("Could not create folder."));
|
||||
add_child(mkdirerr);
|
||||
|
||||
exterr = memnew(AcceptDialog);
|
||||
exterr->set_text(TTR("Must use a valid extension."));
|
||||
add_child(exterr);
|
||||
|
||||
update_filters();
|
||||
update_dir();
|
||||
|
||||
|
|
|
@ -112,7 +112,6 @@ private:
|
|||
LineEdit *file;
|
||||
OptionButton *filter;
|
||||
AcceptDialog *mkdirerr;
|
||||
AcceptDialog *exterr;
|
||||
DirAccess *dir_access;
|
||||
ConfirmationDialog *confirm_save;
|
||||
DependencyRemoveDialog *remove_dialog;
|
||||
|
|
|
@ -2280,8 +2280,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
|
|||
int scene_idx = (p_option == FILE_SAVE_SCENE) ? -1 : tab_closing;
|
||||
|
||||
Node *scene = editor_data.get_edited_scene_root(scene_idx);
|
||||
if (scene && scene->get_filename() != "") {
|
||||
|
||||
if (scene && scene->get_filename() != "" && FileAccess::exists(scene->get_filename())) {
|
||||
if (scene_idx != editor_data.get_edited_scene())
|
||||
_save_scene_with_preview(scene->get_filename(), scene_idx);
|
||||
else
|
||||
|
@ -2326,11 +2325,12 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
|
|||
}
|
||||
|
||||
if (scene->get_filename() != "") {
|
||||
file->set_current_path(scene->get_filename());
|
||||
String path = scene->get_filename();
|
||||
file->set_current_path(path);
|
||||
if (extensions.size()) {
|
||||
String ext = scene->get_filename().get_extension().to_lower();
|
||||
String ext = path.get_extension().to_lower();
|
||||
if (extensions.find(ext) == NULL) {
|
||||
file->set_current_path(scene->get_filename().replacen("." + ext, "." + extensions.front()->get()));
|
||||
file->set_current_path(path.replacen("." + ext, "." + extensions.front()->get()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue