/**************************************************************************/ /* plugin_config_dialog.cpp */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /**************************************************************************/ /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ #include "plugin_config_dialog.h" #include "core/io/config_file.h" #include "core/io/dir_access.h" #include "core/object/script_language.h" #include "editor/editor_file_system.h" #include "editor/editor_node.h" #include "editor/gui/editor_validation_panel.h" #include "editor/plugins/editor_plugin.h" #include "editor/project_settings_editor.h" #include "editor/themes/editor_scale.h" #include "scene/gui/grid_container.h" void PluginConfigDialog::_clear_fields() { name_edit->set_text(""); subfolder_edit->set_text(""); desc_edit->set_text(""); author_edit->set_text(""); version_edit->set_text(""); script_edit->set_text(""); } void PluginConfigDialog::_on_confirmed() { String path = "res://addons/" + _get_subfolder(); if (!_edit_mode) { Ref d = DirAccess::create(DirAccess::ACCESS_RESOURCES); if (d.is_null() || d->make_dir_recursive(path) != OK) { return; } } // Create the plugin.cfg file. Ref cf = memnew(ConfigFile); cf->load(path.path_join("plugin.cfg")); cf->set_value("plugin", "name", name_edit->get_text()); cf->set_value("plugin", "description", desc_edit->get_text()); cf->set_value("plugin", "author", author_edit->get_text()); cf->set_value("plugin", "version", version_edit->get_text()); // Language-specific settings. int lang_index = script_option_edit->get_selected(); _create_script_for_plugin(path, cf, lang_index); // Save and inform the editor. cf->save(path.path_join("plugin.cfg")); EditorNode::get_singleton()->get_project_settings()->update_plugins(); EditorFileSystem::get_singleton()->scan(); _clear_fields(); } void PluginConfigDialog::_create_script_for_plugin(const String &p_plugin_path, Ref p_config_file, int p_script_lang_index) { ScriptLanguage *language = ScriptServer::get_language(p_script_lang_index); ERR_FAIL_COND(language == nullptr); String ext = language->get_extension(); String script_name = script_edit->get_text().is_empty() ? _get_subfolder() : script_edit->get_text(); if (script_name.get_extension() != ext) { script_name += "." + ext; } String script_path = p_plugin_path.path_join(script_name); p_config_file->set_value("plugin", "script", script_name); // If the requested script does not exist, create it. if (!_edit_mode && !FileAccess::exists(script_path)) { String class_name = script_name.get_basename(); String template_content = ""; Vector templates = language->get_built_in_templates("EditorPlugin"); if (!templates.is_empty()) { template_content = templates[0].content; } Ref