Skip to content

Commit

Permalink
Add alternative name styles for signal names
Browse files Browse the repository at this point in the history
Change signal names based on editor option
Add coding_language_style to editor settings
Remove / change original Godot code
  • Loading branch information
valkyrienyanko committed Oct 31, 2024
1 parent 7894cd1 commit 447509f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
54 changes: 29 additions & 25 deletions editor/connections_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,36 +237,40 @@ void ConnectDialog::_remove_bind() {
*/
StringName ConnectDialog::generate_method_callback_name(Node *p_source, const String &p_signal_name, Node *p_target) {
String node_name = p_source->get_name();
for (int i = 0; i < node_name.length(); i++) { // TODO: Regex filter may be cleaner.
char32_t c = node_name[i];
if ((i == 0 && !is_unicode_identifier_start(c)) || (i > 0 && !is_unicode_identifier_continue(c))) {
if (c == ' ') {
// Replace spaces with underlines.
c = '_';
} else {
// Remove any other characters.
node_name.remove_at(i);
i--;
continue;
}
}
node_name[i] = c;
}

Dictionary subst;
subst["NodeName"] = node_name.to_pascal_case();
subst["nodeName"] = node_name.to_camel_case();
subst["node_name"] = node_name.to_snake_case();
String dst_method;
String prefix;
String f_signal_name, f_node_name; // Formatted Names

subst["SignalName"] = p_signal_name.to_pascal_case();
subst["signalName"] = p_signal_name.to_camel_case();
subst["signal_name"] = p_signal_name.to_snake_case();
TextServer::CodingLanguageStyle style = (TextServer::CodingLanguageStyle)(int)EDITOR_GET("interface/editor/coding_language_style");

switch (style) {
case TextServer::SNAKE_CASE_LEADING_UNDERSCORE:
f_signal_name = p_signal_name.to_snake_case();
f_node_name = node_name.to_snake_case();
prefix = "_on_";
break;
case TextServer::SNAKE_CASE:
f_signal_name = p_signal_name.to_snake_case();
f_node_name = node_name.to_snake_case();
prefix = "on_";
break;
case TextServer::PASCAL_CASE:
f_signal_name = p_signal_name.to_pascal_case();
f_node_name = node_name.to_pascal_case();
prefix = "On";
break;
case TextServer::CAMEL_CASE:
f_signal_name = p_signal_name.to_camel_case();
f_node_name = node_name.to_camel_case() + "_";
prefix = "on";
break;
}

String dst_method;
if (p_source == p_target) {
dst_method = String(GLOBAL_GET("editor/naming/default_signal_callback_to_self_name")).format(subst);
dst_method = prefix + f_signal_name;
} else {
dst_method = String(GLOBAL_GET("editor/naming/default_signal_callback_name")).format(subst);
dst_method = prefix + f_node_name + f_signal_name;
}

return dst_method;
Expand Down
1 change: 1 addition & 0 deletions editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
// Editor
EDITOR_SETTING(Variant::BOOL, PROPERTY_HINT_NONE, "interface/editor/localize_settings", true, "")
EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/dock_tab_style", 0, "Text Only,Icon Only,Text and Icon")
EDITOR_SETTING_BASIC(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/coding_language_style", 0, "_snake_case,snake_case,PascalCase,camelCase")
EDITOR_SETTING_USAGE(Variant::INT, PROPERTY_HINT_ENUM, "interface/editor/ui_layout_direction", 0, "Based on Application Locale,Left-to-Right,Right-to-Left,Based on System Locale", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)

// Display what the Auto display scale setting effectively corresponds to.
Expand Down
7 changes: 7 additions & 0 deletions servers/text_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ class TextServer : public RefCounted {
AUTOWRAP_WORD_SMART
};

enum CodingLanguageStyle {
SNAKE_CASE_LEADING_UNDERSCORE,
SNAKE_CASE,
PASCAL_CASE,
CAMEL_CASE
};

enum LineBreakFlag {
BREAK_NONE = 0,
BREAK_MANDATORY = 1 << 0,
Expand Down

0 comments on commit 447509f

Please sign in to comment.