diff options
author | Joshua Leung <aligorith@gmail.com> | 2014-11-26 06:23:30 +0300 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2014-11-26 06:23:30 +0300 |
commit | 4791f0cd7bb288ea6c2b03219c896692d756e803 (patch) | |
tree | 187309459b9e8a8e15b4ed1943f68f541f24441e /source/blender/windowmanager/intern/wm_operators.c | |
parent | e56030c8740d1877e0c5105f82f8e8468bc40f4d (diff) | |
parent | f1ea1da5e50d4319fe96ff75bfc75f73941e5cb1 (diff) |
Merge branch 'master' into GPencil_EditStrokes
Diffstat (limited to 'source/blender/windowmanager/intern/wm_operators.c')
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 68 |
1 files changed, 64 insertions, 4 deletions
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 4c0dfd4a532..5910f82730e 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -38,6 +38,7 @@ #include <stdio.h> #include <stddef.h> #include <assert.h> +#include <errno.h> #include "GHOST_C-api.h" @@ -64,6 +65,7 @@ #include "BLO_readfile.h" +#include "BKE_appdir.h" #include "BKE_autoexec.h" #include "BKE_blender.h" #include "BKE_brush.h" @@ -1399,6 +1401,64 @@ wmOperator *WM_operator_last_redo(const bContext *C) return op; } +/** + * Use for drag & drop a path or name with operators invoke() function. + */ +ID *WM_operator_drop_load_path(struct bContext *C, wmOperator *op, const short idcode) +{ + ID *id = NULL; + /* check input variables */ + if (RNA_struct_property_is_set(op->ptr, "filepath")) { + const bool is_relative_path = RNA_boolean_get(op->ptr, "relative_path"); + char path[FILE_MAX]; + bool exists = false; + + RNA_string_get(op->ptr, "filepath", path); + + errno = 0; + + if (idcode == ID_IM) { + id = (ID *)BKE_image_load_exists_ex(path, &exists); + } + else { + BLI_assert(0); + } + + if (!id) { + BKE_reportf(op->reports, RPT_ERROR, "Cannot read %s '%s': %s", + BKE_idcode_to_name(idcode), path, + errno ? strerror(errno) : TIP_("unsupported format")); + return NULL; + } + + if (is_relative_path ) { + if (exists == false) { + Main *bmain = CTX_data_main(C); + + if (idcode == ID_IM) { + BLI_path_rel(((Image *)id)->name, bmain->name); + } + else { + BLI_assert(0); + } + } + } + } + else if (RNA_struct_property_is_set(op->ptr, "name")) { + char name[MAX_ID_NAME - 2]; + RNA_string_get(op->ptr, "name", name); + id = BKE_libblock_find_name(idcode, name); + if (!id) { + BKE_reportf(op->reports, RPT_ERROR, "%s '%s' not found", + BKE_idcode_to_name(idcode), name); + return NULL; + } + id_us_plus(id); + } + + return id; +} + static void wm_block_redo_cb(bContext *C, void *arg_op, int UNUSED(arg_event)) { wmOperator *op = arg_op; @@ -1776,14 +1836,14 @@ static void wm_block_splash_refreshmenu(bContext *UNUSED(C), void *UNUSED(arg_bl static int wm_resource_check_prev(void) { - const char *res = BLI_get_folder_version(BLENDER_RESOURCE_PATH_USER, BLENDER_VERSION, true); + const char *res = BKE_appdir_folder_id_version(BLENDER_RESOURCE_PATH_USER, BLENDER_VERSION, true); // if (res) printf("USER: %s\n", res); #if 0 /* ignore the local folder */ if (res == NULL) { /* with a local dir, copying old files isn't useful since local dir get priority for config */ - res = BLI_get_folder_version(BLENDER_RESOURCE_PATH_LOCAL, BLENDER_VERSION, true); + res = BKE_appdir_folder_id_version(BLENDER_RESOURCE_PATH_LOCAL, BLENDER_VERSION, true); } #endif @@ -1792,7 +1852,7 @@ static int wm_resource_check_prev(void) return false; } else { - return (BLI_get_folder_version(BLENDER_RESOURCE_PATH_USER, BLENDER_VERSION - 1, true) != NULL); + return (BKE_appdir_folder_id_version(BLENDER_RESOURCE_PATH_USER, BLENDER_VERSION - 1, true) != NULL); } } @@ -2687,7 +2747,7 @@ void WM_recover_last_session(bContext *C, ReportList *reports) { char filepath[FILE_MAX]; - BLI_make_file_string("/", filepath, BLI_temp_dir_base(), BLENDER_QUIT_FILE); + BLI_make_file_string("/", filepath, BKE_tempdir_base(), BLENDER_QUIT_FILE); /* if reports==NULL, it's called directly without operator, we add a quick check here */ if (reports || BLI_exists(filepath)) { G.fileflags |= G_FILE_RECOVER; |