Skip to content

Commit

Permalink
Merge pull request #56909 from Calinou/editor-add-scene-casing-settin…
Browse files Browse the repository at this point in the history
…g-3.x
  • Loading branch information
akien-mga authored Jan 21, 2022
2 parents 45b8cc4 + 8948b36 commit 3e7e701
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
23 changes: 17 additions & 6 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2432,13 +2432,21 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
file->set_current_path(path.replacen("." + ext, "." + extensions.front()->get()));
}
}
} else {
String existing;
if (extensions.size()) {
String root_name(scene->get_name());
existing = root_name + "." + extensions.front()->get().to_lower();
} else if (extensions.size()) {
String root_name = scene->get_name();
// Very similar to node naming logic.
switch (ProjectSettings::get_singleton()->get("editor/scene/scene_naming").operator int()) {
case SCENE_NAME_CASING_AUTO:
// Use casing of the root node.
break;
case SCENE_NAME_CASING_PASCAL_CASE: {
root_name = root_name.capitalize().replace(" ", "");
} break;
case SCENE_NAME_CASING_SNAKE_CASE:
root_name = root_name.capitalize().replace(" ", "").replace("-", "_").camelcase_to_underscore();
break;
}
file->set_current_path(existing);
file->set_current_path(root_name + "." + extensions.front()->get().to_lower());
}
file->popup_centered_ratio();
file->set_title(TTR("Save Scene As..."));
Expand Down Expand Up @@ -5575,6 +5583,9 @@ void EditorNode::_feature_profile_changed() {
}

void EditorNode::_bind_methods() {
GLOBAL_DEF("editor/scene/scene_naming", SCENE_NAME_CASING_AUTO);
ProjectSettings::get_singleton()->set_custom_property_info("editor/scene/scene_naming", PropertyInfo(Variant::INT, "editor/scene/scene_naming", PROPERTY_HINT_ENUM, "Auto,PascalCase,snake_case"));

ClassDB::bind_method("_menu_option", &EditorNode::_menu_option);
ClassDB::bind_method("_tool_menu_option", &EditorNode::_tool_menu_option);
ClassDB::bind_method("_menu_confirm_current", &EditorNode::_menu_confirm_current);
Expand Down
6 changes: 6 additions & 0 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ class EditorNode : public Node {
TOOL_MENU_BASE = 1000
};

enum ScriptNameCasing {
SCENE_NAME_CASING_AUTO,
SCENE_NAME_CASING_PASCAL_CASE,
SCENE_NAME_CASING_SNAKE_CASE
};

Viewport *scene_root; //root of the scene being edited

PanelContainer *scene_root_parent;
Expand Down

0 comments on commit 3e7e701

Please sign in to comment.