[Bf-blender-cvs] [95b3c4c966f] master: File Browser: Refactor access to the selection parameters struct

Julian Eisel noreply at git.blender.org
Tue Dec 8 14:42:10 CET 2020


Commit: 95b3c4c966f9baeb6f73b84568b7f03287e1a350
Author: Julian Eisel
Date:   Tue Dec 8 13:47:37 2020 +0100
Branches: master
https://developer.blender.org/rB95b3c4c966f9baeb6f73b84568b7f03287e1a350

File Browser: Refactor access to the selection parameters struct

* Avoid direct access to `SpaceFile.params`, use a getter instead. This matters
  because once the asset-browser changes are in, there will be an alternative
  selection parameter object. The getter can return the correct one.
* Rename the function to ensure the parameters. The old name
  `ED_fileselect_get_params()` wasn't a mere getter, it would create the
  parameters if necessary. Now we have an actual getter, so better be clear.
* In some instances, I replaced the old "get" function with the new mere
  getter. So the ensure logic is called less often. However, in these cases we
  should be able to assume the selection parameters were created already as
  part of the editor creation routine.

The term "active" in the new function names may seem a bit odd in the current
context, but that is a preparation for the Asset Browser merge as well. Like
said, there will be two file selection parameter objects in the space.

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

M	source/blender/editors/include/ED_fileselect.h
M	source/blender/editors/space_file/file_draw.c
M	source/blender/editors/space_file/file_ops.c
M	source/blender/editors/space_file/file_panels.c
M	source/blender/editors/space_file/filelist.c
M	source/blender/editors/space_file/filesel.c
M	source/blender/editors/space_file/space_file.c
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/windowmanager/intern/wm_operators.c

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

