[Bf-blender-cvs] [ddb157999ee] master: UI: Remember File Browser Display Options in Preferences

Julian Eisel noreply at git.blender.org
Mon Sep 30 19:28:11 CEST 2019


Commit: ddb157999eed6907e3fd8753d61e65491f2f3a6d
Author: Julian Eisel
Date:   Mon Sep 30 18:54:11 2019 +0200
Branches: master
https://developer.blender.org/rBddb157999eed6907e3fd8753d61e65491f2f3a6d

UI: Remember File Browser Display Options in Preferences

This makes it so that some display related properties of the file
browser state are remembered in the Preferences. Otherwise, users often
end up doing the same set up work over and over again, so this is a
nice way to save users some work.
It's typical for other file browsers to remember their state too, so
another benefit is having a more conventional behavior, meeting user
expectations better.

Some points:
 * We currently store: Window size, display type, thumbnail size,
   enabled details-columns, sort options, "Show Hidden" option. More can
   be added easily.
 * No changes are stored to the Preferences if "Auto-save Preferences"
   is disabled. This is how Quick Favorites behave too and it's a
   reasonable way to make this behavior optional.
 * The Preferences are only saved to permanent memory upon closing
   Blender, following existing convention of Preferences and Quick
   Favorites.
 * If settings weren't actually changed, Preference saving is skipped.
 * Only temporary file browsers save their state (invoked through
   actions like open or save), not regular file browser editors. These
   are usually used for different purposes and workflows.
 * Removes "Show Thumbnails" Preferences option. It would need some
   special handling, possibly introducing bugs. For users, this
   simplifies behavior and should make things more predictable.
   Left in DNA data in case we decide to bring it back.

Reviewers: brecht, #user_interface, billreynish, campbellbarton

Reviewed By: #user_interface, William Reynish, Campbell Barton, Brecht
             van Lommel (quick first pass review in person)

Maniphest Tasks: T69460

Differential Revision: https://developer.blender.org/D5893

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

M	release/datafiles/userdef/userdef_default.c
M	release/scripts/startup/bl_ui/space_userpref.py
M	source/blender/blenloader/intern/versioning_userdef.c
M	source/blender/editors/include/ED_fileselect.h
M	source/blender/editors/space_file/filesel.c
M	source/blender/makesdna/DNA_space_types.h
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesdna/intern/dna_defaults.c
M	source/blender/makesrna/intern/rna_userdef.c
M	source/blender/windowmanager/intern/wm_event_system.c

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

diff --git a/release/datafiles/userdef/userdef_default.c b/release/datafiles/userdef/userdef_default.c
index 1b14e8920c9..7785c9d2962 100644
--- a/release/datafiles/userdef/userdef_default.c
+++ b/release/datafiles/userdef/userdef_default.c
@@ -21,6 +21,7 @@
 
 #include "DNA_userdef_types.h"
 #include "DNA_curve_types.h"
+#include "DNA_space_types.h"
 
 #include "BLI_math_rotation.h"
 
@@ -203,6 +204,18 @@ const UserDef U_default = {
             .section_active = USER_SECTION_INTERFACE,
         },
 
