diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-11-24 00:48:48 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-11-24 00:48:48 +0300 |
commit | 929dbc66445ba2004be52bd29f5bd06bcd1f8a26 (patch) | |
tree | 8631422ffb9b089abbbdae5bc187df6d5b71dae7 /source/blender/editors | |
parent | 888ab78edfad4f9c2bdd31764eb95eb347a8c2d8 (diff) |
Cleanup: de-duplicate image drag & drop logic
also don't make library paths relative on image load.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/mesh/mesh_data.c | 19 | ||||
-rw-r--r-- | source/blender/editors/object/object_add.c | 20 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 8 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_add.c | 41 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 37 |
5 files changed, 23 insertions, 102 deletions
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index e2ce97a3bdf..4bffb491581 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -571,24 +571,13 @@ static int drop_named_image_invoke(bContext *C, wmOperator *op, const wmEvent *e return OPERATOR_CANCELLED; } - /* check input variables */ - if (RNA_struct_property_is_set(op->ptr, "filepath")) { - char path[FILE_MAX]; - - RNA_string_get(op->ptr, "filepath", path); - ima = BKE_image_load_exists(path); - } - else { - char name[MAX_ID_NAME - 2]; - RNA_string_get(op->ptr, "name", name); - ima = (Image *)BKE_libblock_find_name(ID_IM, name); - } - + ima = (Image *)WM_operator_drop_load_path(C, op, ID_IM); if (!ima) { - BKE_report(op->reports, RPT_ERROR, "Not an image"); return OPERATOR_CANCELLED; } - + /* handled below */ + id_us_min((ID *)ima); + /* put mesh in editmode */ obedit = base->object; diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 24dcf85cec8..8cea1ce40bb 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -833,24 +833,12 @@ static int empty_drop_named_image_invoke(bContext *C, wmOperator *op, const wmEv Image *ima = NULL; Object *ob = NULL; - /* check image input variables */ - if (RNA_struct_property_is_set(op->ptr, "filepath")) { - char path[FILE_MAX]; - - RNA_string_get(op->ptr, "filepath", path); - ima = BKE_image_load_exists(path); - } - else if (RNA_struct_property_is_set(op->ptr, "name")) { - char name[MAX_ID_NAME - 2]; - - RNA_string_get(op->ptr, "name", name); - ima = (Image *)BKE_libblock_find_name(ID_IM, name); - } - - if (ima == NULL) { - BKE_report(op->reports, RPT_ERROR, "Not an image"); + ima = (Image *)WM_operator_drop_load_path(C, op, ID_IM); + if (!ima) { return OPERATOR_CANCELLED; } + /* handled below */ + id_us_min((ID *)ima); base = ED_view3d_give_base_under_cursor(C, event->mval); diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 2a03dc66ebd..50aee934841 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -1052,6 +1052,7 @@ static int image_open_exec(bContext *C, wmOperator *op) char path[FILE_MAX]; int frame_seq_len = 0; int frame_ofs = 1; + bool exists = false; const bool is_relative_path = RNA_boolean_get(op->ptr, "relative_path"); @@ -1070,7 +1071,7 @@ static int image_open_exec(bContext *C, wmOperator *op) errno = 0; - ima = BKE_image_load_exists(path); + ima = BKE_image_load_exists_ex(path, &exists); if (!ima) { if (op->customdata) MEM_freeN(op->customdata); @@ -1084,8 +1085,9 @@ static int image_open_exec(bContext *C, wmOperator *op) /* only image path after save, never ibuf */ if (is_relative_path) { - const char *relbase = ID_BLEND_PATH(bmain, &ima->id); - BLI_path_rel(ima->name, relbase); + if (!exists) { + BLI_path_rel(ima->name, bmain->name); + } } /* hook into UI */ diff --git a/source/blender/editors/space_node/node_add.c b/source/blender/editors/space_node/node_add.c index a22ccac5ecb..1e7fffa44f7 100644 --- a/source/blender/editors/space_node/node_add.c +++ b/source/blender/editors/space_node/node_add.c @@ -29,8 +29,6 @@ * \ingroup spnode */ -#include <errno.h> - #include "MEM_guardedalloc.h" #include "DNA_node_types.h" @@ -305,43 +303,12 @@ static int node_add_file_exec(bContext *C, wmOperator *op) { SpaceNode *snode = CTX_wm_space_node(C); bNode *node; - Image *ima = NULL; + Image *ima; int type = 0; - bool exists = false; - - const bool is_relative_path = RNA_boolean_get(op->ptr, "relative_path"); - - /* check input variables */ - if (RNA_struct_property_is_set(op->ptr, "filepath")) { - char path[FILE_MAX]; - RNA_string_get(op->ptr, "filepath", path); - - errno = 0; - - ima = BKE_image_load_exists_ex(path, &exists); - - if (!ima) { - BKE_reportf(op->reports, RPT_ERROR, "Cannot read image '%s': %s", - path, errno ? strerror(errno) : TIP_("unsupported format")); - return OPERATOR_CANCELLED; - } - - if (is_relative_path) { - if (exists == false) { - Main *bmain = CTX_data_main(C); - BLI_path_rel(ima->name, bmain->name); - } - } - } - else if (RNA_struct_property_is_set(op->ptr, "name")) { - char name[MAX_ID_NAME - 2]; - RNA_string_get(op->ptr, "name", name); - ima = (Image *)BKE_libblock_find_name(ID_IM, name); - if (!ima) { - BKE_reportf(op->reports, RPT_ERROR, "Image '%s' not found", name); - return OPERATOR_CANCELLED; - } + ima = (Image *)WM_operator_drop_load_path(C, op, ID_IM); + if (!ima) { + return OPERATOR_CANCELLED; } switch (snode->nodetree->type) { diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 4e997d0eec3..aa0e6e5fcc4 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -4282,41 +4282,16 @@ static int background_image_add_invoke(bContext *C, wmOperator *op, const wmEven View3D *v3d = CTX_wm_view3d(C); Image *ima = NULL; BGpic *bgpic; - char name[MAX_ID_NAME - 2]; - bool exists = false; - - const bool is_relative_path = RNA_boolean_get(op->ptr, "relative_path"); - /* check input variables */ - if (RNA_struct_property_is_set(op->ptr, "filepath")) { - char path[FILE_MAX]; - - RNA_string_get(op->ptr, "filepath", path); - ima = BKE_image_load_exists_ex(path, &exists); - } - else if (RNA_struct_property_is_set(op->ptr, "name")) { - RNA_string_get(op->ptr, "name", name); - ima = (Image *)BKE_libblock_find_name(ID_IM, name); - exists = true; + ima = (Image *)WM_operator_drop_load_path(C, op, ID_IM); + if (!ima) { + return OPERATOR_CANCELLED; } - + bgpic = background_image_add(C); - - if (ima) { - if (is_relative_path) { - if (exists == false) { - Main *bmain = CTX_data_main(C); - BLI_path_rel(ima->name, bmain->name); - } - } + bgpic->ima = ima; - bgpic->ima = ima; - - id_us_plus(&ima->id); - - if (!(v3d->flag & V3D_DISPBGPICS)) - v3d->flag |= V3D_DISPBGPICS; - } + v3d->flag |= V3D_DISPBGPICS; WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d); |