Blender  V3.3
wm_menu_type.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
9 #include <stdio.h>
10 
11 #include "BLI_sys_types.h"
12 
14 #include "DNA_workspace_types.h"
15 
16 #include "MEM_guardedalloc.h"
17 
18 #include "BLI_ghash.h"
19 #include "BLI_utildefines.h"
20 
21 #include "BKE_context.h"
22 #include "BKE_screen.h"
23 #include "BKE_workspace.h"
24 
25 #include "WM_api.h"
26 #include "WM_types.h"
27 
29 
30 MenuType *WM_menutype_find(const char *idname, bool quiet)
31 {
32  if (idname[0]) {
34  if (mt) {
35  return mt;
36  }
37  }
38 
39  if (!quiet) {
40  printf("search for unknown menutype %s\n", idname);
41  }
42 
43  return NULL;
44 }
45 
47 {
49 }
50 
52 {
53  BLI_assert((mt->description == NULL) || (mt->description[0]));
55  return true;
56 }
57 
59 {
61 
62  BLI_assert(ok);
64 }
65 
66 void WM_menutype_init(void)
67 {
68  /* reserve size is set based on blender default setup */
69  menutypes_hash = BLI_ghash_str_new_ex("menutypes_hash gh", 512);
70 }
71 
72 void WM_menutype_free(void)
73 {
74  GHashIterator gh_iter;
75 
76  GHASH_ITER (gh_iter, menutypes_hash) {
77  MenuType *mt = BLI_ghashIterator_getValue(&gh_iter);
78  if (mt->rna_ext.free) {
79  mt->rna_ext.free(mt->rna_ext.data);
80  }
81  }
82 
85 }
86 
88 {
89  /* If we're tagged, only use compatible. */
90  if (mt->owner_id[0] != '\0') {
91  const WorkSpace *workspace = CTX_wm_workspace(C);
92  if (BKE_workspace_owner_id_check(workspace, mt->owner_id) == false) {
93  return false;
94  }
95  }
96 
97  if (mt->poll != NULL) {
98  return mt->poll(C, mt);
99  }
100  return true;
101 }
102 
105  PropertyRNA *UNUSED(prop),
106  const char *UNUSED(edit_text),
108  void *visit_user_data)
109 {
110  GHashIterator gh_iter;
111  GHASH_ITER (gh_iter, menutypes_hash) {
112  MenuType *mt = BLI_ghashIterator_getValue(&gh_iter);
113 
114  StringPropertySearchVisitParams visit_params = {NULL};
115  visit_params.text = mt->idname;
116  visit_params.info = mt->label;
117  visit_fn(visit_user_data, &visit_params);
118  }
119 }
struct WorkSpace * CTX_wm_workspace(const bContext *C)
Definition: context.c:728
bool BKE_workspace_owner_id_check(const struct WorkSpace *workspace, const char *owner_id) ATTR_NONNULL()
#define BLI_assert(a)
Definition: BLI_assert.h:46
GHash * BLI_ghash_str_new_ex(const char *info, unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
BLI_INLINE void * BLI_ghashIterator_getValue(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.h:302
#define GHASH_ITER(gh_iter_, ghash_)
Definition: BLI_ghash.h:321
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:734
bool BLI_ghash_remove(GHash *gh, const void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:790
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition: BLI_ghash.c:710
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:863
void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh)
Definition: BLI_ghash.c:898
#define UNUSED_VARS_NDEBUG(...)
#define UNUSED(x)
Read Guarded memory(de)allocation.
void(* StringPropertySearchVisitFunc)(void *visit_user_data, const StringPropertySearchVisitParams *params)
Definition: RNA_types.h:568
#define C
Definition: RandGen.cpp:25
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void * data
Definition: RNA_types.h:765
StructFreeFunc free
Definition: RNA_types.h:768
const char * description
Definition: BKE_screen.h:365
char owner_id[BKE_ST_MAXNAME]
Definition: BKE_screen.h:364
char label[BKE_ST_MAXNAME]
Definition: BKE_screen.h:362
ExtensionRNA rna_ext
Definition: BKE_screen.h:373
char idname[BKE_ST_MAXNAME]
Definition: BKE_screen.h:361
bool(* poll)(const struct bContext *C, struct MenuType *mt)
Definition: BKE_screen.h:368
PointerRNA * ptr
Definition: wm_files.c:3480
void WM_menutype_iter(GHashIterator *ghi)
Definition: wm_menu_type.c:46
void WM_menutype_idname_visit_for_search(const bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), const char *UNUSED(edit_text), StringPropertySearchVisitFunc visit_fn, void *visit_user_data)
Definition: wm_menu_type.c:103
MenuType * WM_menutype_find(const char *idname, bool quiet)
Definition: wm_menu_type.c:30
void WM_menutype_free(void)
Definition: wm_menu_type.c:72
bool WM_menutype_add(MenuType *mt)
Definition: wm_menu_type.c:51
void WM_menutype_init(void)
Definition: wm_menu_type.c:66
bool WM_menutype_poll(bContext *C, MenuType *mt)
Definition: wm_menu_type.c:87
void WM_menutype_freelink(MenuType *mt)
Definition: wm_menu_type.c:58
static GHash * menutypes_hash
Definition: wm_menu_type.c:28