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.cpp64
1 files changed, 27 insertions, 37 deletions
diff --git a/editor/rename_dialog.cpp b/editor/rename_dialog.cpp
index cc9e14975f..317be309a3 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);
@@ -200,7 +199,7 @@ RenameDialog::RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_und
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,7 +306,7 @@ RenameDialog::RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_und
// ---- Connections
- chk_collapse_features->connect("toggled", this, "_features_toggled");
+ cbut_collapse_features->connect("toggled", this, "_features_toggled");
// Substitite Buttons
@@ -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;
}