Added the set/get_setting function in Editor/Project settings. Renamed has() to has_setting. Fixes #11844

This commit is contained in:
Juan Linietsky 2017-10-05 15:34:34 -03:00
parent 928efe06d6
commit 3d87b70f7a
19 changed files with 81 additions and 48 deletions

View file

@ -492,7 +492,7 @@ void ResourceLoader::reload_translation_remaps() {
void ResourceLoader::load_translation_remaps() {
if (!ProjectSettings::get_singleton()->has("locale/translation_remaps"))
if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps"))
return;
Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");

View file

@ -420,7 +420,7 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack) {
return OK;
}
bool ProjectSettings::has(String p_var) const {
bool ProjectSettings::has_setting(String p_var) const {
_THREAD_SAFE_METHOD_
@ -800,7 +800,7 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust
Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default) {
Variant ret;
if (ProjectSettings::get_singleton()->has(p_var)) {
if (ProjectSettings::get_singleton()->has_setting(p_var)) {
ret = ProjectSettings::get_singleton()->get(p_var);
} else {
ProjectSettings::get_singleton()->set(p_var, p_default);
@ -907,9 +907,19 @@ Variant ProjectSettings::property_get_revert(const String &p_name) {
return props[p_name].initial;
}
void ProjectSettings::set_setting(const String &p_setting, const Variant &p_value) {
set(p_setting, p_value);
}
Variant ProjectSettings::get_setting(const String &p_setting) const {
return get(p_setting);
}
void ProjectSettings::_bind_methods() {
ClassDB::bind_method(D_METHOD("has", "name"), &ProjectSettings::has);
ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting);
ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting);
ClassDB::bind_method(D_METHOD("get_setting", "name"), &ProjectSettings::get_setting);
ClassDB::bind_method(D_METHOD("set_order", "name", "position"), &ProjectSettings::set_order);
ClassDB::bind_method(D_METHOD("get_order", "name"), &ProjectSettings::get_order);
ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &ProjectSettings::set_initial_value);

View file

@ -119,7 +119,10 @@ protected:
static void _bind_methods();
public:
bool has(String p_var) const;
void set_setting(const String &p_setting, const Variant &p_value);
Variant get_setting(const String &p_setting) const;
bool has_setting(String p_var) const;
String localize_path(const String &p_path) const;
String globalize_path(const String &p_path) const;

View file

@ -1052,7 +1052,7 @@ TranslationServer *TranslationServer::singleton = NULL;
bool TranslationServer::_load_translations(const String &p_from) {
if (ProjectSettings::get_singleton()->has(p_from)) {
if (ProjectSettings::get_singleton()->has_setting(p_from)) {
PoolVector<String> translations = ProjectSettings::get_singleton()->get(p_from);
int tcount = translations.size();

View file

@ -83,7 +83,7 @@ void CreateDialog::popup_create(bool p_dontclear) {
_update_favorite_list();
// Restore valid window bounds or pop up at default size.
if (EditorSettings::get_singleton()->has("interface/dialogs/create_new_node_bounds")) {
if (EditorSettings::get_singleton()->has_setting("interface/dialogs/create_new_node_bounds")) {
popup(EditorSettings::get_singleton()->get("interface/dialogs/create_new_node_bounds"));
} else {
popup_centered_ratio();

View file

@ -117,7 +117,7 @@ void EditorAutoloadSettings::_autoload_add() {
undo_redo->create_action(TTR("Add AutoLoad"));
undo_redo->add_do_property(ProjectSettings::get_singleton(), name, "*" + path);
if (ProjectSettings::get_singleton()->has(name)) {
if (ProjectSettings::get_singleton()->has_setting(name)) {
undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, ProjectSettings::get_singleton()->get(name));
} else {
undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, Variant());
@ -169,7 +169,7 @@ void EditorAutoloadSettings::_autoload_edited() {
return;
}
if (ProjectSettings::get_singleton()->has("autoload/" + name)) {
if (ProjectSettings::get_singleton()->has_setting("autoload/" + name)) {
ti->set_text(0, old_name);
EditorNode::get_singleton()->show_warning(vformat(TTR("Autoload '%s' already exists!"), name));
return;

View file

@ -1383,7 +1383,7 @@ void EditorFileSystem::_reimport_file(const String &p_file) {
}
}
if (load_default && ProjectSettings::get_singleton()->has("importer_defaults/" + importer->get_importer_name())) {
if (load_default && ProjectSettings::get_singleton()->has_setting("importer_defaults/" + importer->get_importer_name())) {
//use defaults if exist
Dictionary d = ProjectSettings::get_singleton()->get("importer_defaults/" + importer->get_importer_name());
List<Variant> v;

View file

@ -5613,7 +5613,7 @@ EditorNode::EditorNode() {
{
_initializing_addons = true;
Vector<String> addons;
if (ProjectSettings::get_singleton()->has("editor_plugins/enabled")) {
if (ProjectSettings::get_singleton()->has_setting("editor_plugins/enabled")) {
addons = ProjectSettings::get_singleton()->get("editor_plugins/enabled");
}

View file

@ -195,7 +195,17 @@ void EditorSettings::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::ARRAY, "shortcuts", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); //do not edit
}
bool EditorSettings::has(String p_var) const {
void EditorSettings::set_setting(const String &p_setting, const Variant &p_value) {
_THREAD_SAFE_METHOD_
set(p_setting, p_value);
}
Variant EditorSettings::get_setting(const String &p_setting) const {
_THREAD_SAFE_METHOD_
return get(p_setting);
}
bool EditorSettings::has_setting(String p_var) const {
_THREAD_SAFE_METHOD_
@ -218,7 +228,7 @@ void EditorSettings::raise_order(const String &p_name) {
Variant _EDITOR_DEF(const String &p_var, const Variant &p_default) {
if (EditorSettings::get_singleton()->has(p_var))
if (EditorSettings::get_singleton()->has_setting(p_var))
return EditorSettings::get_singleton()->get(p_var);
EditorSettings::get_singleton()->set(p_var, p_default);
EditorSettings::get_singleton()->set_initial_value(p_var, p_default);
@ -228,7 +238,7 @@ Variant _EDITOR_DEF(const String &p_var, const Variant &p_default) {
Variant _EDITOR_GET(const String &p_var) {
ERR_FAIL_COND_V(!EditorSettings::get_singleton()->has(p_var), Variant())
ERR_FAIL_COND_V(!EditorSettings::get_singleton()->has_setting(p_var), Variant())
return EditorSettings::get_singleton()->get(p_var);
}
@ -471,8 +481,8 @@ void EditorSettings::setup_network() {
IP::get_singleton()->get_local_addresses(&local_ip);
String lip = "127.0.0.1";
String hint;
String current = has("network/debug/remote_host") ? get("network/debug/remote_host") : "";
int port = has("network/debug/remote_port") ? (int)get("network/debug/remote_port") : 6007;
String current = has_setting("network/debug/remote_host") ? get("network/debug/remote_host") : "";
int port = has_setting("network/debug/remote_port") ? (int)get("network/debug/remote_port") : 6007;
for (List<IP_Address>::Element *E = local_ip.front(); E; E = E->next()) {
@ -989,7 +999,7 @@ void EditorSettings::load_text_editor_theme() {
String val = cf->get_value("color_theme", key);
// don't load if it's not already there!
if (has("text_editor/highlighting/" + key)) {
if (has_setting("text_editor/highlighting/" + key)) {
// make sure it is actually a color
if (val.is_valid_html_color() && key.find("color") >= 0) {
@ -1194,6 +1204,10 @@ void EditorSettings::set_initial_value(const StringName &p_name, const Variant &
void EditorSettings::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_setting", "name"), &EditorSettings::has_setting);
ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &EditorSettings::set_setting);
ClassDB::bind_method(D_METHOD("get_setting", "name"), &EditorSettings::get_setting);
ClassDB::bind_method(D_METHOD("erase", "property"), &EditorSettings::erase);
ClassDB::bind_method(D_METHOD("get_settings_path"), &EditorSettings::get_settings_path);
ClassDB::bind_method(D_METHOD("get_project_settings_path"), &EditorSettings::get_project_settings_path);
@ -1211,6 +1225,8 @@ void EditorSettings::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_initial_value", "name", "value"), &EditorSettings::set_initial_value);
ClassDB::bind_method(D_METHOD("set_favorite_dirs", "dirs"), &EditorSettings::set_favorite_dirs);
ADD_SIGNAL(MethodInfo("settings_changed"));
}

View file

@ -129,7 +129,11 @@ public:
void set_manually(const StringName &p_name, const Variant &p_value, bool p_emit_signal = false) {
_set(p_name, p_value, p_emit_signal);
}
bool has(String p_var) const;
void set_setting(const String &p_setting, const Variant &p_value);
Variant get_setting(const String &p_setting) const;
bool has_setting(String p_var) const;
static EditorSettings *get_singleton();
void erase(String p_var);
String get_settings_path() const;

View file

@ -137,7 +137,7 @@ void ImportDock::set_edit_path(const String &p_path) {
preset->get_popup()->add_separator();
preset->get_popup()->add_item(vformat(TTR("Set as Default for '%s'"), params->importer->get_visible_name()), ITEM_SET_AS_DEFAULT);
if (ProjectSettings::get_singleton()->has("importer_defaults/" + params->importer->get_importer_name())) {
if (ProjectSettings::get_singleton()->has_setting("importer_defaults/" + params->importer->get_importer_name())) {
preset->get_popup()->add_item(TTR("Load Default"), ITEM_LOAD_DEFAULT);
preset->get_popup()->add_separator();
preset->get_popup()->add_item(vformat(TTR("Clear Default for '%s'"), params->importer->get_visible_name()), ITEM_CLEAR_DEFAULT);
@ -281,7 +281,7 @@ void ImportDock::_preset_selected(int p_idx) {
} break;
case ITEM_LOAD_DEFAULT: {
ERR_FAIL_COND(!ProjectSettings::get_singleton()->has("importer_defaults/" + params->importer->get_importer_name()));
ERR_FAIL_COND(!ProjectSettings::get_singleton()->has_setting("importer_defaults/" + params->importer->get_importer_name()));
Dictionary d = ProjectSettings::get_singleton()->get("importer_defaults/" + params->importer->get_importer_name());
List<Variant> v;

View file

@ -71,7 +71,7 @@ void ProjectExportDialog::popup_export() {
_update_presets();
// Restore valid window bounds or pop up at default size.
if (EditorSettings::get_singleton()->has("interface/dialogs/export_bounds")) {
if (EditorSettings::get_singleton()->has_setting("interface/dialogs/export_bounds")) {
popup(EditorSettings::get_singleton()->get("interface/dialogs/export_bounds"));
} else {
popup_centered_ratio();

View file

@ -506,7 +506,7 @@ public:
if (current->setup(project_path->get_text(), "")) {
set_message(TTR("Couldn't get project.godot in the project path."), MESSAGE_ERROR);
} else if (current->has("application/config/name")) {
} else if (current->has_setting("application/config/name")) {
project_name->set_text(current->get("application/config/name"));
}
project_name->grab_focus();

View file

@ -146,7 +146,7 @@ void ProjectSettingsEditor::_action_edited() {
String action_prop = "input/" + new_name;
if (ProjectSettings::get_singleton()->has(action_prop)) {
if (ProjectSettings::get_singleton()->has_setting(action_prop)) {
ti->set_text(0, old_name);
add_at = "input/" + old_name;
@ -707,7 +707,7 @@ void ProjectSettingsEditor::_update_actions() {
void ProjectSettingsEditor::popup_project_settings() {
// Restore valid window bounds or pop up at default size.
if (EditorSettings::get_singleton()->has("interface/dialogs/project_settings_bounds")) {
if (EditorSettings::get_singleton()->has_setting("interface/dialogs/project_settings_bounds")) {
popup(EditorSettings::get_singleton()->get("interface/dialogs/project_settings_bounds"));
} else {
popup_centered_ratio();
@ -753,7 +753,7 @@ void ProjectSettingsEditor::_item_add() {
undo_redo->add_do_property(ProjectSettings::get_singleton(), name, value);
if (ProjectSettings::get_singleton()->has(name)) {
if (ProjectSettings::get_singleton()->has_setting(name)) {
undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, ProjectSettings::get_singleton()->get(name));
} else {
undo_redo->add_undo_property(ProjectSettings::get_singleton(), name, Variant());
@ -782,7 +782,7 @@ void ProjectSettingsEditor::_item_del() {
String property = globals_editor->get_current_section().plus_file(path);
if (!ProjectSettings::get_singleton()->has(property)) {
if (!ProjectSettings::get_singleton()->has_setting(property)) {
EditorNode::get_singleton()->show_warning(TTR("No property '" + property + "' exists."));
return;
}
@ -823,7 +823,7 @@ void ProjectSettingsEditor::_action_check(String p_action) {
action_add->set_disabled(true);
return;
}
if (ProjectSettings::get_singleton()->has("input/" + p_action)) {
if (ProjectSettings::get_singleton()->has_setting("input/" + p_action)) {
action_add->set_text(TTR("Already existing"));
action_add->set_disabled(true);
return;
@ -965,7 +965,7 @@ void ProjectSettingsEditor::_copy_to_platform(int p_which) {
String new_path = property + "." + feature;
undo_redo->add_do_method(ProjectSettings::get_singleton(), "set", new_path, value);
if (ProjectSettings::get_singleton()->has(new_path)) {
if (ProjectSettings::get_singleton()->has_setting(new_path)) {
undo_redo->add_undo_method(ProjectSettings::get_singleton(), "set", new_path, ProjectSettings::get_singleton()->get(new_path));
}
@ -1042,7 +1042,7 @@ void ProjectSettingsEditor::_translation_res_add(const String &p_path) {
Variant prev;
Dictionary remaps;
if (ProjectSettings::get_singleton()->has("locale/translation_remaps")) {
if (ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) {
remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
prev = remaps;
}
@ -1068,7 +1068,7 @@ void ProjectSettingsEditor::_translation_res_option_file_open() {
}
void ProjectSettingsEditor::_translation_res_option_add(const String &p_path) {
ERR_FAIL_COND(!ProjectSettings::get_singleton()->has("locale/translation_remaps"));
ERR_FAIL_COND(!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps"));
Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
@ -1105,7 +1105,7 @@ void ProjectSettingsEditor::_translation_res_option_changed() {
if (updating_translations)
return;
if (!ProjectSettings::get_singleton()->has("locale/translation_remaps"))
if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps"))
return;
Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
@ -1147,7 +1147,7 @@ void ProjectSettingsEditor::_translation_res_delete(Object *p_item, int p_column
if (updating_translations)
return;
if (!ProjectSettings::get_singleton()->has("locale/translation_remaps"))
if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps"))
return;
Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
@ -1174,7 +1174,7 @@ void ProjectSettingsEditor::_translation_res_option_delete(Object *p_item, int p
if (updating_translations)
return;
if (!ProjectSettings::get_singleton()->has("locale/translation_remaps"))
if (!ProjectSettings::get_singleton()->has_setting("locale/translation_remaps"))
return;
Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
@ -1215,7 +1215,7 @@ void ProjectSettingsEditor::_update_translations() {
translation_list->clear();
TreeItem *root = translation_list->create_item(NULL);
translation_list->set_hide_root(true);
if (ProjectSettings::get_singleton()->has("locale/translations")) {
if (ProjectSettings::get_singleton()->has_setting("locale/translations")) {
PoolStringArray translations = ProjectSettings::get_singleton()->get("locale/translations");
for (int i = 0; i < translations.size(); i++) {
@ -1253,7 +1253,7 @@ void ProjectSettingsEditor::_update_translations() {
langnames += names[i];
}
if (ProjectSettings::get_singleton()->has("locale/translation_remaps")) {
if (ProjectSettings::get_singleton()->has_setting("locale/translation_remaps")) {
Dictionary remaps = ProjectSettings::get_singleton()->get("locale/translation_remaps");
List<Variant> rk;

View file

@ -93,7 +93,7 @@ void EditorSettingsDialog::popup_edit_settings() {
_update_shortcuts();
// Restore valid window bounds or pop up at default size.
if (EditorSettings::get_singleton()->has("interface/dialogs/editor_settings_bounds")) {
if (EditorSettings::get_singleton()->has_setting("interface/dialogs/editor_settings_bounds")) {
popup(EditorSettings::get_singleton()->get("interface/dialogs/editor_settings_bounds"));
} else {
popup_centered_ratio(0.7);

View file

@ -726,7 +726,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
#ifdef TOOLS_ENABLED
if (main_args.size() == 0 && (!ProjectSettings::get_singleton()->has("application/run/main_loop_type")) && (!ProjectSettings::get_singleton()->has("application/run/main_scene") || String(ProjectSettings::get_singleton()->get("application/run/main_scene")) == ""))
if (main_args.size() == 0 && (!ProjectSettings::get_singleton()->has_setting("application/run/main_loop_type")) && (!ProjectSettings::get_singleton()->has_setting("application/run/main_scene") || String(ProjectSettings::get_singleton()->get("application/run/main_scene")) == ""))
use_custom_res = false; //project manager (run without arguments)
#endif
@ -739,21 +739,21 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
//if (video_driver == "") // useless for now, so removing
// video_driver = GLOBAL_DEF("display/driver/name", Variant((const char *)OS::get_singleton()->get_video_driver_name(0)));
if (!force_res && use_custom_res && globals->has("display/window/size/width"))
if (!force_res && use_custom_res && globals->has_setting("display/window/size/width"))
video_mode.width = globals->get("display/window/size/width");
if (!force_res && use_custom_res && globals->has("display/window/size/height"))
if (!force_res && use_custom_res && globals->has_setting("display/window/size/height"))
video_mode.height = globals->get("display/window/size/height");
if (!editor && ((globals->has("display/window/dpi/allow_hidpi") && !globals->get("display/window/dpi/allow_hidpi")) || force_lowdpi)) {
if (!editor && ((globals->has_setting("display/window/dpi/allow_hidpi") && !globals->get("display/window/dpi/allow_hidpi")) || force_lowdpi)) {
OS::get_singleton()->_allow_hidpi = false;
}
if (use_custom_res && globals->has("display/window/size/fullscreen"))
if (use_custom_res && globals->has_setting("display/window/size/fullscreen"))
video_mode.fullscreen = globals->get("display/window/size/fullscreen");
if (use_custom_res && globals->has("display/window/size/resizable"))
if (use_custom_res && globals->has_setting("display/window/size/resizable"))
video_mode.resizable = globals->get("display/window/size/resizable");
if (use_custom_res && globals->has("display/window/size/borderless"))
if (use_custom_res && globals->has_setting("display/window/size/borderless"))
video_mode.borderless_window = globals->get("display/window/size/borderless");
if (!force_res && use_custom_res && globals->has("display/window/size/test_width") && globals->has("display/window/size/test_height")) {
if (!force_res && use_custom_res && globals->has_setting("display/window/size/test_width") && globals->has_setting("display/window/size/test_height")) {
int tw = globals->get("display/window/size/test_width");
int th = globals->get("display/window/size/test_height");
if (tw > 0 && th > 0) {

View file

@ -72,7 +72,7 @@ void GDNativeLibraryEditor::_update_libraries() {
libraries->create_item(); //rppt
Vector<String> enabled_paths;
if (ProjectSettings::get_singleton()->has("gdnative/singletons")) {
if (ProjectSettings::get_singleton()->has_setting("gdnative/singletons")) {
enabled_paths = ProjectSettings::get_singleton()->get("gdnative/singletons");
}
Set<String> enabled_list;
@ -100,7 +100,7 @@ void GDNativeLibraryEditor::_item_edited() {
String path = item->get_metadata(0);
Vector<String> enabled_paths;
if (ProjectSettings::get_singleton()->has("gdnative/singletons")) {
if (ProjectSettings::get_singleton()->has_setting("gdnative/singletons")) {
enabled_paths = ProjectSettings::get_singleton()->get("gdnative/singletons");
}

View file

@ -871,7 +871,7 @@ class EditorExportAndroid : public EditorExportPlatform {
String lang = str.substr(str.find_last("-") + 1, str.length()).replace("-", "_");
String prop = "application/config/name_" + lang;
if (ProjectSettings::get_singleton()->has(prop)) {
if (ProjectSettings::get_singleton()->has_setting(prop)) {
str = ProjectSettings::get_singleton()->get(prop);
} else {
str = get_project_name(package_name);

View file

@ -853,7 +853,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv *en
static void _initialize_java_modules() {
if (!ProjectSettings::get_singleton()->has("android/modules")) {
if (!ProjectSettings::get_singleton()->has_setting("android/modules")) {
print_line("ANDROID MODULES: Nothing to load, aborting");
return;
}