From 929dbc66445ba2004be52bd29f5bd06bcd1f8a26 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 23 Nov 2014 22:48:48 +0100 Subject: Cleanup: de-duplicate image drag & drop logic also don't make library paths relative on image load. --- source/blender/editors/space_node/node_add.c | 41 +++------------------------- 1 file changed, 4 insertions(+), 37 deletions(-) (limited to 'source/blender/editors/space_node/node_add.c') 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 - #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) { -- cgit v1.2.3