summaryrefslogtreecommitdiff
path: root/editor/rename_dialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/rename_dialog.cpp')
-rw-r--r--editor/rename_dialog.cpp34
1 files changed, 9 insertions, 25 deletions
diff --git a/editor/rename_dialog.cpp b/editor/rename_dialog.cpp
index c14462f07d..6a54894f40 100644
--- a/editor/rename_dialog.cpp
+++ b/editor/rename_dialog.cpp
@@ -42,10 +42,9 @@
#include "scene/gui/tab_container.h"
RenameDialog::RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_undo_redo) {
-
scene_tree_editor = p_scene_tree_editor;
undo_redo = p_undo_redo;
- preview_node = NULL;
+ preview_node = nullptr;
set_title(TTR("Batch Rename"));
@@ -341,12 +340,10 @@ RenameDialog::RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_und
}
void RenameDialog::_bind_methods() {
-
ClassDB::bind_method("rename", &RenameDialog::rename);
}
void RenameDialog::_update_substitute() {
-
LineEdit *focus_owner_line_edit = Object::cast_to<LineEdit>(scene_tree_editor->get_focus_owner());
bool is_main_field = _is_main_field(focus_owner_line_edit);
@@ -367,9 +364,8 @@ void RenameDialog::_update_substitute() {
}
void RenameDialog::_post_popup() {
-
EditorSelection *editor_selection = EditorNode::get_singleton()->get_editor_selection();
- preview_node = NULL;
+ preview_node = nullptr;
Array selected_node_list = editor_selection->get_selected_nodes();
ERR_FAIL_COND(selected_node_list.size() == 0);
@@ -385,9 +381,9 @@ void RenameDialog::_update_preview_int(int new_value) {
}
void RenameDialog::_update_preview(String new_text) {
-
- if (lock_preview_update || preview_node == NULL)
+ if (lock_preview_update || preview_node == nullptr) {
return;
+ }
has_errors = false;
add_error_handler(&eh);
@@ -395,7 +391,6 @@ void RenameDialog::_update_preview(String new_text) {
String new_name = _apply_rename(preview_node, spn_count_start->get_value());
if (!has_errors) {
-
lbl_preview_title->set_text(TTR("Preview"));
lbl_preview->set_text(new_name);
@@ -403,7 +398,7 @@ void RenameDialog::_update_preview(String new_text) {
// New name is identical to the old one. Don't color it as much to avoid distracting the user.
const Color accent_color = EditorNode::get_singleton()->get_gui_base()->get_theme_color("accent_color", "Editor");
const Color text_color = EditorNode::get_singleton()->get_gui_base()->get_theme_color("default_color", "RichTextLabel");
- lbl_preview->add_theme_color_override("font_color", accent_color.linear_interpolate(text_color, 0.5));
+ lbl_preview->add_theme_color_override("font_color", accent_color.lerp(text_color, 0.5));
} else {
lbl_preview->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color("success_color", "Editor"));
}
@@ -413,7 +408,6 @@ void RenameDialog::_update_preview(String new_text) {
}
String RenameDialog::_apply_rename(const Node *node, int count) {
-
String search = lne_search->get_text();
String replace = lne_replace->get_text();
String prefix = lne_prefix->get_text();
@@ -428,7 +422,6 @@ String RenameDialog::_apply_rename(const Node *node, int count) {
}
if (cbut_regex->is_pressed()) {
-
new_name = _regex(search, new_name, replace);
} else {
new_name = new_name.replace(search, replace);
@@ -444,7 +437,6 @@ String RenameDialog::_apply_rename(const Node *node, int count) {
}
String RenameDialog::_substitute(const String &subject, const Node *node, int count) {
-
String result = subject.replace("${COUNTER}", vformat("%0" + itos(spn_count_padding->get_value()) + "d", count));
if (node) {
@@ -474,13 +466,13 @@ String RenameDialog::_substitute(const String &subject, const Node *node, int co
}
void RenameDialog::_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) {
-
RenameDialog *self = (RenameDialog *)p_self;
String source_file(p_file);
// Only show first error that is related to "regex"
- if (self->has_errors || source_file.find("regex") < 0)
+ if (self->has_errors || source_file.find("regex") < 0) {
return;
+ }
String err_str;
if (p_errorexp && p_errorexp[0]) {
@@ -496,14 +488,12 @@ void RenameDialog::_error_handler(void *p_self, const char *p_func, const char *
}
String RenameDialog::_regex(const String &pattern, const String &subject, const String &replacement) {
-
RegEx regex(pattern);
return regex.sub(subject, replacement, true);
}
String RenameDialog::_postprocess(const String &subject) {
-
int style_id = opt_style->get_selected();
String result = subject;
@@ -550,12 +540,11 @@ String RenameDialog::_postprocess(const String &subject) {
}
void RenameDialog::_iterate_scene(const Node *node, const Array &selection, int *counter) {
-
- if (!node)
+ if (!node) {
return;
+ }
if (selection.has(node)) {
-
String new_name = _apply_rename(node, *counter);
if (node->get_name() != new_name) {
@@ -581,7 +570,6 @@ void RenameDialog::_iterate_scene(const Node *node, const Array &selection, int
}
void RenameDialog::rename() {
-
// Editor selection is not ordered via scene tree. Instead iterate
// over scene tree until all selected nodes are found in order.
@@ -596,12 +584,10 @@ void RenameDialog::rename() {
_iterate_scene(root_node, selected_node_list, &global_count);
if (undo_redo && !to_rename.empty()) {
-
undo_redo->create_action(TTR("Batch Rename"));
// Make sure to iterate reversed so that child nodes will find parents.
for (int i = to_rename.size() - 1; i >= 0; --i) {
-
Node *n = root_node->get_node(to_rename[i].first);
const String &new_name = to_rename[i].second;
@@ -620,7 +606,6 @@ void RenameDialog::rename() {
}
void RenameDialog::reset() {
-
lock_preview_update = true;
lne_prefix->clear();
@@ -651,7 +636,6 @@ bool RenameDialog::_is_main_field(LineEdit *line_edit) {
}
void RenameDialog::_insert_text(String text) {
-
LineEdit *focus_owner = Object::cast_to<LineEdit>(scene_tree_editor->get_focus_owner());
if (_is_main_field(focus_owner)) {