[Bf-blender-cvs] [962751c] id-remap: Outliner: add a dedicated ID_LI operation handler, and add skeletton for 'relocate' tool...

Bastien Montagne noreply at git.blender.org
Mon Sep 14 22:31:15 CEST 2015


Commit: 962751c1a0a1be898fdd5749747338bb741e54ce
Author: Bastien Montagne
Date:   Mon Sep 14 16:41:21 2015 +0200
Branches: id-remap
https://developer.blender.org/rB962751c1a0a1be898fdd5749747338bb741e54ce

Outliner: add a dedicated ID_LI operation handler, and add skeletton for 'relocate' tool...

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

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_ops.c
M	source/blender/editors/space_outliner/outliner_tools.c

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

diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c
index 8742a7c..e1d51d2 100644
--- a/source/blender/editors/space_outliner/outliner_edit.c
+++ b/source/blender/editors/space_outliner/outliner_edit.c
@@ -290,6 +290,96 @@ void OUTLINER_OT_item_rename(wmOperatorType *ot)
 	ot->poll = ED_operator_outliner_active;
 }
 
+/* Library relocate --------------------------------------------------- */
+
+static void do_lib_rename(ARegion *ar, TreeElement *te, TreeStoreElem *tselem, ReportList *reports)
+{
+	/* can't rename rna datablocks entries or listbases */
+	if (ELEM(tselem->type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM, TSE_ID_BASE)) {
+		/* do nothing */;
+	}
+	else if (ELEM(tselem->type, TSE_ANIM_DATA, TSE_NLA, TSE_DEFGROUP_BASE, TSE_CONSTRAINT_BASE, TSE_MODIFIER_BASE,
+	              TSE_DRIVER_BASE, TSE_POSE_BASE, TSE_POSEGRP_BASE, TSE_R_LAYER_BASE, TSE_R_PASS))
+	{
+		BKE_report(reports, RPT_WARNING, "Cannot edit builtin name");
+	}
+	else if (ELEM(tselem->type, TSE_SEQUENCE, TSE_SEQ_STRIP, TSE_SEQUENCE_DUP)) {
+		BKE_report(reports, RPT_WARNING, "Cannot edit sequence name");
+	}
+	else if (tselem->id->lib) {
+		BKE_report(reports, RPT_WARNING, "Cannot edit external libdata");
+	}
+	else if (te->idcode == ID_LI && ((Library *)tselem->id)->parent) {
+		BKE_report(reports, RPT_WARNING, "Cannot edit the path of an indirectly linked library");
+	}
+	else {
+		tselem->flag |= TSE_TEXTBUT;
+		ED_region_tag_redraw(ar);
+	}
+}
+
+void item_lib_relocate_cb(
+        bContext *C, Scene *UNUSED(scene), TreeElement *te,
+        TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data))
+{
+	ARegion *ar = CTX_wm_region(C);
+	ReportList *reports = CTX_wm_reports(C); // XXX
+	do_lib_rename(ar, te, tselem, reports);
+}
+
+static int do_outliner_lib_relocate(bContext *C, ARegion *ar, SpaceOops *soops, TreeElement *te, const float mval[2])
+{
+	ReportList *reports = CTX_wm_reports(C); // XXX
+
+	if (mval[1] > te->ys && mval[1] < te->ys + UI_UNIT_Y) {
+		TreeStoreElem *tselem = TREESTORE(te);
+
+		/* click on name */
+		if (mval[0] > te->xs + UI_UNIT_X * 2 && mval[0] < te->xend) {
+			do_lib_rename(ar, te, tselem, reports);
+			return 1;
+		}
+		return 0;
+	}
+
+	for (te = te->subtree.first; te; te = te->next) {
+		if (do_outliner_lib_relocate(C, ar, soops, te, mval)) return 1;
+	}
+	return 0;
+}
+
+static int outliner_lib_relocate_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
+{
+	ARegion *ar = CTX_wm_region(C);
+	SpaceOops *soops = CTX_wm_space_outliner(C);
+	TreeElement *te;
+	float fmval[2];
+	bool changed = false;
+
+	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) {
+		if (do_outliner_lib_relocate(C, ar, soops, te, fmval)) {
+			changed = true;
+			break;
+		}
+	}
+
+	return changed ? OPERATOR_FINISHED : OPERATOR_PASS_THROUGH;
+}
+
+
+void OUTLINER_OT_lib_relocate(wmOperatorType *ot)
+{
+	ot->name = "Relocate Library";
+	ot->idname = "OUTLINER_OT_lib_relocate";
+	ot->description = "Relocate library under cursor";
+
+	ot->invoke = outliner_lib_relocate_invoke;
+
+	ot->poll = ED_operator_outliner_active;
+}
+
 /* ************************************************************** */
 /* Setting Toggling Operators */
 
diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h
index 7bee718..a3a2565 100644
--- a/source/blender/editors/space_outliner/outliner_intern.h
+++ b/source/blender/editors/space_outliner/outliner_intern.h
@@ -168,6 +168,9 @@ void group_toggle_selectability_cb(struct bContext *C, struct Scene *scene, Tree
 void group_toggle_renderability_cb(struct bContext *C, struct Scene *scene, TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data);
 
 void item_rename_cb(struct bContext *C, struct Scene *scene, TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data);
+void item_lib_relocate_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);
 /* ...................................................... */
@@ -175,6 +178,7 @@ TreeElement *outliner_dropzone_find(const struct SpaceOops *soops, const float f
 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_show_one_level(struct wmOperatorType *ot);
 void OUTLINER_OT_show_active(struct wmOperatorType *ot);
@@ -211,6 +215,7 @@ void OUTLINER_OT_operation(struct wmOperatorType *ot);
 void OUTLINER_OT_scene_operation(struct wmOperatorType *ot);
 void OUTLINER_OT_object_operation(struct wmOperatorType *ot);
 void OUTLINER_OT_group_operation(struct wmOperatorType *ot);
+void OUTLINER_OT_lib_operation(struct wmOperatorType *ot);
 void OUTLINER_OT_id_operation(struct wmOperatorType *ot);
 void OUTLINER_OT_id_remap(struct wmOperatorType *ot);
 void OUTLINER_OT_data_operation(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_outliner/outliner_ops.c b/source/blender/editors/space_outliner/outliner_ops.c
index ffc0f58..482ea62 100644
--- a/source/blender/editors/space_outliner/outliner_ops.c
+++ b/source/blender/editors/space_outliner/outliner_ops.c
@@ -47,10 +47,12 @@ void outliner_operatortypes(void)
 	WM_operatortype_append(OUTLINER_OT_select_border);
 	WM_operatortype_append(OUTLINER_OT_item_openclose);
 	WM_operatortype_append(OUTLINER_OT_item_rename);
+	WM_operatortype_append(OUTLINER_OT_lib_relocate);
 	WM_operatortype_append(OUTLINER_OT_operation);
 	WM_operatortype_append(OUTLINER_OT_scene_operation);
 	WM_operatortype_append(OUTLINER_OT_object_operation);
 	WM_operatortype_append(OUTLINER_OT_group_operation);
+	WM_operatortype_append(OUTLINER_OT_lib_operation);
 	WM_operatortype_append(OUTLINER_OT_id_operation);
 	WM_operatortype_append(OUTLINER_OT_id_remap);
 	WM_operatortype_append(OUTLINER_OT_data_operation);
diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c
index ae0ac85..9fd4863 100644
--- a/source/blender/editors/space_outliner/outliner_tools.c
+++ b/source/blender/editors/space_outliner/outliner_tools.c
@@ -119,6 +119,7 @@ static void set_operation_types(SpaceOops *soops, ListBase *lb,
 					case ID_MA: case ID_TE: case ID_IP: case ID_IM:
 					case ID_SO: case ID_KE: case ID_WO: case ID_AC:
 					case ID_NLA: case ID_TXT: case ID_GR: case ID_LS:
+					case ID_LI:
 						if (*idlevel == 0) *idlevel = idcode;
 						else if (*idlevel != idcode) *idlevel = -1;
 						break;
@@ -846,7 +847,7 @@ static EnumPropertyItem prop_object_op_types[] = {
 	{OL_OP_DELETE, "DELETE", 0, "Delete", ""},
 	{OL_OP_DELETE_HIERARCHY, "DELETE_HIERARCHY", 0, "Delete Hierarchy", ""},
     {OL_OP_REMAP, "REMAP",   0, "Remap Users",
-     "Make all users of selected datablocks to use instead current (clicked) one"},
+     "Make all users of selected datablocks to use instead a new chosen one"},
 	{OL_OP_TOGVIS, "TOGVIS", 0, "Toggle Visible", ""},
 	{OL_OP_TOGSEL, "TOGSEL", 0, "Toggle Selectable", ""},
 	{OL_OP_TOGREN, "TOGREN", 0, "Toggle Renderable", ""},
@@ -1256,6 +1257,87 @@ void OUTLINER_OT_id_operation(wmOperatorType *ot)
 	ot->prop = RNA_def_enum(ot->srna, "type", prop_id_op_types, 0, "ID data Operation", "");
 }
 
+/* **************************************** */
+
+typedef enum eOutlinerLibOpTypes {
+	OL_LIB_INVALID = 0,
+
+	OL_LIB_RENAME,
+	OL_LIB_RELOCATE,
+} 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"},
+	{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:
+		{
+			/* rename */
+			outliner_do_libdata_operation(C, scene, soops, &soops->tree, item_lib_relocate_cb, NULL);
+
+			WM_event_add_notifier(C, NC_ID | NA_EDITED, NULL);
+			ED_undo_push(C, "Rename");
+			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)
 {
@@ -1323,8 +1405,6 @@ static int outliner_id_remap_invoke(bContext *C, wmOperator *op, const wmEvent *
 	outli

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list