diff --git a/source/blender/editors/include/ED_fileselect.h b/source/blender/editors/include/ED_fileselect.h
index 84808416074..a5a8df916d6 100644
--- a/source/blender/editors/include/ED_fileselect.h
+++ b/source/blender/editors/include/ED_fileselect.h
@@ -101,9 +101,9 @@ typedef struct FileSelection {
 struct View2D;
 struct rcti;
 
-struct FileSelectParams *ED_fileselect_get_params(struct SpaceFile *sfile);
+struct FileSelectParams *ED_fileselect_ensure_active_params(struct SpaceFile *sfile);
+struct FileSelectParams *ED_fileselect_get_active_params(const struct SpaceFile *sfile);
 
-short ED_fileselect_set_params(struct SpaceFile *sfile);
 void ED_fileselect_set_params_from_userdef(struct SpaceFile *sfile);
 void ED_fileselect_params_to_userdef(struct SpaceFile *sfile,
                                      const int temp_win_size[],
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 4b277435f63..e3bdda7c480 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -400,11 +400,12 @@ static void renamebutton_cb(bContext *C, void *UNUSED(arg1), char *oldname)
   wmWindowManager *wm = CTX_wm_manager(C);
   SpaceFile *sfile = (SpaceFile *)CTX_wm_space_data(C);
   ARegion *region = CTX_wm_region(C);
+  FileSelectParams *params = ED_fileselect_get_active_params(sfile);
 
-  BLI_join_dirfile(orgname, sizeof(orgname), sfile->params->dir, oldname);
-  BLI_strncpy(filename, sfile->params->renamefile, sizeof(filename));
+  BLI_join_dirfile(orgname, sizeof(orgname), params->dir, oldname);
+  BLI_strncpy(filename, params->renamefile, sizeof(filename));
   BLI_filename_make_safe(filename);
-  BLI_join_dirfile(newname, sizeof(newname), sfile->params->dir, filename);
+  BLI_join_dirfile(newname, sizeof(newname), params->dir, filename);
 
   if (!STREQ(orgname, newname)) {
     if (!BLI_exists(newname)) {
@@ -415,8 +416,8 @@ static void renamebutton_cb(bContext *C, void *UNUSED(arg1), char *oldname)
       }
       else {
         /* If rename is successful, scroll to newly renamed entry. */
-        BLI_strncpy(sfile->params->renamefile, filename, sizeof(sfile->params->renamefile));
-        sfile->params->rename_flag = FILE_PARAMS_RENAME_POSTSCROLL_PENDING;
+        BLI_strncpy(params->renamefile, filename, sizeof(params->renamefile));
+        params->rename_flag = FILE_PARAMS_RENAME_POSTSCROLL_PENDING;
 
         if (sfile->smoothscroll_timer != NULL) {
           WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), sfile->smoothscroll_timer);
@@ -688,7 +689,7 @@ static void draw_details_columns(const FileSelectParams *params,
 void file_draw_list(const bContext *C, ARegion *region)
 {
   SpaceFile *sfile = CTX_wm_space_file(C);
-  FileSelectParams *params = ED_fileselect_get_params(sfile);
+  FileSelectParams *params = ED_fileselect_get_active_params(sfile);
   FileLayout *layout = ED_fileselect_get_layout(sfile, region);
   View2D *v2d = &region->v2d;
   struct FileList *files = sfile->files;
@@ -847,26 +848,25 @@ void file_draw_list(const bContext *C, ARegion *region)
     }
 
     if (file_selflag & FILE_SEL_EDITING) {
-      uiBut *but;
       const short width = (params->display == FILE_IMGDISPLAY) ?
                               textwidth :
                               layout->attribute_columns[COLUMN_NAME].width -
                                   ATTRIBUTE_COLUMN_PADDING;
 
-      but = uiDefBut(block,
-                     UI_BTYPE_TEXT,
-                     1,
-                     "",
-                     sx + icon_ofs,
-                     sy - layout->tile_h - 0.15f * UI_UNIT_X,
-                     width - icon_ofs,
-                     textheight,
-                     sfile->params->renamefile,
-                     1.0f,
-                     (float)sizeof(sfile->params->renamefile),
-                     0,
-                     0,
-                     "");
+      uiBut *but = uiDefBut(block,
+                            UI_BTYPE_TEXT,
+                            1,
+                            "",
+                            sx + icon_ofs,
+                            sy - layout->tile_h - 0.15f * UI_UNIT_X,
+                            width - icon_ofs,
+                            textheight,
+                            params->renamefile,
+                            1.0f,
+                            (float)sizeof(params->renamefile),
+                            0,
+                            0,
+                            "");
       UI_but_func_rename_set(but, renamebutton_cb, file);
       UI_but_flag_enable(but, UI_BUT_NO_UTF8); /* allow non utf8 names */
       UI_but_flag_disable(but, UI_BUT_UNDO);
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 93367ad3d3c..b98348307f3 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -188,7 +188,7 @@ static FileSelect file_select_do(bContext *C, int selected_idx, bool do_diropen)
   Main *bmain = CTX_data_main(C);
   FileSelect retval = FILE_SELECT_NOTHING;
   SpaceFile *sfile = CTX_wm_space_file(C);
-  FileSelectParams *params = ED_fileselect_get_params(sfile);
+  FileSelectParams *params = ED_fileselect_get_active_params(sfile);
   int numfiles = filelist_files_ensure(sfile->files);
   const FileDirEntry *file;
 
@@ -302,10 +302,10 @@ static FileSelect file_select(
     bContext *C, const rcti *rect, FileSelType select, bool fill, bool do_diropen)
 {
   SpaceFile *sfile = CTX_wm_space_file(C);
+  FileSelectParams *params = ED_fileselect_get_active_params(sfile);
   FileSelect retval = FILE_SELECT_NOTHING;
   FileSelection sel = file_selection_get(C, rect, fill); /* get the selection */
-  const FileCheckType check_type = (sfile->params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS :
-                                                                              CHECK_ALL;
+  const FileCheckType check_type = (params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS : CHECK_ALL;
 
   /* flag the files as selected in the filelist */
   filelist_entries_select_index_range_set(
@@ -325,7 +325,7 @@ static FileSelect file_select(
   }
 
   if (select != FILE_SEL_ADD && !file_is_any_selected(sfile->files)) {
-    sfile->params->active_file = -1;
+    params->active_file = -1;
   }
   else if (sel.last >= 0) {
     ARegion *region = CTX_wm_region(C);
@@ -390,7 +390,7 @@ static int file_box_select_modal(bContext *C, wmOperator *op, const wmEvent *eve
 {
   ARegion *region = CTX_wm_region(C);
   SpaceFile *sfile = CTX_wm_space_file(C);
-  FileSelectParams *params = ED_fileselect_get_params(sfile);
+  FileSelectParams *params = ED_fileselect_get_active_params(sfile);
   FileSelection sel;
   rcti rect;
 
@@ -521,8 +521,9 @@ static int file_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
     return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
   }
 
-  if (sfile && sfile->params) {
-    int idx = sfile->params->highlight_file;
+  const FileSelectParams *params = ED_fileselect_get_active_params(sfile);
+  if (sfile && params) {
+    int idx = params->highlight_file;
     int numfiles = filelist_files_ensure(sfile->files);
 
     if ((idx >= 0) && (idx < numfiles)) {
@@ -613,7 +614,7 @@ static bool file_walk_select_selection_set(wmWindow *win,
                                            const bool extend,
                                            const bool fill)
 {
-  FileSelectParams *params = sfile->params;
+  FileSelectParams *params = ED_fileselect_get_active_params(sfile);
   struct FileList *files = sfile->files;
   const int last_sel = params->active_file; /* store old value */
   int active = active_old; /* could use active_old instead, just for readability */
@@ -804,7 +805,7 @@ static bool file_walk_select_do(bContext *C,
 static int file_walk_select_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
 {
   SpaceFile *sfile = (SpaceFile *)CTX_wm_space_data(C);
-  FileSelectParams *params = sfile->params;
+  FileSelectParams *params = ED_fileselect_get_active_params(sfile);
   const int direction = RNA_enum_get(op->ptr, "direction");
   const bool extend = RNA_boolean_get(op->ptr, "extend");
   const bool fill = RNA_boolean_get(op->ptr, "fill");
@@ -853,6 +854,7 @@ static int file_select_all_exec(bContext *C, wmOperator *op)
 {
   ScrArea *area = CTX_wm_area(C);
   SpaceFile *sfile = CTX_wm_space_file(C);
+  FileSelectParams *params = ED_fileselect_get_active_params(sfile);
   FileSelection sel;
   const int numfiles = filelist_files_ensure(sfile->files);
   int action = RNA_enum_get(op->ptr, "action");
@@ -870,7 +872,7 @@ static int file_select_all_exec(bContext *C, wmOperator *op)
   switch (action) {
     case SEL_SELECT:
     case SEL_INVERT: {
-      check_type = (sfile->params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS : CHECK_FILES;
+      check_type = (params->flag & FILE_DIRSEL_ONLY) ? CHECK_DIRS : CHECK_FILES;
       filesel_type = (action == SEL_INVERT) ? FILE_SEL_TOGGLE : FILE_SEL_ADD;
       break;
     }
@@ -888,11 +890,11 @@ static int file_select_all_exec(bContext *C, wmOperator *op)
   filelist_entries_select_index_range_set(
       sfile->files, &sel, filesel_type, FILE_SEL_SELECTED, check_type);
 
-  sfile->params->active_file = -1;
+  params->active_file = -1;
   if (action != SEL_DESELECT) {
     for (int i = 0; i < numfiles; i++) {
       if (filelist_entry_select_index_get(sfile->files, i, check_type)) {
-        sfile->params->active_file = i;
+        params->active_file = i;
         break;
       }
     }
@@ -935,8 +937,8 @@ static int bookmark_select_exec(bContext *C, wmOperator *op)
   PropertyRNA *prop;
 
   if ((prop = RNA_struct_find_property(op->ptr, "dir"))) {
+    FileSelectParams *params = ED_fileselect_get_active_params(sfile);
     char entry[256];
-    FileSelectParams *params = sfile->params;
 
     RNA_property_string_get(op->ptr, prop, entry);
     BLI_strncpy(params->dir, entry, sizeof(params->dir));
@@ -978,7 +980,7 @@ static int bookmark_add_exec(bContext *C, wmOperator *UNUSED(op))
   ScrArea *area = CTX_wm_area(C);
   SpaceFile *sfile = CTX_wm_space_file(C);
   struct FSMenu *

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list