syntax_highlighter.cpp 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*************************************************************************/
  2. /* syntax_highlighter.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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. #include "syntax_highlighter.h"
  31. #include "core/script_language.h"
  32. #include "scene/gui/text_edit.h"
  33. Dictionary SyntaxHighlighter::get_line_syntax_highlighting(int p_line) {
  34. return call("_get_line_syntax_highlighting", p_line);
  35. }
  36. void SyntaxHighlighter::update_cache() {
  37. call("_update_cache");
  38. }
  39. String SyntaxHighlighter::_get_name() const {
  40. ScriptInstance *si = get_script_instance();
  41. if (si && si->has_method("_get_name")) {
  42. return si->call("_get_name");
  43. }
  44. return "Unamed";
  45. }
  46. Array SyntaxHighlighter::_get_supported_languages() const {
  47. ScriptInstance *si = get_script_instance();
  48. if (si && si->has_method("_get_supported_languages")) {
  49. return si->call("_get_supported_languages");
  50. }
  51. return Array();
  52. }
  53. void SyntaxHighlighter::set_text_edit(TextEdit *p_text_edit) {
  54. text_edit = p_text_edit;
  55. }
  56. TextEdit *SyntaxHighlighter::get_text_edit() {
  57. return text_edit;
  58. }
  59. Ref<SyntaxHighlighter> SyntaxHighlighter::_create() const {
  60. Ref<SyntaxHighlighter> syntax_highlighter;
  61. syntax_highlighter.instance();
  62. if (get_script_instance()) {
  63. syntax_highlighter->set_script(get_script_instance()->get_script());
  64. }
  65. return syntax_highlighter;
  66. }
  67. void SyntaxHighlighter::_bind_methods() {
  68. ClassDB::bind_method(D_METHOD("_get_line_syntax_highlighting", "p_line"), &SyntaxHighlighter::_get_line_syntax_highlighting);
  69. ClassDB::bind_method(D_METHOD("_update_cache"), &SyntaxHighlighter::_update_cache);
  70. ClassDB::bind_method(D_METHOD("get_text_edit"), &SyntaxHighlighter::get_text_edit);
  71. BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_name"));
  72. BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_supported_languages"));
  73. BIND_VMETHOD(MethodInfo(Variant::DICTIONARY, "_get_line_syntax_highlighting", PropertyInfo(Variant::INT, "p_line")));
  74. BIND_VMETHOD(MethodInfo("_update_cache"));
  75. }