Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_region_search.c
| Show First 20 Lines • Show All 310 Lines • ▼ Show 20 Lines | if (data->active != -1) { | ||||
| const char *name = data->items.names[data->active] + | const char *name = data->items.names[data->active] + | ||||
| /* Never include the prefix in the button. */ | /* Never include the prefix in the button. */ | ||||
| (data->items.name_prefix_offsets ? | (data->items.name_prefix_offsets ? | ||||
| data->items.name_prefix_offsets[data->active] : | data->items.name_prefix_offsets[data->active] : | ||||
| 0); | 0); | ||||
| const char *name_sep = data->use_shortcut_sep ? strrchr(name, UI_SEP_CHAR) : NULL; | const char *name_sep = data->use_shortcut_sep ? strrchr(name, UI_SEP_CHAR) : NULL; | ||||
| /* Search button with dynamic string properties may have their own method of applying | |||||
| * the search results, so only copy the result if there is a proper space for it. */ | |||||
JacquesLucke: typo (`there`) | |||||
| if (but->hardmax != 0) { | |||||
| BLI_strncpy(but->editstr, name, name_sep ? (name_sep - name) + 1 : data->items.maxstrlen); | BLI_strncpy(but->editstr, name, name_sep ? (name_sep - name) + 1 : data->items.maxstrlen); | ||||
| } | |||||
| search_but->item_active = data->items.pointers[data->active]; | search_but->item_active = data->items.pointers[data->active]; | ||||
| return true; | return true; | ||||
| } | } | ||||
| if (but->flag & UI_BUT_VALUE_CLEAR) { | if (but->flag & UI_BUT_VALUE_CLEAR) { | ||||
| /* It is valid for _VALUE_CLEAR flavor to have no active element | /* It is valid for _VALUE_CLEAR flavor to have no active element | ||||
| * (it's a valid way to unlink). */ | * (it's a valid way to unlink). */ | ||||
| ▲ Show 20 Lines • Show All 545 Lines • ▼ Show 20 Lines | static ARegion *ui_searchbox_create_generic_ex(bContext *C, | ||||
| /* prepare search data */ | /* prepare search data */ | ||||
| if (data->preview) { | if (data->preview) { | ||||
| data->items.maxitem = data->prv_rows * data->prv_cols; | data->items.maxitem = data->prv_rows * data->prv_cols; | ||||
| } | } | ||||
| else { | else { | ||||
| data->items.maxitem = SEARCH_ITEMS; | data->items.maxitem = SEARCH_ITEMS; | ||||
| } | } | ||||
| data->items.maxstrlen = but->hardmax; | /* In case the button's string is dynamic, make sure there are buffers available. */ | ||||
| data->items.maxstrlen = but->hardmax == 0 ? 256 : but->hardmax; | |||||
Done Inline ActionsWhere does the 256 come from? If it's just an arbitrary, big enough buffer, better to use UI_MAX_DRAW_STR or UI_MAX_NAME_STR. Severin: Where does the 256 come from? If it's just an arbitrary, big enough buffer, better to use… | |||||
| data->items.totitem = 0; | data->items.totitem = 0; | ||||
| data->items.names = MEM_callocN(data->items.maxitem * sizeof(void *), "search names"); | data->items.names = MEM_callocN(data->items.maxitem * sizeof(void *), "search names"); | ||||
| data->items.pointers = MEM_callocN(data->items.maxitem * sizeof(void *), "search pointers"); | data->items.pointers = MEM_callocN(data->items.maxitem * sizeof(void *), "search pointers"); | ||||
| data->items.icons = MEM_callocN(data->items.maxitem * sizeof(int), "search icons"); | data->items.icons = MEM_callocN(data->items.maxitem * sizeof(int), "search icons"); | ||||
| data->items.states = MEM_callocN(data->items.maxitem * sizeof(int), "search flags"); | data->items.states = MEM_callocN(data->items.maxitem * sizeof(int), "search flags"); | ||||
| data->items.name_prefix_offsets = NULL; /* Lazy initialized as needed. */ | data->items.name_prefix_offsets = NULL; /* Lazy initialized as needed. */ | ||||
| for (int i = 0; i < data->items.maxitem; i++) { | for (int i = 0; i < data->items.maxitem; i++) { | ||||
| data->items.names[i] = MEM_callocN(but->hardmax + 1, "search pointers"); | data->items.names[i] = MEM_callocN(data->items.maxstrlen + 1, "search pointers"); | ||||
| } | } | ||||
| return region; | return region; | ||||
| } | } | ||||
| ARegion *ui_searchbox_create_generic(bContext *C, ARegion *butregion, uiButSearch *search_but) | ARegion *ui_searchbox_create_generic(bContext *C, ARegion *butregion, uiButSearch *search_but) | ||||
| { | { | ||||
| return ui_searchbox_create_generic_ex(C, butregion, search_but, false); | return ui_searchbox_create_generic_ex(C, butregion, search_but, false); | ||||
| ▲ Show 20 Lines • Show All 184 Lines • Show Last 20 Lines | |||||
typo (there)