1
0
mirror of https://github.com/godotengine/godot.git synced 2026-01-06 19:41:11 +00:00

Merge pull request #89530 from dalexeev/ed-allow-rename-theme-types

Editor: Add ability to rename theme types
This commit is contained in:
Thaddeus Crews
2025-06-02 18:51:40 -05:00
5 changed files with 326 additions and 28 deletions

View File

@@ -361,6 +361,17 @@ void Theme::remove_icon_type(const StringName &p_theme_type) {
_unfreeze_and_propagate_changes();
}
void Theme::rename_icon_type(const StringName &p_old_theme_type, const StringName &p_theme_type) {
ERR_FAIL_COND_MSG(!is_valid_type_name(p_theme_type), vformat("Invalid type name: '%s'", p_theme_type));
if (!icon_map.has(p_old_theme_type) || icon_map.has(p_theme_type)) {
return;
}
icon_map[p_theme_type] = icon_map[p_old_theme_type];
icon_map.erase(p_old_theme_type);
}
void Theme::get_icon_type_list(List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
@@ -471,6 +482,17 @@ void Theme::remove_stylebox_type(const StringName &p_theme_type) {
_unfreeze_and_propagate_changes();
}
void Theme::rename_stylebox_type(const StringName &p_old_theme_type, const StringName &p_theme_type) {
ERR_FAIL_COND_MSG(!is_valid_type_name(p_theme_type), vformat("Invalid type name: '%s'", p_theme_type));
if (!style_map.has(p_old_theme_type) || style_map.has(p_theme_type)) {
return;
}
style_map[p_theme_type] = style_map[p_old_theme_type];
style_map.erase(p_old_theme_type);
}
void Theme::get_stylebox_type_list(List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
@@ -587,6 +609,17 @@ void Theme::remove_font_type(const StringName &p_theme_type) {
_unfreeze_and_propagate_changes();
}
void Theme::rename_font_type(const StringName &p_old_theme_type, const StringName &p_theme_type) {
ERR_FAIL_COND_MSG(!is_valid_type_name(p_theme_type), vformat("Invalid type name: '%s'", p_theme_type));
if (!font_map.has(p_old_theme_type) || font_map.has(p_theme_type)) {
return;
}
font_map[p_theme_type] = font_map[p_old_theme_type];
font_map.erase(p_old_theme_type);
}
void Theme::get_font_type_list(List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
@@ -679,6 +712,17 @@ void Theme::remove_font_size_type(const StringName &p_theme_type) {
font_size_map.erase(p_theme_type);
}
void Theme::rename_font_size_type(const StringName &p_old_theme_type, const StringName &p_theme_type) {
ERR_FAIL_COND_MSG(!is_valid_type_name(p_theme_type), vformat("Invalid type name: '%s'", p_theme_type));
if (!font_size_map.has(p_old_theme_type) || font_size_map.has(p_theme_type)) {
return;
}
font_size_map[p_theme_type] = font_size_map[p_old_theme_type];
font_size_map.erase(p_old_theme_type);
}
void Theme::get_font_size_type_list(List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
@@ -765,6 +809,17 @@ void Theme::remove_color_type(const StringName &p_theme_type) {
color_map.erase(p_theme_type);
}
void Theme::rename_color_type(const StringName &p_old_theme_type, const StringName &p_theme_type) {
ERR_FAIL_COND_MSG(!is_valid_type_name(p_theme_type), vformat("Invalid type name: '%s'", p_theme_type));
if (!color_map.has(p_old_theme_type) || color_map.has(p_theme_type)) {
return;
}
color_map[p_theme_type] = color_map[p_old_theme_type];
color_map.erase(p_old_theme_type);
}
void Theme::get_color_type_list(List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
@@ -851,6 +906,17 @@ void Theme::remove_constant_type(const StringName &p_theme_type) {
constant_map.erase(p_theme_type);
}
void Theme::rename_constant_type(const StringName &p_old_theme_type, const StringName &p_theme_type) {
ERR_FAIL_COND_MSG(!is_valid_type_name(p_theme_type), vformat("Invalid type name: '%s'", p_theme_type));
if (!constant_map.has(p_old_theme_type) || constant_map.has(p_theme_type)) {
return;
}
constant_map[p_theme_type] = constant_map[p_old_theme_type];
constant_map.erase(p_old_theme_type);
}
void Theme::get_constant_type_list(List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
@@ -1099,6 +1165,31 @@ void Theme::remove_theme_item_type(DataType p_data_type, const StringName &p_the
}
}
void Theme::rename_theme_item_type(DataType p_data_type, const StringName &p_old_theme_type, const StringName &p_theme_type) {
switch (p_data_type) {
case DATA_TYPE_COLOR:
rename_color_type(p_old_theme_type, p_theme_type);
break;
case DATA_TYPE_CONSTANT:
rename_constant_type(p_old_theme_type, p_theme_type);
break;
case DATA_TYPE_FONT:
rename_font_type(p_old_theme_type, p_theme_type);
break;
case DATA_TYPE_FONT_SIZE:
rename_font_size_type(p_old_theme_type, p_theme_type);
break;
case DATA_TYPE_ICON:
rename_icon_type(p_old_theme_type, p_theme_type);
break;
case DATA_TYPE_STYLEBOX:
rename_stylebox_type(p_old_theme_type, p_theme_type);
break;
case DATA_TYPE_MAX:
break; // Can't happen, but silences warning.
}
}
void Theme::get_theme_item_type_list(DataType p_data_type, List<StringName> *p_list) const {
switch (p_data_type) {
case DATA_TYPE_COLOR:
@@ -1217,6 +1308,35 @@ void Theme::remove_type(const StringName &p_theme_type) {
_emit_theme_changed(true);
}
void Theme::rename_type(const StringName &p_old_theme_type, const StringName &p_theme_type) {
// Gracefully rename the record in every data type map.
for (int i = 0; i < Theme::DATA_TYPE_MAX; i++) {
Theme::DataType dt = (Theme::DataType)i;
rename_theme_item_type(dt, p_old_theme_type, p_theme_type);
}
// If type is a variation, replace that connection.
const StringName base_type = get_type_variation_base(p_old_theme_type);
if (base_type != StringName()) {
clear_type_variation(p_old_theme_type);
if (p_theme_type != StringName() && !ClassDB::class_exists(p_theme_type)) {
set_type_variation(p_theme_type, base_type);
}
}
// If type is a variation base, replace all those connections.
List<StringName> names;
get_type_variation_list(p_old_theme_type, &names);
for (const StringName &E : names) {
clear_type_variation(E);
if (p_theme_type != StringName()) {
set_type_variation(E, p_theme_type);
}
}
_emit_theme_changed(true);
}
void Theme::get_type_list(List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
@@ -1769,6 +1889,7 @@ void Theme::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_type", "theme_type"), &Theme::add_type);
ClassDB::bind_method(D_METHOD("remove_type", "theme_type"), &Theme::remove_type);
ClassDB::bind_method(D_METHOD("rename_type", "old_theme_type", "theme_type"), &Theme::rename_type);
ClassDB::bind_method(D_METHOD("get_type_list"), &Theme::_get_type_list);
ClassDB::bind_method(D_METHOD("merge_with", "other"), &Theme::merge_with);

View File

@@ -138,6 +138,7 @@ public:
void get_icon_list(const StringName &p_theme_type, List<StringName> *p_list) const;
void add_icon_type(const StringName &p_theme_type);
void remove_icon_type(const StringName &p_theme_type);
void rename_icon_type(const StringName &p_old_theme_type, const StringName &p_theme_type);
void get_icon_type_list(List<StringName> *p_list) const;
void set_stylebox(const StringName &p_name, const StringName &p_theme_type, const Ref<StyleBox> &p_style);
@@ -149,6 +150,7 @@ public:
void get_stylebox_list(const StringName &p_theme_type, List<StringName> *p_list) const;
void add_stylebox_type(const StringName &p_theme_type);
void remove_stylebox_type(const StringName &p_theme_type);
void rename_stylebox_type(const StringName &p_old_theme_type, const StringName &p_theme_type);
void get_stylebox_type_list(List<StringName> *p_list) const;
void set_font(const StringName &p_name, const StringName &p_theme_type, const Ref<Font> &p_font);
@@ -161,6 +163,7 @@ public:
void get_font_list(const StringName &p_theme_type, List<StringName> *p_list) const;
void add_font_type(const StringName &p_theme_type);
void remove_font_type(const StringName &p_theme_type);
void rename_font_type(const StringName &p_old_theme_type, const StringName &p_theme_type);
void get_font_type_list(List<StringName> *p_list) const;
void set_font_size(const StringName &p_name, const StringName &p_theme_type, int p_font_size);
@@ -173,6 +176,7 @@ public:
void get_font_size_list(const StringName &p_theme_type, List<StringName> *p_list) const;
void add_font_size_type(const StringName &p_theme_type);
void remove_font_size_type(const StringName &p_theme_type);
void rename_font_size_type(const StringName &p_old_theme_type, const StringName &p_theme_type);
void get_font_size_type_list(List<StringName> *p_list) const;
void set_color(const StringName &p_name, const StringName &p_theme_type, const Color &p_color);
@@ -184,6 +188,7 @@ public:
void get_color_list(const StringName &p_theme_type, List<StringName> *p_list) const;
void add_color_type(const StringName &p_theme_type);
void remove_color_type(const StringName &p_theme_type);
void rename_color_type(const StringName &p_old_theme_type, const StringName &p_theme_type);
void get_color_type_list(List<StringName> *p_list) const;
void set_constant(const StringName &p_name, const StringName &p_theme_type, int p_constant);
@@ -195,6 +200,7 @@ public:
void get_constant_list(const StringName &p_theme_type, List<StringName> *p_list) const;
void add_constant_type(const StringName &p_theme_type);
void remove_constant_type(const StringName &p_theme_type);
void rename_constant_type(const StringName &p_old_theme_type, const StringName &p_theme_type);
void get_constant_type_list(List<StringName> *p_list) const;
void set_theme_item(DataType p_data_type, const StringName &p_name, const StringName &p_theme_type, const Variant &p_value);
@@ -206,6 +212,7 @@ public:
void get_theme_item_list(DataType p_data_type, const StringName &p_theme_type, List<StringName> *p_list) const;
void add_theme_item_type(DataType p_data_type, const StringName &p_theme_type);
void remove_theme_item_type(DataType p_data_type, const StringName &p_theme_type);
void rename_theme_item_type(DataType p_data_type, const StringName &p_old_theme_type, const StringName &p_theme_type);
void get_theme_item_type_list(DataType p_data_type, List<StringName> *p_list) const;
void set_type_variation(const StringName &p_theme_type, const StringName &p_base_type);
@@ -216,6 +223,7 @@ public:
void add_type(const StringName &p_theme_type);
void remove_type(const StringName &p_theme_type);
void rename_type(const StringName &p_old_theme_type, const StringName &p_theme_type);
void get_type_list(List<StringName> *p_list) const;
void get_type_dependencies(const StringName &p_base_type, const StringName &p_type_variant, Vector<StringName> &r_result);