From 8ff747171f019aa1004db2a6aa37eb51ae932928 Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Mon, 28 May 2018 16:52:28 +0100 Subject: [PATCH] Allow opening and editing of any utf_8 file in script editor --- editor/editor_node.cpp | 2 + editor/inspector_dock.cpp | 1 + editor/plugins/script_editor_plugin.cpp | 373 ++++++++--- editor/plugins/script_editor_plugin.h | 20 +- editor/plugins/script_text_editor.cpp | 54 +- editor/plugins/script_text_editor.h | 5 +- editor/plugins/text_editor.cpp | 607 ++++++++++++++++++ editor/plugins/text_editor.h | 146 +++++ .../visual_script/visual_script_editor.cpp | 25 +- modules/visual_script/visual_script_editor.h | 4 +- scene/register_scene_types.cpp | 3 + scene/resources/text_file.cpp | 77 +++ scene/resources/text_file.h | 55 ++ 13 files changed, 1240 insertions(+), 132 deletions(-) create mode 100644 editor/plugins/text_editor.cpp create mode 100644 editor/plugins/text_editor.h create mode 100644 scene/resources/text_file.cpp create mode 100644 scene/resources/text_file.h diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index ff97878e718..672d3304e23 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -112,6 +112,7 @@ #include "editor/plugins/sprite_editor_plugin.h" #include "editor/plugins/sprite_frames_editor_plugin.h" #include "editor/plugins/style_box_editor_plugin.h" +#include "editor/plugins/text_editor.h" #include "editor/plugins/texture_editor_plugin.h" #include "editor/plugins/texture_region_editor_plugin.h" #include "editor/plugins/theme_editor_plugin.h" @@ -5469,6 +5470,7 @@ EditorNode::EditorNode() { EditorAudioBuses *audio_bus_editor = EditorAudioBuses::register_editor(); ScriptTextEditor::register_editor(); //register one for text scripts + TextEditor::register_editor(); if (StreamPeerSSL::is_available()) { add_editor_plugin(memnew(AssetLibraryEditorPlugin(this))); diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp index 0d0b12c9116..43baabe2f5c 100644 --- a/editor/inspector_dock.cpp +++ b/editor/inspector_dock.cpp @@ -140,6 +140,7 @@ void InspectorDock::_load_resource(const String &p_type) { void InspectorDock::_resource_file_selected(String p_file) { RES res = ResourceLoader::load(p_file); + if (res.is_null()) { warning_dialog->get_ok()->set_text("Ugh"); warning_dialog->set_text(TTR("Failed to load resource.")); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 876da7f61a7..a1dc7467021 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -31,7 +31,6 @@ #include "script_editor_plugin.h" #include "core/io/resource_loader.h" -#include "core/io/resource_saver.h" #include "core/os/file_access.h" #include "core/os/input.h" #include "core/os/keyboard.h" @@ -283,7 +282,6 @@ void ScriptEditor::_breaked(bool p_breaked, bool p_can_debug) { ScriptEditorBase *se = Object::cast_to(tab_container->get_child(i)); if (!se) { - continue; } @@ -402,7 +400,10 @@ void ScriptEditor::_go_to_tab(int p_idx) { if (is_visible_in_tree()) Object::cast_to(c)->ensure_focus(); - notify_script_changed(Object::cast_to(c)->get_edited_script()); + Ref