From a84a46176729ffab82703bdff62fcde73dd6477d Mon Sep 17 00:00:00 2001 From: Adham Zahran Date: Wed, 12 Oct 2016 22:23:48 +0200 Subject: fix #6031 when creating a script the language will be what you selected last time --- tools/editor/editor_settings.cpp | 28 ++++++++++++++++++++++++++++ tools/editor/editor_settings.h | 3 +++ tools/editor/script_create_dialog.cpp | 14 +++++++++++++- tools/editor/script_create_dialog.h | 2 ++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/tools/editor/editor_settings.cpp b/tools/editor/editor_settings.cpp index 4778a7ce90..7e450fb4ad 100644 --- a/tools/editor/editor_settings.cpp +++ b/tools/editor/editor_settings.cpp @@ -1022,6 +1022,34 @@ void EditorSettings::set_optimize_save(bool p_optimize) { optimize_save=p_optimize; } +String EditorSettings::get_last_selected_language() +{ + Ref 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(last_selected_language); +} + +void EditorSettings::set_last_selected_language(String p_language) +{ + Ref 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() { ObjectTypeDB::bind_method(_MD("erase","property"),&EditorSettings::erase); diff --git a/tools/editor/editor_settings.h b/tools/editor/editor_settings.h index 2a7d3bb4f0..a976602304 100644 --- a/tools/editor/editor_settings.h +++ b/tools/editor/editor_settings.h @@ -160,6 +160,9 @@ public: void set_optimize_save(bool p_optimize); + String get_last_selected_language(); + void set_last_selected_language(String p_language); + EditorSettings(); ~EditorSettings(); diff --git a/tools/editor/script_create_dialog.cpp b/tools/editor/script_create_dialog.cpp index 749198314a..62d5c7cd84 100644 --- a/tools/editor/script_create_dialog.cpp +++ b/tools/editor/script_create_dialog.cpp @@ -121,6 +121,8 @@ void ScriptCreateDialog::ok_pressed() { Ref