Refactor: Ensure there's always a valid file editor tool region
So far the file browser code had some lazy creation for the tool region, even though it should always be there. The only reason I can see for this is compatiblity. So I simply added versioning code to add the region in case it's not there. Now we should be able to savely assume the tool region to be there, whithout any unusual lazy-creation.
This commit is contained in:
@@ -3877,6 +3877,17 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (sl->spacetype == SPACE_FILE) {
|
||||
ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
|
||||
|
||||
if (!do_versions_find_region_or_null(regionbase, RGN_TYPE_TOOLS)) {
|
||||
ARegion *ar_ui = do_versions_find_region(regionbase, RGN_TYPE_UI);
|
||||
ARegion *ar_tools = do_versions_add_region(RGN_TYPE_TOOLS,
|
||||
"versioning file tools region");
|
||||
BLI_insertlinkafter(regionbase, ar_ui, ar_tools);
|
||||
ar_tools->alignment = RGN_ALIGN_LEFT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,8 +109,6 @@ void file_sfile_to_operator_ex(bContext *C,
|
||||
char *filepath);
|
||||
void file_sfile_to_operator(bContext *C, struct wmOperator *op, struct SpaceFile *sfile);
|
||||
|
||||
struct ARegion *file_tools_region_ensure(struct ScrArea *sa, struct ARegion *ar_prev);
|
||||
|
||||
void file_operator_to_sfile(bContext *C, struct SpaceFile *sfile, struct wmOperator *op);
|
||||
|
||||
/* filesel.c */
|
||||
|
||||
@@ -2318,7 +2318,7 @@ void FILE_OT_hidedot(struct wmOperatorType *ot)
|
||||
static int file_bookmark_toggle_exec(bContext *C, wmOperator *UNUSED(unused))
|
||||
{
|
||||
ScrArea *sa = CTX_wm_area(C);
|
||||
ARegion *ar = file_tools_region_ensure(sa, BKE_area_find_region_type(sa, RGN_TYPE_UI));
|
||||
ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS);
|
||||
|
||||
if (ar) {
|
||||
ED_region_toggle_hidden(C, ar);
|
||||
|
||||
@@ -55,27 +55,6 @@
|
||||
#include "filelist.h"
|
||||
#include "GPU_framebuffer.h"
|
||||
|
||||
static ARegion *file_tools_region_create(ListBase *regionbase, ARegion *ar_prev)
|
||||
{
|
||||
ARegion *ar = MEM_callocN(sizeof(ARegion), "tools region for file");
|
||||
BLI_insertlinkafter(regionbase, ar_prev, ar);
|
||||
ar->regiontype = RGN_TYPE_TOOLS;
|
||||
ar->alignment = RGN_ALIGN_LEFT;
|
||||
|
||||
return ar;
|
||||
}
|
||||
|
||||
ARegion *file_tools_region_ensure(ScrArea *sa, ARegion *ar_prev)
|
||||
{
|
||||
ARegion *ar;
|
||||
|
||||
if ((ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS)) != NULL) {
|
||||
return ar;
|
||||
}
|
||||
|
||||
return file_tools_region_create(&sa->regionbase, ar_prev);
|
||||
}
|
||||
|
||||
static ARegion *file_tools_options_toggle_region_ensure(ScrArea *sa, ARegion *ar_prev)
|
||||
{
|
||||
ARegion *ar;
|
||||
@@ -154,7 +133,10 @@ static SpaceLink *file_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scen
|
||||
ar->flag |= RGN_FLAG_DYNAMIC_SIZE;
|
||||
|
||||
/* Tools region */
|
||||
file_tools_region_create(&sfile->regionbase, ar);
|
||||
ar = MEM_callocN(sizeof(ARegion), "tools region for file");
|
||||
BLI_addtail(&sfile->regionbase, ar);
|
||||
ar->regiontype = RGN_TYPE_TOOLS;
|
||||
ar->alignment = RGN_ALIGN_LEFT;
|
||||
|
||||
/* Options toggle, tool props and execute region are added as needed, see file_refresh(). */
|
||||
|
||||
@@ -276,18 +258,12 @@ static void file_ensure_valid_region_state(bContext *C,
|
||||
SpaceFile *sfile,
|
||||
FileSelectParams *params)
|
||||
{
|
||||
ARegion *ar_ui = BKE_area_find_region_type(sa, RGN_TYPE_UI);
|
||||
ARegion *ar_tools_upper = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS);
|
||||
ARegion *ar_props = BKE_area_find_region_type(sa, RGN_TYPE_TOOL_PROPS);
|
||||
ARegion *ar_execute = BKE_area_find_region_type(sa, RGN_TYPE_EXECUTE);
|
||||
ARegion *ar_tools_lower;
|
||||
bool needs_init = false; /* To avoid multiple ED_area_initialize() calls. */
|
||||
|
||||
if (ar_tools_upper == NULL) {
|
||||
ar_tools_upper = file_tools_region_ensure(sa, ar_ui);
|
||||
needs_init = true;
|
||||
}
|
||||
|
||||
/* If there's an file-operation, ensure we have the option and execute region */
|
||||
if (sfile->op && (ar_props == NULL)) {
|
||||
ar_tools_lower = file_tools_options_toggle_region_ensure(sa, ar_tools_upper);
|
||||
|
||||
Reference in New Issue
Block a user