[Bf-blender-cvs] [91be63e] id-remap: Merge branch 'master' into id-remap

Bastien Montagne noreply at git.blender.org
Mon Nov 23 14:22:00 CET 2015


Commit: 91be63e1272a3134361160e2d8708e526bcb9e0e
Author: Bastien Montagne
Date:   Mon Nov 23 14:11:56 2015 +0100
Branches: id-remap
https://developer.blender.org/rB91be63e1272a3134361160e2d8708e526bcb9e0e

Merge branch 'master' into id-remap

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



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

diff --cc source/blender/editors/space_outliner/outliner_tools.c
index c12692e,313a75f..d02afcd
--- a/source/blender/editors/space_outliner/outliner_tools.c
+++ b/source/blender/editors/space_outliner/outliner_tools.c
@@@ -1272,220 -1246,6 +1272,220 @@@ void OUTLINER_OT_id_operation(wmOperato
  
  /* **************************************** */
  
 +typedef enum eOutlinerLibOpTypes {
 +	OL_LIB_INVALID = 0,
 +
 +	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)
 +{
 +	Scene *scene = CTX_data_scene(C);
 +	SpaceOops *soops = CTX_wm_space_outliner(C);
 +	int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0;
 +	eOutlinerIdOpTypes event;
 +
 +	/* check for invalid states */
 +	if (soops == NULL)
 +		return OPERATOR_CANCELLED;
 +
 +	set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
 +
 +	event = RNA_enum_get(op->ptr, "type");
 +
 +	switch (event) {
 +		case OL_LIB_RENAME:
 +		{
 +			/* rename */
 +			outliner_do_libdata_operation(C, scene, soops, &soops->tree, item_rename_cb, NULL);
 +
 +			WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL);
 +			ED_undo_push(C, "Rename");
 +			break;
 +		}
 +		case OL_LIB_RELOCATE:
 +		{
 +			wmOperatorType *ot = WM_operatortype_find("WM_OT_lib_relocate", false);
 +
 +			/* rename */
 +			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;
 +	}
 +
 +	/* wrong notifier still... */
 +	WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL);
 +
 +	/* XXX: this is just so that outliner is always up to date */
 +	WM_event_add_notifier(C, NC_SPACE | ND_SPACE_OUTLINER, NULL);
 +
 +	return OPERATOR_FINISHED;
 +}
 +
 +
 +void OUTLINER_OT_lib_operation(wmOperatorType *ot)
 +{
 +	/* identifiers */
 +	ot->name = "Outliner Library Operation";
 +	ot->idname = "OUTLINER_OT_lib_operation";
 +	ot->description = "";
 +
 +	/* callbacks */
 +	ot->invoke = WM_menu_invoke;
 +	ot->exec = outliner_lib_operation_exec;
 +	ot->poll = ED_operator_outliner_active;
 +
 +	ot->prop = RNA_def_enum(ot->srna, "type", outliner_lib_op_type_items, 0, "Library Operation", "");
 +}
 +
 +/* **************************************** */
 +
 +static void remap_action_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te),
 +                             TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *user_data)
 +{
 +	ID *new_id = user_data;
 +
 +	if (tselem->id && (tselem->id != new_id) && (GS(tselem->id->name) == GS(new_id->name))) {
 +		BKE_libblock_remap(CTX_data_main(C), tselem->id, new_id, true);
 +	}
 +}
 +
 +static int outliner_id_remap_exec(bContext *C, wmOperator *op)
 +{
 +	Main *bmain = CTX_data_main(C);
 +	Scene *scene = CTX_data_scene(C);
 +	SpaceOops *soops = CTX_wm_space_outliner(C);
 +
 +	short id_type = (short)RNA_enum_get(op->ptr, "id_type");
 +	ID *new_id = BLI_findlink(which_libbase(CTX_data_main(C), id_type), RNA_enum_get(op->ptr, "new_id"));
 +
 +	/* check for invalid states */
 +	if (soops == NULL)
 +		return OPERATOR_CANCELLED;
 +
 +	outliner_do_libdata_operation(C, scene, soops, &soops->tree, remap_action_cb, new_id);
 +
 +	ED_undo_push(C, "Remap ID action");
 +
 +	BKE_main_lib_objects_recalc_all(bmain);
 +
 +	/* recreate dependency graph to include new objects */
 +	DAG_scene_relations_rebuild(bmain, scene);
 +
 +	/* free gpu materials, some materials depend on existing objects, such as lamps so freeing correctly refreshes */
 +	GPU_materials_free();
 +
 +	WM_event_add_notifier(C, NC_WINDOW, NULL);
 +
 +	/* We want to redraw everything... */
 +//	WM_event_add_notifier(C, NC_ID | NA_RENAME, NULL);
 +//	WM_event_add_notifier(C, NC_SPACE | ND_SPACE_OUTLINER, NULL);
 +
 +	return OPERATOR_FINISHED;
 +}
 +
 +static bool outliner_id_remap_find_tree_element(bContext *C, wmOperator *op, ListBase *tree, const float y)
 +{
 +	TreeElement *te;
 +
 +	for (te = tree->first; te; te = te->next) {
 +		if (y > te->ys && y < te->ys + UI_UNIT_Y) {
 +			TreeStoreElem *tselem = TREESTORE(te);
 +
 +			if (tselem->type == 0 && tselem->id) {
 +				printf("found id %s (%p)!\n", tselem->id->name, tselem->id);
 +
 +				RNA_enum_set(op->ptr, "id_type", GS(tselem->id->name));
 +				RNA_enum_set_identifier(op->ptr, "new_id", tselem->id->name + 2);
 +				return true;
 +			}
 +		}
 +		if (outliner_id_remap_find_tree_element(C, op, &te->subtree, y)) {
 +			return true;
 +		}
 +	}
 +	return false;
 +}
 +
 +static int outliner_id_remap_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 +{
 +	SpaceOops *soops = CTX_wm_space_outliner(C);
 +	ARegion *ar = CTX_wm_region(C);
 +	float fmval[2];
 +
 +	UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]);
 +
 +	outliner_id_remap_find_tree_element(C, op, &soops->tree, fmval[1]);
 +
 +	return WM_operator_props_dialog_popup(C, op, 200, 100);
 +}
 +
 +static EnumPropertyItem *outliner_id_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *r_free)
 +{
 +	EnumPropertyItem item_tmp = {0}, *item = NULL;
 +	int totitem = 0;
 +	int i = 0;
 +
 +	short id_type = (short)RNA_enum_get(ptr, "id_type");
 +	ID *id = which_libbase(CTX_data_main(C), id_type)->first;
 +
 +	for (; id; id = id->next) {
 +		item_tmp.identifier = item_tmp.name = id->name + 2;
 +		item_tmp.value = i++;
 +		RNA_enum_item_add(&item, &totitem, &item_tmp);
 +	}
 +
 +	RNA_enum_item_end(&item, &totitem);
 +	*r_free = true;
 +
 +	return item;
 +}
 +
 +void OUTLINER_OT_id_remap(wmOperatorType *ot)
 +{
 +	/* identifiers */
 +	ot->name = "Outliner ID data Remap";
 +	ot->idname = "OUTLINER_OT_id_remap";
 +	ot->description = "";
 +
 +	/* callbacks */
 +	ot->invoke = outliner_id_remap_invoke;
 +	ot->exec = outliner_id_remap_exec;
 +	ot->poll = ED_operator_outliner_active;
 +
 +	ot->flag = 0;
 +
- 	RNA_def_enum(ot->srna, "id_type", id_type_items, ID_OB, "ID Type", "");
++	RNA_def_enum(ot->srna, "id_type", rna_enum_id_type_items, ID_OB, "ID Type", "");
 +
 +	ot->prop = RNA_def_enum(ot->srna, "new_id", DummyRNA_NULL_items, 0,
 +	                        "New ID", "New ID to remap all selected IDs' users to");
 +	RNA_def_property_enum_funcs_runtime(ot->prop, NULL, NULL, outliner_id_itemf);
 +	RNA_def_property_flag(ot->prop, PROP_ENUM_NO_TRANSLATE);
 +}
 +
 +/* **************************************** */
 +
  static void outliner_do_id_set_operation(SpaceOops *soops, int type, ListBase *lb, ID *newid,
                                           void (*operation_cb)(TreeElement *, TreeStoreElem *, TreeStoreElem *, ID *))
  {




More information about the Bf-blender-cvs mailing list