[Bf-blender-cvs] [38670bc] id-remap: Some fixes, add basic wrapper code needed for reload feature (not yet implemented).

Bastien Montagne noreply at git.blender.org
Sat Sep 19 20:04:09 CEST 2015


Commit: 38670bc9a9374fa28cedcd7b58c7c8d697bd9272
Author: Bastien Montagne
Date:   Sat Sep 19 18:26:36 2015 +0200
Branches: id-remap
https://developer.blender.org/rB38670bc9a9374fa28cedcd7b58c7c8d697bd9272

Some fixes, add basic wrapper code needed for reload feature (not yet implemented).

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

M	source/blender/editors/space_outliner/outliner_edit.c
M	source/blender/editors/space_outliner/outliner_intern.h
M	source/blender/editors/space_outliner/outliner_tools.c
M	source/blender/windowmanager/intern/wm_operators.c

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

diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c
index 1ccb70c..7593af0 100644
--- a/source/blender/editors/space_outliner/outliner_edit.c
+++ b/source/blender/editors/space_outliner/outliner_edit.c
@@ -299,9 +299,10 @@ void OUTLINER_OT_item_rename(wmOperatorType *ot)
 	ot->poll = ED_operator_outliner_active;
 }
 
-/* Library relocate --------------------------------------------------- */
+/* Library relocate/reload --------------------------------------------------- */
 
-static int item_lib_relocate(bContext *C, TreeElement *te, TreeStoreElem *tselem, wmOperatorType *ot)
+static int item_lib_relocate(
+        bContext *C, TreeElement *te, TreeStoreElem *tselem, wmOperatorType *ot, const bool reload)
 {
 	PointerRNA op_props;
 	int ret = 0;
@@ -311,26 +312,33 @@ static int item_lib_relocate(bContext *C, TreeElement *te, TreeStoreElem *tselem
 
 	WM_operator_properties_create_ptr(&op_props, ot);
 
-	RNA_string_set(&op_props, "library", tselem->id->name);
+	RNA_string_set(&op_props, "library", tselem->id->name + 2);
 
-	ret = WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &op_props);
+	if (reload) {
+		Library *lib = (Library *)tselem->id;
+		char dir[FILE_MAXDIR], filename[FILE_MAX];
 
-	WM_operator_properties_free(&op_props);
+		BLI_split_dirfile(lib->filepath, dir, filename, sizeof(dir), sizeof(filename));
 
-	return ret;
-}
+		/* We assume if both paths in lib are not the same then lib->name was relative... */
+		RNA_boolean_set(&op_props, "relative_path", BLI_path_cmp(lib->filepath, lib->name) != 0);
 
-/* XXX This does work with several items (ot is only called once in the end...). */
-void item_lib_relocate_cb(
-        bContext *C, Scene *UNUSED(scene), TreeElement *te,
-        TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *user_data)
-{
-	wmOperatorType *ot = user_data;
+		RNA_string_set(&op_props, "directory", dir);
+		RNA_string_set(&op_props, "filename", filename);
 
-	item_lib_relocate(C, te, tselem, ot);
+		ret = WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_DEFAULT, &op_props);
+	}
+	else {
+		ret = WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &op_props);
+	}
+
+	WM_operator_properties_free(&op_props);
+
+	return ret;
 }
 
