Commit: 338b9ae00b35a45a3cf4f9a7a63d013817d79790
Author: Julian Eisel
Date:   Fri Sep 20 15:35:28 2019 +0200
Branches: temp-lanpr-cleanup
https://developer.blender.org/rB338b9ae00b35a45a3cf4f9a7a63d013817d79790

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.

===================================================================

M       source/blender/blenloader/intern/versioning_280.c
M       source/blender/editors/space_file/file_intern.h
M       source/blender/editors/space_file/file_ops.c
M       source/blender/editors/space_file/space_file.c

===================================================================

diff --git a/source/blender/blenloader/intern/versioning_280.c 
b/source/blender/blenloader/intern/versioning_280.c
index a2b7e34b45f..84adccde37b 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -3907,6 +3907,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;
+            }
+          }
         }
       }
     }
diff --git a/source/blender/editors/space_file/file_intern.h 
b/source/blender/editors/space_file/file_intern.h
index c3d0f25ea50..b0ff67844d8 100644
--- a/source/blender/editors/space_file/file_intern.h
+++ b/source/blender/editors/space_file/file_intern.h
@@ -108,8 +108,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 */
diff --git a/source/blender/editors/space_file/file_ops.c 
b/source/blender/editors/space_file/file_ops.c
index 43cdea0e7d7..5d96d754bfa 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -2324,7 +2324,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);
diff --git a/source/blender/editors/space_file/space_file.c 
b/source/blender/editors/space_file/space_file.c
index 9fcf5dfdf39..141036f856a 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -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);

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to