diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 731e98d6c..35c047fe3 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -3244,6 +3244,22 @@ void EditorNode::editor_set_visible_by_name(const String &p_name, const bool p_v ERR_FAIL_MSG("The editor name '" + p_name + "' was not found."); } +EditorPlugin *EditorNode::get_editor_by_name(const String &p_name) { + ERR_FAIL_COND_V(p_name == "", NULL); + + String meta_name = "text"; + + for (int i = 0; i < main_editor_buttons.size(); i++) { + if (main_editor_buttons[i]->get_meta(meta_name) == p_name) { + EditorPlugin *editor = editor_table[i]; + ERR_FAIL_COND_V(!editor, NULL); + return editor; + } + } + + ERR_FAIL_V_MSG(NULL, "The editor name '" + p_name + "' was not found."); +} + void EditorNode::add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed) { if (p_editor->has_main_screen()) { ToolButton *tb = memnew(ToolButton); diff --git a/editor/editor_node.h b/editor/editor_node.h index f9972f0f5..6960e0374 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -234,6 +234,8 @@ public: void select_editor_by_name(const String &p_name); void editor_set_visible_by_name(const String &p_name, const bool p_visible); + + EditorPlugin *get_editor_by_name(const String &p_name); void open_request(const String &p_path); diff --git a/editor_modules/text_editor/text_editor_plugin.cpp b/editor_modules/text_editor/text_editor_plugin.cpp index ada4bc823..628d01d22 100644 --- a/editor_modules/text_editor/text_editor_plugin.cpp +++ b/editor_modules/text_editor/text_editor_plugin.cpp @@ -65,6 +65,11 @@ bool TextEditorEditorPlugin::handles(Object *p_object) const { return p_object->is_class("TextEditorFile"); } +void TextEditorEditorPlugin::open_file(const String &p_path) { + window->open_file(p_path); + editor->select_editor_by_name(get_name()); +} + TextEditorEditorPlugin::TextEditorEditorPlugin(EditorNode *p_node) { editor = p_node; @@ -90,5 +95,7 @@ void TextEditorEditorPlugin::_on_filesystem_dock_entry_pressed(int id) { } void TextEditorEditorPlugin::_bind_methods() { + ClassDB::bind_method(D_METHOD("open_file", "file"), &TextEditorEditorPlugin::open_file); + ClassDB::bind_method(D_METHOD("_on_filesystem_dock_entry_pressed"), &TextEditorEditorPlugin::_on_filesystem_dock_entry_pressed); } diff --git a/editor_modules/text_editor/text_editor_plugin.h b/editor_modules/text_editor/text_editor_plugin.h index 3a568efe2..010228fb1 100644 --- a/editor_modules/text_editor/text_editor_plugin.h +++ b/editor_modules/text_editor/text_editor_plugin.h @@ -49,6 +49,8 @@ public: String get_name() const; void edit(Object *p_object); bool handles(Object *p_object) const; + + void open_file(const String &p_path); TextEditorEditorPlugin(EditorNode *p_node); ~TextEditorEditorPlugin(); diff --git a/modules/web/html/editor/resource_importer_html_template_data.cpp b/modules/web/html/editor/resource_importer_html_template_data.cpp index a16ae5636..54d0cb5ca 100644 --- a/modules/web/html/editor/resource_importer_html_template_data.cpp +++ b/modules/web/html/editor/resource_importer_html_template_data.cpp @@ -35,6 +35,10 @@ #include "../html_template_data.h" +#ifdef MODULE_TEXT_EDITOR_ENABLED +#include "editor/editor_node.h" +#endif + String ResourceImporterHTMLTemplateData::get_importer_name() const { return "html_template_data"; } @@ -85,3 +89,26 @@ ResourceImporterHTMLTemplateData::ResourceImporterHTMLTemplateData() { ResourceImporterHTMLTemplateData::~ResourceImporterHTMLTemplateData() { } + +#ifdef MODULE_TEXT_EDITOR_ENABLED + +void HTMLTemplateDataEditorPlugin::edit(Object *p_object) { + Ref f = Ref(Object::cast_to(p_object)); + + if (f.is_valid()) { + EditorPlugin *ep = EditorNode::get_singleton()->get_editor_by_name("Text"); + + if (ep) { + ep->call("open_file", f->get_path()); + } + } +} + +bool HTMLTemplateDataEditorPlugin::handles(Object *p_object) const { + return p_object->is_class("HTMLTemplateData"); +} + +HTMLTemplateDataEditorPlugin::HTMLTemplateDataEditorPlugin(EditorNode *p_node) { +} + +#endif diff --git a/modules/web/html/editor/resource_importer_html_template_data.h b/modules/web/html/editor/resource_importer_html_template_data.h index 948802c80..24fa14557 100644 --- a/modules/web/html/editor/resource_importer_html_template_data.h +++ b/modules/web/html/editor/resource_importer_html_template_data.h @@ -34,6 +34,11 @@ #include "core/io/resource_importer.h" +#include "editor/editor_plugin.h" +#include "modules/modules_enabled.gen.h" + +class EditorNode; + class ResourceImporterHTMLTemplateData : public ResourceImporter { GDCLASS(ResourceImporterHTMLTemplateData, ResourceImporter); @@ -54,4 +59,21 @@ public: ResourceImporterHTMLTemplateData(); ~ResourceImporterHTMLTemplateData(); }; + +#ifdef MODULE_TEXT_EDITOR_ENABLED + +class HTMLTemplateDataEditorPlugin : public EditorPlugin { + GDCLASS(HTMLTemplateDataEditorPlugin, EditorPlugin); + +public: + virtual void edit(Object *p_object); + virtual bool handles(Object *p_object) const; + + HTMLTemplateDataEditorPlugin(EditorNode *p_node); + + virtual String get_name() const { return "HTMLTemplateData"; } +}; + +#endif + #endif // RESOURCE_IMPORTER_HTML_TEMPLATE_DATA_H diff --git a/modules/web/register_types.cpp b/modules/web/register_types.cpp index 7802a3c84..b7d9b0767 100644 --- a/modules/web/register_types.cpp +++ b/modules/web/register_types.cpp @@ -165,6 +165,10 @@ void register_web_types(ModuleRegistrationLevel p_level) { if (p_level == MODULE_REGISTRATION_LEVEL_EDITOR) { EditorPlugins::add_by_type(); +#ifdef MODULE_TEXT_EDITOR_ENABLED + EditorPlugins::add_by_type(); +#endif + Ref html_template_data_importer; html_template_data_importer.instance(); ResourceFormatImporter::get_singleton()->add_importer(html_template_data_importer);