Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements "Batch Rename" editor tool. #15928

Merged
merged 1 commit into from
May 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions editor/editor_data.cpp
Original file line number Diff line number Diff line change
@@ -867,7 +867,7 @@ Array EditorSelection::_get_transformable_selected_nodes() {
return ret;
}

Array EditorSelection::_get_selected_nodes() {
Array EditorSelection::get_selected_nodes() {

Array ret;

@@ -885,7 +885,7 @@ void EditorSelection::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear"), &EditorSelection::clear);
ClassDB::bind_method(D_METHOD("add_node", "node"), &EditorSelection::add_node);
ClassDB::bind_method(D_METHOD("remove_node", "node"), &EditorSelection::remove_node);
ClassDB::bind_method(D_METHOD("get_selected_nodes"), &EditorSelection::_get_selected_nodes);
ClassDB::bind_method(D_METHOD("get_selected_nodes"), &EditorSelection::get_selected_nodes);
ClassDB::bind_method(D_METHOD("get_transformable_selected_nodes"), &EditorSelection::_get_transformable_selected_nodes);
ClassDB::bind_method(D_METHOD("_emit_change"), &EditorSelection::_emit_change);
ADD_SIGNAL(MethodInfo("selection_changed"));
2 changes: 1 addition & 1 deletion editor/editor_data.h
Original file line number Diff line number Diff line change
@@ -224,14 +224,14 @@ class EditorSelection : public Object {
List<Node *> selected_node_list;

void _update_nl();
Array _get_selected_nodes();
Array _get_transformable_selected_nodes();
void _emit_change();

protected:
static void _bind_methods();

public:
Array get_selected_nodes();
void add_node(Node *p_node);
void remove_node(Node *p_node);
bool is_selected(Node *) const;
691 changes: 691 additions & 0 deletions editor/rename_dialog.cpp

Large diffs are not rendered by default.

119 changes: 119 additions & 0 deletions editor/rename_dialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/*************************************************************************/
/* rename_dialog.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/

#ifndef RENAME_DIALOG_H
#define RENAME_DIALOG_H

#include "scene/gui/check_box.h"
#include "scene/gui/check_button.h"
#include "scene/gui/dialogs.h"
#include "scene/gui/option_button.h"
#include "scene/gui/spin_box.h"

#include "editor/scene_tree_editor.h"
#include "undo_redo.h"

/**
@author Blazej Floch
*/

class RenameDialog : public ConfirmationDialog {

GDCLASS(RenameDialog, ConfirmationDialog);

virtual void ok_pressed() { rename(); };
void _cancel_pressed(){};
void _features_toggled(bool pressed);
void _insert_text(String text);
void _update_substitute();
bool _is_main_field(LineEdit *line_edit);

void _iterate_scene(const Node *node, const Array &selection, int *count);
String _apply_rename(const Node *node, int count);
String _substitute(const String &subject, const Node *node, int count);
String _regex(const String &pattern, const String &subject, const String &replacement);
String _postprocess(const String &subject);
void _update_preview(String new_text = "");
void _update_preview_int(int new_value = 0);
static void _error_handler(void *p_self, const char *p_func, const char *p_file, int p_line, const char *p_error, const char *p_errorexp, ErrorHandlerType p_type);

SceneTreeEditor *scene_tree_editor;
UndoRedo *undo_redo;
int global_count;

LineEdit *lne_search;
LineEdit *lne_replace;
LineEdit *lne_prefix;
LineEdit *lne_suffix;

TabContainer *tabc_features;

CheckButton *cbut_substitute;
CheckButton *cbut_regex;
CheckButton *cbut_process;
CheckBox *chk_per_level_counter;

Button *but_insert_name;
Button *but_insert_parent;
Button *but_insert_type;
Button *but_insert_scene;
Button *but_insert_root;
Button *but_insert_count;

SpinBox *spn_count_start;
SpinBox *spn_count_step;
SpinBox *spn_count_padding;

OptionButton *opt_style;
OptionButton *opt_case;

Label *lbl_preview_title;
Label *lbl_preview;

List<Pair<NodePath, String> > to_rename;
Node *preview_node;
bool lock_preview_update;
ErrorHandlerList eh;
bool has_errors;

protected:
void _notification(int p_what){};
static void _bind_methods();
virtual void _post_popup();

public:
void reset();
void rename();

RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_undo_redo = NULL);
~RenameDialog(){};
};

#endif
15 changes: 14 additions & 1 deletion editor/scene_tree_dock.cpp
Original file line number Diff line number Diff line change
@@ -70,7 +70,9 @@ void SceneTreeDock::_unhandled_key_input(Ref<InputEvent> p_event) {
if (!p_event->is_pressed() || p_event->is_echo())
return;

if (ED_IS_SHORTCUT("scene_tree/add_child_node", p_event)) {
if (ED_IS_SHORTCUT("scene_tree/batch_rename", p_event)) {
_tool_selected(TOOL_BATCH_RENAME);
} else if (ED_IS_SHORTCUT("scene_tree/add_child_node", p_event)) {
_tool_selected(TOOL_NEW);
} else if (ED_IS_SHORTCUT("scene_tree/instance_scene", p_event)) {
_tool_selected(TOOL_INSTANCE);
@@ -277,6 +279,12 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {

switch (p_tool) {

case TOOL_BATCH_RENAME: {
Tree *tree = scene_tree->get_scene_tree();
if (tree->is_anything_selected()) {
rename_dialog->popup_centered();
}
} break;
case TOOL_NEW: {

String preferred = "";
@@ -1745,6 +1753,7 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {

menu->clear();

menu->add_icon_shortcut(get_icon("Rename", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/batch_rename"), TOOL_BATCH_RENAME);
if (selection.size() == 1) {

subresources.clear();
@@ -1934,6 +1943,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel
filter_hbc->add_constant_override("separate", 0);
ToolButton *tb;

ED_SHORTCUT("scene_tree/batch_rename", TTR("Batch Rename"), KEY_MASK_CMD | KEY_F2);
ED_SHORTCUT("scene_tree/add_child_node", TTR("Add Child Node"), KEY_MASK_CMD | KEY_A);
ED_SHORTCUT("scene_tree/instance_scene", TTR("Instance Child Scene"));
ED_SHORTCUT("scene_tree/change_node_type", TTR("Change Type"));
@@ -2032,6 +2042,9 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel
add_child(create_dialog);
create_dialog->connect("create", this, "_create");

rename_dialog = memnew(RenameDialog(scene_tree, &editor_data->get_undo_redo()));
add_child(rename_dialog);

script_create_dialog = memnew(ScriptCreateDialog);
add_child(script_create_dialog);
script_create_dialog->connect("script_created", this, "_script_created");
3 changes: 3 additions & 0 deletions editor/scene_tree_dock.h
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@
#include "editor/editor_data.h"
#include "editor/editor_sub_scene.h"
#include "editor/groups_editor.h"
#include "editor/rename_dialog.h"
#include "editor/reparent_dialog.h"
#include "editor/script_create_dialog.h"
#include "scene/animation/animation_player.h"
@@ -58,6 +59,7 @@ class SceneTreeDock : public VBoxContainer {

TOOL_NEW,
TOOL_INSTANCE,
TOOL_BATCH_RENAME,
TOOL_REPLACE,
TOOL_ATTACH_SCRIPT,
TOOL_CLEAR_SCRIPT,
@@ -90,6 +92,7 @@ class SceneTreeDock : public VBoxContainer {

int current_option;
CreateDialog *create_dialog;
RenameDialog *rename_dialog;

ToolButton *button_add;
ToolButton *button_instance;
2 changes: 1 addition & 1 deletion scene/gui/line_edit.h
Original file line number Diff line number Diff line change
@@ -121,7 +121,6 @@ class LineEdit : public Control {
void shift_selection_check_post(bool);

void selection_fill_at_cursor();
void selection_delete();
void set_window_pos(int p_pos);

void set_cursor_at_pixel_pos(int p_x);
@@ -157,6 +156,7 @@ class LineEdit : public Control {

void select(int p_from = 0, int p_to = -1);
void select_all();
void selection_delete();
void deselect();

void delete_char();