Blender
V5.0
source
blender
windowmanager
intern
wm_menu_type.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
10
11
#include <cstdio>
12
13
#include "
DNA_windowmanager_types.h
"
14
15
#include "
MEM_guardedalloc.h
"
16
17
#include "
BLI_utildefines.h
"
18
#include "
BLI_vector_set.hh
"
19
20
#include "
BKE_context.hh
"
21
#include "
BKE_screen.hh
"
22
#include "
BKE_workspace.hh
"
23
24
#include "
WM_api.hh
"
25
#include "
WM_types.hh
"
26
27
using
blender::StringRef
;
28
29
static
auto
&
get_menu_type_map
()
30
{
31
struct
IDNameGetter {
32
StringRef
operator()
(
const
MenuType
*value)
const
33
{
34
return
StringRef
(value->
idname
);
35
}
36
};
37
static
blender::CustomIDVectorSet<MenuType *, IDNameGetter>
map;
38
return
map;
39
}
40
41
MenuType
*
WM_menutype_find
(
const
StringRef
idname,
bool
quiet)
42
{
43
if
(!idname.
is_empty
()) {
44
if
(
MenuType
*
const
*mt =
get_menu_type_map
().lookup_key_ptr_as(idname)) {
45
return
*mt;
46
}
47
}
48
49
if
(!quiet) {
50
printf
(
"search for unknown menutype %s\n"
, std::string(idname).c_str());
51
}
52
53
return
nullptr
;
54
}
55
56
blender::Span<MenuType *>
WM_menutypes_registered_get
()
57
{
58
return
get_menu_type_map
();
59
}
60
61
bool
WM_menutype_add
(
MenuType
*mt)
62
{
63
BLI_assert
((mt->
description
==
nullptr
) || (mt->
description
[0]));
64
get_menu_type_map
().add(mt);
65
return
true
;
66
}
67
68
void
WM_menutype_freelink
(
MenuType
*mt)
69
{
70
bool
ok =
get_menu_type_map
().remove(mt);
71
MEM_freeN
(mt);
72
73
BLI_assert
(ok);
74
UNUSED_VARS_NDEBUG
(ok);
75
}
76
77
void
WM_menutype_init
()
78
{
79
/* Reserve size is set based on blender default setup. */
80
get_menu_type_map
().reserve(512);
81
}
82
83
void
WM_menutype_free
()
84
{
85
for
(
MenuType
*mt :
get_menu_type_map
()) {
86
if
(mt->rna_ext.free) {
87
mt->rna_ext.free(mt->rna_ext.data);
88
}
89
MEM_freeN
(mt);
90
}
91
get_menu_type_map
().clear();
92
}
93
94
bool
WM_menutype_poll
(
bContext
*
C
,
MenuType
*mt)
95
{
96
/* If we're tagged, only use compatible. */
97
if
(mt->
owner_id
[0] !=
'\0'
) {
98
const
WorkSpace
*workspace =
CTX_wm_workspace
(
C
);
99
if
(
BKE_workspace_owner_id_check
(workspace, mt->
owner_id
) ==
false
) {
100
return
false
;
101
}
102
}
103
104
if
(mt->
poll
!=
nullptr
) {
105
return
mt->
poll
(
C
, mt);
106
}
107
return
true
;
108
}
109
110
void
WM_menutype_idname_visit_for_search
(
111
const
bContext
*
/*C*/
,
112
PointerRNA
*
/*ptr*/
,
113
PropertyRNA
*
/*prop*/
,
114
const
char
*
/*edit_text*/
,
115
blender::FunctionRef
<
void
(
StringPropertySearchVisitParams
)> visit_fn)
116
{
117
for
(
MenuType
*mt :
get_menu_type_map
()) {
118
StringPropertySearchVisitParams
visit_params{};
119
visit_params.
text
= mt->idname;
120
visit_params.
info
= mt->label;
121
visit_fn(visit_params);
122
}
123
}
BKE_context.hh
CTX_wm_workspace
WorkSpace * CTX_wm_workspace(const bContext *C)
Definition
blenkernel/intern/context.cc:939
BKE_screen.hh
BKE_workspace.hh
BKE_workspace_owner_id_check
bool BKE_workspace_owner_id_check(const WorkSpace *workspace, const char *owner_id) ATTR_NONNULL()
Definition
workspace.cc:537
BLI_assert
#define BLI_assert(a)
Definition
BLI_assert.h:46
BLI_utildefines.h
UNUSED_VARS_NDEBUG
#define UNUSED_VARS_NDEBUG(...)
Definition
BLI_utildefines.h:509
BLI_vector_set.hh
DNA_windowmanager_types.h
MEM_guardedalloc.h
Read Guarded memory(de)allocation.
C
#define C
Definition
RandGen.cpp:29
WM_api.hh
WM_types.hh
operator()
SIMD_FORCE_INLINE btVector3 operator()(const btVector3 &x) const
Return the transform of the vector.
Definition
btTransform.h:90
blender::FunctionRef
Definition
BLI_function_ref.hh:72
blender::Span
Definition
BLI_span.hh:74
blender::StringRefBase::is_empty
constexpr bool is_empty() const
Definition
BLI_string_ref.hh:186
blender::StringRef
Definition
BLI_string_ref.hh:150
printf
#define printf(...)
Definition
gpu_shader_compat_cxx.hh:37
MEM_freeN
void MEM_freeN(void *vmemh)
Definition
mallocn.cc:113
blender::CustomIDVectorSet
VectorSet< T, InlineBufferCapacity, DefaultProbingStrategy, CustomIDHash< T, GetIDFn >, CustomIDEqual< T, GetIDFn > > CustomIDVectorSet
Definition
BLI_vector_set.hh:1145
MenuType
Definition
BKE_screen.hh:602
MenuType::description
const char * description
Definition
BKE_screen.hh:612
MenuType::poll
bool(* poll)(const bContext *C, MenuType *mt)
Definition
BKE_screen.hh:615
MenuType::idname
char idname[BKE_ST_MAXNAME]
Definition
BKE_screen.hh:606
MenuType::owner_id
char owner_id[128]
Definition
BKE_screen.hh:611
PointerRNA
Definition
RNA_types.hh:50
PropertyRNA
Definition
rna_internal_types.hh:363
StringPropertySearchVisitParams
Definition
RNA_types.hh:769
StringPropertySearchVisitParams::text
std::string text
Definition
RNA_types.hh:771
StringPropertySearchVisitParams::info
std::optional< std::string > info
Definition
RNA_types.hh:773
WorkSpace
Definition
DNA_workspace_types.h:143
bContext
Definition
blenkernel/intern/context.cc:63
WM_menutype_free
void WM_menutype_free()
Definition
wm_menu_type.cc:83
WM_menutype_find
MenuType * WM_menutype_find(const StringRef idname, bool quiet)
Definition
wm_menu_type.cc:41
get_menu_type_map
static auto & get_menu_type_map()
Definition
wm_menu_type.cc:29
WM_menutype_idname_visit_for_search
void WM_menutype_idname_visit_for_search(const bContext *, PointerRNA *, PropertyRNA *, const char *, blender::FunctionRef< void(StringPropertySearchVisitParams)> visit_fn)
Definition
wm_menu_type.cc:110
WM_menutype_add
bool WM_menutype_add(MenuType *mt)
Definition
wm_menu_type.cc:61
WM_menutype_poll
bool WM_menutype_poll(bContext *C, MenuType *mt)
Definition
wm_menu_type.cc:94
WM_menutypes_registered_get
blender::Span< MenuType * > WM_menutypes_registered_get()
Definition
wm_menu_type.cc:56
WM_menutype_init
void WM_menutype_init()
Definition
wm_menu_type.cc:77
WM_menutype_freelink
void WM_menutype_freelink(MenuType *mt)
Definition
wm_menu_type.cc:68
Generated on
for Blender by
doxygen
1.16.1