Skip to content

Commit 7df702b

Browse files
committed
Merge pull request #108342 from KoBeWi/automatization
Automatically open newly created script
2 parents 6b17d35 + 19e3242 commit 7df702b

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

editor/docks/filesystem_dock.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2746,6 +2746,10 @@ void FileSystemDock::_resource_created() {
27462746
EditorNode::get_singleton()->save_resource_as(Ref<Resource>(r), fpath);
27472747
}
27482748

2749+
void FileSystemDock::_script_or_shader_created(const Ref<Resource> &p_resource) {
2750+
EditorNode::get_singleton()->push_item(p_resource.ptr());
2751+
}
2752+
27492753
void FileSystemDock::_search_changed(const String &p_text, const Control *p_from) {
27502754
if (searched_tokens.is_empty()) {
27512755
// Register the uncollapsed paths before they change.
@@ -4441,9 +4445,12 @@ FileSystemDock::FileSystemDock() {
44414445
make_script_dialog = memnew(ScriptCreateDialog);
44424446
make_script_dialog->set_title(TTRC("Create Script"));
44434447
add_child(make_script_dialog);
4448+
make_script_dialog->connect("script_created", callable_mp(this, &FileSystemDock::_script_or_shader_created));
44444449

44454450
make_shader_dialog = memnew(ShaderCreateDialog);
44464451
add_child(make_shader_dialog);
4452+
make_shader_dialog->connect("shader_created", callable_mp(this, &FileSystemDock::_script_or_shader_created));
4453+
make_shader_dialog->connect("shader_include_created", callable_mp(this, &FileSystemDock::_script_or_shader_created));
44474454

44484455
new_resource_dialog = memnew(CreateDialog);
44494456
add_child(new_resource_dialog);

editor/docks/filesystem_dock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ class FileSystemDock : public EditorDock {
313313
void _folder_removed(const String &p_folder);
314314

315315
void _resource_created();
316+
void _script_or_shader_created(const Ref<Resource> &p_resource);
316317
void _make_scene_confirm();
317318
void _rename_operation_confirm();
318319
void _duplicate_operation_confirm(const String &p_path);

editor/script/script_editor_plugin.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,13 +1305,13 @@ void ScriptEditor::_file_dialog_action(const String &p_file) {
13051305
EditorFileSystem::get_singleton()->update_file(p_file);
13061306
}
13071307
}
1308-
1309-
if (!open_textfile_after_create) {
1310-
return;
1311-
}
13121308
[[fallthrough]];
13131309
}
13141310
case FILE_MENU_OPEN: {
1311+
if (!is_visible_in_tree()) {
1312+
// When created from outside the editor.
1313+
EditorNode::get_singleton()->get_editor_main_screen()->select(EditorMainScreen::EDITOR_SCRIPT);
1314+
}
13151315
open_file(p_file);
13161316
file_dialog_option = -1;
13171317
} break;
@@ -1390,7 +1390,6 @@ void ScriptEditor::_menu_option(int p_option) {
13901390
}
13911391
file_dialog->set_title(TTRC("New Text File..."));
13921392
file_dialog->popup_file_dialog();
1393-
open_textfile_after_create = true;
13941393
} break;
13951394
case FILE_MENU_OPEN: {
13961395
file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
@@ -2895,7 +2894,6 @@ void ScriptEditor::open_text_file_create_dialog(const String &p_base_path, const
28952894
_menu_option(FILE_MENU_NEW_TEXTFILE);
28962895
file_dialog->set_current_dir(p_base_path);
28972896
file_dialog->set_current_file(p_base_name);
2898-
open_textfile_after_create = false;
28992897
}
29002898

29012899
Ref<Resource> ScriptEditor::open_file(const String &p_file) {

editor/script/script_editor_plugin.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,6 @@ class ScriptEditor : public PanelContainer {
451451
void _scene_saved_callback(const String &p_path);
452452
void _mark_built_in_scripts_as_saved(const String &p_parent_path);
453453

454-
bool open_textfile_after_create = true;
455454
bool trim_trailing_whitespace_on_save;
456455
bool trim_final_newlines_on_save;
457456
bool convert_indent_on_save;

0 commit comments

Comments
 (0)