mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-11-22 00:48:09 +01:00
Added an editor plugin for HTMLTemplateData. Double clicking one in the editor will open the underlying file on the text editor tab (if enabled).
This commit is contained in:
parent
83facbff3b
commit
5c9996fd58
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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<HTMLTemplateData> f = Ref<HTMLTemplateData>(Object::cast_to<HTMLTemplateData>(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
|
||||
|
@ -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
|
||||
|
@ -165,6 +165,10 @@ void register_web_types(ModuleRegistrationLevel p_level) {
|
||||
if (p_level == MODULE_REGISTRATION_LEVEL_EDITOR) {
|
||||
EditorPlugins::add_by_type<WebNodeEditorPlugin>();
|
||||
|
||||
#ifdef MODULE_TEXT_EDITOR_ENABLED
|
||||
EditorPlugins::add_by_type<HTMLTemplateDataEditorPlugin>();
|
||||
#endif
|
||||
|
||||
Ref<ResourceImporterHTMLTemplateData> html_template_data_importer;
|
||||
html_template_data_importer.instance();
|
||||
ResourceFormatImporter::get_singleton()->add_importer(html_template_data_importer);
|
||||
|
Loading…
Reference in New Issue
Block a user