[Bf-blender-cvs] [c05785e] master: Fix T42649: Use Relative Paths for Node Editor & 3D View Images

julianeisel noreply at git.blender.org
Sun Nov 23 19:42:20 CET 2014


Commit: c05785ec93d3b7c38d2b7b5070bb7ad124dd68dc
Author: julianeisel
Date:   Sun Nov 23 19:38:27 2014 +0100
Branches: master
https://developer.blender.org/rBc05785ec93d3b7c38d2b7b5070bb7ad124dd68dc

Fix T42649: Use Relative Paths for Node Editor & 3D View Images

Images are now added with relative paths to the Node Editor and the 3D View.

===================================================================

M	source/blender/editors/space_node/node_add.c
M	source/blender/editors/space_view3d/view3d_edit.c

===================================================================

diff --git a/source/blender/editors/space_node/node_add.c b/source/blender/editors/space_node/node_add.c
index 7140eb7..33eb24a 100644
--- a/source/blender/editors/space_node/node_add.c
+++ b/source/blender/editors/space_node/node_add.c
@@ -37,6 +37,7 @@
 
 #include "BLI_listbase.h"
 #include "BLI_math.h"
+#include "BLI_path_util.h"
 
 #include "BLF_translation.h"
 
@@ -307,6 +308,8 @@ static int node_add_file_exec(bContext *C, wmOperator *op)
 	Image *ima = NULL;
 	int type = 0;
 
+	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];
@@ -321,6 +324,12 @@ static int node_add_file_exec(bContext *C, wmOperator *op)
 			            path, errno ? strerror(errno) : TIP_("unsupported format"));
 			return OPERATOR_CANCELLED;
 		}
+
+		if (is_relative_path) {
+			Main *bmain = CTX_data_main(C);
+			const char *relbase = ID_BLEND_PATH(bmain, &ima->id);
+			BLI_path_rel(ima->name, relbase);
+		}
 	}
 	else if (RNA_struct_property_is_set(op->ptr, "name")) {
 		char name[MAX_ID_NAME - 2];
@@ -398,7 +407,7 @@ void NODE_OT_add_file(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
 	WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE, FILE_SPECIAL, FILE_OPENFILE,
-	                               WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY);  //XXX TODO, relative_path
+	                               WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY);
 	RNA_def_string(ot->srna, "name", "Image", MAX_ID_NAME - 2, "Name", "Datablock name to assign");
 }
 
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index d3bd59c..1eed56a 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -51,6 +51,7 @@
 #include "BKE_font.h"
 #include "BKE_image.h"
 #include "BKE_library.h"
+#include "BKE_main.h"
 #include "BKE_object.h"
 #include "BKE_paint.h"
 #include "BKE_report.h"
@@ -4282,6 +4283,8 @@ static int background_image_add_invoke(bContext *C, wmOperator *op, const wmEven
 	Image *ima = NULL;
 	BGpic *bgpic;
 	char name[MAX_ID_NAME - 2];
+
+	const bool is_relative_path = RNA_boolean_get(op->ptr, "relative_path");
 	
 	/* check input variables */
 	if (RNA_struct_property_is_set(op->ptr, "filepath")) {
@@ -4298,6 +4301,12 @@ static int background_image_add_invoke(bContext *C, wmOperator *op, const wmEven
 	bgpic = background_image_add(C);
 	
 	if (ima) {
+		if (is_relative_path) {
+			Main *bmain = CTX_data_main(C);
+			const char *relbase = ID_BLEND_PATH(bmain, &ima->id);
+			BLI_path_rel(ima->name, relbase);
+		}
+
 		bgpic->ima = ima;
 		
 		id_us_plus(&ima->id);
@@ -4330,7 +4339,8 @@ void VIEW3D_OT_background_image_add(wmOperatorType *ot)
 	
 	/* properties */
 	RNA_def_string(ot->srna, "name", "Image", MAX_ID_NAME - 2, "Name", "Image name to assign");
-	RNA_def_string(ot->srna, "filepath", "Path", FILE_MAX, "Filepath", "Path to image file");
+	WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE, FILE_SPECIAL, FILE_OPENFILE,
+	                               WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH, FILE_DEFAULTDISPLAY);
 }




More information about the Bf-blender-cvs mailing list