Blender V4.3
interface_template_search_operator.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
12#include <cstring>
13#include <fmt/format.h>
14
15#include "DNA_object_types.h"
16#include "DNA_texture_types.h"
17
18#include "BLI_array.hh"
19#include "BLI_ghash.h"
21#include "BLI_string.h"
22#include "BLI_utildefines.h"
23
24#include "BLT_translation.hh"
25
26#include "BKE_global.hh"
27
28#include "WM_api.hh"
29#include "WM_types.hh"
30
31#include "UI_interface.hh"
32#include "interface_intern.hh"
33
34/* -------------------------------------------------------------------- */
38static void operator_search_exec_fn(bContext *C, void * /*arg1*/, void *arg2)
39{
40 wmOperatorType *ot = static_cast<wmOperatorType *>(arg2);
41
42 if (ot) {
44 }
45}
46
48 void * /*arg*/,
49 const char *str,
50 uiSearchItems *items,
51 const bool /*is_first*/)
52{
53 /* Prepare BLI_string_all_words_matched. */
54 const size_t str_len = strlen(str);
55 const int words_max = BLI_string_max_possible_word_count(str_len);
56 blender::Array<blender::int2> words(words_max);
57 const int words_len = BLI_string_find_split_words(
58 str, str_len, ' ', (int(*)[2])words.data(), words_max);
59
61 const char *ot_ui_name = CTX_IFACE_(ot->translation_context, ot->name);
62
63 if ((ot->flag & OPTYPE_INTERNAL) && (G.debug & G_DEBUG_WM) == 0) {
64 continue;
65 }
66
67 if (BLI_string_all_words_matched(ot_ui_name, str, (int(*)[2])words.data(), words_len)) {
68 if (WM_operator_poll((bContext *)C, ot)) {
69 std::string name = ot_ui_name;
70 if (const std::optional<std::string> kmi_str = WM_key_event_operator_string(
71 C, ot->idname, WM_OP_EXEC_DEFAULT, nullptr, true))
72 {
73 name += UI_SEP_CHAR;
74 name += *kmi_str;
75 }
76
77 if (!UI_search_item_add(items, name.c_str(), ot, ICON_NONE, 0, 0)) {
78 break;
79 }
80 }
81 }
82 }
83}
84
87/* -------------------------------------------------------------------- */
92{
96 nullptr,
97 false,
98 nullptr,
100 nullptr);
101}
102
104{
105 uiBlock *block;
106 uiBut *but;
107 static char search[256] = "";
108
109 block = uiLayoutGetBlock(layout);
110 UI_block_layout_set_current(block, layout);
111
112 but = uiDefSearchBut(
113 block, search, 0, ICON_VIEWZOOM, sizeof(search), 0, 0, UI_UNIT_X * 6, UI_UNIT_Y, "");
115}
116
@ G_DEBUG_WM
int bool bool bool size_t size_t size_t int BLI_string_max_possible_word_count(int str_len) ATTR_WARN_UNUSED_RESULT
Definition string.c:569
bool bool BLI_string_all_words_matched(const char *name, const char *str, int(*words)[2], int words_len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
bool bool int BLI_string_find_split_words(const char *str, size_t str_maxlen, char delim, int r_words[][2], int words_max) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
#define CTX_IFACE_(context, msgid)
Object is a sort of wrapper for general info.
#define UI_UNIT_Y
#define UI_SEP_CHAR
void UI_but_func_search_set(uiBut *but, uiButSearchCreateFn search_create_fn, uiButSearchUpdateFn search_update_fn, void *arg, bool free_arg, uiFreeArgFunc search_arg_free_fn, uiButHandleFunc search_exec_fn, void *active)
bool UI_search_item_add(uiSearchItems *items, const char *name, void *poin, int iconid, int but_flag, uint8_t name_prefix_offset)
uiBlock * uiLayoutGetBlock(uiLayout *layout)
uiBut * uiDefSearchBut(uiBlock *block, void *arg, int retval, int icon, int maxncpy, int x, int y, short width, short height, const char *tip)
void UI_block_layout_set_current(uiBlock *block, uiLayout *layout)
#define UI_UNIT_X
@ OPTYPE_INTERNAL
Definition WM_types.hh:182
@ WM_OP_INVOKE_DEFAULT
Definition WM_types.hh:218
@ WM_OP_EXEC_DEFAULT
Definition WM_types.hh:225
const T * data() const
Definition BLI_array.hh:301
ValueIterator values() const
Definition BLI_map.hh:846
#define str(s)
ARegion * ui_searchbox_create_operator(bContext *C, ARegion *butregion, uiButSearch *search_but)
void uiTemplateOperatorSearch(uiLayout *layout)
void UI_but_func_operator_search(uiBut *but)
static void operator_search_exec_fn(bContext *C, void *, void *arg2)
static void operator_search_update_fn(const bContext *C, void *, const char *str, uiSearchItems *items, const bool)
#define G(x, y, z)
const char * name
Definition WM_types.hh:990
const char * idname
Definition WM_types.hh:992
const char * translation_context
Definition WM_types.hh:994
bool WM_operator_poll(bContext *C, wmOperatorType *ot)
int WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, wmOperatorCallContext context, PointerRNA *properties, const wmEvent *event)
wmOperatorType * ot
Definition wm_files.cc:4125
std::optional< std::string > WM_key_event_operator_string(const bContext *C, const char *opname, wmOperatorCallContext opcontext, IDProperty *properties, const bool is_strict)
const wmOperatorTypeMap & WM_operatortype_map()