Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-01-28 22:33:05 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-01-28 22:33:05 +0400
commit8c688a052c79e006b586598d2ac55a550cea3550 (patch)
treeacd4aec837cd8c38b2cdde3f3b54cb1d91c4a60b /source/blender/windowmanager
parent39202a53b559debb5ce1413c08f131173515c3cd (diff)
File Reading: add wrapper function for WM_file_read
also return cancelled when an operator fails to load a file
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/WM_api.h2
-rw-r--r--source/blender/windowmanager/intern/wm_files.c9
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c77
3 files changed, 53 insertions, 35 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 9e960f89f55..c13731e2459 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -106,7 +106,7 @@ bool WM_is_draw_triple(struct wmWindow *win);
/* files */
void WM_file_autoexec_init(const char *filepath);
-void WM_file_read(struct bContext *C, const char *filepath, struct ReportList *reports);
+bool WM_file_read(struct bContext *C, const char *filepath, struct ReportList *reports);
void WM_autosave_init(struct wmWindowManager *wm);
void WM_recover_last_session(struct bContext *C, struct ReportList *reports);
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index b99246dc34b..7bbf78ef089 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -388,8 +388,9 @@ void WM_file_autoexec_init(const char *filepath)
}
}
-void WM_file_read(bContext *C, const char *filepath, ReportList *reports)
+bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
{
+ bool success = false;
int retval;
/* so we can get the error message */
@@ -412,7 +413,7 @@ void WM_file_read(bContext *C, const char *filepath, ReportList *reports)
ListBase wmbase;
/* assume automated tasks with background, don't write recent file list */
- const int do_history = (G.background == FALSE) && (CTX_wm_manager(C)->op_undo_depth == 0);
+ const bool do_history = (G.background == FALSE) && (CTX_wm_manager(C)->op_undo_depth == 0);
/* put aside screens to match with persistent windows later */
/* also exit screens and editors */
@@ -496,6 +497,8 @@ void WM_file_read(bContext *C, const char *filepath, ReportList *reports)
BKE_reset_undo();
BKE_write_undo(C, "original"); /* save current state */
+
+ success = true;
}
else if (retval == BKE_READ_EXOTIC_OK_OTHER)
BKE_write_undo(C, "Import file");
@@ -516,6 +519,8 @@ void WM_file_read(bContext *C, const char *filepath, ReportList *reports)
WM_cursor_wait(0);
+ return success;
+
}
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 06d42659fd3..ac23983d8ed 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -2127,6 +2127,27 @@ static void WM_OT_read_factory_settings(wmOperatorType *ot)
/* *************** open file **************** */
+/**
+ * Wrap #WM_file_read, shared by file reading operators.
+ */
+static bool wm_file_read_opwrap(bContext *C, const char *filepath, ReportList *reports,
+ const bool autoexec_init)
+{
+ bool success;
+
+ /* XXX wm in context is not set correctly after WM_file_read -> crash */
+ /* do it before for now, but is this correct with multiple windows? */
+ WM_event_add_notifier(C, NC_WINDOW, NULL);
+
+ if (autoexec_init) {
+ WM_file_autoexec_init(filepath);
+ }
+
+ success = WM_file_read(C, filepath, reports);
+
+ return success;
+}
+
/* currently fits in a pointer */
struct FileRuntime {
bool is_untrusted;
@@ -2186,9 +2207,10 @@ static int wm_open_mainfile_invoke(bContext *C, wmOperator *op, const wmEvent *U
static int wm_open_mainfile_exec(bContext *C, wmOperator *op)
{
- char path[FILE_MAX];
+ char filepath[FILE_MAX];
+ bool success;
- RNA_string_get(op->ptr, "filepath", path);
+ RNA_string_get(op->ptr, "filepath", filepath);
/* re-use last loaded setting so we can reload a file without changing */
open_set_load_ui(op, false);
@@ -2204,20 +2226,17 @@ static int wm_open_mainfile_exec(bContext *C, wmOperator *op)
else
G.f &= ~G_SCRIPT_AUTOEXEC;
- /* XXX wm in context is not set correctly after WM_file_read -> crash */
- /* do it before for now, but is this correct with multiple windows? */
- WM_event_add_notifier(C, NC_WINDOW, NULL);
-
- /* autoexec is already set correctly for invoke() for exec() though we need to initialize */
- if (!RNA_struct_property_is_set(op->ptr, "use_scripts")) {
- WM_file_autoexec_init(path);
- }
- WM_file_read(C, path, op->reports);
+ success = wm_file_read_opwrap(C, filepath, op->reports, !(G.f & G_SCRIPT_AUTOEXEC));
/* for file open also popup for warnings, not only errors */
BKE_report_print_level_set(op->reports, RPT_WARNING);
- return OPERATOR_FINISHED;
+ if (success) {
+ return OPERATOR_FINISHED;
+ }
+ else {
+ return OPERATOR_CANCELLED;
+ }
}
static bool wm_open_mainfile_check(bContext *UNUSED(C), wmOperator *op)
@@ -2498,20 +2517,14 @@ static void WM_OT_link_append(wmOperatorType *ot)
void WM_recover_last_session(bContext *C, ReportList *reports)
{
- char filename[FILE_MAX];
+ char filepath[FILE_MAX];
- BLI_make_file_string("/", filename, BLI_temporary_dir(), BLENDER_QUIT_FILE);
+ BLI_make_file_string("/", filepath, BLI_temporary_dir(), BLENDER_QUIT_FILE);
/* if reports==NULL, it's called directly without operator, we add a quick check here */
- if (reports || BLI_exists(filename)) {
+ if (reports || BLI_exists(filepath)) {
G.fileflags |= G_FILE_RECOVER;
- /* XXX wm in context is not set correctly after WM_file_read -> crash */
- /* do it before for now, but is this correct with multiple windows? */
- WM_event_add_notifier(C, NC_WINDOW, NULL);
-
- /* load file */
- WM_file_autoexec_init(filename);
- WM_file_read(C, filename, reports);
+ wm_file_read_opwrap(C, filepath, reports, true);
G.fileflags &= ~G_FILE_RECOVER;
@@ -2545,23 +2558,23 @@ static void WM_OT_recover_last_session(wmOperatorType *ot)
static int wm_recover_auto_save_exec(bContext *C, wmOperator *op)
{
- char path[FILE_MAX];
+ char filepath[FILE_MAX];
+ bool success;
- RNA_string_get(op->ptr, "filepath", path);
+ RNA_string_get(op->ptr, "filepath", filepath);
G.fileflags |= G_FILE_RECOVER;
- /* XXX wm in context is not set correctly after WM_file_read -> crash */
- /* do it before for now, but is this correct with multiple windows? */
- WM_event_add_notifier(C, NC_WINDOW, NULL);
-
- /* load file */
- WM_file_autoexec_init(path);
- WM_file_read(C, path, op->reports);
+ success = wm_file_read_opwrap(C, filepath, op->reports, true);
G.fileflags &= ~G_FILE_RECOVER;
- return OPERATOR_FINISHED;
+ if (success) {
+ return OPERATOR_FINISHED;
+ }
+ else {
+ return OPERATOR_CANCELLED;
+ }
}
static int wm_recover_auto_save_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))