Blender
V4.3
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
11
#include <cstdio>
12
13
#include "
BLI_sys_types.h
"
14
15
#include "
DNA_windowmanager_types.h
"
16
17
#include "
MEM_guardedalloc.h
"
18
19
#include "
BLI_ghash.h
"
20
#include "
BLI_utildefines.h
"
21
22
#include "
BKE_context.hh
"
23
#include "
BKE_screen.hh
"
24
#include "
BKE_workspace.hh
"
25
26
#include "
WM_api.hh
"
27
#include "
WM_types.hh
"
28
29
static
GHash
*
menutypes_hash
=
nullptr
;
30
31
MenuType
*
WM_menutype_find
(
const
char
*idname,
bool
quiet)
32
{
33
if
(idname[0]) {
34
MenuType
*mt =
static_cast<
MenuType
*
>
(
BLI_ghash_lookup
(
menutypes_hash
, idname));
35
if
(mt) {
36
return
mt;
37
}
38
}
39
40
if
(!quiet) {
41
printf
(
"search for unknown menutype %s\n"
, idname);
42
}
43
44
return
nullptr
;
45
}
46
47
void
WM_menutype_iter
(
GHashIterator
*ghi)
48
{
49
BLI_ghashIterator_init
(ghi,
menutypes_hash
);
50
}
51
52
bool
WM_menutype_add
(
MenuType
*mt)
53
{
54
BLI_assert
((mt->
description
==
nullptr
) || (mt->
description
[0]));
55
BLI_ghash_insert
(
menutypes_hash
, mt->
idname
, mt);
56
return
true
;
57
}
58
59
void
WM_menutype_freelink
(
MenuType
*mt)
60
{
61
bool
ok =
BLI_ghash_remove
(
menutypes_hash
, mt->
idname
,
nullptr
,
MEM_freeN
);
62
63
BLI_assert
(ok);
64
UNUSED_VARS_NDEBUG
(ok);
65
}
66
67
void
WM_menutype_init
()
68
{
69
/* Reserve size is set based on blender default setup. */
70
menutypes_hash
=
BLI_ghash_str_new_ex
(
"menutypes_hash gh"
, 512);
71
}
72
73
void
WM_menutype_free
()
74
{
75
GHashIterator
gh_iter;
76
77
GHASH_ITER
(gh_iter,
menutypes_hash
) {
78
MenuType
*mt =
static_cast<
MenuType
*
>
(
BLI_ghashIterator_getValue
(&gh_iter));
79
if
(mt->
rna_ext
.
free
) {
80
mt->
rna_ext
.
free
(mt->
rna_ext
.
data
);
81
}
82
}
83
84
BLI_ghash_free
(
menutypes_hash
,
nullptr
,
MEM_freeN
);
85
menutypes_hash
=
nullptr
;
86
}
87
88
bool
WM_menutype_poll
(
bContext
*C,
MenuType
*mt)
89
{
90
/* If we're tagged, only use compatible. */
91
if
(mt->
owner_id
[0] !=
'\0'
) {
92
const
WorkSpace
*workspace =
CTX_wm_workspace
(C);
93
if
(
BKE_workspace_owner_id_check
(workspace, mt->
owner_id
) ==
false
) {
94
return
false
;
95
}
96
}
97
98
if
(mt->
poll
!=
nullptr
) {
99
return
mt->
poll
(C, mt);
100
}
101
return
true
;
102
}
103
104
void
WM_menutype_idname_visit_for_search
(
105
const
bContext
*
/*C*/
,
106
PointerRNA
*
/*ptr*/
,
107
PropertyRNA
*
/*prop*/
,
108
const
char
*
/*edit_text*/
,
109
blender::FunctionRef
<
void
(
StringPropertySearchVisitParams
)> visit_fn)
110
{
111
GHashIterator
gh_iter;
112
GHASH_ITER
(gh_iter,
menutypes_hash
) {
113
MenuType
*mt =
static_cast<
MenuType
*
>
(
BLI_ghashIterator_getValue
(&gh_iter));
114
115
StringPropertySearchVisitParams
visit_params{};
116
visit_params.
text
= mt->
idname
;
117
visit_params.info = mt->
label
;
118
visit_fn(visit_params);
119
}
120
}
BKE_context.hh
CTX_wm_workspace
WorkSpace * CTX_wm_workspace(const bContext *C)
Definition
blenkernel/intern/context.cc:740
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:536
BLI_assert
#define BLI_assert(a)
Definition
BLI_assert.h:50
BLI_ghash.h
BLI_ghashIterator_getValue
BLI_INLINE void * BLI_ghashIterator_getValue(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
Definition
BLI_ghash.h:303
GHASH_ITER
#define GHASH_ITER(gh_iter_, ghash_)
Definition
BLI_ghash.h:322
BLI_ghash_str_new_ex
GHash * BLI_ghash_str_new_ex(const char *info, unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition
BLI_ghash_utils.cc:198
BLI_ghash_remove
bool BLI_ghash_remove(GHash *gh, const void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition
BLI_ghash.c:787
BLI_ghash_lookup
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition
BLI_ghash.c:731
BLI_ghash_insert
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition
BLI_ghash.c:707
BLI_ghash_free
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition
BLI_ghash.c:860
BLI_ghashIterator_init
void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh)
Definition
BLI_ghash.c:895
BLI_sys_types.h
BLI_utildefines.h
UNUSED_VARS_NDEBUG
#define UNUSED_VARS_NDEBUG(...)
Definition
BLI_utildefines.h:537
DNA_windowmanager_types.h
MEM_guardedalloc.h
Read Guarded memory(de)allocation.
WM_api.hh
WM_types.hh
blender::FunctionRef
Definition
BLI_function_ref.hh:74
printf
#define printf
MEM_freeN
void MEM_freeN(void *vmemh)
Definition
mallocn.cc:105
ExtensionRNA::data
void * data
Definition
RNA_types.hh:779
ExtensionRNA::free
StructFreeFunc free
Definition
RNA_types.hh:782
GHashIterator
Definition
BLI_ghash.h:45
GHash
Definition
BLI_ghash.c:80
MenuType
Definition
BKE_screen.hh:499
MenuType::description
const char * description
Definition
BKE_screen.hh:506
MenuType::label
char label[BKE_ST_MAXNAME]
Definition
BKE_screen.hh:503
MenuType::poll
bool(* poll)(const bContext *C, MenuType *mt)
Definition
BKE_screen.hh:509
MenuType::rna_ext
ExtensionRNA rna_ext
Definition
BKE_screen.hh:517
MenuType::idname
char idname[BKE_ST_MAXNAME]
Definition
BKE_screen.hh:502
MenuType::owner_id
char owner_id[128]
Definition
BKE_screen.hh:505
PointerRNA
Definition
RNA_types.hh:39
PropertyRNA
Definition
rna_internal_types.hh:318
StringPropertySearchVisitParams
Definition
RNA_types.hh:561
StringPropertySearchVisitParams::text
std::string text
Definition
RNA_types.hh:563
WorkSpace
Definition
DNA_workspace_types.h:126
bContext
Definition
blenkernel/intern/context.cc:61
WM_menutype_iter
void WM_menutype_iter(GHashIterator *ghi)
Definition
wm_menu_type.cc:47
WM_menutype_free
void WM_menutype_free()
Definition
wm_menu_type.cc:73
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:104
WM_menutype_add
bool WM_menutype_add(MenuType *mt)
Definition
wm_menu_type.cc:52
WM_menutype_find
MenuType * WM_menutype_find(const char *idname, bool quiet)
Definition
wm_menu_type.cc:31
WM_menutype_poll
bool WM_menutype_poll(bContext *C, MenuType *mt)
Definition
wm_menu_type.cc:88
WM_menutype_init
void WM_menutype_init()
Definition
wm_menu_type.cc:67
WM_menutype_freelink
void WM_menutype_freelink(MenuType *mt)
Definition
wm_menu_type.cc:59
menutypes_hash
static GHash * menutypes_hash
Definition
wm_menu_type.cc:29
Generated on Thu Feb 6 2025 07:36:39 for Blender by
doxygen
1.11.0