rename_dialog.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*************************************************************************/
  2. /* rename_dialog.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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. #ifndef RENAME_DIALOG_H
  31. #define RENAME_DIALOG_H
  32. #include "modules/modules_enabled.gen.h" // For regex.
  33. #ifdef MODULE_REGEX_ENABLED
  34. #include "core/object/undo_redo.h"
  35. #include "editor/scene_tree_editor.h"
  36. #include "scene/gui/check_box.h"
  37. #include "scene/gui/check_button.h"
  38. #include "scene/gui/dialogs.h"
  39. #include "scene/gui/option_button.h"
  40. #include "scene/gui/spin_box.h"
  41. #include "scene/gui/tab_container.h"
  42. class RenameDialog : public ConfirmationDialog {
  43. GDCLASS(RenameDialog, ConfirmationDialog);
  44. virtual void ok_pressed() override { rename(); };
  45. void _cancel_pressed() {}
  46. void _features_toggled(bool pressed);
  47. void _insert_text(String text);
  48. void _update_substitute();
  49. bool _is_main_field(LineEdit *line_edit);
  50. void _iterate_scene(const Node *node, const Array &selection, int *count);
  51. String _apply_rename(const Node *node, int count);
  52. String _substitute(const String &subject, const Node *node, int count);
  53. String _regex(const String &pattern, const String &subject, const String &replacement);
  54. String _postprocess(const String &subject);
  55. void _update_preview(String new_text = "");
  56. void _update_preview_int(int new_value = 0);
  57. 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);
  58. SceneTreeEditor *scene_tree_editor = nullptr;
  59. UndoRedo *undo_redo = nullptr;
  60. int global_count = 0;
  61. LineEdit *lne_search = nullptr;
  62. LineEdit *lne_replace = nullptr;
  63. LineEdit *lne_prefix = nullptr;
  64. LineEdit *lne_suffix = nullptr;
  65. TabContainer *tabc_features = nullptr;
  66. CheckBox *cbut_substitute = nullptr;
  67. CheckButton *cbut_regex = nullptr;
  68. CheckBox *cbut_process = nullptr;
  69. CheckBox *chk_per_level_counter = nullptr;
  70. Button *but_insert_name = nullptr;
  71. Button *but_insert_parent = nullptr;
  72. Button *but_insert_type = nullptr;
  73. Button *but_insert_scene = nullptr;
  74. Button *but_insert_root = nullptr;
  75. Button *but_insert_count = nullptr;
  76. SpinBox *spn_count_start = nullptr;
  77. SpinBox *spn_count_step = nullptr;
  78. SpinBox *spn_count_padding = nullptr;
  79. OptionButton *opt_style = nullptr;
  80. OptionButton *opt_case = nullptr;
  81. Label *lbl_preview_title = nullptr;
  82. Label *lbl_preview = nullptr;
  83. List<Pair<NodePath, String>> to_rename;
  84. Node *preview_node = nullptr;
  85. bool lock_preview_update = false;
  86. ErrorHandlerList eh;
  87. bool has_errors = false;
  88. protected:
  89. static void _bind_methods();
  90. virtual void _post_popup() override;
  91. public:
  92. void reset();
  93. void rename();
  94. RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_undo_redo = nullptr);
  95. ~RenameDialog() {}
  96. };
  97. #endif // MODULE_REGEX_ENABLED
  98. #endif // RENAME_DIALOG_H