[Bf-blender-cvs] [8e76ac4] gooseberry: Delete operator for cache library datablocks.

Lukas Tönne noreply at git.blender.org
Mon Mar 23 13:01:56 CET 2015


Commit: 8e76ac4744740e9bc419d9e4400f5cb4d51169bb
Author: Lukas Tönne
Date:   Fri Feb 27 16:22:19 2015 +0100
Branches: gooseberry
https://developer.blender.org/rB8e76ac4744740e9bc419d9e4400f5cb4d51169bb

Delete operator for cache library datablocks.

CacheLibrary datablock has a generic unlink function now, but currently
nothing actually links to cache libs themselves, so it's empty. Still
good to keep this in mind for the future.

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

M	release/scripts/startup/bl_ui/properties_scene.py
M	source/blender/blenkernel/BKE_cache_library.h
M	source/blender/blenkernel/intern/cache_library.c
M	source/blender/blenkernel/intern/library.c
M	source/blender/editors/io/io_cache_library.c
M	source/blender/editors/io/io_cache_library.h
M	source/blender/editors/io/io_ops.c

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

diff --git a/release/scripts/startup/bl_ui/properties_scene.py b/release/scripts/startup/bl_ui/properties_scene.py
index cf9b13d..a76bd5f 100644
--- a/release/scripts/startup/bl_ui/properties_scene.py
+++ b/release/scripts/startup/bl_ui/properties_scene.py
@@ -455,6 +455,7 @@ class SCENE_PT_cache_manager(SceneButtonsPanel, Panel):
         sub = row.row(align=True)
         sub.alignment = 'RIGHT'
         sub.prop(cachelib, "use_fake_user", text="F", toggle=True)
+        sub.operator("cachelibrary.delete", text="", icon='X')
 
         row = layout.row(align=True)
         row.alignment = 'LEFT'
diff --git a/source/blender/blenkernel/BKE_cache_library.h b/source/blender/blenkernel/BKE_cache_library.h
index 9edfff9..98006d0 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -45,6 +45,7 @@ struct ClothModifierData;
 struct CacheLibrary *BKE_cache_library_add(struct Main *bmain, const char *name);
 struct CacheLibrary *BKE_cache_library_copy(struct CacheLibrary *cachelib);
 void BKE_cache_library_free(struct CacheLibrary *cachelib);
+void BKE_cache_library_unlink(struct CacheLibrary *cachelib);
 
 void BKE_cache_library_make_object_list(struct Main *bmain, struct CacheLibrary *cachelib, struct ListBase *lb);
 
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 893717a..6cc5dc3 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -84,6 +84,10 @@ void BKE_cache_library_free(CacheLibrary *cachelib)
 		BLI_ghash_free(cachelib->items_hash, NULL, NULL);
 }
 
+void BKE_cache_library_unlink(CacheLibrary *cachelib)
+{
+}
+
 /* ========================================================================= */
 
 static void cache_library_tag_recursive(CacheLibrary *cachelib, int level, Object *ob)
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index d164178..a77ab86 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -412,6 +412,10 @@ bool id_unlink(ID *id, int test)
 			if (test) return true;
 			BKE_object_unlink((Object *)id);
 			break;
+		case ID_CL:
+			if (test) return true;
+			BKE_cache_library_unlink((CacheLibrary *)id);
+			break;
 	}
 
 	if (id->us == 0) {
diff --git a/source/blender/editors/io/io_cache_library.c b/source/blender/editors/io/io_cache_library.c
index 6328c04..2b4f53d 100644
--- a/source/blender/editors/io/io_cache_library.c
+++ b/source/blender/editors/io/io_cache_library.c
@@ -46,6 +46,7 @@
 #include "BKE_cache_library.h"
 #include "BKE_context.h"
 #include "BKE_global.h"
+#include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_report.h"
 #include "BKE_scene.h"
@@ -100,7 +101,7 @@ static int new_cachelib_exec(bContext *C, wmOperator *UNUSED(op))
 		RNA_property_update(C, &ptr, prop);
 	}
 	
-	WM_event_add_notifier(C, NC_OBJECT, cachelib);
+	WM_event_add_notifier(C, NC_SCENE, cachelib);
 	
 	return OPERATOR_FINISHED;
 }
@@ -119,6 +120,50 @@ void CACHELIBRARY_OT_new(wmOperatorType *ot)
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
 }
 
+/********************** delete cache library operator *********************/
+
+static int cache_library_delete_poll(bContext *C)
+{
+	CacheLibrary *cachelib = CTX_data_pointer_get_type(C, "cache_library", &RNA_CacheLibrary).data;
+	
+	if (!cachelib)
+		return false;
+	
+	return true;
+}
+
+static int cache_library_delete_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	Main *bmain = CTX_data_main(C);
+	CacheLibrary *cachelib = CTX_data_pointer_get_type(C, "cache_library", &RNA_CacheLibrary).data;
+	
+	BKE_cache_library_unlink(cachelib);
+	BKE_libblock_free(bmain, cachelib);
+	
+	WM_event_add_notifier(C, NC_SCENE, cachelib);
+	
+	return OPERATOR_FINISHED;
+}
+
+void CACHELIBRARY_OT_delete(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Delete Cache Library";
+	ot->idname = "CACHELIBRARY_OT_delete";
+	ot->description = "Delete a cache library data block";
+	
+	/* api callbacks */
+	ot->exec = cache_library_delete_exec;
+	/* XXX confirm popup would be nicer, but problem is the popup layout
+	 * does not inherit the cache_library context pointer, so poll fails ...
+	 */
+	/*ot->invoke = WM_operator_confirm;*/
+	ot->poll = cache_library_delete_poll;
+	
+	/* flags */
+	ot->flag = OPTYPE_UNDO;
+}
+
 /********************** enable cache item operator *********************/
 
 static int cache_item_enable_poll(bContext *C)
diff --git a/source/blender/editors/io/io_cache_library.h b/source/blender/editors/io/io_cache_library.h
index e3d5b8d..f08b9eb 100644
--- a/source/blender/editors/io/io_cache_library.h
+++ b/source/blender/editors/io/io_cache_library.h
@@ -33,6 +33,7 @@
 struct wmOperatorType;
 
 void CACHELIBRARY_OT_new(struct wmOperatorType *ot);
+void CACHELIBRARY_OT_delete(struct wmOperatorType *ot);
 
 void CACHELIBRARY_OT_item_enable(struct wmOperatorType *ot);
 
diff --git a/source/blender/editors/io/io_ops.c b/source/blender/editors/io/io_ops.c
index 08198b5..3e8ed53 100644
--- a/source/blender/editors/io/io_ops.c
+++ b/source/blender/editors/io/io_ops.c
@@ -40,6 +40,7 @@
 void ED_operatortypes_io(void) 
 {
 	WM_operatortype_append(CACHELIBRARY_OT_new);
+	WM_operatortype_append(CACHELIBRARY_OT_delete);
 	WM_operatortype_append(CACHELIBRARY_OT_item_enable);
 	WM_operatortype_append(CACHELIBRARY_OT_bake);




More information about the Bf-blender-cvs mailing list