Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2016-03-24 15:28:46 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-03-24 15:30:51 +0300
commit8249046b82f7a7a79eac42f3870349604eeb2711 (patch)
tree4cf28d9664b2ce18b6346fbd34cf4afab2bd1418
parent70fcecc1f788772ac0ecdbd647583afe995423bb (diff)
UI: search operator's by word prefix
Would match middle of words which wasn't very useful in most cases.
-rw-r--r--source/blender/editors/interface/interface_templates.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index e48b09d1858..9f98c0dea30 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -25,6 +25,7 @@
*/
+#include <ctype.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
@@ -3271,6 +3272,22 @@ static void operator_call_cb(bContext *C, void *UNUSED(arg1), void *arg2)
WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, NULL);
}
+static bool has_word_prefix(const char *haystack, const char *needle, size_t needle_len)
+{
+ const char *match = BLI_strncasestr(haystack, needle, needle_len);
+ if (match) {
+ if ((match == haystack) || (*(match - 1) == ' ') || ispunct(*(match - 1))) {
+ return true;
+ }
+ else {
+ return has_word_prefix(match + 1, needle, needle_len);
+ }
+ }
+ else {
+ return false;
+ }
+}
+
static void operator_search_cb(const bContext *C, void *UNUSED(arg), const char *str, uiSearchItems *items)
{
GHashIterator iter;
@@ -3290,7 +3307,7 @@ static void operator_search_cb(const bContext *C, void *UNUSED(arg), const char
/* match name against all search words */
for (index = 0; index < words_len; index++) {
- if (!BLI_strncasestr(ot_ui_name, str + words[index][0], words[index][1])) {
+ if (!has_word_prefix(ot_ui_name, str + words[index][0], words[index][1])) {
break;
}
}