diff options
author | Julian Eisel <julian@blender.org> | 2020-11-03 01:55:59 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2020-11-03 02:00:41 +0300 |
commit | c067b7460a1fb54dc6b21c3cbc2819d9398392ef (patch) | |
tree | f1c2c50728f1b222acf291fda719f438b1adbfbc /source/blender/windowmanager/intern/wm_operator_props.c | |
parent | a750acab78cf38ca8f010c4ac81ec948faa79dd5 (diff) |
Fix C operators can't set default display or sort type for File Browser
`WM_operator_properties_filesel()` allows C operators to set a display or sort
type for the File Browser to use. But the File Browser would always override
that because of an invalid `_is_set()` check. (The operators don't actually set
the value, they only set the property's default value.)
The only operator affected by this is "Recover Auto Save". It is supposed to
show a vertical list ordered chronologically. It used settings from the
previous File Browser usage before this patch.
Operators using the File Browser should generally use
`FILE_DEFAULTDISPLAY`/`FILE_SORT_DEFAULT` now, except if they have a reason not
to. See comments at their definition.
----
This makes it so operators that set a different display or sort type
don't change the sort or display type for the next File Browser operation.
So using "Recover Auto Save" entirely isolates display and sort type from other
operations.
Differential Revision: https://developer.blender.org/D8598
Reviewed by: Bastien Montagne
Diffstat (limited to 'source/blender/windowmanager/intern/wm_operator_props.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_operator_props.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/source/blender/windowmanager/intern/wm_operator_props.c b/source/blender/windowmanager/intern/wm_operator_props.c index 62294d70306..87716a61c39 100644 --- a/source/blender/windowmanager/intern/wm_operator_props.c +++ b/source/blender/windowmanager/intern/wm_operator_props.c @@ -48,6 +48,30 @@ void WM_operator_properties_confirm_or_exec(wmOperatorType *ot) RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); } +/** + * Extends rna_enum_fileselect_params_sort_items with a default item for operators to use. + */ +static const EnumPropertyItem *wm_operator_properties_filesel_sort_items_itemf( + struct bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free) +{ + EnumPropertyItem *items; + const EnumPropertyItem default_item = { + FILE_SORT_DEFAULT, + "DEFAULT", + 0, + "Default", + "Automatically determine sort method for files", + }; + int totitem = 0; + + RNA_enum_item_add(&items, &totitem, &default_item); + RNA_enum_items_add(&items, &totitem, rna_enum_fileselect_params_sort_items); + RNA_enum_item_end(&items, &totitem); + *r_free = true; + + return items; +} + /* default properties for fileselect */ void WM_operator_properties_filesel(wmOperatorType *ot, int filter, @@ -204,8 +228,8 @@ void WM_operator_properties_filesel(wmOperatorType *ot, prop = RNA_def_enum(ot->srna, "display_type", file_display_items, display, "Display Type", ""); RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); - prop = RNA_def_enum( - ot->srna, "sort_method", rna_enum_file_sort_items, sort, "File sorting mode", ""); + prop = RNA_def_enum(ot->srna, "sort_method", DummyRNA_NULL_items, sort, "File sorting mode", ""); + RNA_def_enum_funcs(prop, wm_operator_properties_filesel_sort_items_itemf); RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); } |