Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_buttons/space_buttons.c
| Show First 20 Lines • Show All 387 Lines • ▼ Show 20 Lines | if (BLI_BITMAP_TEST(sbuts->runtime->tab_search_results, i)) { | ||||
| sbuts->mainbuser = context_tabs_array[i]; | sbuts->mainbuser = context_tabs_array[i]; | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void property_search_all_tabs(const bContext *C, | static void property_search_all_tabs(const bContext *C, | ||||
| SpaceProperties *sbuts, | SpaceProperties *sbuts, | ||||
| ARegion *main_region, | ARegion *region_original, | ||||
| const short *context_tabs_array, | const short *context_tabs_array, | ||||
| const int tabs_len) | const int tabs_len) | ||||
| { | { | ||||
| /* Use local copies of the area and duplicate the region as a mainly-paranoid protection | /* Use local copies of the area and duplicate the region as a mainly-paranoid protection | ||||
| * against changing any of the space / region data while running the search. */ | * against changing any of the space / region data while running the search. */ | ||||
| ScrArea area_copy = *CTX_wm_area(C); | ScrArea *area_original = CTX_wm_area(C); | ||||
| ARegion *region_copy = BKE_area_region_copy(area_copy.type, main_region); | ScrArea area_copy = *area_original; | ||||
Severin: Eeeh, this shallow copy troubles me, didn't notice that before. What if something modifies data… | |||||
| bContext *C_copy = CTX_copy(C); | ARegion *region_copy = BKE_area_region_copy(area_copy.type, region_original); | ||||
| CTX_wm_area_set(C_copy, &area_copy); | CTX_wm_area_set((bContext *)C, &area_copy); | ||||
| CTX_wm_region_set(C_copy, region_copy); | CTX_wm_region_set((bContext *)C, region_copy); | ||||
| SpaceProperties sbuts_copy = *sbuts; | SpaceProperties sbuts_copy = *sbuts; | ||||
| sbuts_copy.path = NULL; | sbuts_copy.path = NULL; | ||||
| sbuts_copy.texuser = NULL; | sbuts_copy.texuser = NULL; | ||||
| sbuts_copy.runtime = MEM_dupallocN(sbuts->runtime); | sbuts_copy.runtime = MEM_dupallocN(sbuts->runtime); | ||||
| sbuts_copy.runtime->tab_search_results = NULL; | sbuts_copy.runtime->tab_search_results = NULL; | ||||
| area_copy.spacedata.first = &sbuts_copy; | BLI_listbase_clear(&area_copy.spacedata); | ||||
| BLI_addtail(&area_copy.spacedata, &sbuts_copy); | |||||
| /* Loop through the tabs added to the properties editor. */ | /* Loop through the tabs added to the properties editor. */ | ||||
| for (int i = 0; i < tabs_len; i++) { | for (int i = 0; i < tabs_len; i++) { | ||||
| /* -1 corresponds to a spacer. */ | /* -1 corresponds to a spacer. */ | ||||
| if (context_tabs_array[i] == -1) { | if (context_tabs_array[i] == -1) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* Handle search for the current tab in the normal layout pass. */ | /* Handle search for the current tab in the normal layout pass. */ | ||||
| if (context_tabs_array[i] == sbuts->mainb) { | if (context_tabs_array[i] == sbuts->mainb) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| sbuts_copy.mainb = sbuts_copy.mainbo = sbuts_copy.mainbuser = context_tabs_array[i]; | sbuts_copy.mainb = sbuts_copy.mainbo = sbuts_copy.mainbuser = context_tabs_array[i]; | ||||
| /* Actually do the search and store the result in the bitmap. */ | /* Actually do the search and store the result in the bitmap. */ | ||||
| BLI_BITMAP_SET(sbuts->runtime->tab_search_results, | BLI_BITMAP_SET(sbuts->runtime->tab_search_results, | ||||
| i, | i, | ||||
| property_search_for_context(C_copy, region_copy, &sbuts_copy)); | property_search_for_context(C, region_copy, &sbuts_copy)); | ||||
| UI_blocklist_free(C_copy, ®ion_copy->uiblocks); | UI_blocklist_free(C, ®ion_copy->uiblocks); | ||||
| } | } | ||||
| BKE_area_region_free(area_copy.type, region_copy); | BKE_area_region_free(area_copy.type, region_copy); | ||||
| MEM_freeN(region_copy); | MEM_freeN(region_copy); | ||||
| buttons_free((SpaceLink *)&sbuts_copy); | buttons_free((SpaceLink *)&sbuts_copy); | ||||
| MEM_freeN(C_copy); | |||||
| CTX_wm_area_set((bContext *)C, area_original); | |||||
| CTX_wm_region_set((bContext *)C, region_original); | |||||
| } | } | ||||
| /** | /** | ||||
| * Handle property search for the layout pass, including finding which tabs have | * Handle property search for the layout pass, including finding which tabs have | ||||
| * search results and switching if the current tab doesn't have a result. | * search results and switching if the current tab doesn't have a result. | ||||
| */ | */ | ||||
| static void buttons_main_region_property_search(const bContext *C, | static void buttons_main_region_property_search(const bContext *C, | ||||
| SpaceProperties *sbuts, | SpaceProperties *sbuts, | ||||
| ▲ Show 20 Lines • Show All 545 Lines • Show Last 20 Lines | |||||
Eeeh, this shallow copy troubles me, didn't notice that before. What if something modifies data the area points to (hard to tell since we call many general properties-space functions and a draw callback)?
I think we should try to sandbox the off-screen environment.
Logic to copy the SpaceProperties data can also easily get out of sync with buttons_duplicate, so maybe that should be called? I notice there's some special handling for the search data here, but that's not a big issue.
So, may be better to just temporarily override the spacedata list and call ED_area_data_copy() for a deep copy.
Also another point that could break: Code may assume that an area is always inside a screen (or window in case of top-bar/status-bar). So far this was always true I think, now not anymore. Good to be aware of.