Blender V5.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
8
10
11#include "BLI_listbase.hh"
12#include "BLI_string_utf8.hh"
13
14#include "BKE_context.hh"
15#include "BKE_global.hh"
16#include "BKE_screen.hh"
17
18#include "DNA_text_types.h"
19
20#include "ED_screen.hh"
21
22#include "WM_api.hh"
23#include "WM_types.hh"
24
25#include "UI_interface.hh"
26
27#include "text_intern.hh"
28
29namespace blender {
30
31/* ************************ header area region *********************** */
32
33/************************** properties ******************************/
34
36{
37 ARegion *region, *arnew;
38
40 if (region) {
41 return region;
42 }
43
44 /* Add subdiv level; after header. */
46
47 /* Is error! */
48 if (region == nullptr) {
49 return nullptr;
50 }
51
52 arnew = BKE_area_region_new();
53
54 BLI_insertlinkafter(&area->regionbase, region, arnew);
55 arnew->regiontype = RGN_TYPE_UI;
57
58 arnew->flag = RGN_FLAG_HIDDEN;
59
60 return arnew;
61}
62
64{
65 return (CTX_wm_space_text(C) != nullptr);
66}
67
69{
70 ScrArea *area = CTX_wm_area(C);
71 ARegion *region = text_has_properties_region(area);
73
74 if (region) {
75 Text *text = st->text;
76
77 /* Use active text selection as search query, if selection is on a single line. */
78 if (text && (text->curl == text->sell) && (text->curc != text->selc)) {
79 const ARegion *active_region = CTX_wm_region(C);
80 if (active_region && active_region->regiontype == RGN_TYPE_WINDOW) {
81 const char *sel_start = text->curl->line + std::min(text->curc, text->selc);
82 const int sel_len = std::abs(text->curc - text->selc);
83 BLI_strncpy_utf8(st->findstr, sel_start, std::min(sel_len + 1, ST_MAX_FIND_STR));
84 }
85 }
86
87 const char *active_category = ui::panel_category_active_get(region, false);
88 if (active_category && !STREQ(active_category, "Text")) {
89 ui::panel_category_active_set(region, "Text");
90 }
93 }
94 ED_region_activate_rna_prop(C, region, st, "find_text");
95 }
96 return OPERATOR_FINISHED;
97}
98
100{
101 /* Identifiers. */
102 ot->name = "Find";
103 ot->description = "Start searching text";
104 ot->idname = "TEXT_OT_start_find";
105
106 /* API callbacks. */
109}
110
111} // namespace blender
#define ST_MAX_FIND_STR
#define C
Definition RandGen.cpp:29
#define NC_SCREEN
Definition WM_types.hh:390
#define NA_EDITED
Definition WM_types.hh:634
#define STREQ(a, b)
bool panel_region_visible_width_ensure(ARegion *region)
void panel_category_active_set(ARegion *region, const char *idname)
const char * panel_category_active_get(ARegion *region, bool set_fallback)
BMesh Iterators.
ScrArea * CTX_wm_area(const bContext *C)
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
static wmOperatorStatus text_text_search_exec(bContext *C, wmOperator *)
SpaceText * CTX_wm_space_text(const bContext *C)
static bool text_properties_poll(bContext *C)
void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:339
ARegion * BKE_area_region_new()
Definition screen.cc:522
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void TEXT_OT_start_find(wmOperatorType *ot)
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:1024
static ARegion * text_has_properties_region(ScrArea *area)
void ED_region_activate_rna_prop(bContext *C, ARegion *region, const void *data, StringRefNull prop_name)
Definition area.cc:696
ARegion * CTX_wm_region(const bContext *C)
eRegion_Alignment alignment
eRegion_Type regiontype
ListBaseT< ARegion > regionbase
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165