Blender V5.0
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 "WM_api.hh"
18# include "WM_types.hh"
19
20static void rna_Text_clear(Text *text)
21{
22 BKE_text_clear(text);
24}
25
26static void rna_Text_write(Text *text, const char *str)
27{
28 BKE_text_write(text, str, strlen(str));
30}
31
32static void rna_Text_from_string(Text *text, const char *str)
33{
34 BKE_text_clear(text);
35 BKE_text_write(text, str, strlen(str));
36}
37
38static void rna_Text_as_string(Text *text, const char **result, int *r_result_len)
39{
40 size_t result_len;
41 *result = txt_to_buf(text, &result_len);
42 *r_result_len = result_len;
43}
44
45static void rna_Text_select_set(Text *text, int startl, int startc, int endl, int endc)
46{
47 txt_sel_set(text, startl, startc, endl, endc);
49}
50
51static void rna_Text_cursor_set(Text *text, int line, int ch, bool select)
52{
53 txt_move_to(text, line, ch, select);
55}
56
57#else
58
60{
61 FunctionRNA *func;
62 PropertyRNA *parm;
63
64 func = RNA_def_function(srna, "clear", "rna_Text_clear");
65 RNA_def_function_ui_description(func, "clear the text block");
66
67 func = RNA_def_function(srna, "write", "rna_Text_write");
69 func, "write text at the cursor location and advance to the end of the text block");
70 parm = RNA_def_string(func, "text", "Text", 0, "", "New text for this data-block");
72
73 func = RNA_def_function(srna, "from_string", "rna_Text_from_string");
74 RNA_def_function_ui_description(func, "Replace text with this string.");
75 parm = RNA_def_string(func, "text", "Text", 0, "", "");
77
78 func = RNA_def_function(srna, "as_string", "rna_Text_as_string");
79 RNA_def_function_ui_description(func, "Return the text as a string");
80 parm = RNA_def_string(func, "text", "Text", 0, "", "");
82
83 func = RNA_def_function(
84 srna, "is_syntax_highlight_supported", "ED_text_is_syntax_highlight_supported");
86 RNA_def_boolean(func, "is_syntax_highlight_supported", false, "", ""));
88 "Returns True if the editor supports syntax highlighting "
89 "for the current text data-block");
90
91 func = RNA_def_function(srna, "select_set", "rna_Text_select_set");
92 RNA_def_function_ui_description(func, "Set selection range by line and character index");
93 parm = RNA_def_int(func, "line_start", 0, INT_MIN, INT_MAX, "Start Line", "", INT_MIN, INT_MAX);
95 parm = RNA_def_int(
96 func, "char_start", 0, INT_MIN, INT_MAX, "Start Character", "", INT_MIN, INT_MAX);
98 parm = RNA_def_int(func, "line_end", 0, INT_MIN, INT_MAX, "End Line", "", INT_MIN, INT_MAX);
100 parm = RNA_def_int(func, "char_end", 0, INT_MIN, INT_MAX, "End Character", "", INT_MIN, INT_MAX);
102
103 func = RNA_def_function(srna, "cursor_set", "rna_Text_cursor_set");
104 RNA_def_function_ui_description(func, "Set cursor by line and (optionally) character index");
105 parm = RNA_def_int(func, "line", 0, 0, INT_MAX, "Line", "", 0, INT_MAX);
107 parm = RNA_def_int(func, "character", 0, 0, INT_MAX, "Character", "", 0, INT_MAX);
108 RNA_def_boolean(func, "select", false, "", "Select when moving the cursor");
109}
110
111#endif
void txt_sel_set(struct Text *text, int startl, int startc, int endl, int endc)
Definition text.cc:1283
char * txt_to_buf(struct Text *text, size_t *r_buf_strlen) ATTR_NONNULL(1
struct Text struct Text void BKE_text_clear(struct Text *text) ATTR_NONNULL(1)
Definition text.cc:511
void txt_move_to(struct Text *text, unsigned int line, unsigned int ch, bool sel)
Definition text.cc:1100
void BKE_text_write(struct Text *text, const char *str, int str_len) ATTR_NONNULL(1
@ PARM_REQUIRED
Definition RNA_types.hh:545
@ PARM_OUTPUT
Definition RNA_types.hh:546
PropertyFlag
Definition RNA_types.hh:300
@ PROP_DYNAMIC
Definition RNA_types.hh:428
#define NA_EDITED
Definition WM_types.hh:584
#define NC_TEXT
Definition WM_types.hh:386
#define str(s)
#define select(A, B, C)
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_return(FunctionRNA *func, PropertyRNA *ret)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
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)
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_api_text(StructRNA *srna)
void WM_main_add_notifier(uint type, void *reference)