Create function focus_file_text

This function focuses the text field when saving a file
It is called when the save file dialogue is opened
This commit is contained in:
Ger Hean 2022-01-03 17:08:03 +08:00
parent b6bdbd2650
commit 9dbe314da6
4 changed files with 26 additions and 12 deletions

View file

@ -52,6 +52,15 @@ EditorFileDialog::RegisterFunc EditorFileDialog::unregister_func = nullptr;
void EditorFileDialog::popup_file_dialog() { void EditorFileDialog::popup_file_dialog() {
popup_centered_clamped(Size2(1050, 700) * EDSCALE, 0.8); popup_centered_clamped(Size2(1050, 700) * EDSCALE, 0.8);
_focus_file_text();
}
void EditorFileDialog::_focus_file_text() {
int lp = file->get_text().rfind(".");
if (lp != -1) {
file->select(0, lp);
file->grab_focus();
}
} }
VBoxContainer *EditorFileDialog::get_vbox() { VBoxContainer *EditorFileDialog::get_vbox() {
@ -974,11 +983,7 @@ void EditorFileDialog::set_current_file(const String &p_file) {
file->set_text(p_file); file->set_text(p_file);
update_dir(); update_dir();
invalidate(); invalidate();
int lp = p_file.rfind("."); _focus_file_text();
if (lp != -1) {
file->select(0, lp);
file->grab_focus();
}
if (is_visible()) { if (is_visible()) {
_request_single_thumbnail(get_current_dir().plus_file(get_current_file())); _request_single_thumbnail(get_current_dir().plus_file(get_current_file()));

View file

@ -149,6 +149,8 @@ private:
void update_file_list(); void update_file_list();
void update_filters(); void update_filters();
void _focus_file_text();
void _update_favorites(); void _update_favorites();
void _favorite_pressed(); void _favorite_pressed();
void _favorite_selected(int p_idx); void _favorite_selected(int p_idx);

View file

@ -42,6 +42,17 @@ FileDialog::RegisterFunc FileDialog::unregister_func = nullptr;
void FileDialog::popup_file_dialog() { void FileDialog::popup_file_dialog() {
popup_centered_clamped(Size2i(700, 500), 0.8f); popup_centered_clamped(Size2i(700, 500), 0.8f);
_focus_file_text();
}
void FileDialog::_focus_file_text() {
int lp = file->get_text().rfind(".");
if (lp != -1) {
file->select(0, lp);
if (file->is_inside_tree() && !get_tree()->is_node_being_edited(file)) {
file->grab_focus();
}
}
} }
VBoxContainer *FileDialog::get_vbox() { VBoxContainer *FileDialog::get_vbox() {
@ -688,13 +699,7 @@ void FileDialog::set_current_file(const String &p_file) {
file->set_text(p_file); file->set_text(p_file);
update_dir(); update_dir();
invalidate(); invalidate();
int lp = p_file.rfind("."); _focus_file_text();
if (lp != -1) {
file->select(0, lp);
if (file->is_inside_tree() && !get_tree()->is_node_being_edited(file)) {
file->grab_focus();
}
}
} }
void FileDialog::set_current_path(const String &p_path) { void FileDialog::set_current_path(const String &p_path) {

View file

@ -113,6 +113,8 @@ private:
void update_file_list(); void update_file_list();
void update_filters(); void update_filters();
void _focus_file_text();
void _tree_multi_selected(Object *p_object, int p_cell, bool p_selected); void _tree_multi_selected(Object *p_object, int p_cell, bool p_selected);
void _tree_selected(); void _tree_selected();