Skip to content

Commit

Permalink
Moves cursor to and selects "new_script" in Create Script dialog
Browse files Browse the repository at this point in the history
When Create Script dialog pops up, the cursor in the Path LineEdit is
moved to the "new_script" name placeholder and it is selected.
  • Loading branch information
rxlecky committed Feb 8, 2019
1 parent 16d4021 commit a83877a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions editor/script_create_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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);
}
Expand Down Expand Up @@ -586,6 +602,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);
Expand Down Expand Up @@ -760,6 +777,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");
Expand Down
1 change: 1 addition & 0 deletions editor/script_create_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class ScriptCreateDialog : public ConfirmationDialog {
String script_template;
Vector<String> template_list;

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());
Expand Down

0 comments on commit a83877a

Please sign in to comment.