2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* editor_settings.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifndef EDITOR_SETTINGS_H
|
|
|
|
#define EDITOR_SETTINGS_H
|
|
|
|
|
2016-02-22 00:15:47 +01:00
|
|
|
#include "core/io/config_file.h"
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/io/resource.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/os/thread_safe.h"
|
2022-05-19 17:00:06 +02:00
|
|
|
#include "core/templates/rb_set.h"
|
2016-06-05 02:31:29 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
class EditorPlugin;
|
2022-02-14 14:00:03 +01:00
|
|
|
class InputEvent;
|
|
|
|
class Shortcut;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
class EditorSettings : public Resource {
|
2017-01-03 03:03:46 +01:00
|
|
|
GDCLASS(EditorSettings, Resource);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
_THREAD_SAFE_CLASS_
|
|
|
|
|
|
|
|
public:
|
|
|
|
struct Plugin {
|
2020-11-24 10:12:55 +01:00
|
|
|
EditorPlugin *instance = nullptr;
|
2014-02-10 02:10:30 +01:00
|
|
|
String path;
|
|
|
|
String name;
|
|
|
|
String author;
|
|
|
|
String version;
|
|
|
|
String description;
|
2020-11-24 10:12:55 +01:00
|
|
|
bool installs = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
String script;
|
|
|
|
Vector<String> install_files;
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
private:
|
2014-02-10 02:10:30 +01:00
|
|
|
struct VariantContainer {
|
2020-05-12 17:01:17 +02:00
|
|
|
int order = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
Variant variant;
|
2017-09-25 05:26:41 +02:00
|
|
|
Variant initial;
|
2020-05-12 17:01:17 +02:00
|
|
|
bool has_default_value = false;
|
|
|
|
bool hide_from_editor = false;
|
|
|
|
bool save = false;
|
|
|
|
bool restart_if_changed = false;
|
|
|
|
|
|
|
|
VariantContainer() {}
|
|
|
|
|
2018-12-08 21:07:33 +01:00
|
|
|
VariantContainer(const Variant &p_variant, int p_order) :
|
|
|
|
order(p_order),
|
2020-05-12 17:01:17 +02:00
|
|
|
variant(p_variant) {
|
2017-03-05 16:44:50 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-10-28 15:40:55 +02:00
|
|
|
static Ref<EditorSettings> singleton;
|
|
|
|
|
2022-05-19 17:00:06 +02:00
|
|
|
HashSet<String> changed_settings;
|
2021-10-15 14:34:11 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
HashMap<String, PropertyInfo> hints;
|
|
|
|
HashMap<String, VariantContainer> props;
|
2017-10-28 15:40:55 +02:00
|
|
|
int last_order;
|
2017-09-25 05:26:41 +02:00
|
|
|
|
2017-10-28 15:40:55 +02:00
|
|
|
Ref<Resource> clipboard;
|
2022-05-13 15:04:37 +02:00
|
|
|
mutable HashMap<String, Ref<Shortcut>> shortcuts;
|
|
|
|
HashMap<String, List<Ref<InputEvent>>> builtin_action_overrides;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-09-18 14:02:59 +02:00
|
|
|
Vector<String> favorites;
|
2017-10-28 15:40:55 +02:00
|
|
|
Vector<String> recent_dirs;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-02-15 15:56:58 +01:00
|
|
|
bool save_changed_setting = true;
|
|
|
|
bool optimize_save = true; //do not save stuff that came from config but was not set from engine
|
2016-06-12 02:16:14 +02:00
|
|
|
|
2018-01-06 12:40:43 +01:00
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _set_only(const StringName &p_name, const Variant &p_value);
|
2017-10-28 15:40:55 +02:00
|
|
|
bool _get(const StringName &p_name, Variant &r_ret) const;
|
|
|
|
void _initial_set(const StringName &p_name, const Variant &p_value);
|
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
|
|
|
void _add_property_info_bind(const Dictionary &p_info);
|
2022-08-12 20:43:14 +02:00
|
|
|
bool _property_can_revert(const StringName &p_name) const;
|
|
|
|
bool _property_get_revert(const StringName &p_name, Variant &r_property) const;
|
2017-10-28 15:40:55 +02:00
|
|
|
|
2020-03-03 10:46:03 +01:00
|
|
|
void _load_defaults(Ref<ConfigFile> p_extra_config = Ref<ConfigFile>());
|
2021-05-27 10:22:36 +02:00
|
|
|
void _load_godot2_text_editor_theme();
|
2016-04-12 16:45:31 +02:00
|
|
|
bool _save_text_editor_theme(String p_file);
|
2019-06-26 15:08:25 +02:00
|
|
|
bool _is_default_text_editor_theme(String p_theme_name);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2014-02-10 02:10:30 +01:00
|
|
|
enum {
|
|
|
|
NOTIFICATION_EDITOR_SETTINGS_CHANGED = 10000
|
|
|
|
};
|
|
|
|
|
|
|
|
static EditorSettings *get_singleton();
|
|
|
|
|
2017-10-28 15:40:55 +02:00
|
|
|
static void create();
|
2016-05-28 00:58:28 +02:00
|
|
|
void setup_language();
|
2015-08-06 07:37:40 +02:00
|
|
|
void setup_network();
|
2014-02-10 02:10:30 +01:00
|
|
|
static void save();
|
|
|
|
static void destroy();
|
2017-10-28 15:40:55 +02:00
|
|
|
void set_optimize_save(bool p_optimize);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-10-28 23:25:28 +02:00
|
|
|
bool has_default_value(const String &p_setting) const;
|
2017-10-28 15:40:55 +02:00
|
|
|
void set_setting(const String &p_setting, const Variant &p_value);
|
|
|
|
Variant get_setting(const String &p_setting) const;
|
2017-10-31 15:24:35 +01:00
|
|
|
bool has_setting(const String &p_setting) const;
|
|
|
|
void erase(const String &p_setting);
|
|
|
|
void raise_order(const String &p_setting);
|
2018-02-01 09:57:10 +01:00
|
|
|
void set_initial_value(const StringName &p_setting, const Variant &p_value, bool p_update_current = false);
|
2018-07-19 23:58:15 +02:00
|
|
|
void set_restart_if_changed(const StringName &p_setting, bool p_restart);
|
2017-10-31 15:24:35 +01:00
|
|
|
void set_manually(const StringName &p_setting, const Variant &p_value, bool p_emit_signal = false) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_emit_signal) {
|
2018-01-06 12:40:43 +01:00
|
|
|
_set(p_setting, p_value);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2018-01-06 12:40:43 +01:00
|
|
|
_set_only(p_setting, p_value);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-10-28 15:40:55 +02:00
|
|
|
}
|
|
|
|
void add_property_hint(const PropertyInfo &p_hint);
|
2022-08-05 03:41:48 +02:00
|
|
|
PackedStringArray get_changed_settings() const;
|
2021-10-15 14:34:11 +02:00
|
|
|
bool check_changed_settings_in_group(const String &p_setting_prefix) const;
|
|
|
|
void mark_setting_changed(const String &p_setting);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void set_resource_clipboard(const Ref<Resource> &p_resource) { clipboard = p_resource; }
|
|
|
|
Ref<Resource> get_resource_clipboard() const { return clipboard; }
|
|
|
|
|
2017-10-28 15:40:55 +02:00
|
|
|
void set_project_metadata(const String &p_section, const String &p_key, Variant p_data);
|
2018-05-16 17:23:20 +02:00
|
|
|
Variant get_project_metadata(const String &p_section, const String &p_key, Variant p_default) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-09-18 14:02:59 +02:00
|
|
|
void set_favorites(const Vector<String> &p_favorites);
|
|
|
|
Vector<String> get_favorites() const;
|
2015-06-06 14:44:38 +02:00
|
|
|
void set_recent_dirs(const Vector<String> &p_recent_dirs);
|
|
|
|
Vector<String> get_recent_dirs() const;
|
2022-02-03 01:21:52 +01:00
|
|
|
void load_favorites_and_recent_dirs();
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2018-06-10 16:30:49 +02:00
|
|
|
bool is_dark_theme();
|
|
|
|
|
2016-04-12 16:45:31 +02:00
|
|
|
void list_text_editor_themes();
|
|
|
|
void load_text_editor_theme();
|
|
|
|
bool import_text_editor_theme(String p_file);
|
|
|
|
bool save_text_editor_theme();
|
|
|
|
bool save_text_editor_theme_as(String p_file);
|
2019-05-23 17:18:24 +02:00
|
|
|
bool is_default_text_editor_theme();
|
2016-04-12 16:45:31 +02:00
|
|
|
|
2019-08-22 17:59:43 +02:00
|
|
|
Vector<String> get_script_templates(const String &p_extension, const String &p_custom_path = String());
|
2017-11-17 21:48:24 +01:00
|
|
|
String get_editor_layouts_config() const;
|
2021-06-16 14:36:09 +02:00
|
|
|
float get_auto_display_scale() const;
|
2017-06-13 22:03:08 +02:00
|
|
|
|
2023-02-21 07:08:53 +01:00
|
|
|
void _add_shortcut_default(const String &p_name, const Ref<Shortcut> &p_shortcut);
|
2022-04-05 12:40:26 +02:00
|
|
|
void add_shortcut(const String &p_name, const Ref<Shortcut> &p_shortcut);
|
2017-05-20 17:38:03 +02:00
|
|
|
bool is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const;
|
2020-09-09 21:53:24 +02:00
|
|
|
Ref<Shortcut> get_shortcut(const String &p_name) const;
|
2016-06-05 02:31:29 +02:00
|
|
|
void get_shortcut_list(List<String> *r_shortcuts);
|
|
|
|
|
2022-08-31 19:24:04 +02:00
|
|
|
void set_builtin_action_override(const String &p_name, const TypedArray<InputEvent> &p_events);
|
2020-12-07 12:31:51 +01:00
|
|
|
const Array get_builtin_action_overrides(const String &p_name) const;
|
|
|
|
|
2017-10-28 15:40:55 +02:00
|
|
|
void notify_changes();
|
2017-09-25 05:26:41 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
EditorSettings();
|
|
|
|
~EditorSettings();
|
|
|
|
};
|
|
|
|
|
|
|
|
//not a macro any longer
|
|
|
|
|
|
|
|
#define EDITOR_DEF(m_var, m_val) _EDITOR_DEF(m_var, Variant(m_val))
|
2018-07-19 23:58:15 +02:00
|
|
|
#define EDITOR_DEF_RST(m_var, m_val) _EDITOR_DEF(m_var, Variant(m_val), true)
|
|
|
|
Variant _EDITOR_DEF(const String &p_setting, const Variant &p_default, bool p_restart_if_changed = false);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-26 05:40:45 +02:00
|
|
|
#define EDITOR_GET(m_var) _EDITOR_GET(m_var)
|
2017-10-31 15:24:35 +01:00
|
|
|
Variant _EDITOR_GET(const String &p_setting);
|
2017-08-26 05:40:45 +02:00
|
|
|
|
2016-06-05 02:31:29 +02:00
|
|
|
#define ED_IS_SHORTCUT(p_name, p_ev) (EditorSettings::get_singleton()->is_shortcut(p_name, p_ev))
|
2023-02-20 23:11:57 +01:00
|
|
|
Ref<Shortcut> ED_SHORTCUT(const String &p_path, const String &p_name, Key p_keycode = Key::NONE, bool p_physical = false);
|
|
|
|
Ref<Shortcut> ED_SHORTCUT_ARRAY(const String &p_path, const String &p_name, const PackedInt32Array &p_keycodes, bool p_physical = false);
|
|
|
|
void ED_SHORTCUT_OVERRIDE(const String &p_path, const String &p_feature, Key p_keycode = Key::NONE, bool p_physical = false);
|
|
|
|
void ED_SHORTCUT_OVERRIDE_ARRAY(const String &p_path, const String &p_feature, const PackedInt32Array &p_keycodes, bool p_physical = false);
|
2020-09-09 21:53:24 +02:00
|
|
|
Ref<Shortcut> ED_GET_SHORTCUT(const String &p_path);
|
2016-06-05 02:31:29 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif // EDITOR_SETTINGS_H
|