WM: explicitly skip auto-save when in modes that don't support it #118892

Merged
Jacques Lucke merged 8 commits from JacquesLucke/blender:auto-save-active-memfile into main 2024-02-29 13:15:08 +01:00
4 changed files with 33 additions and 15 deletions
Showing only changes of commit de05f60e27 - Show all commits

View File

@ -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

I would put this autosave_schedule in wm next to wm->autosavetimer, and then have a WM_autosave_if_scheduled function.

Seems better to me to me than spreading this state across more places.

I would put this `autosave_schedule` in `wm` next to `wm->autosavetimer`, and then have a `WM_autosave_if_scheduled` function. Seems better to me to me than spreading this state across more places.
};
/* **************** GLOBAL ********************* */

View File

@ -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;
}

View File

@ -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.
*/

View File

@ -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, &params, 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, &params, nullptr);
G.autosave_scheduled = false;
JacquesLucke marked this conversation as resolved

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")) {