Fix T77171: File selector doesn't tag preferences to be saved
This commit is contained in:
parent
e43a948a2c
commit
3f648f5b42
Notes:
blender-bot
2023-10-12 12:49:04 +02:00
Referenced by issue #77171, Userprefs not saved when setting StringProperty of subtype='DIR_PATH' with directory browser
|
@ -764,6 +764,7 @@ bool UI_but_online_manual_id(const uiBut *but,
|
|||
bool UI_but_online_manual_id_from_active(const struct bContext *C,
|
||||
char *r_str,
|
||||
size_t maxlength) ATTR_WARN_UNUSED_RESULT;
|
||||
bool UI_but_is_userdef(const uiBut *but);
|
||||
|
||||
/* Buttons
|
||||
*
|
||||
|
@ -2445,7 +2446,8 @@ void UI_context_update_anim_flag(const struct bContext *C);
|
|||
void UI_context_active_but_prop_get_filebrowser(const struct bContext *C,
|
||||
struct PointerRNA *r_ptr,
|
||||
struct PropertyRNA **r_prop,
|
||||
bool *r_is_undo);
|
||||
bool *r_is_undo,
|
||||
bool *r_is_userdef);
|
||||
void UI_context_active_but_prop_get_templateID(struct bContext *C,
|
||||
struct PointerRNA *r_ptr,
|
||||
struct PropertyRNA **r_prop);
|
||||
|
|
|
@ -585,7 +585,7 @@ static bool ui_but_dragedit_update_mval(uiHandleButtonData *data, int mx)
|
|||
return true;
|
||||
}
|
||||
|
||||
static void ui_rna_update_preferences_dirty(PointerRNA *ptr, PropertyRNA *prop)
|
||||
static bool ui_rna_is_userdef(PointerRNA *ptr, PropertyRNA *prop)
|
||||
{
|
||||
/* Not very elegant, but ensures preference changes force re-save. */
|
||||
bool tag = false;
|
||||
|
@ -598,8 +598,18 @@ static void ui_rna_update_preferences_dirty(PointerRNA *ptr, PropertyRNA *prop)
|
|||
tag = true;
|
||||
}
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
if (tag) {
|
||||
bool UI_but_is_userdef(const uiBut *but)
|
||||
{
|
||||
/* This is read-only, RNA API isn't using const when it could. */
|
||||
return ui_rna_is_userdef((PointerRNA *)&but->rnapoin, but->rnaprop);
|
||||
}
|
||||
|
||||
static void ui_rna_update_preferences_dirty(PointerRNA *ptr, PropertyRNA *prop)
|
||||
{
|
||||
if (ui_rna_is_userdef(ptr, prop)) {
|
||||
U.runtime.is_dirty = true;
|
||||
WM_main_add_notifier(NC_WINDOW, NULL);
|
||||
}
|
||||
|
|
|
@ -1069,7 +1069,8 @@ static uiBut *ui_item_with_label(uiLayout *layout,
|
|||
void UI_context_active_but_prop_get_filebrowser(const bContext *C,
|
||||
PointerRNA *r_ptr,
|
||||
PropertyRNA **r_prop,
|
||||
bool *r_is_undo)
|
||||
bool *r_is_undo,
|
||||
bool *r_is_userdef)
|
||||
{
|
||||
ARegion *region = CTX_wm_menu(C) ? CTX_wm_menu(C) : CTX_wm_region(C);
|
||||
uiBlock *block;
|
||||
|
@ -1078,6 +1079,7 @@ void UI_context_active_but_prop_get_filebrowser(const bContext *C,
|
|||
memset(r_ptr, 0, sizeof(*r_ptr));
|
||||
*r_prop = NULL;
|
||||
*r_is_undo = false;
|
||||
*r_is_userdef = false;
|
||||
|
||||
if (!region) {
|
||||
return;
|
||||
|
@ -1096,6 +1098,7 @@ void UI_context_active_but_prop_get_filebrowser(const bContext *C,
|
|||
*r_ptr = prevbut->rnapoin;
|
||||
*r_prop = prevbut->rnaprop;
|
||||
*r_is_undo = (prevbut->flag & UI_BUT_UNDO) != 0;
|
||||
*r_is_userdef = UI_but_is_userdef(prevbut);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,6 +83,7 @@ typedef struct FileBrowseOp {
|
|||
PointerRNA ptr;
|
||||
PropertyRNA *prop;
|
||||
bool is_undo;
|
||||
bool is_userdef;
|
||||
} FileBrowseOp;
|
||||
|
||||
static int file_browse_exec(bContext *C, wmOperator *op)
|
||||
|
@ -148,6 +149,11 @@ static int file_browse_exec(bContext *C, wmOperator *op)
|
|||
}
|
||||
}
|
||||
|
||||
/* Tag user preferences as dirty. */
|
||||
if (fbo->is_userdef) {
|
||||
U.runtime.is_dirty = true;
|
||||
}
|
||||
|
||||
MEM_freeN(op->customdata);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
|
@ -164,6 +170,7 @@ static int file_browse_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
|||
PointerRNA ptr;
|
||||
PropertyRNA *prop;
|
||||
bool is_undo;
|
||||
bool is_userdef;
|
||||
FileBrowseOp *fbo;
|
||||
char *str;
|
||||
|
||||
|
@ -172,7 +179,7 @@ static int file_browse_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
|||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
UI_context_active_but_prop_get_filebrowser(C, &ptr, &prop, &is_undo);
|
||||
UI_context_active_but_prop_get_filebrowser(C, &ptr, &prop, &is_undo, &is_userdef);
|
||||
|
||||
if (!prop) {
|
||||
return OPERATOR_CANCELLED;
|
||||
|
@ -209,6 +216,7 @@ static int file_browse_invoke(bContext *C, wmOperator *op, const wmEvent *event)
|
|||
fbo->ptr = ptr;
|
||||
fbo->prop = prop;
|
||||
fbo->is_undo = is_undo;
|
||||
fbo->is_userdef = is_userdef;
|
||||
op->customdata = fbo;
|
||||
|
||||
/* normally ED_fileselect_get_params would handle this but we need to because of stupid
|
||||
|
|
Loading…
Reference in New Issue