summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorIgnacio Etcheverry <ignalfonsore@gmail.com>2019-01-23 14:54:33 +0100
committerIgnacio Etcheverry <ignalfonsore@gmail.com>2019-01-23 14:54:33 +0100
commit504508e61c17e59984393262e181cf546be9740c (patch)
tree1a8ed0fac73dd2cc2d11ae0a55c2f384a05772b5 /editor
parent6a187f639511726583db05f8cd80957b1f936d03 (diff)
PluginConfigDialog: Add partial support for more script language
Diffstat (limited to 'editor')
-rw-r--r--editor/plugin_config_dialog.cpp29
1 files changed, 21 insertions, 8 deletions
diff --git a/editor/plugin_config_dialog.cpp b/editor/plugin_config_dialog.cpp
index 1b99059f32..88672bdf34 100644
--- a/editor/plugin_config_dialog.cpp
+++ b/editor/plugin_config_dialog.cpp
@@ -65,11 +65,16 @@ void PluginConfigDialog::_on_confirmed() {
cf->save(path.plus_file("plugin.cfg"));
if (!_edit_mode) {
- String type = script_option_edit->get_item_text(script_option_edit->get_selected());
+ int lang_idx = script_option_edit->get_selected();
+ String lang_name = ScriptServer::get_language(lang_idx)->get_name();
Ref<Script> script;
- if (type == GDScriptLanguage::get_singleton()->get_name()) {
+ // 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).
+
+ if (lang_name == GDScriptLanguage::get_singleton()->get_name()) {
+ // Hard-coded GDScript template to keep usability until we use script templates.
Ref<GDScript> gdscript = memnew(GDScript);
gdscript->set_source_code(
"tool\n"
@@ -84,8 +89,13 @@ void PluginConfigDialog::_on_confirmed() {
gdscript->set_path(script_path);
ResourceSaver::save(script_path, gdscript);
script = gdscript;
+ } else {
+ 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);
}
- //TODO: other languages
emit_signal("plugin_ready", script.operator->(), active_edit->is_pressed() ? subfolder_edit->get_text() : "");
} else {
@@ -98,8 +108,9 @@ void PluginConfigDialog::_on_cancelled() {
_clear_fields();
}
-void PluginConfigDialog::_on_required_text_changed(const String &p_text) {
- String ext = script_option_edit->get_item_metadata(script_option_edit->get_selected());
+void PluginConfigDialog::_on_required_text_changed(const String &) {
+ int lang_idx = script_option_edit->get_selected();
+ String ext = ScriptServer::get_language(lang_idx)->get_extension();
get_ok()->set_disabled(script_edit->get_text().get_basename().empty() || script_edit->get_text().get_extension() != ext || name_edit->get_text().empty());
}
@@ -204,10 +215,11 @@ PluginConfigDialog::PluginConfigDialog() {
grid->add_child(script_option_lb);
script_option_edit = memnew(OptionButton);
- script_option_edit->add_item(GDScriptLanguage::get_singleton()->get_name());
- script_option_edit->set_item_metadata(0, GDScriptLanguage::get_singleton()->get_extension());
+ for (int i = 0; i < ScriptServer::get_language_count(); i++) {
+ ScriptLanguage *lang = ScriptServer::get_language(i);
+ script_option_edit->add_item(lang->get_name());
+ }
script_option_edit->select(0);
- //TODO: add other languages
grid->add_child(script_option_edit);
Label *script_lb = memnew(Label);
@@ -219,6 +231,7 @@ PluginConfigDialog::PluginConfigDialog() {
script_edit->set_placeholder("\"plugin.gd\" -> res://addons/my_plugin/plugin.gd");
grid->add_child(script_edit);
+ // TODO Make this option work better with languages like C#. Right now, it does not work because the C# project must be compiled first.
Label *active_lb = memnew(Label);
active_lb->set_text(TTR("Activate now?"));
grid->add_child(active_lb);