summaryrefslogtreecommitdiff
path: root/editor/plugin_config_dialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugin_config_dialog.cpp')
-rw-r--r--editor/plugin_config_dialog.cpp71
1 files changed, 20 insertions, 51 deletions
diff --git a/editor/plugin_config_dialog.cpp b/editor/plugin_config_dialog.cpp
index 91ca1465df..755bf7ce07 100644
--- a/editor/plugin_config_dialog.cpp
+++ b/editor/plugin_config_dialog.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -36,12 +36,6 @@
#include "editor/editor_plugin.h"
#include "editor/editor_scale.h"
#include "editor/project_settings_editor.h"
-#include "scene/gui/grid_container.h"
-
-#include "modules/modules_enabled.gen.h"
-#ifdef MODULE_GDSCRIPT_ENABLED
-#include "modules/gdscript/gdscript.h"
-#endif
void PluginConfigDialog::_clear_fields() {
name_edit->set_text("");
@@ -56,8 +50,8 @@ void PluginConfigDialog::_on_confirmed() {
String path = "res://addons/" + subfolder_edit->get_text();
if (!_edit_mode) {
- DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
- if (!d || d->make_dir_recursive(path) != OK) {
+ Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
+ if (d.is_null() || d->make_dir_recursive(path) != OK) {
return;
}
}
@@ -76,42 +70,16 @@ void PluginConfigDialog::_on_confirmed() {
String lang_name = ScriptServer::get_language(lang_idx)->get_name();
Ref<Script> script;
-
- // TODO Use script templates. Right now, this code won't add the 'tool' annotation to other languages.
- // TODO Better support script languages with named classes (has_named_classes).
-
- // FIXME: It's hacky to have hardcoded access to the GDScript module here.
- // The editor code should not have to know what languages are enabled.
-#ifdef MODULE_GDSCRIPT_ENABLED
- if (lang_name == GDScriptLanguage::get_singleton()->get_name()) {
- // Hard-coded GDScript template to keep usability until we use script templates.
- Ref<Script> gdscript = memnew(GDScript);
- gdscript->set_source_code(
- "@tool\n"
- "extends EditorPlugin\n"
- "\n"
- "\n"
- "func _enter_tree()%VOID_RETURN%:\n"
- "%TS%pass\n"
- "\n"
- "\n"
- "func _exit_tree()%VOID_RETURN%:\n"
- "%TS%pass\n");
- GDScriptLanguage::get_singleton()->make_template("", "", gdscript);
- String script_path = path.plus_file(script_edit->get_text());
- gdscript->set_path(script_path);
- ResourceSaver::save(script_path, gdscript);
- script = gdscript;
- } else {
-#endif
- String script_path = path.plus_file(script_edit->get_text());
- String class_name = script_path.get_file().get_basename();
- script = ScriptServer::get_language(lang_idx)->get_template(class_name, "EditorPlugin");
- script->set_path(script_path);
- ResourceSaver::save(script_path, script);
-#ifdef MODULE_GDSCRIPT_ENABLED
+ String script_path = path.plus_file(script_edit->get_text());
+ String class_name = script_path.get_file().get_basename();
+ String template_content = "";
+ Vector<ScriptLanguage::ScriptTemplate> templates = ScriptServer::get_language(lang_idx)->get_built_in_templates("EditorPlugin");
+ if (templates.size() > 0) {
+ template_content = templates.get(0).content;
}
-#endif
+ script = ScriptServer::get_language(lang_idx)->make_template(template_content, class_name, "EditorPlugin");
+ script->set_path(script_path);
+ ResourceSaver::save(script_path, script);
emit_signal(SNAME("plugin_ready"), script.operator->(), active_edit->is_pressed() ? _to_absolute_plugin_path(subfolder_edit->get_text()) : "");
} else {
@@ -149,7 +117,7 @@ void PluginConfigDialog::_on_required_text_changed(const String &) {
if (name_edit->get_text().is_empty()) {
is_valid = false;
name_validation->set_texture(invalid_icon);
- name_validation->set_tooltip(TTR("Plugin name cannot not be blank."));
+ name_validation->set_tooltip(TTR("Plugin name cannot be blank."));
}
if (script_edit->get_text().get_extension() != ext) {
is_valid = false;
@@ -159,7 +127,7 @@ void PluginConfigDialog::_on_required_text_changed(const String &) {
if (script_edit->get_text().get_basename().is_empty()) {
is_valid = false;
script_validation->set_texture(invalid_icon);
- script_validation->set_tooltip(TTR("Script name cannot not be blank."));
+ script_validation->set_tooltip(TTR("Script name cannot be blank."));
}
if (subfolder_edit->get_text().is_empty()) {
is_valid = false;
@@ -169,7 +137,7 @@ void PluginConfigDialog::_on_required_text_changed(const String &) {
subfolder_validation->set_texture(invalid_icon);
subfolder_validation->set_tooltip(TTR("Subfolder name is not a valid folder name."));
} else {
- DirAccessRef dir = DirAccess::create(DirAccess::ACCESS_RESOURCES);
+ Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_RESOURCES);
String path = "res://addons/" + subfolder_edit->get_text();
if (dir->dir_exists(path) && !_edit_mode) { // Only show this error if in "create" mode.
is_valid = false;
@@ -192,6 +160,7 @@ void PluginConfigDialog::_notification(int p_what) {
name_edit->grab_focus();
}
} break;
+
case NOTIFICATION_READY: {
connect("confirmed", callable_mp(this, &PluginConfigDialog::_on_confirmed));
get_cancel_button()->connect("pressed", callable_mp(this, &PluginConfigDialog::_on_cancelled));
@@ -216,6 +185,7 @@ void PluginConfigDialog::config(const String &p_config_path) {
active_edit->hide();
Object::cast_to<Label>(active_edit->get_parent()->get_child(active_edit->get_index() - 2))->hide();
subfolder_edit->hide();
+ subfolder_validation->hide();
Object::cast_to<Label>(subfolder_edit->get_parent()->get_child(subfolder_edit->get_index() - 2))->hide();
set_title(TTR("Edit a Plugin"));
} else {
@@ -224,6 +194,7 @@ void PluginConfigDialog::config(const String &p_config_path) {
active_edit->show();
Object::cast_to<Label>(active_edit->get_parent()->get_child(active_edit->get_index() - 2))->show();
subfolder_edit->show();
+ subfolder_validation->show();
Object::cast_to<Label>(subfolder_edit->get_parent()->get_child(subfolder_edit->get_index() - 2))->show();
set_title(TTR("Create a Plugin"));
}
@@ -329,11 +300,9 @@ PluginConfigDialog::PluginConfigDialog() {
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
ScriptLanguage *lang = ScriptServer::get_language(i);
script_option_edit->add_item(lang->get_name());
-#ifdef MODULE_GDSCRIPT_ENABLED
- if (lang == GDScriptLanguage::get_singleton()) {
+ if (lang->get_name() == "GDScript") {
default_lang = i;
}
-#endif
}
script_option_edit->select(default_lang);
grid->add_child(script_option_edit);