Blender
V5.0
source
blender
editors
space_text
text_header.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2008 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9
#include "
DNA_windowmanager_types.h
"
10
11
#include "
BLI_listbase.h
"
12
#include "
BLI_string_utf8.h
"
13
14
#include "
BKE_context.hh
"
15
#include "
BKE_screen.hh
"
16
17
#include "
DNA_text_types.h
"
18
19
#include "
ED_screen.hh
"
20
21
#include "
WM_types.hh
"
22
23
#include "
UI_interface.hh
"
24
25
#include "
text_intern.hh
"
26
27
/* ************************ header area region *********************** */
28
29
/************************** properties ******************************/
30
31
static
ARegion
*
text_has_properties_region
(
ScrArea
*area)
32
{
33
ARegion
*region, *arnew;
34
35
region =
BKE_area_find_region_type
(area,
RGN_TYPE_UI
);
36
if
(region) {
37
return
region;
38
}
39
40
/* Add subdiv level; after header. */
41
region =
BKE_area_find_region_type
(area,
RGN_TYPE_HEADER
);
42
43
/* Is error! */
44
if
(region ==
nullptr
) {
45
return
nullptr
;
46
}
47
48
arnew =
BKE_area_region_new
();
49
50
BLI_insertlinkafter
(&area->
regionbase
, region, arnew);
51
arnew->
regiontype
=
RGN_TYPE_UI
;
52
arnew->
alignment
=
RGN_ALIGN_LEFT
;
53
54
arnew->
flag
=
RGN_FLAG_HIDDEN
;
55
56
return
arnew;
57
}
58
59
static
bool
text_properties_poll
(
bContext
*
C
)
60
{
61
return
(
CTX_wm_space_text
(
C
) !=
nullptr
);
62
}
63
64
static
wmOperatorStatus
text_text_search_exec
(
bContext
*
C
,
wmOperator
*
/*op*/
)
65
{
66
ScrArea
*area =
CTX_wm_area
(
C
);
67
ARegion
*region =
text_has_properties_region
(area);
68
SpaceText
*st =
CTX_wm_space_text
(
C
);
69
70
if
(region) {
71
Text
*text = st->
text
;
72
73
/* Use active text selection as search query, if selection is on a single line. */
74
if
(text && (text->
curl
== text->
sell
) && (text->
curc
!= text->
selc
)) {
75
const
ARegion
*active_region =
CTX_wm_region
(
C
);
76
if
(active_region && active_region->
regiontype
==
RGN_TYPE_WINDOW
) {
77
const
char
*sel_start = text->
curl
->
line
+ std::min(text->
curc
, text->
selc
);
78
const
int
sel_len = std::abs(text->
curc
- text->
selc
);
79
BLI_strncpy_utf8
(st->
findstr
, sel_start, std::min(sel_len + 1,
ST_MAX_FIND_STR
));
80
}
81
}
82
83
bool
draw =
false
;
84
85
if
(region->
flag
&
RGN_FLAG_HIDDEN
) {
86
ED_region_toggle_hidden
(
C
, region);
87
draw =
true
;
88
}
89
90
const
char
*active_category =
UI_panel_category_active_get
(region,
false
);
91
if
(active_category && !
STREQ
(active_category,
"Text"
)) {
92
UI_panel_category_active_set
(region,
"Text"
);
93
draw =
true
;
94
}
95
96
/* Build the layout and draw so `find_text` text button can be activated. */
97
if
(draw) {
98
ED_region_do_layout
(
C
, region);
99
ED_region_do_draw
(
C
, region);
100
}
101
102
UI_textbutton_activate_rna
(
C
, region, st,
"find_text"
);
103
104
ED_region_tag_redraw
(region);
105
}
106
return
OPERATOR_FINISHED
;
107
}
108
109
void
TEXT_OT_start_find
(
wmOperatorType
*
ot
)
110
{
111
/* Identifiers. */
112
ot
->name =
"Find"
;
113
ot
->description =
"Start searching text"
;
114
ot
->idname =
"TEXT_OT_start_find"
;
115
116
/* API callbacks. */
117
ot
->exec =
text_text_search_exec
;
118
ot
->poll =
text_properties_poll
;
119
}
BKE_context.hh
CTX_wm_space_text
SpaceText * CTX_wm_space_text(const bContext *C)
Definition
blenkernel/intern/context.cc:1018
CTX_wm_area
ScrArea * CTX_wm_area(const bContext *C)
Definition
blenkernel/intern/context.cc:950
CTX_wm_region
ARegion * CTX_wm_region(const bContext *C)
Definition
blenkernel/intern/context.cc:961
BKE_screen.hh
BKE_area_region_new
ARegion * BKE_area_region_new()
Definition
screen.cc:387
BKE_area_find_region_type
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition
screen.cc:846
BLI_listbase.h
BLI_insertlinkafter
void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
Definition
listbase.cc:332
BLI_string_utf8.h
BLI_strncpy_utf8
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
STREQ
#define STREQ(a, b)
Definition
BLI_utildefines.h:422
RGN_ALIGN_LEFT
@ RGN_ALIGN_LEFT
Definition
DNA_screen_types.h:753
RGN_TYPE_UI
@ RGN_TYPE_UI
Definition
DNA_screen_types.h:717
RGN_TYPE_WINDOW
@ RGN_TYPE_WINDOW
Definition
DNA_screen_types.h:713
RGN_TYPE_HEADER
@ RGN_TYPE_HEADER
Definition
DNA_screen_types.h:714
RGN_FLAG_HIDDEN
@ RGN_FLAG_HIDDEN
Definition
DNA_screen_types.h:780
ST_MAX_FIND_STR
#define ST_MAX_FIND_STR
Definition
DNA_space_enums.h:817
DNA_text_types.h
wmOperatorStatus
wmOperatorStatus
Definition
DNA_windowmanager_enums.h:16
OPERATOR_FINISHED
@ OPERATOR_FINISHED
Definition
DNA_windowmanager_enums.h:19
DNA_windowmanager_types.h
ED_screen.hh
ED_region_toggle_hidden
void ED_region_toggle_hidden(bContext *C, ARegion *region)
Definition
area.cc:2373
ED_region_do_layout
void ED_region_do_layout(bContext *C, ARegion *region)
Definition
area.cc:456
ED_region_do_draw
void ED_region_do_draw(bContext *C, ARegion *region)
Definition
area.cc:479
ED_region_tag_redraw
void ED_region_tag_redraw(ARegion *region)
Definition
area.cc:618
C
#define C
Definition
RandGen.cpp:29
UI_interface.hh
UI_textbutton_activate_rna
bool UI_textbutton_activate_rna(const bContext *C, ARegion *region, const void *rna_poin_data, const char *rna_prop_id)
Definition
interface_handlers.cc:12371
UI_panel_category_active_set
void UI_panel_category_active_set(ARegion *region, const char *idname)
Definition
interface_panel.cc:2456
UI_panel_category_active_get
const char * UI_panel_category_active_get(ARegion *region, bool set_fallback)
Definition
interface_panel.cc:2479
WM_types.hh
ARegion
Definition
DNA_screen_types.h:509
ARegion::flag
short flag
Definition
DNA_screen_types.h:529
ARegion::alignment
short alignment
Definition
DNA_screen_types.h:527
ARegion::regiontype
short regiontype
Definition
DNA_screen_types.h:525
ScrArea
Definition
DNA_screen_types.h:441
ScrArea::regionbase
ListBase regionbase
Definition
DNA_screen_types.h:499
SpaceText
Definition
DNA_space_types.h:704
SpaceText::text
struct Text * text
Definition
DNA_space_types.h:713
SpaceText::findstr
char findstr[256]
Definition
DNA_space_types.h:740
TextLine::line
char * line
Definition
DNA_text_types.h:19
Text
Definition
DNA_text_types.h:26
Text::curl
TextLine * curl
Definition
DNA_text_types.h:53
Text::selc
int selc
Definition
DNA_text_types.h:54
Text::sell
TextLine * sell
Definition
DNA_text_types.h:53
Text::curc
int curc
Definition
DNA_text_types.h:54
bContext
Definition
blenkernel/intern/context.cc:63
wmOperatorType
Definition
WM_types.hh:1031
wmOperator
Definition
DNA_windowmanager_types.h:531
text_has_properties_region
static ARegion * text_has_properties_region(ScrArea *area)
Definition
text_header.cc:31
TEXT_OT_start_find
void TEXT_OT_start_find(wmOperatorType *ot)
Definition
text_header.cc:109
text_properties_poll
static bool text_properties_poll(bContext *C)
Definition
text_header.cc:59
text_text_search_exec
static wmOperatorStatus text_text_search_exec(bContext *C, wmOperator *)
Definition
text_header.cc:64
text_intern.hh
ot
wmOperatorType * ot
Definition
wm_files.cc:4237
Generated on
for Blender by
doxygen
1.16.1