Blender V5.0
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
11
12#include <cstring>
13#include <fmt/format.h>
14
15#include "BLI_array.hh"
17#include "BLI_string.h"
18
19#include "BLT_translation.hh"
20
21#include "BKE_global.hh"
22
23#include "WM_api.hh"
24#include "WM_types.hh"
25
27#include "interface_intern.hh"
28
29/* -------------------------------------------------------------------- */
32
33static void operator_search_exec_fn(bContext *C, void * /*arg1*/, void *arg2)
34{
35 wmOperatorType *ot = static_cast<wmOperatorType *>(arg2);
36
37 if (ot) {
39 }
40}
41
43 void * /*arg*/,
44 const char *str,
45 uiSearchItems *items,
46 const bool /*is_first*/)
47{
48 /* Prepare BLI_string_all_words_matched. */
49 const size_t str_len = strlen(str);
50 const int words_max = BLI_string_max_possible_word_count(str_len);
51 blender::Array<blender::int2> words(words_max);
52 const int words_len = BLI_string_find_split_words(
53 str, str_len, ' ', (int (*)[2])words.data(), words_max);
54
56 const char *ot_ui_name = CTX_IFACE_(ot->translation_context, ot->name);
57
58 if ((ot->flag & OPTYPE_INTERNAL) && (G.debug & G_DEBUG_WM) == 0) {
59 continue;
60 }
61
62 if (BLI_string_all_words_matched(ot_ui_name, str, (int (*)[2])words.data(), words_len)) {
63 if (WM_operator_poll((bContext *)C, ot)) {
64 std::string name = ot_ui_name;
65 if (const std::optional<std::string> kmi_str = WM_key_event_operator_string(
66 C, ot->idname, blender::wm::OpCallContext::ExecDefault, nullptr, true))
67 {
69 name += *kmi_str;
70 }
71
72 if (!UI_search_item_add(items, name, ot, ICON_NONE, 0, 0)) {
73 break;
74 }
75 }
76 }
77 }
78}
79
81
82/* -------------------------------------------------------------------- */
85
87{
91 nullptr,
92 false,
93 nullptr,
95 nullptr);
96}
97
99{
100 uiBlock *block;
101 uiBut *but;
102 static char search[256] = "";
103
104 block = layout->block();
106
107 but = uiDefSearchBut(
108 block, search, 0, ICON_VIEWZOOM, sizeof(search), 0, 0, UI_UNIT_X * 6, UI_UNIT_Y, "");
110}
111
@ 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.cc:573
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)
#define C
Definition RandGen.cpp:29
#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)
uiBut * uiDefSearchBut(uiBlock *block, void *arg, int retval, int icon, int maxncpy, int x, int y, short width, short height, std::optional< blender::StringRef > tip)
bool UI_search_item_add(uiSearchItems *items, blender::StringRef name, void *poin, int iconid, int but_flag, uint8_t name_prefix_offset)
#define UI_UNIT_X
@ OPTYPE_INTERNAL
Definition WM_types.hh:202
const T * data() const
Definition BLI_array.hh:312
#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)
void block_layout_set_current(uiBlock *block, uiLayout *layout)
const char * name
uiBlock * block() const
wmOperatorStatus WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, blender::wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
bool WM_operator_poll(bContext *C, wmOperatorType *ot)
wmOperatorType * ot
Definition wm_files.cc:4237
std::optional< std::string > WM_key_event_operator_string(const bContext *C, const char *opname, blender::wm::OpCallContext opcontext, IDProperty *properties, const bool is_strict)
blender::Span< wmOperatorType * > WM_operatortypes_registered_get()