Blender V5.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
11
12#include <cstring>
13#include <fmt/format.h>
14
15#include "BLI_array.hh"
17#include "BLI_string.hh"
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
29namespace blender::ui {
30
31/* -------------------------------------------------------------------- */
34
35static void operator_search_exec_fn(bContext *C, void * /*arg1*/, void *arg2)
36{
37 wmOperatorType *ot = static_cast<wmOperatorType *>(arg2);
38
39 if (ot) {
41 }
42}
43
45 void * /*arg*/,
46 const char *str,
47 SearchItems *items,
48 const bool /*is_first*/)
49{
50 /* Prepare BLI_string_all_words_matched. */
51 const size_t str_len = strlen(str);
52 const int words_max = BLI_string_max_possible_word_count(str_len);
53 Array<int2> words(words_max);
54 const int words_len = BLI_string_find_split_words(
55 str, str_len, ' ', reinterpret_cast<int (*)[2]>(words.data()), words_max);
56
58 const char *ot_ui_name = CTX_IFACE_(ot->translation_context, ot->name);
59
60 if ((ot->flag & OPTYPE_INTERNAL) && (G.debug & G_DEBUG_WM) == 0) {
61 continue;
62 }
63
65 ot_ui_name, str, reinterpret_cast<int (*)[2]>(words.data()), words_len))
66 {
67 if (WM_operator_poll(const_cast<bContext *>(C), ot)) {
68 std::string name = ot_ui_name;
69 if (const std::optional<std::string> kmi_str = WM_key_event_operator_string(
70 C, ot->idname, wm::OpCallContext::ExecDefault, nullptr, true))
71 {
72 name += UI_SEP_CHAR;
73 name += *kmi_str;
74 }
75
76 if (!search_item_add(items, name, ot, ICON_NONE, 0, 0)) {
77 break;
78 }
79 }
80 }
81 }
82}
83
85
86/* -------------------------------------------------------------------- */
89
91{
95 nullptr,
96 false,
97 nullptr,
99 nullptr);
100}
101
103{
104 Block *block;
105 Button *but;
106 static char search[256] = "";
107
108 block = layout->block();
109 block_layout_set_current(block, layout);
110
111 but = uiDefSearchBut(
112 block, search, ICON_VIEWZOOM, sizeof(search), 0, 0, UI_UNIT_X * 6, UI_UNIT_Y, "");
114}
115
117
118} // namespace blender::ui
#define CTX_IFACE_(context, msgid)
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_SEP_CHAR
#define UI_UNIT_X
const T * data() const
Definition BLI_array.hh:323
#define str(s)
void uiTemplateOperatorSearch(Layout *layout)
static void operator_search_exec_fn(bContext *C, void *, void *arg2)
ARegion * searchbox_create_operator(bContext *C, ARegion *butregion, ButtonSearch *search_but)
Button * uiDefSearchBut(Block *block, void *arg, int icon, int maxncpy, int x, int y, short width, short height, std::optional< StringRef > tip)
void button_func_operator_search(Button *but)
static void operator_search_update_fn(const bContext *C, void *, const char *str, SearchItems *items, const bool)
bool search_item_add(SearchItems *items, StringRef name, void *poin, int iconid, int64_t but_flag, uint8_t name_prefix_offset)
void block_layout_set_current(Block *block, Layout *layout)
void button_func_search_set(Button *but, ButtonSearchCreateFn search_create_fn, ButtonSearchUpdateFn search_update_fn, void *arg, bool free_arg, FreeArgFunc search_arg_free_fn, ButtonHandleFunc search_exec_fn, void *active)
std::optional< std::string > WM_key_event_operator_string(const bContext *C, const char *opname, wm::OpCallContext opcontext, IDProperty *properties, const bool is_strict)
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
Span< wmOperatorType * > WM_operatortypes_registered_get()
Global G
Definition blender.cc:57
int bool bool bool size_t size_t size_t int BLI_string_max_possible_word_count(int str_len) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
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
@ OPTYPE_INTERNAL
Definition WM_types.hh:210
bool WM_operator_poll(bContext *C, wmOperatorType *ot)