Blender V5.0
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
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
32{
33 ARegion *region, *arnew;
34
36 if (region) {
37 return region;
38 }
39
40 /* Add subdiv level; after 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;
53
54 arnew->flag = RGN_FLAG_HIDDEN;
55
56 return arnew;
57}
58
60{
61 return (CTX_wm_space_text(C) != nullptr);
62}
63
65{
66 ScrArea *area = CTX_wm_area(C);
67 ARegion *region = text_has_properties_region(area);
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) {
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
110{
111 /* Identifiers. */
112 ot->name = "Find";
113 ot->description = "Start searching text";
114 ot->idname = "TEXT_OT_start_find";
115
116 /* API callbacks. */
118 ot->poll = text_properties_poll;
119}
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_region_new()
Definition screen.cc:387
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:846
void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:332
char * BLI_strncpy_utf8(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
@ OPERATOR_FINISHED
void ED_region_toggle_hidden(bContext *C, ARegion *region)
Definition area.cc:2373
void ED_region_do_layout(bContext *C, ARegion *region)
Definition area.cc:456
void ED_region_do_draw(bContext *C, ARegion *region)
Definition area.cc:479
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:618
#define C
Definition RandGen.cpp:29
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)
ListBase regionbase
struct Text * text
char findstr[256]
char * line
TextLine * curl
TextLine * sell
static ARegion * text_has_properties_region(ScrArea *area)
void TEXT_OT_start_find(wmOperatorType *ot)
static bool text_properties_poll(bContext *C)
static wmOperatorStatus text_text_search_exec(bContext *C, wmOperator *)
wmOperatorType * ot
Definition wm_files.cc:4237