Blender V5.3
rna_text_api.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10
11#include "RNA_define.hh"
12
13#include "rna_internal.hh" /* own include */
14
15#ifdef RNA_RUNTIME
16
17# include "DNA_text_types.h"
18
19# include "BKE_text.h"
20
21# include "WM_api.hh"
22# include "WM_types.hh"
23
24namespace blender {
25
26static void rna_Text_clear(Text *text)
27{
28 BKE_text_clear(text);
30}
31
32static void rna_Text_write(Text *text, const char *str)
33{
34 BKE_text_write(text, str, strlen(str));
36}
37
38static void rna_Text_from_string(Text *text, const char *str)
39{
40 BKE_text_clear(text);
41 BKE_text_write(text, str, strlen(str));
42}
43
44static void rna_Text_as_string(Text *text, const char **result, int *r_result_len)
45{
46 size_t result_len;
47 *result = txt_to_buf(text, &result_len);
48 *r_result_len = result_len;
49}
50
51static void rna_Text_select_set(Text *text, int startl, int startc, int endl, int endc)
52{
53 txt_sel_set(text, startl, startc, endl, endc);
55}
56
57static void rna_Text_cursor_set(Text *text, int line, int ch, bool select)
58{
59 txt_move_to(text, line, ch, select);
61}
62
63} // namespace blender
64
65#else
66
67namespace blender {
68
70{
71 FunctionRNA *func;
72 PropertyRNA *parm;
73
74 func = RNA_def_function(srna, "clear", "rna_Text_clear");
75 RNA_def_function_ui_description(func, "clear the text block");
76
77 func = RNA_def_function(srna, "write", "rna_Text_write");
79 func, "write text at the cursor location and advance to the end of the text block");
80 parm = RNA_def_string(func, "text", "Text", 0, "", "New text for this data-block");
82
83 func = RNA_def_function(srna, "from_string", "rna_Text_from_string");
84 RNA_def_function_ui_description(func, "Replace text with this string.");
85 parm = RNA_def_string(func, "text", "Text", 0, "", "");
87
88 func = RNA_def_function(srna, "as_string", "rna_Text_as_string");
89 RNA_def_function_ui_description(func, "Return the text as a string");
90 parm = RNA_def_string(func, "text", "Text", 0, "", "");
92
93 func = RNA_def_function(
94 srna, "is_syntax_highlight_supported", "ED_text_is_syntax_highlight_supported");
96 RNA_def_boolean(func, "is_syntax_highlight_supported", false, "", ""));
98 "Returns True if the editor supports syntax highlighting "
99 "for the current text data-block");
100
101 func = RNA_def_function(srna, "select_set", "rna_Text_select_set");
102 RNA_def_function_ui_description(func, "Set selection range by line and character index");
103 parm = RNA_def_int(func, "line_start", 0, INT_MIN, INT_MAX, "Start Line", "", INT_MIN, INT_MAX);
105 parm = RNA_def_int(
106 func, "char_start", 0, INT_MIN, INT_MAX, "Start Character", "", INT_MIN, INT_MAX);
108 parm = RNA_def_int(func, "line_end", 0, INT_MIN, INT_MAX, "End Line", "", INT_MIN, INT_MAX);
110 parm = RNA_def_int(func, "char_end", 0, INT_MIN, INT_MAX, "End Character", "", INT_MIN, INT_MAX);
112
113 func = RNA_def_function(srna, "cursor_set", "rna_Text_cursor_set");
114 RNA_def_function_ui_description(func, "Set cursor by line and (optionally) character index");
115 parm = RNA_def_int(func, "line", 0, 0, INT_MAX, "Line", "", 0, INT_MAX);
117 parm = RNA_def_int(func, "character", 0, 0, INT_MAX, "Character", "", 0, INT_MAX);
118 RNA_def_boolean(func, "select", false, "", "Select when moving the cursor");
119}
120
121} // namespace blender
122
123#endif
#define NA_EDITED
Definition WM_types.hh:634
#define NC_TEXT
Definition WM_types.hh:399
#define str(s)
#define INT_MAX
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
void txt_sel_set(struct Text *text, int startl, int startc, int endl, int endc)
Definition text.cc:1287
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier_c_str, const char *call)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
char * txt_to_buf(struct Text *text, size_t *r_buf_strlen) ATTR_NONNULL(1
Definition text.cc:1434
@ PROP_DYNAMIC
Definition RNA_types.hh:498
void RNA_api_text(StructRNA *srna)
void BKE_text_write(struct Text *text, const char *str, int str_len) ATTR_NONNULL(1
Definition text.cc:522
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
@ PARM_REQUIRED
Definition RNA_types.hh:631
@ PARM_OUTPUT
Definition RNA_types.hh:632
void txt_move_to(struct Text *text, unsigned int line, unsigned int ch, bool sel)
Definition text.cc:1104
struct Text struct Text void BKE_text_clear(struct Text *text) ATTR_NONNULL(1)
Definition text.cc:515