UI: Remember File Browser Display Options in Preferences
authorJulian Eisel <eiseljulian@gmail.com>
Mon, 30 Sep 2019 16:54:11 +0000 (18:54 +0200)
committerJulian Eisel <eiseljulian@gmail.com>
Mon, 30 Sep 2019 17:27:02 +0000 (19:27 +0200)
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

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

index 1b14e8920c9b0025e47b2deb9a67f122f21e54a5..7785c9d29625f68784a36d3f9e2cc079e73d7038 100644 (file)
@@ -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,
index 2384cd0fe38f9fabe0d2f37738caf10953983ae8..be41fb5211806401d4595fdb31bb394aba316457 100644 (file)
@@ -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):
index ad11be1a5f54bd053cb856aafb74dfb11bd3597b..bbae1c8e85e76399d731bd5ba565eb4ca5e45719 100644 (file)
@@ -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) {
index 37090ce34218b4c9c0f0d8b3fd79119fdad86a6c..83890c1621c0d1ae654e3f6e16a25e8cd37f5d86 100644 (file)
@@ -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);
 
index 6e57600633290003c312e782a43f4249998c9785..e2c9bb8d6e532b56d9e18cd1f49bb15ec23fe4e6 100644 (file)
@@ -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;
   }
index 3be3daa8dfb2ec00cfe9c18483002e98c595e31b..0f957a946d99ad2476e09efd9e37141465fae4c9 100644 (file)
@@ -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;
 
index 4006cbc977e1ac0b58cadbd83e737f32752a8779..126b4638ca1081c1df92edf605192e8cdb20b519 100644 (file)
@@ -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 struct UserDef {
   /** UserDef has separate do-version handling, and can be read from other files. */
   int versionfile, subversionfile;
@@ -823,6 +841,7 @@ typedef struct UserDef {
 
   /** The UI for the user preferences. */
   UserDef_SpaceData space_data;
+  UserDef_FileSpaceData file_space_data;
 
   /** Runtime data (keep last). */
   UserDef_Runtime runtime;
@@ -972,7 +991,11 @@ typedef enum eUserpref_UI_Flag {
   USER_ZOOM_HORIZ = (1 << 26), /* for CONTINUE and DOLLY zoom */
   USER_SPLASH_DISABLE = (1 << 27),
   USER_HIDE_RECENT = (1 << 28),
-  USER_SHOW_THUMBNAILS = (1 << 29),
+#ifdef DNA_DEPRECATED
+  USER_SHOW_THUMBNAILS =
+      (1 << 29), /* deprecated - We're just trying if there's much desire for this feature, or if
+                    we can make it go for good. Should be cleared if so - Julian, Oct. 2019 */
+#endif
   USER_SAVE_PROMPT = (1 << 30),
   USER_HIDE_SYSTEM_BOOKMARKS = (1u << 31),
 } eUserpref_UI_Flag;
index 76d076a8638a4a5bf363fc115b06464a16ac8c73..260f1cd20f62416d900ffde9700009639e332c01 100644 (file)
@@ -250,6 +250,7 @@ const void *DNA_default_table[SDNA_TYPE_MAX] = {
     SDNA_DEFAULT_DECL(UserDef),
     SDNA_DEFAULT_DECL(bTheme),
     SDNA_DEFAULT_DECL_EX(UserDef_SpaceData, UserDef.space_data),
+    SDNA_DEFAULT_DECL_EX(UserDef_FileSpaceData, UserDef.file_space_data),
     SDNA_DEFAULT_DECL_EX(WalkNavigation, UserDef.walk_navigation),
 
     /* DNA_view3d_defaults.h */
index bba4bc1cb543cc46e141fbdad5885982355c3425..c9b6f46ab04cf57e718e88a95119169a97529d15 100644 (file)
@@ -5573,11 +5573,6 @@ static void rna_def_userdef_filepaths(BlenderRNA *brna)
   RNA_def_property_ui_text(
       prop, "Hide System Bookmarks", "Hide system bookmarks in the file selector");
 
-  prop = RNA_def_property(srna, "show_thumbnails", PROP_BOOLEAN, PROP_NONE);
-  RNA_def_property_boolean_sdna(prop, NULL, "uiflag", USER_SHOW_THUMBNAILS);
-  RNA_def_property_ui_text(
-      prop, "Show Thumbnails", "Open in thumbnail view for images and movies");
-
   prop = RNA_def_property(srna, "use_relative_paths", PROP_BOOLEAN, PROP_NONE);
   RNA_def_property_boolean_sdna(prop, NULL, "flag", USER_RELPATHS);
   RNA_def_property_ui_text(
index fb91a65a7cc8f43c6d273cb12d84f969f9bbd6c9..6b4327d5f44c56f15d06543c01c7a3980f5fbfba 100644 (file)
@@ -2338,22 +2338,19 @@ static int wm_handler_fileselect_do(bContext *C,
                                     int val)
 {
   wmWindowManager *wm = CTX_wm_manager(C);
-  SpaceFile *sfile;
   int action = WM_HANDLER_CONTINUE;
 
   switch (val) {
     case EVT_FILESELECT_FULL_OPEN: {
       wmWindow *win = CTX_wm_window(C);
-      const int sizex = 1020 * UI_DPI_FAC;
-      const int sizey = 600 * UI_DPI_FAC;
       ScrArea *area;
 
       if ((area = ED_screen_temp_space_open(C,
                                             IFACE_("Blender File View"),
                                             WM_window_pixels_x(win) / 2,
                                             WM_window_pixels_y(win) / 2,
-                                            sizex,
-                                            sizey,
+                                            U.file_space_data.temp_win_sizex * UI_DPI_FAC,
+                                            U.file_space_data.temp_win_sizey * UI_DPI_FAC,
                                             SPACE_FILE,
                                             U.filebrowser_display_type))) {
         ARegion *region_header = BKE_area_find_region_type(area, RGN_TYPE_HEADER);
@@ -2365,10 +2362,10 @@ static int wm_handler_fileselect_do(bContext *C,
         region_header->alignment = RGN_ALIGN_BOTTOM;
 
         /* settings for filebrowser, sfile is not operator owner but sends events */
-        sfile = (SpaceFile *)area->spacedata.first;
+        SpaceFile *sfile = (SpaceFile *)area->spacedata.first;
         sfile->op = handler->op;
 
-        ED_fileselect_set_params(sfile);
+        ED_fileselect_set_params_from_userdef(sfile);
       }
       else {
         BKE_report(&wm->reports, RPT_ERROR, "Failed to open window!");
@@ -2402,6 +2399,15 @@ static int wm_handler_fileselect_do(bContext *C,
           ScrArea *file_sa = screen->areabase.first;
 
           if (screen->temp && (file_sa->spacetype == SPACE_FILE)) {
+            int win_size[2];
+
+            /* 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(file_sa->spacedata.first, win_size);
+
             if (BLI_listbase_is_single(&file_sa->spacedata)) {
               BLI_assert(ctx_win != temp_win);
 
@@ -2430,6 +2436,7 @@ static int wm_handler_fileselect_do(bContext *C,
         }
 
         if (!temp_win && ctx_sa->full) {
+          ED_fileselect_params_to_userdef(ctx_sa->spacedata.first, NULL);
           ED_screen_full_prevspace(C, ctx_sa);
         }
       }