diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-04-30 13:57:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-30 13:57:14 +0200 |
commit | 8a7cf6f0d1ae886bc1be40a91d9119fa5dfc61e5 (patch) | |
tree | d465f56c25afb2d99c43a5c8b7dde27f9ad2ffad | |
parent | 1b08ba1a4833be4a2c9c9697d47193c58e357764 (diff) | |
parent | a83877a8e84b949061b7c48a92e4636fbfd3d19d (diff) |
Merge pull request #25708 from SeleckyErik/issue-25611-script_dialog_cursor
Moves cursor to and selects "new_script" in Create Script dialog
-rw-r--r-- | editor/script_create_dialog.cpp | 18 | ||||
-rw-r--r-- | editor/script_create_dialog.h | 1 |
2 files changed, 19 insertions, 0 deletions
diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index d76afcd2f4..292cb8ddc3 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -52,6 +52,22 @@ void ScriptCreateDialog::_notification(int p_what) { } } +void ScriptCreateDialog::_path_hbox_sorted() { + if (is_visible()) { + int filename_start_pos = initial_bp.find_last("/") + 1; + int filename_end_pos = initial_bp.length(); + + file_path->select(filename_start_pos, filename_end_pos); + + // First set cursor to the end of line to scroll LineEdit view + // to the right and then set the actual cursor position. + file_path->set_cursor_position(file_path->get_text().length()); + file_path->set_cursor_position(filename_start_pos); + + file_path->grab_focus(); + } +} + bool ScriptCreateDialog::_can_be_built_in() { return (supports_built_in && built_in_enabled); } @@ -604,6 +620,7 @@ void ScriptCreateDialog::_update_dialog() { void ScriptCreateDialog::_bind_methods() { + ClassDB::bind_method("_path_hbox_sorted", &ScriptCreateDialog::_path_hbox_sorted); ClassDB::bind_method("_class_name_changed", &ScriptCreateDialog::_class_name_changed); ClassDB::bind_method("_parent_name_changed", &ScriptCreateDialog::_parent_name_changed); ClassDB::bind_method("_lang_changed", &ScriptCreateDialog::_lang_changed); @@ -786,6 +803,7 @@ ScriptCreateDialog::ScriptCreateDialog() { /* Path */ hb = memnew(HBoxContainer); + hb->connect("sort_children", this, "_path_hbox_sorted"); file_path = memnew(LineEdit); file_path->connect("text_changed", this, "_path_changed"); file_path->connect("text_entered", this, "_path_entered"); diff --git a/editor/script_create_dialog.h b/editor/script_create_dialog.h index 7473e77c29..f5c335c00a 100644 --- a/editor/script_create_dialog.h +++ b/editor/script_create_dialog.h @@ -80,6 +80,7 @@ class ScriptCreateDialog : public ConfirmationDialog { Vector<String> template_list; String base_type; + void _path_hbox_sorted(); bool _can_be_built_in(); void _path_changed(const String &p_path = String()); void _path_entered(const String &p_path = String()); |