+    .file_space_data =
+        {
+            .display_type = FILE_VERTICALDISPLAY,
+            .thumbnail_size = 128,
+            .sort_type = FILE_SORT_ALPHA,
+            .details_flags = FILE_DETAILS_SIZE | FILE_DETAILS_DATETIME,
+            .flag = FILE_HIDE_DOT,
+
+            .temp_win_sizex = 1020,
+            .temp_win_sizey = 600,
+        },
+
     .runtime =
         {
             .is_dirty = 0,
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 2384cd0fe38..be41fb52118 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -1405,7 +1405,6 @@ class USERPREF_PT_saveload_file_browser(PreferencePanel, Panel):
         flow.prop(paths, "show_hidden_files_datablocks")
         flow.prop(paths, "hide_recent_locations")
         flow.prop(paths, "hide_system_bookmarks")
-        flow.prop(paths, "show_thumbnails")
 
 
 class USERPREF_MT_ndof_settings(Menu):
diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c
index ad11be1a5f5..bbae1c8e85e 100644
--- a/source/blender/blenloader/intern/versioning_userdef.c
+++ b/source/blender/blenloader/intern/versioning_userdef.c
@@ -29,6 +29,7 @@
 #include "DNA_curve_types.h"
 #include "DNA_windowmanager_types.h"
 #include "DNA_scene_types.h"
+#include "DNA_space_types.h"
 
 #include "BKE_addon.h"
 #include "BKE_colorband.h"
@@ -627,6 +628,10 @@ void BLO_version_defaults_userpref_blend(Main *bmain, UserDef *userdef)
    */
   {
     /* pass */
+    if (userdef->file_space_data.display_type == FILE_DEFAULTDISPLAY) {
+      memcpy(
+          &userdef->file_space_data, &U_default.file_space_data, sizeof(userdef->file_space_data));
+    }
   }
 
   if (userdef->pixelsize == 0.0f) {
diff --git a/source/blender/editors/include/ED_fileselect.h b/source/blender/editors/include/ED_fileselect.h
index 37090ce3421..83890c1621c 100644
--- a/source/blender/editors/include/ED_fileselect.h
+++ b/source/blender/editors/include/ED_fileselect.h
@@ -98,6 +98,8 @@ struct rcti;
 struct FileSelectParams *ED_fileselect_get_params(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, int temp_win_size[]);
 
 void ED_fileselect_reset_params(struct SpaceFile *sfile);
 
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index 6e576006332..e2c9bb8d6e5 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.c
@@ -49,6 +49,8 @@
 #include "BLI_utildefines.h"
 #include "BLI_fnmatch.h"
 
+#include "BLO_readfile.h"
+
 #include "BLT_translation.h"
 
 #include "BKE_appdir.h"
@@ -102,9 +104,9 @@ short ED_fileselect_set_params(SpaceFile *sfile)
                       sizeof(sfile->params->file));
     sfile->params->filter_glob[0] = '\0';
     /* set the default thumbnails size */
-    sfile->params->thumbnail_size = 128;
+    sfile->params->thumbnail_size = U_default.file_space_data.thumbnail_size;
     /* Show size column by default. */
-    sfile->params->details_flags = FILE_DETAILS_SIZE | FILE_DETAILS_DATETIME;
+    sfile->params->details_flags = U_default.file_space_data.details_flags;
   }
 
   params = sfile->params;
@@ -274,26 +276,11 @@ short ED_fileselect_set_params(SpaceFile *sfile)
       params->sort = RNA_property_enum_get(op->ptr, prop);
     }
     else {
-      params->sort = FILE_SORT_ALPHA;
+      params->sort = U_default.file_space_data.sort_type;
     }
 
     if (params->display == FILE_DEFAULTDISPLAY) {
-      if (params->display_previous == FILE_DEFAULTDISPLAY) {
-        if (U.uiflag & USER_SHOW_THUMBNAILS) {
-          if (params->filter & (FILE_TYPE_IMAGE | FILE_TYPE_MOVIE | FILE_TYPE_FTFONT)) {
-            params->display = FILE_IMGDISPLAY;
-          }
-          else {
-            params->display = FILE_VERTICALDISPLAY;
-          }
-        }
-        else {
-          params->display = FILE_VERTICALDISPLAY;
-        }
-      }
-      else {
-        params->display = params->display_previous;
-      }
+      params->display = U_default.file_space_data.display_type;
     }
 
     if (is_relative_path) {
@@ -307,10 +294,9 @@ short ED_fileselect_set_params(SpaceFile *sfile)
   else {
     /* default values, if no operator */
     params->type = FILE_UNIX;
-    params->flag |= FILE_HIDE_DOT;
+    params->flag |= U_default.file_space_data.flag;
     params->flag &= ~FILE_DIRSEL_ONLY;
     params->display = FILE_VERTICALDISPLAY;
-    params->display_previous = FILE_DEFAULTDISPLAY;
     params->sort = FILE_SORT_ALPHA;
     params->filter = 0;
     params->filter_glob[0] = '\0';
@@ -346,6 +332,63 @@ short ED_fileselect_set_params(SpaceFile *sfile)
   return 1;
 }
 
+/* The subset of FileSelectParams.flag items we store into preferences. */
+#define PARAMS_FLAGS_REMEMBERED (FILE_HIDE_DOT | FILE_SORT_INVERT)
+
+void ED_fileselect_set_params_from_userdef(SpaceFile *sfile)
+{
+  wmOperator *op = sfile->op;
+  UserDef_FileSpaceData *sfile_udata = &U.file_space_data;
+
+  ED_fileselect_set_params(sfile);
+
+  if (!op) {
+    return;
+  }
+
+  if (!RNA_struct_property_is_set(op->ptr, "display_type")) {
+    sfile->params->display = sfile_udata->display_type;
+  }
+  if (!RNA_struct_property_is_set(op->ptr, "sort_method")) {
+    sfile->params->sort = sfile_udata->sort_type;
+  }
+  sfile->params->thumbnail_size = sfile_udata->thumbnail_size;
+  sfile->params->details_flags = sfile_udata->details_flags;
+
+  /* Combine flags we take from params with the flags we take from userdef. */
+  sfile->params->flag = (sfile->params->flag & ~PARAMS_FLAGS_REMEMBERED) |
+                        (sfile_udata->flag & PARAMS_FLAGS_REMEMBERED);
+}
+
+/**
+ * Update the user-preference data for the file space. In fact, this also contains some
+ * non-FileSelectParams data, but it's neglectable.
+ *
+ * \param temp_win_size: If the browser was opened in a temporary window, pass its size here so we
+ *                       can store that in the preferences. Otherwise NULL.
+ */
+void ED_fileselect_params_to_userdef(SpaceFile *sfile, int temp_win_size[2])
+{
+  UserDef_FileSpaceData *sfile_udata_new = &U.file_space_data;
+  UserDef_FileSpaceData sfile_udata_old = U.file_space_data;
+
+  sfile_udata_new->display_type = sfile->params->display;
+  sfile_udata_new->thumbnail_size = sfile->params->thumbnail_size;
+  sfile_udata_new->sort_type = sfile->params->sort;
+  sfile_udata_new->details_flags = sfile->params->details_flags;
+  sfile_udata_new->flag = sfile->params->flag & PARAMS_FLAGS_REMEMBERED;
+
+  if (temp_win_size) {
+    sfile_udata_new->temp_win_sizex = temp_win_size[0];
+    sfile_udata_new->temp_win_sizey = temp_win_size[1];
+  }
+
+  /* Tag prefs as dirty if something has changed. */
+  if (memcmp(sfile_udata_new, &sfile_udata_old, sizeof(sfile_udata_old)) != 0) {
+    U.runtime.is_dirty = true;
+  }
+}
+
 void ED_fileselect_reset_params(SpaceFile *sfile)
 {
   sfile->params->type = FILE_UNIX;
@@ -766,7 +809,6 @@ void ED_fileselect_init_layout(struct SpaceFile *sfile, ARegion *ar)
                     layout->tile_border_x * 2;
     layout->flag = FILE_LAYOUT_HOR;
   }
-  params->display_previous = params->display;
   layout->dirty = false;
 }
 
