Option to load startup file with empty-data
Useful for batch conversion and tests.
This commit is contained in:
@@ -50,6 +50,7 @@ bool BKE_blendfile_read_from_memory(
|
||||
bool BKE_blendfile_read_from_memfile(
|
||||
struct bContext *C, struct MemFile *memfile,
|
||||
struct ReportList *reports, int skip_flag);
|
||||
void BKE_blendfile_read_make_empty(struct bContext *C);
|
||||
|
||||
struct UserDef *BKE_blendfile_userdef_read(
|
||||
const char *filepath, struct ReportList *reports);
|
||||
|
@@ -426,6 +426,32 @@ bool BKE_blendfile_read_from_memfile(
|
||||
return (bfd != NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility to make a file 'empty' used for startup to optionally give an empty file.
|
||||
* Handy for tests.
|
||||
*/
|
||||
void BKE_blendfile_read_make_empty(bContext *C)
|
||||
{
|
||||
Main *bmain = CTX_data_main(C);
|
||||
|
||||
ListBase *lbarray[MAX_LIBARRAY];
|
||||
ID *id;
|
||||
int a;
|
||||
|
||||
a = set_listbasepointers(bmain, lbarray);
|
||||
while (a--) {
|
||||
id = lbarray[a]->first;
|
||||
if (id != NULL) {
|
||||
if (ELEM(GS(id->name), ID_SCE, ID_SCR, ID_WM)) {
|
||||
continue;
|
||||
}
|
||||
while ((id = lbarray[a]->first)) {
|
||||
BKE_libblock_delete(bmain, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* only read the userdef from a .blend */
|
||||
UserDef *BKE_blendfile_userdef_read(const char *filepath, ReportList *reports)
|
||||
{
|
||||
|
@@ -643,7 +643,8 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
|
||||
* When not-null, this is written into the user preferences.
|
||||
*/
|
||||
int wm_homefile_read(
|
||||
bContext *C, ReportList *reports, bool use_factory_settings,
|
||||
bContext *C, ReportList *reports,
|
||||
bool use_factory_settings, bool use_empty_data,
|
||||
const char *filepath_startup_override, const char *app_template_override)
|
||||
{
|
||||
ListBase wmbase;
|
||||
@@ -779,6 +780,10 @@ int wm_homefile_read(
|
||||
}
|
||||
}
|
||||
|
||||
if (use_empty_data) {
|
||||
BKE_blendfile_read_make_empty(C);
|
||||
}
|
||||
|
||||
/* Load template preferences,
|
||||
* unlike regular preferences we only use some of the settings,
|
||||
* see: BKE_blender_userdef_set_app_template */
|
||||
@@ -1551,6 +1556,7 @@ static int wm_homefile_read_exec(bContext *C, wmOperator *op)
|
||||
const char *app_template;
|
||||
PropertyRNA *prop_app_template = RNA_struct_find_property(op->ptr, "app_template");
|
||||
const bool use_splash = !use_factory_settings && RNA_boolean_get(op->ptr, "use_splash");
|
||||
const bool use_empty_data = RNA_boolean_get(op->ptr, "use_empty");
|
||||
|
||||
if (prop_app_template && RNA_property_is_set(op->ptr, prop_app_template)) {
|
||||
RNA_property_string_get(op->ptr, prop_app_template, app_template_buf);
|
||||
@@ -1560,7 +1566,7 @@ static int wm_homefile_read_exec(bContext *C, wmOperator *op)
|
||||
app_template = NULL;
|
||||
}
|
||||
|
||||
if (wm_homefile_read(C, op->reports, use_factory_settings, filepath, app_template)) {
|
||||
if (wm_homefile_read(C, op->reports, use_factory_settings, use_empty_data, filepath, app_template)) {
|
||||
if (use_splash) {
|
||||
WM_init_splash(C);
|
||||
}
|
||||
@@ -1591,6 +1597,9 @@ void WM_OT_read_homefile(wmOperatorType *ot)
|
||||
"Load user interface setup from the .blend file");
|
||||
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
|
||||
prop = RNA_def_boolean(ot->srna, "use_empty", false, "Empty", "");
|
||||
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
|
||||
/* So the splash can be kept open after loading a file (for templates). */
|
||||
prop = RNA_def_boolean(ot->srna, "use_splash", false, "Splash", "");
|
||||
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
@@ -1615,6 +1624,9 @@ void WM_OT_read_factory_settings(wmOperatorType *ot)
|
||||
prop = RNA_def_string(ot->srna, "app_template", "Template", sizeof(U.app_template), "", "");
|
||||
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
|
||||
prop = RNA_def_boolean(ot->srna, "use_empty", false, "Empty", "");
|
||||
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
|
||||
|
||||
/* omit poll to run in background mode */
|
||||
}
|
||||
|
||||
|
@@ -192,7 +192,7 @@ void WM_init(bContext *C, int argc, const char **argv)
|
||||
wm_init_reports(C);
|
||||
|
||||
/* get the default database, plus a wm */
|
||||
wm_homefile_read(C, NULL, G.factory_startup, NULL, NULL);
|
||||
wm_homefile_read(C, NULL, G.factory_startup, false, NULL, NULL);
|
||||
|
||||
|
||||
BLT_lang_set(NULL);
|
||||
|
@@ -36,7 +36,8 @@ struct wmOperatorType;
|
||||
/* wm_files.c */
|
||||
void wm_history_file_read(void);
|
||||
int wm_homefile_read(
|
||||
struct bContext *C, struct ReportList *reports, bool use_factory_settings,
|
||||
struct bContext *C, struct ReportList *reports,
|
||||
bool use_factory_settings, bool use_empty_data,
|
||||
const char *filepath_startup_override, const char *app_template_override);
|
||||
void wm_file_read_report(bContext *C);
|
||||
|
||||
|
Reference in New Issue
Block a user