diff options
Diffstat (limited to 'editor/plugins/script_editor_plugin.cpp')
-rw-r--r-- | editor/plugins/script_editor_plugin.cpp | 158 |
1 files changed, 132 insertions, 26 deletions
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index c605844728..51550acb94 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -40,7 +40,9 @@ #include "core/version.h" #include "editor/debugger/editor_debugger_node.h" #include "editor/debugger/script_editor_debugger.h" +#include "editor/editor_command_palette.h" #include "editor/editor_help_search.h" +#include "editor/editor_interface.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" #include "editor/editor_scale.h" @@ -54,6 +56,8 @@ #include "editor/node_dock.h" #include "editor/plugins/shader_editor_plugin.h" #include "editor/plugins/text_shader_editor.h" +#include "editor/window_wrapper.h" +#include "scene/main/node.h" #include "scene/main/window.h" #include "scene/scene_string_names.h" #include "script_text_editor.h" @@ -1584,23 +1588,10 @@ void ScriptEditor::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { EditorRunBar::get_singleton()->connect("stop_pressed", callable_mp(this, &ScriptEditor::_editor_stop)); - EditorNode::get_singleton()->connect("script_add_function_request", callable_mp(this, &ScriptEditor::_add_callback)); - EditorNode::get_singleton()->connect("resource_saved", callable_mp(this, &ScriptEditor::_res_saved_callback)); - EditorNode::get_singleton()->connect("scene_saved", callable_mp(this, &ScriptEditor::_scene_saved_callback)); - FileSystemDock::get_singleton()->connect("files_moved", callable_mp(this, &ScriptEditor::_files_moved)); - FileSystemDock::get_singleton()->connect("file_removed", callable_mp(this, &ScriptEditor::_file_removed)); - script_list->connect("item_selected", callable_mp(this, &ScriptEditor::_script_selected)); - - members_overview->connect("item_selected", callable_mp(this, &ScriptEditor::_members_overview_selected)); - help_overview->connect("item_selected", callable_mp(this, &ScriptEditor::_help_overview_selected)); - script_split->connect("dragged", callable_mp(this, &ScriptEditor::_split_dragged)); - list_split->connect("dragged", callable_mp(this, &ScriptEditor::_split_dragged)); - - EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &ScriptEditor::_editor_settings_changed)); - EditorFileSystem::get_singleton()->connect("filesystem_changed", callable_mp(this, &ScriptEditor::_filesystem_changed)); _editor_settings_changed(); [[fallthrough]]; } + case NOTIFICATION_TRANSLATION_CHANGED: case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: case NOTIFICATION_THEME_CHANGED: { @@ -1635,6 +1626,20 @@ void ScriptEditor::_notification(int p_what) { InspectorDock::get_singleton()->connect("request_help", callable_mp(this, &ScriptEditor::_help_class_open)); EditorNode::get_singleton()->connect("request_help_search", callable_mp(this, &ScriptEditor::_help_search)); EditorNode::get_singleton()->connect("scene_closed", callable_mp(this, &ScriptEditor::_close_builtin_scripts_from_scene)); + EditorNode::get_singleton()->connect("script_add_function_request", callable_mp(this, &ScriptEditor::_add_callback)); + EditorNode::get_singleton()->connect("resource_saved", callable_mp(this, &ScriptEditor::_res_saved_callback)); + EditorNode::get_singleton()->connect("scene_saved", callable_mp(this, &ScriptEditor::_scene_saved_callback)); + FileSystemDock::get_singleton()->connect("files_moved", callable_mp(this, &ScriptEditor::_files_moved)); + FileSystemDock::get_singleton()->connect("file_removed", callable_mp(this, &ScriptEditor::_file_removed)); + script_list->connect("item_selected", callable_mp(this, &ScriptEditor::_script_selected)); + + members_overview->connect("item_selected", callable_mp(this, &ScriptEditor::_members_overview_selected)); + help_overview->connect("item_selected", callable_mp(this, &ScriptEditor::_help_overview_selected)); + script_split->connect("dragged", callable_mp(this, &ScriptEditor::_split_dragged)); + list_split->connect("dragged", callable_mp(this, &ScriptEditor::_split_dragged)); + + EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &ScriptEditor::_editor_settings_changed)); + EditorFileSystem::get_singleton()->connect("filesystem_changed", callable_mp(this, &ScriptEditor::_filesystem_changed)); } break; case NOTIFICATION_EXIT_TREE: { @@ -2320,7 +2325,6 @@ bool ScriptEditor::edit(const Ref<Resource> &p_resource, int p_line, int p_col, if (tab_container->get_current_tab() != i) { _go_to_tab(i); - _update_script_names(); } if (is_visible_in_tree()) { se->ensure_focus(); @@ -2702,7 +2706,7 @@ void ScriptEditor::_save_layout() { return; } - EditorNode::get_singleton()->save_layout(); + EditorNode::get_singleton()->save_editor_layout_delayed(); } void ScriptEditor::_editor_settings_changed() { @@ -3246,12 +3250,24 @@ void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) { restoring_layout = false; _update_script_names(); + + if (p_layout->has_section_key("ScriptEditor", "selected_script")) { + String selected_script = p_layout->get_value("ScriptEditor", "selected_script"); + // If the selected script is not in the list of open scripts, select nothing. + for (int i = 0; i < tab_container->get_tab_count(); i++) { + ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_tab_control(i)); + if (se && se->get_edited_resource()->get_path() == selected_script) { + _go_to_tab(i); + break; + } + } + } } void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) { Array scripts; Array helps; - + String selected_script; for (int i = 0; i < tab_container->get_tab_count(); i++) { ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_tab_control(i)); if (se) { @@ -3260,6 +3276,10 @@ void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) { continue; } + if (tab_container->get_current_tab_control() == tab_container->get_tab_control(i)) { + selected_script = path; + } + _save_editor_state(se); scripts.push_back(path); } @@ -3272,6 +3292,7 @@ void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) { } p_layout->set_value("ScriptEditor", "open_scripts", scripts); + p_layout->set_value("ScriptEditor", "selected_script", selected_script); p_layout->set_value("ScriptEditor", "open_help", helps); p_layout->set_value("ScriptEditor", "script_split_offset", script_split->get_split_offset()); p_layout->set_value("ScriptEditor", "list_split_offset", list_split->get_split_offset()); @@ -3711,6 +3732,10 @@ void ScriptEditor::_on_find_in_files_modified_files(PackedStringArray paths) { _update_modified_scripts_for_external_editor(); } +void ScriptEditor::_window_changed(bool p_visible) { + make_floating->set_visible(!p_visible); +} + void ScriptEditor::_filter_scripts_text_changed(const String &p_newtext) { _update_script_names(); } @@ -3747,7 +3772,8 @@ void ScriptEditor::_bind_methods() { ADD_SIGNAL(MethodInfo("script_close", PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script"))); } -ScriptEditor::ScriptEditor() { +ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { + window_wrapper = p_wrapper; current_theme = ""; script_editor_cache.instantiate(); @@ -3973,6 +3999,16 @@ ScriptEditor::ScriptEditor() { menu_hb->add_child(help_search); help_search->set_tooltip_text(TTR("Search the reference documentation.")); + if (p_wrapper->is_window_available()) { + make_floating = memnew(ScreenSelect); + make_floating->set_flat(true); + make_floating->set_tooltip_text(TTR("Make the script editor floating.")); + make_floating->connect("request_open_in_screen", callable_mp(window_wrapper, &WindowWrapper::enable_window_on_screen).bind(true)); + + menu_hb->add_child(make_floating); + p_wrapper->connect("window_visibility_changed", callable_mp(this, &ScriptEditor::_window_changed)); + } + menu_hb->add_child(memnew(VSeparator)); script_back = memnew(Button); @@ -4079,6 +4115,39 @@ ScriptEditor::~ScriptEditor() { memdelete(completion_cache); } +void ScriptEditorPlugin::_focus_another_editor() { + if (window_wrapper->get_window_enabled()) { + ERR_FAIL_COND(last_editor.is_empty()); + EditorInterface::get_singleton()->set_main_screen_editor(last_editor); + } +} + +void ScriptEditorPlugin::_save_last_editor(String p_editor) { + if (p_editor != get_name()) { + last_editor = p_editor; + } +} + +void ScriptEditorPlugin::_window_visibility_changed(bool p_visible) { + _focus_another_editor(); + if (p_visible) { + script_editor->add_theme_style_override("panel", script_editor->get_theme_stylebox("ScriptEditorPanelFloating", "EditorStyles")); + } else { + script_editor->add_theme_style_override("panel", script_editor->get_theme_stylebox("ScriptEditorPanel", "EditorStyles")); + } +} + +void ScriptEditorPlugin::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + connect("main_screen_changed", callable_mp(this, &ScriptEditorPlugin::_save_last_editor)); + } break; + case NOTIFICATION_EXIT_TREE: { + disconnect("main_screen_changed", callable_mp(this, &ScriptEditorPlugin::_save_last_editor)); + } break; + } +} + void ScriptEditorPlugin::edit(Object *p_object) { if (Object::cast_to<Script>(p_object)) { Script *p_script = Object::cast_to<Script>(p_object); @@ -4119,17 +4188,20 @@ bool ScriptEditorPlugin::handles(Object *p_object) const { void ScriptEditorPlugin::make_visible(bool p_visible) { if (p_visible) { - script_editor->show(); + window_wrapper->show(); script_editor->set_process(true); script_editor->ensure_select_current(); } else { - script_editor->hide(); - script_editor->set_process(false); + window_wrapper->hide(); + if (!window_wrapper->get_window_enabled()) { + script_editor->set_process(false); + } } } void ScriptEditorPlugin::selected_notify() { script_editor->ensure_select_current(); + _focus_another_editor(); } void ScriptEditorPlugin::save_external_data() { @@ -4142,10 +4214,37 @@ void ScriptEditorPlugin::apply_changes() { void ScriptEditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) { script_editor->set_window_layout(p_layout); + + if (EDITOR_GET("interface/multi_window/restore_windows_on_load") && window_wrapper->is_window_available() && p_layout->has_section_key("ScriptEditor", "window_rect")) { + window_wrapper->restore_window_from_saved_position( + p_layout->get_value("ScriptEditor", "window_rect", Rect2i()), + p_layout->get_value("ScriptEditor", "window_screen", -1), + p_layout->get_value("ScriptEditor", "window_screen_rect", Rect2i())); + } else { + window_wrapper->set_window_enabled(false); + } } void ScriptEditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) { script_editor->get_window_layout(p_layout); + + if (window_wrapper->get_window_enabled()) { + p_layout->set_value("ScriptEditor", "window_rect", window_wrapper->get_window_rect()); + int screen = window_wrapper->get_window_screen(); + p_layout->set_value("ScriptEditor", "window_screen", screen); + p_layout->set_value("ScriptEditor", "window_screen_rect", DisplayServer::get_singleton()->screen_get_usable_rect(screen)); + + } else { + if (p_layout->has_section_key("ScriptEditor", "window_rect")) { + p_layout->erase_section_key("ScriptEditor", "window_rect"); + } + if (p_layout->has_section_key("ScriptEditor", "window_screen")) { + p_layout->erase_section_key("ScriptEditor", "window_screen"); + } + if (p_layout->has_section_key("ScriptEditor", "window_screen_rect")) { + p_layout->erase_section_key("ScriptEditor", "window_screen_rect"); + } + } } void ScriptEditorPlugin::get_breakpoints(List<String> *p_breakpoints) { @@ -4157,11 +4256,18 @@ void ScriptEditorPlugin::edited_scene_changed() { } ScriptEditorPlugin::ScriptEditorPlugin() { - script_editor = memnew(ScriptEditor); - EditorNode::get_singleton()->get_main_screen_control()->add_child(script_editor); - script_editor->set_v_size_flags(Control::SIZE_EXPAND_FILL); - - script_editor->hide(); + window_wrapper = memnew(WindowWrapper); + window_wrapper->set_window_title(TTR("Script Editor - Godot Engine")); + window_wrapper->set_margins_enabled(true); + + script_editor = memnew(ScriptEditor(window_wrapper)); + Ref<Shortcut> make_floating_shortcut = ED_SHORTCUT_AND_COMMAND("script_editor/make_floating", TTR("Make Floating")); + window_wrapper->set_wrapped_control(script_editor, make_floating_shortcut); + + EditorNode::get_singleton()->get_main_screen_control()->add_child(window_wrapper); + window_wrapper->set_v_size_flags(Control::SIZE_EXPAND_FILL); + window_wrapper->hide(); + window_wrapper->connect("window_visibility_changed", callable_mp(this, &ScriptEditorPlugin::_window_visibility_changed)); EDITOR_GET("text_editor/behavior/files/auto_reload_scripts_on_external_change"); ScriptServer::set_reload_scripts_on_save(EDITOR_DEF("text_editor/behavior/files/auto_reload_and_parse_scripts_on_save", true)); |