Skip to content

Commit

Permalink
Add LineEdit focus_edit state
Browse files Browse the repository at this point in the history
  • Loading branch information
WhalesState committed Jan 29, 2024
1 parent e83525d commit 31993c5
Show file tree
Hide file tree
Showing 46 changed files with 276 additions and 198 deletions.
27 changes: 27 additions & 0 deletions doc/classes/LineEdit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@
Returns the selection end column.
</description>
</method>
<method name="grab_focus_edit">
<return type="void" />
<param index="0" name="select_all" type="bool" default="false" />
<description>
Focus the [LineEdit] in edit mode.
If [param select_all] is [code]true[/code], it will select all [member text] and move the caret to it's length.
</description>
</method>
<method name="has_selection" qualifiers="const">
<return type="bool" />
<description>
Expand All @@ -139,6 +147,12 @@
Inserts [param text] at the caret. If the resulting value is longer than [member max_length], nothing happens.
</description>
</method>
<method name="is_focus_edit" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code] if the [LineEdit] is in focus edit mode.
</description>
</method>
<method name="is_menu_visible" qualifiers="const">
<return type="bool" />
<description>
Expand Down Expand Up @@ -180,6 +194,13 @@
Selects the whole [String].
</description>
</method>
<method name="set_focus_edit">
<return type="void" />
<param index="0" name="focus_edit" type="bool" />
<description>
Toggles focus edit mode, if [member editable] is [code]false[/code] it will just focus the [LineEdit].
</description>
</method>
</methods>
<members>
<member name="alignment" type="int" setter="set_horizontal_alignment" getter="get_horizontal_alignment" enum="HorizontalAlignment" default="0">
Expand Down Expand Up @@ -301,6 +322,12 @@
</member>
</members>
<signals>
<signal name="focus_edit_toggled">
<param index="0" name="toggled_on" type="bool" />
<description>
Emitted when is focused and switches between focus and focus edit.
</description>
</signal>
<signal name="text_change_rejected">
<param index="0" name="rejected_substring" type="String" />
<description>
Expand Down
4 changes: 2 additions & 2 deletions editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2805,7 +2805,7 @@ void AnimationTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
path_popup->set_position(get_screen_position() + path_rect.position - theme_ofs);
path_popup->set_size(path_rect.size);
path_popup->popup();
path->grab_focus();
path->grab_focus_edit();
path->set_caret_column(path->get_text().length());
clicking_on_name = false;
}
Expand Down Expand Up @@ -4668,7 +4668,7 @@ void AnimationTrackEditor::_add_track(int p_type) {
adding_track_type = p_type;
pick_track->popup_scenetree_dialog();
pick_track->get_filter_line_edit()->clear();
pick_track->get_filter_line_edit()->grab_focus();
pick_track->get_filter_line_edit()->grab_focus_edit();
}

