[Bf-blender-cvs] [d611109ef84] temp-lanpr-cleanup: Rewrite file region handling for non-editor mode

Julian Eisel noreply at git.blender.org
Wed Sep 25 03:50:46 CEST 2019


Commit: d611109ef84238f85aa337ae370eec4c1341c871
Author: Julian Eisel
Date:   Fri Sep 20 15:09:47 2019 +0200
Branches: temp-lanpr-cleanup
https://developer.blender.org/rBd611109ef84238f85aa337ae370eec4c1341c871

Rewrite file region handling for non-editor mode

This makes it so that regions only needed when the file browser is
invoked as an operation (e.g. Ctrl+O rather than a regular editor) are
lazy created then, and removed if the file browser is changed into a
regular editor then (e.g. Ctrl+O over regular file browser editor ->
Cancel).

That should remove some troublesome assumptions and makes versioning
redundant.
It also fixes the issue of an empty execute region at the bottom after
cancelling a file operation invoked from a regular file browser editor.

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

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 3f832d54391..a2b7e34b45f 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -3907,26 +3907,6 @@ 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;
-            ARegion *ar_tools = do_versions_find_region_or_null(regionbase, RGN_TYPE_TOOLS);
-
-            if (ar_tools) {
-              ARegion *ar_next = ar_tools->next;
-
-              /* We temporarily had two tools regions, get rid of the second one. */
-              if (ar_next && ar_next->regiontype == RGN_TYPE_TOOLS) {
-                do_versions_remove_region(regionbase, RGN_TYPE_TOOLS);
-              }
-            }
-            else {
-              ARegion *ar_ui = do_versions_find_region(regionbase, RGN_TYPE_UI);
-
-              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 b0ff67844d8..c3d0f25ea50 100644
--- a/source/blender/editors/space_file/file_intern.h
+++ b/source/blender/editors/space_file/file_intern.h
@@ -108,6 +108,8 @@ 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 b4b51de302d..43cdea0e7d7 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -2321,6 +2321,30 @@ void FILE_OT_hidedot(struct wmOperatorType *ot)
   ot->poll = ED_operator_file_active; /* <- important, handler is on window level */
 }
 
