Convert case of property names

This commit is contained in:
don-tnowe 2022-09-30 20:56:25 +03:00
parent a1fadfd47d
commit 41b8737609
3 changed files with 27 additions and 15 deletions

View File

@ -197,7 +197,7 @@ func _create_table(columns_changed : bool):
for x in columns:
new_node = table_header_scene.instance()
headers_node.add_child(new_node)
new_node.get_node("Button").text = x
new_node.get_node("Button").text = TextEditingUtils.string_snake_to_naming_case(x)
new_node.get_node("Button").hint_tooltip = x
new_node.get_node("Button").connect("pressed", self, "_set_sorting", [x])
@ -258,7 +258,11 @@ func _update_row(row_index : int, color_rows : bool = true):
else:
current_node = root_node.get_child(row_index * columns.size() + i)
current_node.hint_tooltip = columns[i] + "\nOf " + rows[row_index].resource_path.get_file().get_basename()
current_node.hint_tooltip = (
TextEditingUtils.string_snake_to_naming_case(columns[i])
+ "\n---\n"
+ "Of " + rows[row_index].resource_path.get_file().get_basename()
)
column_editors[i].set_value(current_node, rows[row_index].get(columns[i]))
if columns[i] == "resource_path":

View File

@ -7,7 +7,7 @@ const SETTING_PREFIX = "addons/resources_spreadsheet_view/"
func _ready():
for x in get_children():
var setting = SETTING_PREFIX + camel_case_to_snake_case(x.name)
var setting = SETTING_PREFIX + TextEditingUtils.pascal_case_to_snake_case(x.name)
if x is BaseButton:
x.connect("toggled", self, "_set_setting", [setting])
if !ProjectSettings.has_setting(setting):
@ -25,17 +25,5 @@ func _ready():
x.value = ProjectSettings.get_setting(setting)
static func camel_case_to_snake_case(string : String) -> String:
var i = 0
while i < string.length():
if string.ord_at(i) < 97:
string = string.left(i) + ("_" if i > 0 else "") + string[i].to_lower() + string.substr(i + 1)
i += 1
i += 1
return string
func _set_setting(new_value, setting):
ProjectSettings.set_setting(setting, new_value)

View File

@ -140,3 +140,23 @@ static func _step_cursor(text : String, start : int, step : int = 1, ctrl_presse
return start
return 0
static func string_snake_to_naming_case(string : String, add_spaces : bool = true) -> String:
var split = string.split("_")
for i in split.size():
split[i] = split[i][0].to_upper() + split[i].substr(1).to_lower()
return (" " if add_spaces else "").join(split)
static func pascal_case_to_snake_case(string : String) -> String:
var i = 0
while i < string.length():
if string.ord_at(i) < 97:
string = string.left(i) + ("_" if i > 0 else "") + string[i].to_lower() + string.substr(i + 1)
i += 1
i += 1
return string