void AnimationTrackEditor::_new_track_property_selected(String p_name) {
Expand Down
7 changes: 3 additions & 4 deletions editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ void GotoLineDialog::popup_find_line(CodeEdit *p_edit) {

// Add 1 because text_editor->get_caret_line() starts from 0, but the editor user interface starts from 1.
line->set_text(itos(text_editor->get_caret_line() + 1));
line->select_all();
popup_centered(Size2(180, 80) * EDSCALE);
line->grab_focus();
line->grab_focus_edit(true);
}

int GotoLineDialog::get_line() const {
Expand Down Expand Up @@ -517,10 +516,10 @@ void FindReplaceBar::_show_search(bool p_focus_replace, bool p_show_only) {

if (p_focus_replace) {
search_text->deselect();
replace_text->call_deferred(SNAME("grab_focus"));
replace_text->call_deferred(SNAME("grab_focus_edit"));
} else {
replace_text->deselect();
search_text->call_deferred(SNAME("grab_focus"));
search_text->call_deferred(SNAME("grab_focus_edit"));
}

if (text_editor->has_selection(0) && !is_selection_only()) {
Expand Down
2 changes: 1 addition & 1 deletion editor/connections_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ void ConnectDialog::_method_check_button_pressed(const CheckButton *p_button) {
void ConnectDialog::_open_method_popup() {
method_popup->popup_centered();
method_search->clear();
method_search->grab_focus();
method_search->grab_focus_edit();
}

/*
Expand Down
5 changes: 2 additions & 3 deletions editor/create_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void CreateDialog::popup_create(bool p_dont_clear, bool p_replace_mode, const St
search_box->set_text(p_current_type);
}

search_box->grab_focus();
search_box->grab_focus_edit();
_update_search();

if (p_replace_mode) {
Expand Down Expand Up @@ -474,8 +474,7 @@ void CreateDialog::_notification(int p_what) {

case NOTIFICATION_VISIBILITY_CHANGED: {
if (is_visible()) {
search_box->call_deferred(SNAME("grab_focus")); // still not visible
search_box->select_all();
search_box->call_deferred(SNAME("grab_focus_edit"), true); // still not visible
} else {
EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "create_new_node", Rect2(get_position(), get_size()));
}
Expand Down
2 changes: 1 addition & 1 deletion editor/directory_create_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void DirectoryCreateDialog::ok_pressed() {

void DirectoryCreateDialog::_post_popup() {
ConfirmationDialog::_post_popup();
dir_path->grab_focus();
dir_path->grab_focus_edit();
}

void DirectoryCreateDialog::config(const String &p_base_dir) {
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_command_palette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void EditorCommandPalette::open_popup() {
}

command_search_box->clear();
command_search_box->grab_focus();
command_search_box->grab_focus_edit();

search_options->scroll_to_item(search_options->get_root());
}
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_feature_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ void EditorFeatureProfileManager::_profile_action(int p_action) {
case PROFILE_NEW: {
new_profile_dialog->popup_centered(Size2(240, 60) * EDSCALE);
new_profile_name->clear();
new_profile_name->grab_focus();
new_profile_name->grab_focus_edit();
} break;
case PROFILE_ERASE: {
String selected = _get_selected_profile();
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2954,7 +2954,7 @@ void FindBar::popup_search() {
show();
bool grabbed_focus = false;
if (!search_text->has_focus()) {
search_text->grab_focus();
search_text->grab_focus_edit();
grabbed_focus = true;
}

Expand Down
2 changes: 1 addition & 1 deletion editor/editor_help_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void EditorHelpSearch::popup_dialog(const String &p_term) {
search_box->set_text(p_term);
search_box->select_all();
}
search_box->grab_focus();
search_box->grab_focus_edit();
_update_results();
}

Expand Down
5 changes: 2 additions & 3 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1646,8 +1646,7 @@ void EditorInspectorArray::_rmb_popup_id_pressed(int p_id) {
new_size_spin_box->set_value(count);
resize_dialog->get_ok_button()->set_disabled(true);
resize_dialog->popup_centered(Size2(250, 0) * EDSCALE);
new_size_spin_box->get_line_edit()->grab_focus();
new_size_spin_box->get_line_edit()->select_all();
new_size_spin_box->get_line_edit()->grab_focus_edit(true);
break;
default:
break;
Expand Down Expand Up @@ -4178,7 +4177,7 @@ void EditorInspector::_show_add_meta_dialog() {
}

add_meta_dialog->popup_centered();
add_meta_name->grab_focus();
add_meta_name->grab_focus_edit();
add_meta_name->set_text("");
validation_panel->update();
}
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_layouts_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void EditorLayoutsDialog::_post_popup() {
layout_names->add_item(E);
}
if (name->is_visible()) {
name->grab_focus();
name->grab_focus_edit();
} else {
layout_names->grab_focus();
}
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void EditorLog::_set_filter_active(bool p_active, MessageType p_message_type) {
void EditorLog::_set_search_visible(bool p_visible) {
search_box->set_visible(p_visible);
if (p_visible) {
search_box->grab_focus();
search_box->grab_focus_edit();
}
_start_state_save_timer();
}
Expand Down
6 changes: 2 additions & 4 deletions editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ void EditorPropertyText::_text_submitted(const String &p_string) {
}

if (text->has_focus()) {
text->release_focus();
_text_changed(p_string);
}
}
Expand Down Expand Up @@ -266,7 +265,7 @@ void EditorPropertyTextEnum::_option_selected(int p_which) {
void EditorPropertyTextEnum::_edit_custom_value() {
default_layout->hide();
edit_custom_layout->show();
custom_value_edit->grab_focus();
custom_value_edit->grab_focus_edit();
}

void EditorPropertyTextEnum::_custom_value_submitted(String p_value) {
Expand Down Expand Up @@ -815,9 +814,8 @@ void EditorPropertyLayersGrid::_rename_pressed(int p_menu) {
String name = names[renamed_layer_index];
rename_dialog->set_title(vformat(TTR("Renaming layer %d:"), renamed_layer_index + 1));
rename_dialog_text->set_text(name);
rename_dialog_text->select(0, name.length());
rename_dialog->popup_centered(Size2(300, 80) * EDSCALE);
rename_dialog_text->grab_focus();
rename_dialog_text->grab_focus_edit(true);
}

void EditorPropertyLayersGrid::_rename_operation_confirm() {
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_quick_open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void EditorQuickOpen::popup_dialog(const String &p_base, bool p_enable_multi, bo
} else {
search_box->clear(); // This will emit text_changed.
}
search_box->grab_focus();
search_box->grab_focus_edit();
}

void EditorQuickOpen::_build_search_cache(EditorFileSystemDirectory *p_efsd) {
Expand Down
6 changes: 2 additions & 4 deletions editor/editor_settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ void EditorSettingsDialog::popup_edit_settings() {
inspector->edit(EditorSettings::get_singleton());
inspector->get_inspector()->update_tree();

search_box->select_all();
search_box->grab_focus();
search_box->grab_focus_edit(true);

_update_shortcuts();
set_process_shortcut_input(true);
Expand Down Expand Up @@ -674,8 +673,7 @@ void EditorSettingsDialog::_focus_current_search_box() {
}

if (current_search_box) {
current_search_box->grab_focus();
current_search_box->select_all();
current_search_box->grab_focus_edit(true);
}
}

Expand Down
9 changes: 4 additions & 5 deletions editor/filesystem_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ bool FileSystemList::edit_selected() {

String name = get_item_text(s);
line_editor->set_text(name);
line_editor->grab_focus_edit();
line_editor->select(0, name.rfind("."));

popup_editor->popup();
popup_editor->child_controls_changed();
line_editor->grab_focus();
return true;
}

Expand Down Expand Up @@ -2268,15 +2268,15 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
String name = to_duplicate.path.get_file();
duplicate_dialog->set_title(TTR("Duplicating file:") + " " + name);
duplicate_dialog_text->set_text(name);
duplicate_dialog_text->grab_focus_edit();
duplicate_dialog_text->select(0, name.rfind("."));
} else {
String name = to_duplicate.path.substr(0, to_duplicate.path.length() - 1).get_file();
duplicate_dialog->set_title(TTR("Duplicating folder:") + " " + name);
duplicate_dialog_text->set_text(name);
duplicate_dialog_text->select(0, name.length());
duplicate_dialog_text->grab_focus_edit(true);
}
duplicate_dialog->popup_centered(Size2(250, 80) * EDSCALE);
duplicate_dialog_text->grab_focus();
}
} break;

Expand Down Expand Up @@ -2441,8 +2441,7 @@ void FileSystemDock::focus_on_filter() {
}

if (current_search_box) {
current_search_box->grab_focus();
current_search_box->select_all();
current_search_box->grab_focus_edit(true);
}
}

Expand Down
3 changes: 1 addition & 2 deletions editor/find_in_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,7 @@ void FindInFilesDialog::_notification(int p_what) {
case NOTIFICATION_VISIBILITY_CHANGED: {
if (is_visible()) {
// Doesn't work more than once if not deferred...
_search_text_line_edit->call_deferred(SNAME("grab_focus"));
_search_text_line_edit->select_all();
_search_text_line_edit->call_deferred(SNAME("grab_focus_edit"), true);
// Extensions might have changed in the meantime, we clean them and instance them again.
for (int i = 0; i < _filters_container->get_child_count(); i++) {
_filters_container->get_child(i)->queue_free();
Expand Down
2 changes: 1 addition & 1 deletion editor/gui/editor_dir_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void EditorDirDialog::_make_dir() {
}

makedialog->popup_centered(Size2(250, 80));
makedirname->grab_focus();
makedirname->grab_focus_edit();
}

void EditorDirDialog::_make_dir_confirm() {
Expand Down
8 changes: 4 additions & 4 deletions editor/gui/editor_file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ void EditorFileDialog::popup_file_dialog() {
void EditorFileDialog::_focus_file_text() {
int lp = file->get_text().rfind(".");
if (lp != -1) {
file->grab_focus_edit();
file->select(0, lp);
file->grab_focus();
}
}

Expand Down Expand Up @@ -218,7 +218,7 @@ void EditorFileDialog::shortcut_input(const Ref<InputEvent> &p_event) {
handled = true;
}
if (ED_IS_SHORTCUT("file_dialog/focus_path", p_event)) {
dir->grab_focus();
dir->grab_focus_edit();
handled = true;
}
if (ED_IS_SHORTCUT("file_dialog/move_favorite_up", p_event)) {
Expand Down Expand Up @@ -312,7 +312,7 @@ void EditorFileDialog::_post_popup() {
set_current_dir(current);

if (mode == FILE_MODE_SAVE_FILE) {
file->grab_focus();
file->grab_focus_edit();
} else {
item_list->grab_focus();
}
Expand Down Expand Up @@ -1203,7 +1203,7 @@ void EditorFileDialog::_make_dir_confirm() {

void EditorFileDialog::_make_dir() {
makedialog->popup_centered(Size2(250, 80) * EDSCALE);
makedirname->grab_focus();
makedirname->grab_focus_edit();
}

void EditorFileDialog::_delete_items() {
Expand Down
3 changes: 1 addition & 2 deletions editor/gui/editor_spin_slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,7 @@ void EditorSpinSlider::_focus_entered() {
value_input->set_text(get_text_value());
value_input_popup->set_size(get_size());
value_input_popup->call_deferred(SNAME("show"));
value_input->call_deferred(SNAME("grab_focus"));
value_input->call_deferred(SNAME("select_all"));
value_input->call_deferred(SNAME("grab_focus_edit"), true);
value_input->set_focus_next(find_next_valid_focus()->get_path());
value_input->set_focus_previous(find_prev_valid_focus()->get_path());
emit_signal("value_focus_entered");
Expand Down
2 changes: 1 addition & 1 deletion editor/gui/scene_tree_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@ void SceneTreeDialog::_notification(int p_what) {
tree->update_tree();

// Select the search bar by default.
filter->call_deferred(SNAME("grab_focus"));
filter->call_deferred(SNAME("grab_focus_edit"));
}
} break;

Expand Down
2 changes: 1 addition & 1 deletion editor/input_event_configuration_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ int InputEventConfigurationDialog::_get_current_device() const {
void InputEventConfigurationDialog::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_VISIBILITY_CHANGED: {
event_listener->grab_focus();
event_listener->grab_focus_edit();
} break;

case NOTIFICATION_THEME_CHANGED: {
Expand Down
2 changes: 1 addition & 1 deletion editor/plugin_config_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void PluginConfigDialog::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_VISIBILITY_CHANGED: {
if (is_visible()) {
name_edit->grab_focus();
name_edit->grab_focus_edit();
}
} break;

Expand Down
Loading

0 comments on commit 31993c5

Please sign in to comment.