+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));
+
+  if (ar) {
+    ED_region_toggle_hidden(C, ar);
+  }
+
+  return OPERATOR_FINISHED;
+}
+
+void FILE_OT_bookmark_toggle(struct wmOperatorType *ot)
+{
+  /* identifiers */
+  ot->name = "Toggle Bookmarks";
+  ot->description = "Toggle bookmarks display";
+  ot->idname = "FILE_OT_bookmark_toggle";
+
+  /* api callbacks */
+  ot->exec = file_bookmark_toggle_exec;
+  ot->poll = ED_operator_file_active; /* <- important, handler is on window level */
+}
+
 static bool file_filenum_poll(bContext *C)
 {
   SpaceFile *sfile = CTX_wm_space_file(C);
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c
index 021e53ca5f9..9fcf5dfdf39 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -55,6 +55,46 @@
 #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;
+
+  if ((ar = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS)) != NULL && (ar->next != NULL) &&
+      (ar->next->regiontype == RGN_TYPE_TOOLS)) {
+    BLI_assert(ar->alignment == (RGN_ALIGN_BOTTOM | RGN_SPLIT_PREV));
+    return ar;
+  }
+
+  ar = MEM_callocN(sizeof(ARegion), "options toggle region for file");
+  BLI_insertlinkafter(&sa->regionbase, ar_prev, ar);
+  ar->regiontype = RGN_TYPE_TOOLS;
+  ar->alignment = RGN_ALIGN_BOTTOM | RGN_SPLIT_PREV;
+  ar->flag |= RGN_FLAG_DYNAMIC_SIZE;
+
+  return ar;
+}
+
 static ARegion *file_execute_region_ensure(ScrArea *sa, ARegion *ar_prev)
 {
   ARegion *ar;
@@ -114,12 +154,9 @@ static SpaceLink *file_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scen
   ar->flag |= RGN_FLAG_DYNAMIC_SIZE;
 
   /* Tools region */
-  ar = MEM_callocN(sizeof(ARegion), "tools region for file");
-  BLI_addtail(&sfile->regionbase, ar);
-  ar->regiontype = RGN_TYPE_TOOLS;
-  ar->alignment = RGN_ALIGN_LEFT;
+  file_tools_region_create(&sfile->regionbase, ar);
 
-  /* Tool props and execute region are added as needed, see file_refresh(). */
+  /* Options toggle, tool props and execute region are added as needed, see file_refresh(). */
 
   /* main region */
   ar = MEM_callocN(sizeof(ARegion), "main region for file");
@@ -239,14 +276,22 @@ static void file_ensure_valid_region_state(bContext *C,
                                            SpaceFile *sfile,
                                            FileSelectParams *params)
 {
-  ARegion *ar_tools = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS);
+  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_execute = file_execute_region_ensure(sa, ar_tools);
+    ar_tools_lower = file_tools_options_toggle_region_ensure(sa, ar_tools_upper);
+    ar_execute = file_execute_region_ensure(sa, ar_tools_lower);
     ar_props = file_tool_props_region_ensure(sa, ar_execute);
 
     if (params->flag & FILE_HIDE_TOOL_PROPS) {
@@ -260,10 +305,15 @@ static void file_ensure_valid_region_state(bContext *C,
   }
   /* If there's _no_ file-operation, ensure we _don't_ have the option and execute region */
   else if ((sfile->op == NULL) && (ar_props != NULL)) {
+    ar_tools_lower = ar_tools_upper->next;
+
     BLI_assert(ar_execute != NULL);
+    BLI_assert(ar_tools_lower != NULL);
+    BLI_assert(ar_tools_lower->regiontype == RGN_TYPE_TOOLS);
 
     ED_region_remove(C, sa, ar_props);
     ED_region_remove(C, sa, ar_execute);
+    ED_region_remove(C, sa, ar_tools_lower);
     needs_init = true;
   }
 
@@ -279,7 +329,6 @@ static void file_refresh(const bContext *C, ScrArea *sa)
   SpaceFile *sfile = CTX_wm_space_file(C);
   FileSelectParams *params = ED_fileselect_get_params(sfile);
   struct FSMenu *fsmenu = ED_fsmenu_get();
-  ARegion *region_tool_props = BKE_area_find_region_type(sa, RGN_TYPE_TOOL_PROPS);
 
   if (!sfile->folders_prev) {
     sfile->folders_prev = folderlist_new();
@@ -342,26 +391,8 @@ static void file_refresh(const bContext *C, ScrArea *sa)
   }
 
   /* Might be called with NULL sa, see file_main_region_draw() below. */
-  if (sa && BKE_area_find_region_type(sa, RGN_TYPE_TOOLS) == NULL) {
-    /* Create TOOLS region. */
-    file_tools_region(sa);
-
-    ED_area_initialize(wm, win, sa);
-  }
-
-  /* If there's an file-operation, ensure we have the option region */
-  if (sa && sfile->op && (region_tool_props == NULL)) {
-    ARegion *region_props = file_tool_props_region(sa);
-
-    if (params->flag & FILE_HIDE_TOOL_PROPS) {
-      region_props->flag |= RGN_FLAG_HIDDEN;
-    }
-
-    ED_area_initialize(wm, win, sa);
-  }
-  /* If there's _no_ file-operation, ensure we _don't_ have the option region */
-  else if (sa && (sfile->op == NULL) && (region_tool_props != NULL)) {
-    ED_region_remove((bContext *)C, sa, region_tool_props);
+  if (sa) {
+    file_ensure_valid_region_state((bContext *)C, wm, win, sa, sfile, params);
   }
 
   ED_area_tag_redraw(sa);



More information about the Bf-blender-cvs mailing list