forked from bartvdbraak/blender
D54: Added a filepath attribute to the read_homefile operator.
This attribute allows to open a blend file as an alternative start-up file. The attribute is only available from python. This is an example call: bpy.ops.wm.read_homefile(filepath='path/to/a/file.blend') This patch also changes readfile.c to ensure that unintentionally stored cursor states are not imported from the loaded file.
This commit is contained in:
parent
e2429d6492
commit
72272d2e4f
@ -5531,6 +5531,10 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm)
|
|||||||
win->drawmethod = -1;
|
win->drawmethod = -1;
|
||||||
win->drawfail = 0;
|
win->drawfail = 0;
|
||||||
win->active = 0;
|
win->active = 0;
|
||||||
|
|
||||||
|
win->cursor = 0;
|
||||||
|
win->lastcursor = 0;
|
||||||
|
win->modalcursor = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
wm->timers.first = wm->timers.last = NULL;
|
wm->timers.first = wm->timers.last = NULL;
|
||||||
|
@ -517,7 +517,9 @@ void WM_file_read(bContext *C, const char *filepath, ReportList *reports)
|
|||||||
/* called on startup, (context entirely filled with NULLs) */
|
/* called on startup, (context entirely filled with NULLs) */
|
||||||
/* or called for 'New File' */
|
/* or called for 'New File' */
|
||||||
/* both startup.blend and userpref.blend are checked */
|
/* both startup.blend and userpref.blend are checked */
|
||||||
int wm_homefile_read(bContext *C, ReportList *UNUSED(reports), short from_memory)
|
/* the optional paramater custom_file points to an alterntive startup page */
|
||||||
|
/* custom_file can be NULL */
|
||||||
|
int wm_homefile_read(bContext *C, ReportList *reports, short from_memory, const char *custom_file)
|
||||||
{
|
{
|
||||||
ListBase wmbase;
|
ListBase wmbase;
|
||||||
char startstr[FILE_MAX];
|
char startstr[FILE_MAX];
|
||||||
@ -529,7 +531,17 @@ int wm_homefile_read(bContext *C, ReportList *UNUSED(reports), short from_memory
|
|||||||
G.relbase_valid = 0;
|
G.relbase_valid = 0;
|
||||||
if (!from_memory) {
|
if (!from_memory) {
|
||||||
const char * const cfgdir = BLI_get_folder(BLENDER_USER_CONFIG, NULL);
|
const char * const cfgdir = BLI_get_folder(BLENDER_USER_CONFIG, NULL);
|
||||||
if (cfgdir) {
|
if (custom_file) {
|
||||||
|
BLI_strncpy(startstr, custom_file, FILE_MAX);
|
||||||
|
|
||||||
|
if (cfgdir) {
|
||||||
|
BLI_make_file_string(G.main->name, prefstr, cfgdir, BLENDER_USERPREF_FILE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
prefstr[0] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (cfgdir) {
|
||||||
BLI_make_file_string(G.main->name, startstr, cfgdir, BLENDER_STARTUP_FILE);
|
BLI_make_file_string(G.main->name, startstr, cfgdir, BLENDER_STARTUP_FILE);
|
||||||
BLI_make_file_string(G.main->name, prefstr, cfgdir, BLENDER_USERPREF_FILE);
|
BLI_make_file_string(G.main->name, prefstr, cfgdir, BLENDER_USERPREF_FILE);
|
||||||
}
|
}
|
||||||
@ -544,13 +556,12 @@ int wm_homefile_read(bContext *C, ReportList *UNUSED(reports), short from_memory
|
|||||||
G.fileflags &= ~G_FILE_NO_UI;
|
G.fileflags &= ~G_FILE_NO_UI;
|
||||||
|
|
||||||
/* put aside screens to match with persistent windows later */
|
/* put aside screens to match with persistent windows later */
|
||||||
wm_window_match_init(C, &wmbase);
|
wm_window_match_init(C, &wmbase);
|
||||||
|
|
||||||
if (!from_memory) {
|
if (!from_memory) {
|
||||||
if (BLI_exists(startstr)) {
|
if (BLI_access(startstr, R_OK) == 0) {
|
||||||
success = (BKE_read_file(C, startstr, NULL) != BKE_READ_FILE_FAIL);
|
success = (BKE_read_file(C, startstr, NULL) != BKE_READ_FILE_FAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (U.themes.first == NULL) {
|
if (U.themes.first == NULL) {
|
||||||
if (G.debug & G_DEBUG)
|
if (G.debug & G_DEBUG)
|
||||||
printf("\nNote: No (valid) '%s' found, fall back to built-in default.\n\n", startstr);
|
printf("\nNote: No (valid) '%s' found, fall back to built-in default.\n\n", startstr);
|
||||||
@ -558,6 +569,11 @@ int wm_homefile_read(bContext *C, ReportList *UNUSED(reports), short from_memory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (success == 0 && custom_file && reports) {
|
||||||
|
BKE_reportf(reports, RPT_ERROR, "Could not read '%s'", custom_file);
|
||||||
|
/*We can not return from here because wm is already reset*/
|
||||||
|
}
|
||||||
|
|
||||||
if (success == 0) {
|
if (success == 0) {
|
||||||
success = BKE_read_file_from_memory(C, datatoc_startup_blend, datatoc_startup_blend_size, NULL, true);
|
success = BKE_read_file_from_memory(C, datatoc_startup_blend, datatoc_startup_blend_size, NULL, true);
|
||||||
if (wmbase.first == NULL) wm_clear_default_size(C);
|
if (wmbase.first == NULL) wm_clear_default_size(C);
|
||||||
@ -581,7 +597,7 @@ int wm_homefile_read(bContext *C, ReportList *UNUSED(reports), short from_memory
|
|||||||
G.fileflags &= ~G_FILE_RELATIVE_REMAP;
|
G.fileflags &= ~G_FILE_RELATIVE_REMAP;
|
||||||
|
|
||||||
/* check userdef before open window, keymaps etc */
|
/* check userdef before open window, keymaps etc */
|
||||||
wm_init_userdef(C, from_memory);
|
wm_init_userdef(C, (bool)from_memory);
|
||||||
|
|
||||||
/* match the read WM with current WM */
|
/* match the read WM with current WM */
|
||||||
wm_window_match_do(C, &wmbase);
|
wm_window_match_do(C, &wmbase);
|
||||||
@ -636,8 +652,23 @@ int wm_history_read_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
|
|||||||
|
|
||||||
int wm_homefile_read_exec(bContext *C, wmOperator *op)
|
int wm_homefile_read_exec(bContext *C, wmOperator *op)
|
||||||
{
|
{
|
||||||
int from_memory = strcmp(op->type->idname, "WM_OT_read_factory_settings") == 0;
|
int from_memory = (strcmp(op->type->idname, "WM_OT_read_factory_settings") == 0);
|
||||||
return wm_homefile_read(C, op->reports, from_memory) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
|
char filepath_buffer[FILE_MAX] = "";
|
||||||
|
char *filepath = NULL;
|
||||||
|
|
||||||
|
if (!from_memory)
|
||||||
|
{
|
||||||
|
RNA_string_get(op->ptr, "filepath", filepath_buffer);
|
||||||
|
if (filepath_buffer[0] != '\0') {
|
||||||
|
filepath = filepath_buffer;
|
||||||
|
if (BLI_access(filepath, R_OK)) {
|
||||||
|
BKE_reportf(op->reports, RPT_ERROR, "Can't read alternative start-up file: '%s'", filepath);
|
||||||
|
return OPERATOR_CANCELLED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return wm_homefile_read(C, op->reports, from_memory, filepath) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wm_read_history(void)
|
void wm_read_history(void)
|
||||||
|
@ -159,7 +159,7 @@ void WM_init(bContext *C, int argc, const char **argv)
|
|||||||
BLF_lang_init();
|
BLF_lang_init();
|
||||||
|
|
||||||
/* get the default database, plus a wm */
|
/* get the default database, plus a wm */
|
||||||
wm_homefile_read(C, NULL, G.factory_startup);
|
wm_homefile_read(C, NULL, G.factory_startup, NULL);
|
||||||
|
|
||||||
BLF_lang_set(NULL);
|
BLF_lang_set(NULL);
|
||||||
|
|
||||||
|
@ -2029,12 +2029,19 @@ static void WM_OT_read_history(wmOperatorType *ot)
|
|||||||
|
|
||||||
static void WM_OT_read_homefile(wmOperatorType *ot)
|
static void WM_OT_read_homefile(wmOperatorType *ot)
|
||||||
{
|
{
|
||||||
|
PropertyRNA *prop;
|
||||||
ot->name = "Reload Start-Up File";
|
ot->name = "Reload Start-Up File";
|
||||||
ot->idname = "WM_OT_read_homefile";
|
ot->idname = "WM_OT_read_homefile";
|
||||||
ot->description = "Open the default file (doesn't save the current file)";
|
ot->description = "Open the default file (doesn't save the current file)";
|
||||||
|
|
||||||
ot->invoke = WM_operator_confirm;
|
ot->invoke = WM_operator_confirm;
|
||||||
ot->exec = wm_homefile_read_exec;
|
ot->exec = wm_homefile_read_exec;
|
||||||
|
|
||||||
|
prop = RNA_def_string_file_path(ot->srna, "filepath", "",
|
||||||
|
FILE_MAX, "File Path",
|
||||||
|
"Path to an alternative start-up file");
|
||||||
|
RNA_def_property_flag(prop, PROP_HIDDEN);
|
||||||
|
|
||||||
/* ommit poll to run in background mode */
|
/* ommit poll to run in background mode */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ void wm_read_history(void);
|
|||||||
int wm_file_write(struct bContext *C, const char *target, int fileflags, struct ReportList *reports);
|
int wm_file_write(struct bContext *C, const char *target, int fileflags, struct ReportList *reports);
|
||||||
int wm_history_read_exec(bContext *C, wmOperator *op);
|
int wm_history_read_exec(bContext *C, wmOperator *op);
|
||||||
int wm_homefile_read_exec(struct bContext *C, struct wmOperator *op);
|
int wm_homefile_read_exec(struct bContext *C, struct wmOperator *op);
|
||||||
int wm_homefile_read(struct bContext *C, struct ReportList *reports, short from_memory);
|
int wm_homefile_read(struct bContext *C, struct ReportList *reports, short from_memory, const char *filepath);
|
||||||
int wm_homefile_write_exec(struct bContext *C, struct wmOperator *op);
|
int wm_homefile_write_exec(struct bContext *C, struct wmOperator *op);
|
||||||
int wm_userpref_write_exec(struct bContext *C, struct wmOperator *op);
|
int wm_userpref_write_exec(struct bContext *C, struct wmOperator *op);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user