diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2019-09-30 19:54:11 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2019-09-30 20:27:02 +0300 |
commit | ddb157999eed6907e3fd8753d61e65491f2f3a6d (patch) | |
tree | 4235cd3bc8f647a8ff71fe5ca17efe1ddbcf2c2f /source/blender/editors/space_file/filesel.c | |
parent | 5940f6b3d9cfa99a1b893b6149d36ee0a8c51584 (diff) |
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
Diffstat (limited to 'source/blender/editors/space_file/filesel.c')
-rw-r--r-- | source/blender/editors/space_file/filesel.c | 97 |
1 files changed, 75 insertions, 22 deletions
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; } |