summaryrefslogtreecommitdiff
path: root/tools/editor
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2016-10-07 20:25:29 +0200
committerPedro J. Estébanez <pedrojrulez@gmail.com>2016-10-08 21:49:16 +0200
commit9b2e2935d06f870171353cb0e3f52caa6fc74c5b (patch)
tree803ed760d484c2e5cf89096f83fdce7f001e4d76 /tools/editor
parent88a32c11f1d35c57a7af4b8f6733595b95ab4e4b (diff)
Refactor node naming APIs used by editor
Make 'name_num_separator' a project setting Make all node operations separator-aware
Diffstat (limited to 'tools/editor')
-rw-r--r--tools/editor/editor_settings.cpp2
-rw-r--r--tools/editor/scene_tree_dock.cpp53
2 files changed, 6 insertions, 49 deletions
diff --git a/tools/editor/editor_settings.cpp b/tools/editor/editor_settings.cpp
index 4778a7ce90..a5ba4847f5 100644
--- a/tools/editor/editor_settings.cpp
+++ b/tools/editor/editor_settings.cpp
@@ -565,8 +565,6 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
set("text_editor/restore_scripts_on_load",true);
- set("scenetree_editor/duplicate_node_name_num_separator",0);
- hints["scenetree_editor/duplicate_node_name_num_separator"]=PropertyInfo(Variant::INT,"scenetree_editor/duplicate_node_name_num_separator",PROPERTY_HINT_ENUM, "None,Space,Underscore,Dash");
//set("scenetree_editor/display_old_action_buttons",false);
set("scenetree_editor/start_create_dialog_fully_expanded",false);
set("scenetree_editor/draw_relationship_lines",false);
diff --git a/tools/editor/scene_tree_dock.cpp b/tools/editor/scene_tree_dock.cpp
index d69f1ac58f..342e6b98c8 100644
--- a/tools/editor/scene_tree_dock.cpp
+++ b/tools/editor/scene_tree_dock.cpp
@@ -227,7 +227,7 @@ void SceneTreeDock::_perform_instance_scenes(const Vector<String>& p_files,Node*
editor_data->get_undo_redo().add_do_reference(instanced_scene);
editor_data->get_undo_redo().add_undo_method(parent,"remove_child",instanced_scene);
- String new_name = parent->validate_child_name(instanced_scene->get_name());
+ String new_name = parent->validate_child_name(instanced_scene);
ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
editor_data->get_undo_redo().add_do_method(sed,"live_debug_instance_node",edited_scene->get_path_to(parent),p_files[i],new_name);
editor_data->get_undo_redo().add_undo_method(sed,"live_debug_remove_node",NodePath(String(edited_scene->get_path_to(parent))+"/"+new_name));
@@ -257,17 +257,6 @@ bool SceneTreeDock::_cyclical_dependency_exists(const String& p_target_scene_pat
}
-static String _get_name_num_separator() {
- switch(EditorSettings::get_singleton()->get("scenetree_editor/duplicate_node_name_num_separator").operator int()) {
- case 0: return "";
- case 1: return " ";
- case 2: return "_";
- case 3: return "-";
- }
- return " ";
-}
-
-
void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
current_option=p_tool;
@@ -474,37 +463,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
if (selection.size()==1)
dupsingle=dup;
- String name = node->get_name();
-
- String nums;
- for(int i=name.length()-1;i>=0;i--) {
- CharType n=name[i];
- if (n>='0' && n<='9') {
- nums=String::chr(name[i])+nums;
- } else {
- break;
- }
- }
-
- int num=nums.to_int();
- if (num<1)
- num=1;
- else
- num++;
-
- String nnsep = _get_name_num_separator();
- name = name.substr(0,name.length()-nums.length()).strip_edges();
- if ( name.substr(name.length()-nnsep.length(),nnsep.length()) == nnsep) {
- name = name.substr(0,name.length()-nnsep.length());
- }
- String attempt = (name + nnsep + itos(num)).strip_edges();
-
- while(parent->has_node(attempt)) {
- num++;
- attempt = (name + nnsep + itos(num)).strip_edges();
- }
-
- dup->set_name(attempt);
+ dup->set_name(parent->validate_child_name(dup));
editor_data->get_undo_redo().add_do_method(parent,"_add_child_below_node",node, dup);
for (List<Node*>::Element *F=owned.front();F;F=F->next()) {
@@ -522,8 +481,8 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
- editor_data->get_undo_redo().add_do_method(sed,"live_debug_duplicate_node",edited_scene->get_path_to(node),attempt);
- editor_data->get_undo_redo().add_undo_method(sed,"live_debug_remove_node",NodePath(String(edited_scene->get_path_to(parent))+"/"+attempt));
+ editor_data->get_undo_redo().add_do_method(sed,"live_debug_duplicate_node",edited_scene->get_path_to(node),dup->get_name());
+ editor_data->get_undo_redo().add_undo_method(sed,"live_debug_remove_node",NodePath(String(edited_scene->get_path_to(parent))+"/"+dup->get_name()));
//parent->add_child(dup);
//reselect.push_back(dup);
@@ -1142,7 +1101,7 @@ void SceneTreeDock::_do_reparent(Node* p_new_parent,int p_position_in_parent,Vec
editor_data->get_undo_redo().add_do_method(new_parent,"move_child",node,p_position_in_parent+inc);
ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
- String new_name = new_parent->validate_child_name(node->get_name());
+ String new_name = new_parent->validate_child_name(node);
editor_data->get_undo_redo().add_do_method(sed,"live_debug_reparent_node",edited_scene->get_path_to(node),edited_scene->get_path_to(new_parent),new_name,-1);
editor_data->get_undo_redo().add_undo_method(sed,"live_debug_reparent_node",NodePath(String(edited_scene->get_path_to(new_parent))+"/"+new_name),edited_scene->get_path_to(node->get_parent()),node->get_name(),node->get_index());
@@ -1363,7 +1322,7 @@ void SceneTreeDock::_create() {
editor_data->get_undo_redo().add_undo_method(parent,"remove_child",child);
- String new_name = parent->validate_child_name(child->get_type());
+ String new_name = parent->validate_child_name(child);
ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
editor_data->get_undo_redo().add_do_method(sed,"live_debug_create_node",edited_scene->get_path_to(parent),child->get_type(),new_name);
editor_data->get_undo_redo().add_undo_method(sed,"live_debug_remove_node",NodePath(String(edited_scene->get_path_to(parent))+"/"+new_name));