@@ -923,6 +965,17 @@ void ED_fileselect_exit(wmWindowManager *wm, ScrArea *sa, SpaceFile *sfile)
     return;
   }
   if (sfile->op) {
+    wmWindow *temp_win = WM_window_is_temp_screen(wm->winactive) ? wm->winactive : NULL;
+    int win_size[2];
+
+    if (temp_win) {
+      /* Get DPI/pixelsize independent size to be stored in preferences. */
+      WM_window_set_dpi(temp_win); /* Ensure the DPI is taken from the right window. */
+      win_size[0] = WM_window_pixels_x(temp_win) / UI_DPI_FAC;
+      win_size[1] = WM_window_pixels_y(temp_win) / UI_DPI_FAC;
+    }
+    ED_fileselect_params_to_userdef(sfile, temp_win ? win_size : NULL);
+
     WM_event_fileselect_event(wm, sfile->op, EVT_FILESELECT_EXTERNAL_CANCEL);
     sfile->op = NULL;
   }
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index 3be3daa8dfb..0f957a946d9 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -676,10 +676,9 @@ typedef struct FileSelectParams {
   short sort;
   /** Display mode flag. */
   short display;
-  short display_previous;
   /** Details toggles (file size, creation date, etc.) */
   char details_flags;
-  char _pad2;
+  char _pad2[3];
   /** Filter when (flags & FILE_FILTER) is true. */
   int filter;
 
diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h
index 4006cbc977e..126b4638ca1 100644
--- a/source/blender/makesdna/DNA_userdef_types.h
+++ b/source/blender/makesdna/DNA_userdef_types.h
@@ -577,6 +577,24 @@ typedef struct UserDef_SpaceData {
   char _pad0[6];
 } UserDef_SpaceData;
 
+/**
+ * Storage for UI data that to keep it even after the window was closed. (Similar to
+ * #UserDef_SpaceData.)
+ */
+typedef struct UserDef_FileSpaceData {
+  int display_type;   /* FileSelectParams.display */
+  int thumbnail_size; /* FileSelectParams.thumbnail_size */
+  int sort_type;      /* FileSelectParams.sort */
+  int details_flags;  /* FileSelectParams.details_flags */
+  int flag;           /* FileSelectParams.flag */
+
+  char _pad[4];
+
+  /** Info used when creating the file browser in a temporary window. */
+  int temp_win_sizex;
+  int temp_win_sizey;
+} UserDef_FileSpaceData;
+
 typedef

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list