-static int outliner_lib_relocate_invoke_do(bContext *C, ReportList *reports, TreeElement *te, const float mval[2])
+static int outliner_lib_relocate_invoke_do(
+        bContext *C, ReportList *reports, TreeElement *te, const float mval[2], const bool reload)
 {
 	if (mval[1] > te->ys && mval[1] < te->ys + UI_UNIT_Y) {
 		TreeStoreElem *tselem = TREESTORE(te);
@@ -344,20 +352,20 @@ static int outliner_lib_relocate_invoke_do(bContext *C, ReportList *reports, Tre
 			else {
 				wmOperatorType *ot = WM_operatortype_find("WM_OT_lib_relocate", false);
 
-				return item_lib_relocate(C, te, tselem, ot);
+				return item_lib_relocate(C, te, tselem, ot, reload);
 			}
 		}
 	}
 	else {
 		for (te = te->subtree.first; te; te = te->next) {
 			int ret;
-			if ((ret = outliner_lib_relocate_invoke_do(C, reports, te, mval)) >= 0) {
+			if ((ret = outliner_lib_relocate_invoke_do(C, reports, te, mval, reload))) {
 				return ret;
 			}
 		}
 	}
 
-	return -1;
+	return 0;
 }
 
 static int outliner_lib_relocate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
@@ -374,7 +382,7 @@ static int outliner_lib_relocate_invoke(bContext *C, wmOperator *op, const wmEve
 	for (te = soops->tree.first; te; te = te->next) {
 		int ret;
 
-		if ((ret = outliner_lib_relocate_invoke_do(C, op->reports, te, fmval)) >= 0) {
+		if ((ret = outliner_lib_relocate_invoke_do(C, op->reports, te, fmval, false))) {
 			return ret;
 		}
 	}
@@ -386,12 +394,65 @@ void OUTLINER_OT_lib_relocate(wmOperatorType *ot)
 {
 	ot->name = "Relocate Library";
 	ot->idname = "OUTLINER_OT_lib_relocate";
-	ot->description = "Relocate library under cursor";
+	ot->description = "Relocate the library under cursor";
 
 	ot->invoke = outliner_lib_relocate_invoke;
 	ot->poll = ED_operator_outliner_active;
 }
 
+/* XXX This does not work with several items
+ *     (ot is only called once in the end, due to the 'deffered' filebrowser invocation through event system...). */
+void item_lib_relocate_cb(
+        bContext *C, Scene *UNUSED(scene), TreeElement *te,
+        TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *user_data)
+{
+	wmOperatorType *ot = user_data;
+
+	item_lib_relocate(C, te, tselem, ot, false);
+}
+
+
+static int outliner_lib_reload_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+	ARegion *ar = CTX_wm_region(C);
+	SpaceOops *soops = CTX_wm_space_outliner(C);
+	TreeElement *te;
+	float fmval[2];
+
+	BLI_assert(ar && soops);
+
+	UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]);
+
+	for (te = soops->tree.first; te; te = te->next) {
+		int ret;
+
+		if ((ret = outliner_lib_relocate_invoke_do(C, op->reports, te, fmval, true))) {
+			return ret;
+		}
+	}
+
+	return OPERATOR_CANCELLED;
+}
+
+void OUTLINER_OT_lib_reload(wmOperatorType *ot)
+{
+	ot->name = "Reload Library";
+	ot->idname = "OUTLINER_OT_lib_reload";
+	ot->description = "Reload the library under cursor";
+
+	ot->invoke = outliner_lib_reload_invoke;
+	ot->poll = ED_operator_outliner_active;
+}
+
+void item_lib_reload_cb(
+        bContext *C, Scene *UNUSED(scene), TreeElement *te,
+        TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *user_data)
+{
+	wmOperatorType *ot = user_data;
+
+	item_lib_relocate(C, te, tselem, ot, true);
+}
+
 /* ************************************************************** */
 /* Setting Toggling Operators */
 
diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h
index a3a2565..541608d 100644
--- a/source/blender/editors/space_outliner/outliner_intern.h
+++ b/source/blender/editors/space_outliner/outliner_intern.h
@@ -171,6 +171,9 @@ void item_rename_cb(struct bContext *C, struct Scene *scene, TreeElement *te, st
 void item_lib_relocate_cb(
         struct bContext *C, struct Scene *scene, struct TreeElement *te,
         struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data);
+void item_lib_reload_cb(
+        struct bContext *C, struct Scene *scene, struct TreeElement *te,
+        struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data);
 
 TreeElement *outliner_dropzone_find(const struct SpaceOops *soops, const float fmval[2], const bool children);
 /* ...................................................... */
@@ -179,6 +182,7 @@ void OUTLINER_OT_item_activate(struct wmOperatorType *ot);
 void OUTLINER_OT_item_openclose(struct wmOperatorType *ot);
 void OUTLINER_OT_item_rename(struct wmOperatorType *ot);
 void OUTLINER_OT_lib_relocate(struct wmOperatorType *ot);
+void OUTLINER_OT_lib_reload(struct wmOperatorType *ot);
 
 void OUTLINER_OT_show_one_level(struct wmOperatorType *ot);
 void OUTLINER_OT_show_active(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c
index 7da5fd2..1b3b41b 100644
--- a/source/blender/editors/space_outliner/outliner_tools.c
+++ b/source/blender/editors/space_outliner/outliner_tools.c
@@ -1266,12 +1266,15 @@ typedef enum eOutlinerLibOpTypes {
 
 	OL_LIB_RENAME,
 	OL_LIB_RELOCATE,
+	OL_LIB_RELOAD,
 } eOutlinerLibOpTypes;
 
 static EnumPropertyItem outliner_lib_op_type_items[] = {
 	{OL_LIB_RENAME, "RENAME", 0, "Rename", ""},
     {OL_LIB_RELOCATE, "RELOCATE", 0, "Relocate", "Select a new path for this library, and reload all its data"},
+    {OL_LIB_RELOAD, "RELOAD", 0, "Reload", "Reload all data from this library"},
 	{0, NULL, 0, NULL, NULL}
+
 };
 
 static int outliner_lib_operation_exec(bContext *C, wmOperator *op)
@@ -1307,6 +1310,14 @@ static int outliner_lib_operation_exec(bContext *C, wmOperator *op)
 			outliner_do_libdata_operation(C, scene, soops, &soops->tree, item_lib_relocate_cb, ot);
 			break;
 		}
+		case OL_LIB_RELOAD:
+		{
+			wmOperatorType *ot = WM_operatortype_find("WM_OT_lib_reload", false);
+
+			/* rename */
+			outliner_do_libdata_operation(C, scene, soops, &soops->tree, item_lib_reload_cb, ot);
+			break;
+		}
 		default:
 			/* invalid - unhandled */
 			break;
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 1908610..980d1c8 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -2978,10 +2978,10 @@ static void WM_OT_append(wmOperatorType *ot)
 static int wm_lib_relocate_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
 {
 	Library *lib;
-	char lib_name[MAX_ID_NAME];
+	char lib_name[MAX_NAME];
 
 	RNA_string_get(op->ptr, "library", lib_name);
-	lib = (Library *)BKE_libblock_find_name_ex(CTX_data_main(C), ID_LI, lib_name + 2);
+	lib = (Library *)BKE_libblock_find_name_ex(CTX_data_main(C), ID_LI, lib_name);
 
 	if (lib) {
 		if (lib->parent) {
@@ -3002,10 +3002,10 @@ static int wm_lib_relocate_invoke(bContext *C, wmOperator *op, const wmEvent *UN
 static int wm_lib_relocate_exec(bContext *C, wmOperator *op)
 {
 	Library *lib;
-	char lib_name[MAX_ID_NAME];
+	char lib_name[MAX_NAME];
 
 	RNA_string_get(op->ptr, "library", lib_name);
-	lib = (Library *)BKE_libblock_find_name_ex(CTX_data_main(C), ID_LI, lib_name + 2);
+	lib = (Library *)BKE_libblock_find_name_ex(CTX_data_main(C), ID_LI, lib_name);
 
 	if (lib) {
 		Main *bmain = CTX_data_main(C);
@@ -3033,8 +3033,10 @@ static int wm_lib_relocate_exec(bContext *C, wmOperator *op)
 			return OPERATOR_CANCELLED;
 		}
 
-		if (BLI_path_cmp(lib->filepath, libname) == 0) {
-			printf("We are supposed to reload '%s' lib...\n", lib->filepath);
+		BLI_join_dirfile(path, sizeof(path), root, libname);
+
+		if (BLI_path_cmp(lib->filepath, path) == 0) {
+			printf("We are supposed to reload '%s' lib (%d)...\n", lib->filepath, lib->id.us);
 
 			return OPERATOR_FINISHED;
 		}
@@ -3078,7 +3080,6 @@ static int wm_lib_relocate_exec(bContext *C, wmOperator *op)
 				RNA_END;
 			}
 			else {
-				BLI_join_dirfile(path, sizeof(path), root, libname);
 		

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list