| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/io/resource.h" |
| 34 |
#include "core/object/gdvirtual.gen.inc" |
| 35 |
#include "core/templates/rb_map.h" |
| 36 |
|
| 37 |
class TextEdit; |
| 38 |
|
| 39 |
class SyntaxHighlighter : public Resource { |
| 40 |
GDCLASS(SyntaxHighlighter, Resource) |
| 41 |
|
| 42 |
private: |
| 43 |
RBMap<int, Dictionary> highlighting_cache; |
| 44 |
void _lines_edited_from(int p_from_line, int p_to_line); |
| 45 |
|
| 46 |
protected: |
| 47 |
ObjectID text_edit_instance_id; |
| 48 |
TextEdit *text_edit = nullptr; |
| 49 |
|
| 50 |
static void _bind_methods(); |
| 51 |
|
| 52 |
GDVIRTUAL1RC(Dictionary, _get_line_syntax_highlighting, int) |
| 53 |
GDVIRTUAL0(_clear_highlighting_cache) |
| 54 |
GDVIRTUAL0(_update_cache) |
| 55 |
public: |
| 56 |
Dictionary get_line_syntax_highlighting(int p_line); |
| 57 |
virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) { return Dictionary(); } |
| 58 |
|
| 59 |
void clear_highlighting_cache(); |
| 60 |
virtual void _clear_highlighting_cache() {} |
| 61 |
|
| 62 |
void update_cache(); |
| 63 |
virtual void _update_cache() {} |
| 64 |
|
| 65 |
void set_text_edit(TextEdit *p_text_edit); |
| 66 |
TextEdit *get_text_edit() const; |
| 67 |
|
| 68 |
virtual ~SyntaxHighlighter() {} |
| 69 |
}; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
class CodeHighlighter : public SyntaxHighlighter { |
| 74 |
GDCLASS(CodeHighlighter, SyntaxHighlighter) |
| 75 |
|
| 76 |
private: |
| 77 |
struct ColorRegion { |
| 78 |
Color color; |
| 79 |
String start_key; |
| 80 |
String end_key; |
| 81 |
bool line_only = false; |
| 82 |
}; |
| 83 |
Vector<ColorRegion> color_regions; |
| 84 |
HashMap<int, int> color_region_cache; |
| 85 |
|
| 86 |
Dictionary keywords; |
| 87 |
Dictionary member_keywords; |
| 88 |
|
| 89 |
Color font_color; |
| 90 |
Color member_color; |
| 91 |
Color function_color; |
| 92 |
Color symbol_color; |
| 93 |
Color number_color; |
| 94 |
|
| 95 |
bool uint_suffix_enabled = false; |
| 96 |
|
| 97 |
protected: |
| 98 |
static void _bind_methods(); |
| 99 |
|
| 100 |
public: |
| 101 |
virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override; |
| 102 |
|
| 103 |
virtual void _clear_highlighting_cache() override; |
| 104 |
virtual void _update_cache() override; |
| 105 |
|
| 106 |
void add_keyword_color(const String &p_keyword, const Color &p_color); |
| 107 |
void remove_keyword_color(const String &p_keyword); |
| 108 |
bool has_keyword_color(const String &p_keyword) const; |
| 109 |
Color get_keyword_color(const String &p_keyword) const; |
| 110 |
|
| 111 |
void set_keyword_colors(const Dictionary p_keywords); |
| 112 |
void clear_keyword_colors(); |
| 113 |
Dictionary get_keyword_colors() const; |
| 114 |
|
| 115 |
void add_member_keyword_color(const String &p_member_keyword, const Color &p_color); |
| 116 |
void remove_member_keyword_color(const String &p_member_keyword); |
| 117 |
bool has_member_keyword_color(const String &p_member_keyword) const; |
| 118 |
Color get_member_keyword_color(const String &p_member_keyword) const; |
| 119 |
|
| 120 |
void set_member_keyword_colors(const Dictionary &p_color_regions); |
| 121 |
void clear_member_keyword_colors(); |
| 122 |
Dictionary get_member_keyword_colors() const; |
| 123 |
|
| 124 |
void add_color_region(const String &p_start_key, const String &p_end_key, const Color &p_color, bool p_line_only = false); |
| 125 |
void remove_color_region(const String &p_start_key); |
| 126 |
bool has_color_region(const String &p_start_key) const; |
| 127 |
|
| 128 |
void set_color_regions(const Dictionary &p_member_keyword); |
| 129 |
void clear_color_regions(); |
| 130 |
Dictionary get_color_regions() const; |
| 131 |
|
| 132 |
void set_number_color(Color p_color); |
| 133 |
Color get_number_color() const; |
| 134 |
|
| 135 |
void set_symbol_color(Color p_color); |
| 136 |
Color get_symbol_color() const; |
| 137 |
|
| 138 |
void set_function_color(Color p_color); |
| 139 |
Color get_function_color() const; |
| 140 |
|
| 141 |
void set_member_variable_color(Color p_color); |
| 142 |
Color get_member_variable_color() const; |
| 143 |
|
| 144 |
void set_uint_suffix_enabled(bool p_enabled); |
| 145 |
}; |