diff options
Diffstat (limited to 'editor/plugins/script_editor_plugin.cpp')
-rw-r--r-- | editor/plugins/script_editor_plugin.cpp | 72 |
1 files changed, 42 insertions, 30 deletions
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index dbbb34614d..eb1c5d249b 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -191,6 +191,16 @@ void EditorStandardSyntaxHighlighter::_update_cache() { highlighter->add_color_region(beg, end, comment_color, end.is_empty()); } + /* Doc comments */ + const Color doc_comment_color = EDITOR_GET("text_editor/theme/highlighting/doc_comment_color"); + List<String> doc_comments; + scr->get_language()->get_doc_comment_delimiters(&doc_comments); + for (const String &doc_comment : doc_comments) { + String beg = doc_comment.get_slice(" ", 0); + String end = doc_comment.get_slice_count(" ") > 1 ? doc_comment.get_slice(" ", 1) : String(); + highlighter->add_color_region(beg, end, doc_comment_color, end.is_empty()); + } + /* Strings */ const Color string_color = EDITOR_GET("text_editor/theme/highlighting/string_color"); List<String> strings; @@ -423,7 +433,11 @@ ScriptEditor *ScriptEditor::script_editor = nullptr; String ScriptEditor::_get_debug_tooltip(const String &p_text, Node *_se) { String val = EditorDebuggerNode::get_singleton()->get_var_value(p_text); + const int display_limit = 300; if (!val.is_empty()) { + if (val.size() > display_limit) { + val = val.left(display_limit) + " [...] truncated!"; + } return p_text + ": " + val; } else { return String(); @@ -431,7 +445,7 @@ String ScriptEditor::_get_debug_tooltip(const String &p_text, Node *_se) { } void ScriptEditor::_breaked(bool p_breaked, bool p_can_debug) { - if (bool(EDITOR_GET("text_editor/external/use_external_editor"))) { + if (external_editor_active) { return; } @@ -534,7 +548,7 @@ void ScriptEditor::_set_breakpoint(Ref<RefCounted> p_script, int p_line, bool p_ } state["breakpoints"] = breakpoints; script_editor_cache->set_value(scr->get_path(), "state", state); - EditorDebuggerNode::get_singleton()->set_breakpoint(scr->get_path(), p_line + 1, false); + EditorDebuggerNode::get_singleton()->set_breakpoint(scr->get_path(), p_line + 1, p_enabled); } } @@ -863,6 +877,10 @@ void ScriptEditor::_close_current_tab(bool p_save) { } void ScriptEditor::_close_discard_current_tab(const String &p_str) { + Ref<Script> scr = _get_current_script(); + if (scr.is_valid()) { + scr->reload_from_file(); + } _close_tab(tab_container->get_current_tab(), false); erase_tab_confirm->hide(); } @@ -983,7 +1001,7 @@ void ScriptEditor::_res_saved_callback(const Ref<Resource> &p_res) { } _update_script_names(); - _trigger_live_script_reload(); + trigger_live_script_reload(); } void ScriptEditor::_scene_saved_callback(const String &p_path) { @@ -1011,7 +1029,7 @@ void ScriptEditor::_scene_saved_callback(const String &p_path) { } } -void ScriptEditor::_trigger_live_script_reload() { +void ScriptEditor::trigger_live_script_reload() { if (!pending_auto_reload && auto_reload_running_scripts) { call_deferred(SNAME("_live_auto_reload_running_scripts")); pending_auto_reload = true; @@ -1409,11 +1427,7 @@ void ScriptEditor::_menu_option(int p_option) { path = path.get_slice("::", 0); // Show the scene instead. } - FileSystemDock *file_system_dock = FileSystemDock::get_singleton(); - file_system_dock->navigate_to_path(path); - // Ensure that the FileSystem dock is visible. - TabContainer *dock_tab_container = (TabContainer *)file_system_dock->get_parent_control(); - dock_tab_container->set_current_tab(dock_tab_container->get_tab_idx_from_control(file_system_dock)); + FileSystemDock::get_singleton()->navigate_to_path(path); } } break; case CLOSE_DOCS: { @@ -2260,7 +2274,7 @@ bool ScriptEditor::edit(const Ref<Resource> &p_resource, int p_line, int p_col, // Don't open dominant script if using an external editor. bool use_external_editor = - EDITOR_GET("text_editor/external/use_external_editor") || + external_editor_active || (scr.is_valid() && scr->get_language()->overrides_external_editor()); use_external_editor = use_external_editor && !(scr.is_valid() && scr->is_built_in()); // Ignore external editor for built-in scripts. const bool open_dominant = EDITOR_GET("text_editor/behavior/files/open_dominant_script_on_scene_change"); @@ -2502,17 +2516,7 @@ void ScriptEditor::save_current_script() { clear_docs_from_script(scr); } - if (resource->is_built_in()) { - // If built-in script, save the scene instead. - const String scene_path = resource->get_path().get_slice("::", 0); - if (!scene_path.is_empty()) { - Vector<String> scene_to_save; - scene_to_save.push_back(scene_path); - EditorNode::get_singleton()->save_scene_list(scene_to_save); - } - } else { - EditorNode::get_singleton()->save_resource(resource); - } + EditorNode::get_singleton()->save_resource(resource); if (scr.is_valid()) { update_docs_from_script(scr); @@ -2520,7 +2524,7 @@ void ScriptEditor::save_current_script() { } void ScriptEditor::save_all_scripts() { - Vector<String> scenes_to_save; + HashSet<String> scenes_to_save; for (int i = 0; i < tab_container->get_tab_count(); i++) { ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_tab_control(i)); @@ -2569,7 +2573,7 @@ void ScriptEditor::save_all_scripts() { // For built-in scripts, save their scenes instead. const String scene_path = edited_res->get_path().get_slice("::", 0); if (!scene_path.is_empty() && !scenes_to_save.has(scene_path)) { - scenes_to_save.push_back(scene_path); + scenes_to_save.insert(scene_path); } } } @@ -2592,6 +2596,9 @@ void ScriptEditor::apply_scripts() const { } void ScriptEditor::reload_scripts(bool p_refresh_only) { + if (external_editor_active) { + return; + } 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) { @@ -2759,6 +2766,7 @@ void ScriptEditor::_editor_settings_changed() { members_overview_enabled = EDITOR_GET("text_editor/script_list/show_members_overview"); help_overview_enabled = EDITOR_GET("text_editor/help/show_help_index"); + external_editor_active = EDITOR_GET("text_editor/external/use_external_editor"); _update_members_overview_visibility(); _update_help_overview_visibility(); @@ -2955,7 +2963,7 @@ bool ScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data } for (int i = 0; i < files.size(); i++) { - String file = files[i]; + const String &file = files[i]; if (file.is_empty() || !FileAccess::exists(file)) { continue; } @@ -3035,7 +3043,7 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co } int num_tabs_before = tab_container->get_tab_count(); for (int i = 0; i < files.size(); i++) { - String file = files[i]; + const String &file = files[i]; if (file.is_empty() || !FileAccess::exists(file)) { continue; } @@ -3554,7 +3562,7 @@ TypedArray<ScriptEditorBase> ScriptEditor::_get_open_script_editors() const { void ScriptEditor::set_scene_root_script(Ref<Script> p_script) { // Don't open dominant script if using an external editor. bool use_external_editor = - EDITOR_GET("text_editor/external/use_external_editor") || + external_editor_active || (p_script.is_valid() && p_script->get_language()->overrides_external_editor()); use_external_editor = use_external_editor && !(p_script.is_valid() && p_script->is_built_in()); // Ignore external editor for built-in scripts. const bool open_dominant = EDITOR_GET("text_editor/behavior/files/open_dominant_script_on_scene_change"); @@ -3822,6 +3830,7 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { waiting_update_names = false; pending_auto_reload = false; auto_reload_running_scripts = true; + external_editor_active = false; members_overview_enabled = EDITOR_GET("text_editor/script_list/show_members_overview"); help_overview_enabled = EDITOR_GET("text_editor/help/show_help_index"); @@ -3850,6 +3859,7 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { scripts_vbox->add_child(filter_scripts); script_list = memnew(ItemList); + script_list->set_auto_translate(false); scripts_vbox->add_child(script_list); script_list->set_custom_minimum_size(Size2(150, 60) * EDSCALE); //need to give a bit of limit to avoid it from disappearing script_list->set_v_size_flags(SIZE_EXPAND_FILL); @@ -3894,6 +3904,7 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { overview_vbox->add_child(filter_methods); members_overview = memnew(ItemList); + members_overview->set_auto_translate(false); overview_vbox->add_child(members_overview); members_overview->set_allow_reselect(true); @@ -3902,6 +3913,7 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { members_overview->set_allow_rmb_select(true); help_overview = memnew(ItemList); + help_overview->set_auto_translate(false); overview_vbox->add_child(help_overview); help_overview->set_allow_reselect(true); help_overview->set_custom_minimum_size(Size2(0, 60) * EDSCALE); //need to give a bit of limit to avoid it from disappearing @@ -3949,8 +3961,8 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { _update_recent_scripts(); file_menu->get_popup()->add_separator(); - file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/save", TTR("Save"), KeyModifierMask::CMD_OR_CTRL | Key::S), FILE_SAVE); - file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/save_as", TTR("Save As..."), KeyModifierMask::CMD_OR_CTRL | KeyModifierMask::SHIFT | Key::S), FILE_SAVE_AS); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/save", TTR("Save"), KeyModifierMask::ALT | KeyModifierMask::CMD_OR_CTRL | Key::S), FILE_SAVE); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/save_as", TTR("Save As...")), FILE_SAVE_AS); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/save_all", TTR("Save All"), KeyModifierMask::SHIFT | KeyModifierMask::ALT | Key::S), FILE_SAVE_ALL); ED_SHORTCUT_OVERRIDE("script_editor/save_all", "macos", KeyModifierMask::META | KeyModifierMask::CTRL | Key::S); file_menu->get_popup()->add_separator(); @@ -4008,8 +4020,8 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { debugger->connect("set_execution", callable_mp(this, &ScriptEditor::_set_execution)); debugger->connect("clear_execution", callable_mp(this, &ScriptEditor::_clear_execution)); debugger->connect("breaked", callable_mp(this, &ScriptEditor::_breaked)); - debugger->get_default_debugger()->connect("set_breakpoint", callable_mp(this, &ScriptEditor::_set_breakpoint)); - debugger->get_default_debugger()->connect("clear_breakpoints", callable_mp(this, &ScriptEditor::_clear_breakpoints)); + debugger->connect("breakpoint_set_in_tree", callable_mp(this, &ScriptEditor::_set_breakpoint)); + debugger->connect("breakpoints_cleared_in_tree", callable_mp(this, &ScriptEditor::_clear_breakpoints)); menu_hb->add_spacer(); |