code_editor.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*************************************************************************/
  2. /* code_editor.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef CODE_EDITOR_H
  30. #define CODE_EDITOR_H
  31. #include "tools/editor/editor_plugin.h"
  32. #include "scene/gui/text_edit.h"
  33. #include "scene/gui/dialogs.h"
  34. #include "scene/main/timer.h"
  35. #include "scene/gui/check_button.h"
  36. #include "scene/gui/line_edit.h"
  37. class GotoLineDialog : public ConfirmationDialog {
  38. OBJ_TYPE(GotoLineDialog,ConfirmationDialog);
  39. Label *line_label;
  40. LineEdit *line;
  41. TextEdit *text_editor;
  42. virtual void ok_pressed();
  43. public:
  44. void popup_find_line(TextEdit *p_edit);
  45. int get_line() const;
  46. void set_text_editor(TextEdit *p_text_editor);
  47. GotoLineDialog();
  48. };
  49. class FindReplaceDialog : public ConfirmationDialog {
  50. OBJ_TYPE(FindReplaceDialog,ConfirmationDialog);
  51. LineEdit *search_text;
  52. LineEdit *replace_text;
  53. CheckButton *whole_words;
  54. CheckButton *case_sensitive;
  55. CheckButton *backwards;
  56. CheckButton *prompt;
  57. CheckButton *selection_only;
  58. Button *skip;
  59. Label *error_label;
  60. MarginContainer *replace_mc;
  61. Label *replace_label;
  62. VBoxContainer *replace_vb;
  63. void _search_text_entered(const String& p_text);
  64. void _replace_text_entered(const String& p_text);
  65. void _prompt_changed();
  66. void _skip_pressed();
  67. TextEdit *text_edit;
  68. protected:
  69. void _search_callback();
  70. void _replace_skip_callback();
  71. bool _search();
  72. void _replace();
  73. virtual void ok_pressed();
  74. static void _bind_methods();
  75. public:
  76. String get_search_text() const;
  77. String get_replace_text() const;
  78. bool is_whole_words() const;
  79. bool is_case_sensitive() const;
  80. bool is_backwards() const;
  81. bool is_replace_mode() const;
  82. bool is_replace_all_mode() const;
  83. bool is_replace_selection_only() const;
  84. void set_replace_selection_only(bool p_enable);
  85. void set_error(const String& p_error);
  86. void popup_search();
  87. void popup_replace();
  88. void set_text_edit(TextEdit *p_text_edit);
  89. void search_next();
  90. FindReplaceDialog();
  91. };
  92. class CodeTextEditor : public Control {
  93. OBJ_TYPE(CodeTextEditor,Control);
  94. TextEdit *text_editor;
  95. Label *line_col;
  96. Label *info;
  97. Timer *idle;
  98. Timer *code_complete_timer;
  99. bool enable_complete_timer;
  100. Label *error;
  101. void _on_settings_change();
  102. void _complete_request(const String& p_request,int p_line);
  103. protected:
  104. void set_error(const String& p_error);
  105. virtual void _load_theme_settings() {}
  106. virtual void _validate_script()=0;
  107. virtual void _code_complete_script(const String& p_code, const String& p_keyword,int p_line, List<String>* r_options) {};
  108. void _text_changed_idle_timeout();
  109. void _code_complete_timer_timeout();
  110. void _text_changed();
  111. void _line_col_changed();
  112. void _notification(int);
  113. static void _bind_methods();
  114. public:
  115. TextEdit *get_text_edit() { return text_editor; }
  116. virtual void apply_code() {}
  117. CodeTextEditor();
  118. };
  119. #endif // CODE_EDITOR_H