diff --git a/modules/text_editor/text_editor_plugin.cpp b/modules/text_editor/text_editor_plugin.cpp index 36c5baa31..4f4393cd5 100644 --- a/modules/text_editor/text_editor_plugin.cpp +++ b/modules/text_editor/text_editor_plugin.cpp @@ -24,6 +24,9 @@ SOFTWARE. #include "text_editor_file.h" #include "text_file_editor.h" +#include "editor/editor_node.h" + +#include "editor/filesystem_dock.h" void TextEditorEditorPlugin::make_visible(const bool visible) { window->set_visible(visible); @@ -59,6 +62,10 @@ TextEditorEditorPlugin::TextEditorEditorPlugin(EditorNode *p_node) { window = memnew(TextFileEditor); get_editor_interface()->get_editor_viewport()->add_child(window); + + _filesystem_dock_entry_id = get_editor_interface()->get_file_system_dock()->add_custom_popup_creation_entry("New Textfile...", "TextEditorFile", "EditorIcons"); + get_editor_interface()->get_file_system_dock()->connect("custom_popup_creation_entry_pressed", this, "_on_filesystem_dock_entry_pressed"); + make_visible(false); _icon = get_editor_interface()->get_base_control()->get_theme_icon("File", "EditorIcons"); } @@ -66,5 +73,13 @@ TextEditorEditorPlugin::TextEditorEditorPlugin(EditorNode *p_node) { TextEditorEditorPlugin::~TextEditorEditorPlugin() { } -void TextEditorEditorPlugin::_bind_methods() { +void TextEditorEditorPlugin::_on_filesystem_dock_entry_pressed(int id) { + if (_filesystem_dock_entry_id == id) { + editor->select_editor_by_name(get_name()); + window->create_selected_file(); + } +} + +void TextEditorEditorPlugin::_bind_methods() { + ClassDB::bind_method(D_METHOD("_on_filesystem_dock_entry_pressed"), &TextEditorEditorPlugin::_on_filesystem_dock_entry_pressed); } diff --git a/modules/text_editor/text_editor_plugin.h b/modules/text_editor/text_editor_plugin.h index 2191f79dd..80c223048 100644 --- a/modules/text_editor/text_editor_plugin.h +++ b/modules/text_editor/text_editor_plugin.h @@ -49,9 +49,12 @@ public: TextFileEditor *window; protected: + void _on_filesystem_dock_entry_pressed(int id); + static void _bind_methods(); Ref _icon; + int _filesystem_dock_entry_id; }; #endif