Blender V4.3
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
10
11#include "MEM_guardedalloc.h"
12
13#include "BLI_blenlib.h"
14
15#include "BKE_context.hh"
16#include "BKE_screen.hh"
17
18#include "DNA_text_types.h"
19
20#include "ED_screen.hh"
21
22#include "WM_types.hh"
23
24#include "UI_interface.hh"
25
26#include "text_intern.hh"
27
28/* ************************ header area region *********************** */
29
30/************************** properties ******************************/
31
33{
34 ARegion *region, *arnew;
35
37 if (region) {
38 return region;
39 }
40
41 /* add subdiv level; after header */
43
44 /* is error! */
45 if (region == nullptr) {
46 return nullptr;
47 }
48
49 arnew = static_cast<ARegion *>(MEM_callocN(sizeof(ARegion), "properties region"));
50
51 BLI_insertlinkafter(&area->regionbase, region, arnew);
52 arnew->regiontype = RGN_TYPE_UI;
54
55 arnew->flag = RGN_FLAG_HIDDEN;
56
57 return arnew;
58}
59
61{
62 return (CTX_wm_space_text(C) != nullptr);
63}
64
66{
67 ScrArea *area = CTX_wm_area(C);
68 ARegion *region = text_has_properties_region(area);
70
71 if (region) {
72 Text *text = st->text;
73
74 /* Use active text selection as search query, if selection is on a single line. */
75 if (text && (text->curl == text->sell) && (text->curc != text->selc)) {
76 const ARegion *active_region = CTX_wm_region(C);
77 if (active_region && active_region->regiontype == RGN_TYPE_WINDOW) {
78 const char *sel_start = text->curl->line + std::min(text->curc, text->selc);
79 const int sel_len = std::abs(text->curc - text->selc);
80 BLI_strncpy(st->findstr, sel_start, std::min(sel_len + 1, ST_MAX_FIND_STR));
81 }
82 }
83
84 bool draw = false;
85
86 if (region->flag & RGN_FLAG_HIDDEN) {
87 ED_region_toggle_hidden(C, region);
88 draw = true;
89 }
90
91 const char *active_category = UI_panel_category_active_get(region, false);
92 if (active_category && !STREQ(active_category, "Text")) {
93 UI_panel_category_active_set(region, "Text");
94 draw = true;
95 }
96
97 /* Build the layout and draw so `find_text` text button can be activated. */
98 if (draw) {
99 ED_region_do_layout(C, region);
100 ED_region_do_draw(C, region);
101 }
102
103 UI_textbutton_activate_rna(C, region, st, "find_text");
104
105 ED_region_tag_redraw(region);
106 }
107 return OPERATOR_FINISHED;
108}
109
111{
112 /* identifiers */
113 ot->name = "Find";
114 ot->description = "Start searching text";
115 ot->idname = "TEXT_OT_start_find";
116
117 /* api callbacks */
120}
SpaceText * CTX_wm_space_text(const bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:815
void BLI_insertlinkafter(struct ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:331
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
#define STREQ(a, b)
@ RGN_ALIGN_LEFT
@ RGN_TYPE_UI
@ RGN_TYPE_WINDOW
@ RGN_TYPE_HEADER
@ RGN_FLAG_HIDDEN
#define ST_MAX_FIND_STR
void ED_region_toggle_hidden(bContext *C, ARegion *region)
Definition area.cc:2276
void ED_region_do_layout(bContext *C, ARegion *region)
Definition area.cc:476
void ED_region_do_draw(bContext *C, ARegion *region)
Definition area.cc:499
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:634
Read Guarded memory(de)allocation.
bool UI_textbutton_activate_rna(const bContext *C, ARegion *region, const void *rna_poin_data, const char *rna_prop_id)
void UI_panel_category_active_set(ARegion *region, const char *idname)
const char * UI_panel_category_active_get(ARegion *region, bool set_fallback)
void *(* MEM_callocN)(size_t len, const char *str)
Definition mallocn.cc:42
struct Text * text
char findstr[256]
const char * name
Definition WM_types.hh:990
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1042
const char * idname
Definition WM_types.hh:992
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1006
const char * description
Definition WM_types.hh:996
static ARegion * text_has_properties_region(ScrArea *area)
static int text_text_search_exec(bContext *C, wmOperator *)
void TEXT_OT_start_find(wmOperatorType *ot)
static bool text_properties_poll(bContext *C)
wmOperatorType * ot
Definition wm_files.cc:4125