You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-12 13:20:55 +00:00
fix #6031 when creating a script the language will be what you selected last time
This commit is contained in:
@@ -1022,6 +1022,34 @@ void EditorSettings::set_optimize_save(bool p_optimize) {
|
|||||||
optimize_save=p_optimize;
|
optimize_save=p_optimize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String EditorSettings::get_last_selected_language()
|
||||||
|
{
|
||||||
|
Ref<ConfigFile> cf = memnew( ConfigFile );
|
||||||
|
String path = get_project_settings_path().plus_file("project_metadata.cfg");
|
||||||
|
Error err = cf->load(path);
|
||||||
|
if (err != OK) {
|
||||||
|
WARN_PRINTS("Can't load config file: " + path);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
Variant last_selected_language = cf->get_value("script_setup", "last_selected_language");
|
||||||
|
if (last_selected_language.get_type() != Variant::STRING)
|
||||||
|
return "";
|
||||||
|
return static_cast<String>(last_selected_language);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorSettings::set_last_selected_language(String p_language)
|
||||||
|
{
|
||||||
|
Ref<ConfigFile> cf = memnew( ConfigFile );
|
||||||
|
String path = get_project_settings_path().plus_file("project_metadata.cfg");
|
||||||
|
Error err = cf->load(path);
|
||||||
|
if (err != OK) {
|
||||||
|
WARN_PRINTS("Can't load config file: " + path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cf->set_value("script_setup", "last_selected_language", p_language);
|
||||||
|
cf->save(path);
|
||||||
|
}
|
||||||
|
|
||||||
void EditorSettings::_bind_methods() {
|
void EditorSettings::_bind_methods() {
|
||||||
|
|
||||||
ObjectTypeDB::bind_method(_MD("erase","property"),&EditorSettings::erase);
|
ObjectTypeDB::bind_method(_MD("erase","property"),&EditorSettings::erase);
|
||||||
|
|||||||
@@ -160,6 +160,9 @@ public:
|
|||||||
|
|
||||||
void set_optimize_save(bool p_optimize);
|
void set_optimize_save(bool p_optimize);
|
||||||
|
|
||||||
|
String get_last_selected_language();
|
||||||
|
void set_last_selected_language(String p_language);
|
||||||
|
|
||||||
EditorSettings();
|
EditorSettings();
|
||||||
~EditorSettings();
|
~EditorSettings();
|
||||||
|
|
||||||
|
|||||||
@@ -121,6 +121,8 @@ void ScriptCreateDialog::ok_pressed() {
|
|||||||
Ref<Script> scr = ScriptServer::get_language( language_menu->get_selected() )->get_template(cname,parent_name->get_text());
|
Ref<Script> scr = ScriptServer::get_language( language_menu->get_selected() )->get_template(cname,parent_name->get_text());
|
||||||
//scr->set_source_code(text);
|
//scr->set_source_code(text);
|
||||||
|
|
||||||
|
String selected_language = language_menu->get_item_text(language_menu->get_selected());
|
||||||
|
editor_settings->set_last_selected_language(selected_language);
|
||||||
|
|
||||||
if (cname!="")
|
if (cname!="")
|
||||||
scr->set_name(cname);
|
scr->set_name(cname);
|
||||||
@@ -330,7 +332,17 @@ ScriptCreateDialog::ScriptCreateDialog() {
|
|||||||
language_menu->add_item(ScriptServer::get_language(i)->get_name());
|
language_menu->add_item(ScriptServer::get_language(i)->get_name());
|
||||||
}
|
}
|
||||||
|
|
||||||
language_menu->select(0);
|
editor_settings = EditorSettings::get_singleton();
|
||||||
|
String last_selected_language = editor_settings->get_last_selected_language();
|
||||||
|
if (last_selected_language != "")
|
||||||
|
for (int i = 0; i < language_menu->get_item_count(); i++)
|
||||||
|
if (language_menu->get_item_text(i) == last_selected_language)
|
||||||
|
{
|
||||||
|
language_menu->select(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else language_menu->select(0);
|
||||||
|
|
||||||
language_menu->connect("item_selected",this,"_lang_changed");
|
language_menu->connect("item_selected",this,"_lang_changed");
|
||||||
|
|
||||||
//parent_name->set_text();
|
//parent_name->set_text();
|
||||||
|
|||||||
@@ -33,6 +33,7 @@
|
|||||||
#include "scene/gui/line_edit.h"
|
#include "scene/gui/line_edit.h"
|
||||||
#include "scene/gui/option_button.h"
|
#include "scene/gui/option_button.h"
|
||||||
#include "tools/editor/editor_file_dialog.h"
|
#include "tools/editor/editor_file_dialog.h"
|
||||||
|
#include "tools/editor/editor_settings.h"
|
||||||
#include "scene/gui/check_button.h"
|
#include "scene/gui/check_button.h"
|
||||||
|
|
||||||
class ScriptCreateDialog : public ConfirmationDialog {
|
class ScriptCreateDialog : public ConfirmationDialog {
|
||||||
@@ -50,6 +51,7 @@ class ScriptCreateDialog : public ConfirmationDialog {
|
|||||||
AcceptDialog *alert;
|
AcceptDialog *alert;
|
||||||
bool path_valid;
|
bool path_valid;
|
||||||
String initial_bp;
|
String initial_bp;
|
||||||
|
EditorSettings *editor_settings;
|
||||||
|
|
||||||
|
|
||||||
void _path_changed(const String& p_path=String());
|
void _path_changed(const String& p_path=String());
|
||||||
|
|||||||
Reference in New Issue
Block a user