Merge pull request #6710 from lordadamson/master
fix #6031 when creating a script the default language will be what yo…
This commit is contained in:
commit
ac765fd518
4 changed files with 46 additions and 1 deletions
|
@ -1026,6 +1026,34 @@ void EditorSettings::set_optimize_save(bool 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() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("erase","property"),&EditorSettings::erase);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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());
|
||||
//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!="")
|
||||
scr->set_name(cname);
|
||||
|
@ -330,7 +332,17 @@ ScriptCreateDialog::ScriptCreateDialog() {
|
|||
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");
|
||||
|
||||
//parent_name->set_text();
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "scene/gui/line_edit.h"
|
||||
#include "scene/gui/option_button.h"
|
||||
#include "tools/editor/editor_file_dialog.h"
|
||||
#include "tools/editor/editor_settings.h"
|
||||
#include "scene/gui/check_button.h"
|
||||
|
||||
class ScriptCreateDialog : public ConfirmationDialog {
|
||||
|
@ -50,6 +51,7 @@ class ScriptCreateDialog : public ConfirmationDialog {
|
|||
AcceptDialog *alert;
|
||||
bool path_valid;
|
||||
String initial_bp;
|
||||
EditorSettings *editor_settings;
|
||||
|
||||
|
||||
void _path_changed(const String& p_path=String());
|
||||
|
|
Loading…
Reference in a new issue