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.cpp120
1 files changed, 55 insertions, 65 deletions
diff --git a/editor/rename_dialog.cpp b/editor/rename_dialog.cpp
index cc9e14975f..aa8352aa25 100644
--- a/editor/rename_dialog.cpp
+++ b/editor/rename_dialog.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 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 */
@@ -32,6 +32,7 @@
#include "core/print_string.h"
#include "editor_node.h"
+#include "editor_scale.h"
#include "editor_settings.h"
#include "editor_themes.h"
#include "modules/regex/regex.h"
@@ -106,17 +107,15 @@ RenameDialog::RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_und
// -- Feature Tabs
- const int feature_min_height = 160;
+ const int feature_min_height = 160 * EDSCALE;
- Ref<Theme> collapse_theme = create_editor_theme();
- collapse_theme->set_icon("checked", "CheckBox", collapse_theme->get_icon("GuiTreeArrowDown", "EditorIcons"));
- collapse_theme->set_icon("unchecked", "CheckBox", collapse_theme->get_icon("GuiTreeArrowRight", "EditorIcons"));
+ cbut_regex = memnew(CheckButton);
+ cbut_regex->set_text(TTR("Use Regular Expressions"));
+ vbc->add_child(cbut_regex);
- CheckBox *chk_collapse_features = memnew(CheckBox);
- chk_collapse_features->set_text(TTR("Advanced Options"));
- chk_collapse_features->set_theme(collapse_theme);
- chk_collapse_features->set_focus_mode(FOCUS_NONE);
- vbc->add_child(chk_collapse_features);
+ CheckButton *cbut_collapse_features = memnew(CheckButton);
+ cbut_collapse_features->set_text(TTR("Advanced Options"));
+ vbc->add_child(cbut_collapse_features);
tabc_features = memnew(TabContainer);
tabc_features->set_tab_align(TabContainer::ALIGN_LEFT);
@@ -145,7 +144,7 @@ RenameDialog::RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_und
but_insert_name->set_text("NAME");
but_insert_name->set_tooltip(String("${NAME}\n") + TTR("Node name"));
but_insert_name->set_focus_mode(FOCUS_NONE);
- but_insert_name->connect("pressed", this, "_insert_text", make_binds("${NAME}"));
+ but_insert_name->connect_compat("pressed", this, "_insert_text", make_binds("${NAME}"));
but_insert_name->set_h_size_flags(SIZE_EXPAND_FILL);
grd_substitute->add_child(but_insert_name);
@@ -155,7 +154,7 @@ RenameDialog::RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_und
but_insert_parent->set_text("PARENT");
but_insert_parent->set_tooltip(String("${PARENT}\n") + TTR("Node's parent name, if available"));
but_insert_parent->set_focus_mode(FOCUS_NONE);
- but_insert_parent->connect("pressed", this, "_insert_text", make_binds("${PARENT}"));
+ but_insert_parent->connect_compat("pressed", this, "_insert_text", make_binds("${PARENT}"));
but_insert_parent->set_h_size_flags(SIZE_EXPAND_FILL);
grd_substitute->add_child(but_insert_parent);
@@ -165,7 +164,7 @@ RenameDialog::RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_und
but_insert_type->set_text("TYPE");
but_insert_type->set_tooltip(String("${TYPE}\n") + TTR("Node type"));
but_insert_type->set_focus_mode(FOCUS_NONE);
- but_insert_type->connect("pressed", this, "_insert_text", make_binds("${TYPE}"));
+ but_insert_type->connect_compat("pressed", this, "_insert_text", make_binds("${TYPE}"));
but_insert_type->set_h_size_flags(SIZE_EXPAND_FILL);
grd_substitute->add_child(but_insert_type);
@@ -175,7 +174,7 @@ RenameDialog::RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_und
but_insert_scene->set_text("SCENE");
but_insert_scene->set_tooltip(String("${SCENE}\n") + TTR("Current scene name"));
but_insert_scene->set_focus_mode(FOCUS_NONE);
- but_insert_scene->connect("pressed", this, "_insert_text", make_binds("${SCENE}"));
+ but_insert_scene->connect_compat("pressed", this, "_insert_text", make_binds("${SCENE}"));
but_insert_scene->set_h_size_flags(SIZE_EXPAND_FILL);
grd_substitute->add_child(but_insert_scene);
@@ -185,7 +184,7 @@ RenameDialog::RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_und
but_insert_root->set_text("ROOT");
but_insert_root->set_tooltip(String("${ROOT}\n") + TTR("Root node name"));
but_insert_root->set_focus_mode(FOCUS_NONE);
- but_insert_root->connect("pressed", this, "_insert_text", make_binds("${ROOT}"));
+ but_insert_root->connect_compat("pressed", this, "_insert_text", make_binds("${ROOT}"));
but_insert_root->set_h_size_flags(SIZE_EXPAND_FILL);
grd_substitute->add_child(but_insert_root);
@@ -195,12 +194,12 @@ RenameDialog::RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_und
but_insert_count->set_text("COUNTER");
but_insert_count->set_tooltip(String("${COUNTER}\n") + TTR("Sequential integer counter.\nCompare counter options."));
but_insert_count->set_focus_mode(FOCUS_NONE);
- but_insert_count->connect("pressed", this, "_insert_text", make_binds("${COUNTER}"));
+ but_insert_count->connect_compat("pressed", this, "_insert_text", make_binds("${COUNTER}"));
but_insert_count->set_h_size_flags(SIZE_EXPAND_FILL);
grd_substitute->add_child(but_insert_count);
chk_per_level_counter = memnew(CheckBox);
- chk_per_level_counter->set_text(TTR("Per Level counter"));
+ chk_per_level_counter->set_text(TTR("Per-level Counter"));
chk_per_level_counter->set_tooltip(TTR("If set the counter restarts for each group of child nodes"));
vbc_substitute->add_child(chk_per_level_counter);
@@ -238,18 +237,6 @@ RenameDialog::RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_und
spn_count_padding->set_step(1);
hbc_count_options->add_child(spn_count_padding);
- // ---- Tab RegEx
-
- VBoxContainer *vbc_regex = memnew(VBoxContainer);
- vbc_regex->set_h_size_flags(SIZE_EXPAND_FILL);
- vbc_regex->set_name(TTR("Regular Expressions"));
- vbc_regex->set_custom_minimum_size(Size2(0, feature_min_height));
- tabc_features->add_child(vbc_regex);
-
- cbut_regex = memnew(CheckBox);
- cbut_regex->set_text(TTR("Regular Expressions"));
- vbc_regex->add_child(cbut_regex);
-
// ---- Tab Process
VBoxContainer *vbc_process = memnew(VBoxContainer);
@@ -273,8 +260,8 @@ RenameDialog::RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_und
opt_style = memnew(OptionButton);
opt_style->add_item(TTR("Keep"));
- opt_style->add_item(TTR("CamelCase to under_scored"));
- opt_style->add_item(TTR("under_scored to CamelCase"));
+ opt_style->add_item(TTR("PascalCase to snake_case"));
+ opt_style->add_item(TTR("snake_case to PascalCase"));
hbc_style->add_child(opt_style);
// ------ Case
@@ -304,7 +291,7 @@ RenameDialog::RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_und
lbl_preview = memnew(Label);
lbl_preview->set_text("");
- lbl_preview->add_color_override("font_color", Color(1, 0.5f, 0, 1));
+ lbl_preview->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor"));
vbc->add_child(lbl_preview);
// ---- Dialog related
@@ -319,35 +306,35 @@ RenameDialog::RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_und
// ---- Connections
- chk_collapse_features->connect("toggled", this, "_features_toggled");
+ cbut_collapse_features->connect_compat("toggled", this, "_features_toggled");
// Substitite Buttons
- lne_search->connect("focus_entered", this, "_update_substitute");
- lne_search->connect("focus_exited", this, "_update_substitute");
- lne_replace->connect("focus_entered", this, "_update_substitute");
- lne_replace->connect("focus_exited", this, "_update_substitute");
- lne_prefix->connect("focus_entered", this, "_update_substitute");
- lne_prefix->connect("focus_exited", this, "_update_substitute");
- lne_suffix->connect("focus_entered", this, "_update_substitute");
- lne_suffix->connect("focus_exited", this, "_update_substitute");
+ lne_search->connect_compat("focus_entered", this, "_update_substitute");
+ lne_search->connect_compat("focus_exited", this, "_update_substitute");
+ lne_replace->connect_compat("focus_entered", this, "_update_substitute");
+ lne_replace->connect_compat("focus_exited", this, "_update_substitute");
+ lne_prefix->connect_compat("focus_entered", this, "_update_substitute");
+ lne_prefix->connect_compat("focus_exited", this, "_update_substitute");
+ lne_suffix->connect_compat("focus_entered", this, "_update_substitute");
+ lne_suffix->connect_compat("focus_exited", this, "_update_substitute");
// Preview
- lne_prefix->connect("text_changed", this, "_update_preview");
- lne_suffix->connect("text_changed", this, "_update_preview");
- lne_search->connect("text_changed", this, "_update_preview");
- lne_replace->connect("text_changed", this, "_update_preview");
- spn_count_start->connect("value_changed", this, "_update_preview_int");
- spn_count_step->connect("value_changed", this, "_update_preview_int");
- spn_count_padding->connect("value_changed", this, "_update_preview_int");
- opt_style->connect("item_selected", this, "_update_preview_int");
- opt_case->connect("item_selected", this, "_update_preview_int");
- cbut_substitute->connect("pressed", this, "_update_preview", varray(""));
- cbut_regex->connect("pressed", this, "_update_preview", varray(""));
- cbut_process->connect("pressed", this, "_update_preview", varray(""));
-
- but_reset->connect("pressed", this, "reset");
+ lne_prefix->connect_compat("text_changed", this, "_update_preview");
+ lne_suffix->connect_compat("text_changed", this, "_update_preview");
+ lne_search->connect_compat("text_changed", this, "_update_preview");
+ lne_replace->connect_compat("text_changed", this, "_update_preview");
+ spn_count_start->connect_compat("value_changed", this, "_update_preview_int");
+ spn_count_step->connect_compat("value_changed", this, "_update_preview_int");
+ spn_count_padding->connect_compat("value_changed", this, "_update_preview_int");
+ opt_style->connect_compat("item_selected", this, "_update_preview_int");
+ opt_case->connect_compat("item_selected", this, "_update_preview_int");
+ cbut_substitute->connect_compat("pressed", this, "_update_preview", varray(""));
+ cbut_regex->connect_compat("pressed", this, "_update_preview", varray(""));
+ cbut_process->connect_compat("pressed", this, "_update_preview", varray(""));
+
+ but_reset->connect_compat("pressed", this, "reset");
reset();
_features_toggled(false);
@@ -419,9 +406,12 @@ void RenameDialog::_update_preview(String new_text) {
lbl_preview->set_text(new_name);
if (new_name == preview_node->get_name()) {
- lbl_preview->add_color_override("font_color", Color(0, 0.5f, 0.25f, 1));
+ // 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_color("accent_color", "Editor");
+ const Color text_color = EditorNode::get_singleton()->get_gui_base()->get_color("default_color", "RichTextLabel");
+ lbl_preview->add_color_override("font_color", accent_color.linear_interpolate(text_color, 0.5));
} else {
- lbl_preview->add_color_override("font_color", Color(0, 1, 0.5f, 1));
+ lbl_preview->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("success_color", "Editor"));
}
}
@@ -506,9 +496,9 @@ void RenameDialog::_error_handler(void *p_self, const char *p_func, const char *
}
self->has_errors = true;
- self->lbl_preview_title->set_text(TTR("Error"));
- self->lbl_preview->add_color_override("font_color", Color(1, 0.25f, 0, 1));
- self->lbl_preview->set_text(err_str);
+ self->lbl_preview_title->set_text(TTR("Regular Expression Error"));
+ self->lbl_preview->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor"));
+ self->lbl_preview->set_text(vformat(TTR("At character %s"), err_str));
}
String RenameDialog::_regex(const String &pattern, const String &subject, const String &replacement) {
@@ -525,18 +515,18 @@ String RenameDialog::_postprocess(const String &subject) {
String result = subject;
if (style_id == 1) {
+ // PascalCase to snake_case
- // CamelCase to Under_Line
result = result.camelcase_to_underscore(true);
result = _regex("_+", result, "_");
} else if (style_id == 2) {
+ // snake_case to PascalCase
- // Under_Line to CamelCase
RegEx pattern("_+(.?)");
Array matches = pattern.search_all(result);
- // _ name would become empty. Ignore
+ // The name `_` would become empty; ignore it.
if (matches.size() && result != "_") {
String buffer;
int start = 0;
@@ -622,7 +612,7 @@ void RenameDialog::rename() {
const String &new_name = to_rename[i].second;
if (!n) {
- ERR_PRINTS("Skipping missing node: " + to_rename[i].first.get_concatenated_subnames());
+ ERR_PRINT("Skipping missing node: " + to_rename[i].first.get_concatenated_subnames());
continue;
}