| 1 | /**************************************************************************/ |
| 2 | /* rename_dialog.h */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #ifndef RENAME_DIALOG_H |
| 32 | #define RENAME_DIALOG_H |
| 33 | |
| 34 | #include "modules/modules_enabled.gen.h" // For regex. |
| 35 | #ifdef MODULE_REGEX_ENABLED |
| 36 | |
| 37 | #include "editor/gui/scene_tree_editor.h" |
| 38 | #include "scene/gui/dialogs.h" |
| 39 | #include "scene/gui/line_edit.h" |
| 40 | |
| 41 | class Button; |
| 42 | class CheckBox; |
| 43 | class CheckButton; |
| 44 | class Label; |
| 45 | class OptionButton; |
| 46 | class SpinBox; |
| 47 | class TabContainer; |
| 48 | |
| 49 | class RenameDialog : public ConfirmationDialog { |
| 50 | GDCLASS(RenameDialog, ConfirmationDialog); |
| 51 | |
| 52 | virtual void ok_pressed() override { rename(); }; |
| 53 | void _cancel_pressed() {} |
| 54 | void _features_toggled(bool pressed); |
| 55 | void _insert_text(String text); |
| 56 | void _update_substitute(); |
| 57 | bool _is_main_field(LineEdit *line_edit); |
| 58 | |
| 59 | void _iterate_scene(const Node *node, const Array &selection, int *count); |
| 60 | String _apply_rename(const Node *node, int count); |
| 61 | String _substitute(const String &subject, const Node *node, int count); |
| 62 | String _regex(const String &pattern, const String &subject, const String &replacement); |
| 63 | String _postprocess(const String &subject); |
| 64 | void _update_preview(String new_text = "" ); |
| 65 | void _update_preview_int(int new_value = 0); |
| 66 | 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, bool p_editor_notify, ErrorHandlerType p_type); |
| 67 | |
| 68 | SceneTreeEditor *scene_tree_editor = nullptr; |
| 69 | int global_count = 0; |
| 70 | |
| 71 | LineEdit *lne_search = nullptr; |
| 72 | LineEdit *lne_replace = nullptr; |
| 73 | LineEdit *lne_prefix = nullptr; |
| 74 | LineEdit *lne_suffix = nullptr; |
| 75 | |
| 76 | TabContainer *tabc_features = nullptr; |
| 77 | |
| 78 | CheckBox *cbut_substitute = nullptr; |
| 79 | CheckButton *cbut_regex = nullptr; |
| 80 | CheckBox *cbut_process = nullptr; |
| 81 | CheckBox *chk_per_level_counter = nullptr; |
| 82 | |
| 83 | Button *but_insert_name = nullptr; |
| 84 | Button *but_insert_parent = nullptr; |
| 85 | Button *but_insert_type = nullptr; |
| 86 | Button *but_insert_scene = nullptr; |
| 87 | Button *but_insert_root = nullptr; |
| 88 | Button *but_insert_count = nullptr; |
| 89 | |
| 90 | SpinBox *spn_count_start = nullptr; |
| 91 | SpinBox *spn_count_step = nullptr; |
| 92 | SpinBox *spn_count_padding = nullptr; |
| 93 | |
| 94 | OptionButton *opt_style = nullptr; |
| 95 | OptionButton *opt_case = nullptr; |
| 96 | |
| 97 | Label *lbl_preview_title = nullptr; |
| 98 | Label *lbl_preview = nullptr; |
| 99 | |
| 100 | List<Pair<NodePath, String>> to_rename; |
| 101 | Node *preview_node = nullptr; |
| 102 | bool lock_preview_update = false; |
| 103 | ErrorHandlerList eh; |
| 104 | bool has_errors = false; |
| 105 | |
| 106 | protected: |
| 107 | static void _bind_methods(); |
| 108 | virtual void () override; |
| 109 | |
| 110 | public: |
| 111 | void reset(); |
| 112 | void rename(); |
| 113 | |
| 114 | RenameDialog(SceneTreeEditor *p_scene_tree_editor); |
| 115 | }; |
| 116 | |
| 117 | #endif // MODULE_REGEX_ENABLED |
| 118 | |
| 119 | #endif // RENAME_DIALOG_H |
| 120 | |