WM: explicitly skip auto-save when in modes that don't support it #118892
|
@ -158,6 +158,9 @@ struct Global {
|
|||
bool opengl_deprecation_usage_detected;
|
||||
const char *opengl_deprecation_usage_filename;
|
||||
int opengl_deprecation_usage_lineno;
|
||||
|
||||
/** Auto-save timer was up, but it wasn't possible to auto-save in the current mode. */
|
||||
bool autosave_scheduled;
|
||||
JacquesLucke marked this conversation as resolved
Outdated
|
||||
};
|
||||
|
||||
/* **************** GLOBAL ********************* */
|
||||
|
|
|
@ -1862,6 +1862,10 @@ static int object_mode_set_exec(bContext *C, wmOperator *op)
|
|||
}
|
||||
}
|
||||
|
||||
if (G.autosave_scheduled) {
|
||||
WM_autosave_write(CTX_data_main(C));
|
||||
}
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
|
|
|
@ -1720,6 +1720,9 @@ void WM_main_playanim(int argc, const char **argv);
|
|||
*/
|
||||
bool write_crash_blend();
|
||||
|
||||
/** Flushes all changes from edit modes and stores the auto-save file. */
|
||||
void WM_autosave_write(Main *bmain);
|
||||
|
||||
/**
|
||||
* Lock the interface for any communication.
|
||||
*/
|
||||
|
|
|
@ -2121,20 +2121,29 @@ static bool wm_autosave_write_try(Main *bmain, wmWindowManager *wm)
|
|||
return true;
|
||||
}
|
||||
if ((U.uiflag & USER_GLOBALUNDO) == 0) {
|
||||
/* Save as regular blend file with recovery information. */
|
||||
const int fileflags = (G.fileflags & ~G_FILE_COMPRESS) | G_FILE_RECOVER_WRITE;
|
||||
|
||||
ED_editors_flush_edits(bmain);
|
||||
|
||||
/* Error reporting into console. */
|
||||
BlendFileWriteParams params{};
|
||||
BLO_write_file(bmain, filepath, fileflags, ¶ms, nullptr);
|
||||
WM_autosave_write(bmain);
|
||||
return true;
|
||||
}
|
||||
/* Can't auto-save with MemFile right now, try again later. */
|
||||
return false;
|
||||
}
|
||||
|
||||
void WM_autosave_write(Main *bmain)
|
||||
{
|
||||
ED_editors_flush_edits(bmain);
|
||||
|
||||
char filepath[FILE_MAX];
|
||||
wm_autosave_location(filepath);
|
||||
/* Save as regular blend file with recovery information. */
|
||||
const int fileflags = (G.fileflags & ~G_FILE_COMPRESS) | G_FILE_RECOVER_WRITE;
|
||||
|
||||
/* Error reporting into console. */
|
||||
BlendFileWriteParams params{};
|
||||
BLO_write_file(bmain, filepath, fileflags, ¶ms, nullptr);
|
||||
|
||||
G.autosave_scheduled = false;
|
||||
JacquesLucke marked this conversation as resolved
Brecht Van Lommel
commented
I think this should reset the autosave timer if called from mode switching? I think this should reset the autosave timer if called from mode switching?
|
||||
}
|
||||
|
||||
static void wm_autosave_timer_begin_ex(wmWindowManager *wm, double timestep)
|
||||
{
|
||||
wm_autosave_timer_end(wm);
|
||||
|
@ -2180,14 +2189,12 @@ void wm_autosave_timer(Main *bmain, wmWindowManager *wm, wmTimer * /*wt*/)
|
|||
}
|
||||
}
|
||||
|
||||
if (wm_autosave_write_try(bmain, wm)) {
|
||||
/* Restart the timer after file write, just in case file write takes a long time. */
|
||||
wm_autosave_timer_begin(wm);
|
||||
}
|
||||
else {
|
||||
/* Couldn't auto-save right now, try again later. */
|
||||
wm_autosave_timer_begin_ex(wm, 0.01);
|
||||
G.autosave_scheduled = false;
|
||||
if (!wm_autosave_write_try(bmain, wm)) {
|
||||
G.autosave_scheduled = true;
|
||||
}
|
||||
/* Restart the timer after file write, just in case file write takes a long time. */
|
||||
wm_autosave_timer_begin(wm);
|
||||
}
|
||||
|
||||
void wm_autosave_delete()
|
||||
|
@ -3411,6 +3418,7 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
|
|||
* often saving manually. */
|
||||
wm_autosave_timer_end(wm);
|
||||
wm_autosave_timer_begin(wm);
|
||||
G.autosave_scheduled = false;
|
||||
}
|
||||
|
||||
if (!is_save_as && RNA_boolean_get(op->ptr, "exit")) {
|
||||
|
|
Loading…
Reference in New Issue
I would put this
autosave_schedule
inwm
next towm->autosavetimer
, and then have aWM_autosave_if_scheduled
function.Seems better to me to me than spreading this state across more places.