[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43277] trunk/blender/source/blender/ editors: Change how object menu selection works, use an operator with an enum rather then a menu with ' OBJECT_OT_select_name',

Campbell Barton ideasman42 at gmail.com
Wed Jan 11 04:40:29 CET 2012


Revision: 43277
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43277
Author:   campbellbarton
Date:     2012-01-11 03:40:20 +0000 (Wed, 11 Jan 2012)
Log Message:
-----------
Change how object menu selection works, use an operator with an enum rather then a menu with 'OBJECT_OT_select_name',

remove 'OBJECT_OT_select_name' operator since its no longer needed.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/object/object_intern.h
    trunk/blender/source/blender/editors/object/object_ops.c
    trunk/blender/source/blender/editors/object/object_select.c
    trunk/blender/source/blender/editors/space_view3d/view3d_intern.h
    trunk/blender/source/blender/editors/space_view3d/view3d_ops.c
    trunk/blender/source/blender/editors/space_view3d/view3d_select.c

Modified: trunk/blender/source/blender/editors/object/object_intern.h
===================================================================
--- trunk/blender/source/blender/editors/object/object_intern.h	2012-01-11 02:25:43 UTC (rev 43276)
+++ trunk/blender/source/blender/editors/object/object_intern.h	2012-01-11 03:40:20 UTC (rev 43277)
@@ -103,7 +103,6 @@
 void OBJECT_OT_select_linked(struct wmOperatorType *ot);
 void OBJECT_OT_select_grouped(struct wmOperatorType *ot);
 void OBJECT_OT_select_mirror(struct wmOperatorType *ot);
-void OBJECT_OT_select_name(struct wmOperatorType *ot);
 void OBJECT_OT_select_same_group(struct wmOperatorType *ot);
 
 /* object_add.c */

Modified: trunk/blender/source/blender/editors/object/object_ops.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_ops.c	2012-01-11 02:25:43 UTC (rev 43276)
+++ trunk/blender/source/blender/editors/object/object_ops.c	2012-01-11 03:40:20 UTC (rev 43277)
@@ -103,7 +103,6 @@
 	WM_operatortype_append(OBJECT_OT_select_linked);
 	WM_operatortype_append(OBJECT_OT_select_grouped);
 	WM_operatortype_append(OBJECT_OT_select_mirror);
-	WM_operatortype_append(OBJECT_OT_select_name); /* XXX - weak, not compat with linked objects */
 
 	WM_operatortype_append(GROUP_OT_create);
 	WM_operatortype_append(GROUP_OT_objects_remove);

Modified: trunk/blender/source/blender/editors/object/object_select.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_select.c	2012-01-11 02:25:43 UTC (rev 43276)
+++ trunk/blender/source/blender/editors/object/object_select.c	2012-01-11 03:40:20 UTC (rev 43277)
@@ -939,63 +939,6 @@
 }
 
 
-static int object_select_name_exec(bContext *C, wmOperator *op)
-{
-	char *name= RNA_string_get_alloc(op->ptr, "name", NULL, 0);
-	short extend= RNA_boolean_get(op->ptr, "extend");
-	short changed = 0;
-
-	if(!extend) {
-		CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
-			if(base->flag & SELECT) {
-				ED_base_object_select(base, BA_DESELECT);
-				changed= 1;
-			}
-		}
-		CTX_DATA_END;
-	}
-
-	CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
-		/* this is a bit dodjy, there should only be ONE object with this name, but library objects can mess this up */
-		if(strcmp(name, base->object->id.name+2)==0) {
-			ED_base_object_activate(C, base);
-			ED_base_object_select(base, BA_SELECT);
-			changed= 1;
-		}
-	}
-	CTX_DATA_END;
-
-	MEM_freeN(name);
-
-	/* undo? */
-	if(changed) {
-		WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
-		return OPERATOR_FINISHED;
-	}
-	else {
-		return OPERATOR_CANCELLED;
-	}
-}
-
-void OBJECT_OT_select_name(wmOperatorType *ot)
-{
-
-	/* identifiers */
-	ot->name= "Select Name";
-	ot->description = "Select an object with this name";
-	ot->idname= "OBJECT_OT_select_name";
-
-	/* api callbacks */
-	ot->exec= object_select_name_exec;
-	ot->poll= objects_selectable_poll;
-
-	/* flags */
-	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-
-	RNA_def_string(ot->srna, "name", "", 0, "Name", "Object name to select");
-	RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend selection instead of deselecting everything first");
-}
-
 /**************************** Select Random ****************************/
 
 static int object_select_random_exec(bContext *C, wmOperator *op)

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_intern.h	2012-01-11 02:25:43 UTC (rev 43276)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_intern.h	2012-01-11 03:40:20 UTC (rev 43277)
@@ -152,6 +152,7 @@
 void VIEW3D_OT_select_circle(struct wmOperatorType *ot);
 void VIEW3D_OT_select_border(struct wmOperatorType *ot);
 void VIEW3D_OT_select_lasso(struct wmOperatorType *ot);
+void VIEW3D_OT_select_menu(struct wmOperatorType *ot);
 
 void VIEW3D_OT_smoothview(struct wmOperatorType *ot);
 void VIEW3D_OT_camera_to_view(struct wmOperatorType *ot);

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_ops.c	2012-01-11 02:25:43 UTC (rev 43276)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_ops.c	2012-01-11 03:40:20 UTC (rev 43277)
@@ -85,6 +85,7 @@
 	WM_operatortype_append(VIEW3D_OT_enable_manipulator);
 	WM_operatortype_append(VIEW3D_OT_cursor3d);
 	WM_operatortype_append(VIEW3D_OT_select_lasso);
+	WM_operatortype_append(VIEW3D_OT_select_menu);
 	WM_operatortype_append(VIEW3D_OT_camera_to_view);
 	WM_operatortype_append(VIEW3D_OT_camera_to_view_selected);
 	WM_operatortype_append(VIEW3D_OT_object_as_camera);

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_select.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_select.c	2012-01-11 02:25:43 UTC (rev 43276)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_select.c	2012-01-11 03:40:20 UTC (rev 43277)
@@ -74,6 +74,7 @@
 
 #include "RNA_access.h"
 #include "RNA_define.h"
+#include "RNA_enum_types.h"
 
 #include "ED_armature.h"
 #include "ED_curve.h"
@@ -1045,8 +1046,105 @@
 
 
 /* The max number of menu items in an object select menu */
+typedef struct SelMenuItemF {
+	char idname[MAX_ID_NAME-2];
+	int icon;
+} SelMenuItemF;
+
 #define SEL_MENU_SIZE	22
+static SelMenuItemF object_mouse_select_menu_data[SEL_MENU_SIZE];
 
+/* special (crappy) operator only for menu select */
+static EnumPropertyItem *object_select_menu_enum_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), int *free)
+{
+	EnumPropertyItem *item= NULL, item_tmp= {0};
+	int totitem= 0;
+	int i= 0;
+
+	/* dont need context but avoid docgen using this */
+	if (C == NULL || object_mouse_select_menu_data[i].idname[0] == '\0') {
+		return DummyRNA_NULL_items;
+	}
+
+	for (; i < SEL_MENU_SIZE && object_mouse_select_menu_data[i].idname[0] != '\0'; i++) {
+		item_tmp.name= object_mouse_select_menu_data[i].idname;
+		item_tmp.identifier= object_mouse_select_menu_data[i].idname;
+		item_tmp.value= i;
+		item_tmp.icon= object_mouse_select_menu_data[i].icon;
+		RNA_enum_item_add(&item, &totitem, &item_tmp);
+	}
+
+	RNA_enum_item_end(&item, &totitem);
+	*free= 1;
+
+	return item;
+}
+
+static int object_select_menu_exec(bContext *C, wmOperator *op)
+{
+	int name_index= RNA_enum_get(op->ptr, "name");
+	short extend= RNA_boolean_get(op->ptr, "extend");
+	short changed = 0;
+	const char *name= object_mouse_select_menu_data[name_index].idname;
+
+	if(!extend) {
+		CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
+			if(base->flag & SELECT) {
+				ED_base_object_select(base, BA_DESELECT);
+				changed= 1;
+			}
+		}
+		CTX_DATA_END;
+	}
+
+	CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
+		/* this is a bit dodjy, there should only be ONE object with this name, but library objects can mess this up */
+		if(strcmp(name, base->object->id.name+2)==0) {
+			ED_base_object_activate(C, base);
+			ED_base_object_select(base, BA_SELECT);
+			changed= 1;
+		}
+	}
+	CTX_DATA_END;
+
+	/* weak but ensures we activate menu again before using the enum */
+	memset(object_mouse_select_menu_data, 0, sizeof(object_mouse_select_menu_data));
+
+	/* undo? */
+	if(changed) {
+		WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
+		return OPERATOR_FINISHED;
+	}
+	else {
+		return OPERATOR_CANCELLED;
+	}
+}
+
+void VIEW3D_OT_select_menu(wmOperatorType *ot)
+{
+	PropertyRNA *prop;
+
+	/* identifiers */
+	ot->name= "Select Menu";
+	ot->description = "Menu object selection";
+	ot->idname= "VIEW3D_OT_select_menu";
+
+	/* api callbacks */
+	ot->invoke= WM_menu_invoke;
+	ot->exec= object_select_menu_exec;
+
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+	/* keyingset to use (dynamic enum) */
+	prop= RNA_def_enum(ot->srna, "name", DummyRNA_NULL_items, 0, "Object Name", "");
+	RNA_def_enum_funcs(prop, object_select_menu_enum_itemf);
+	RNA_def_property_flag(prop, PROP_HIDDEN);
+	ot->prop= prop;
+
+	RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend selection instead of deselecting everything first");
+}
+
 static void deselectall_except(Scene *scene, Base *b)   /* deselect all except b */
 {
 	Base *base;
@@ -1060,7 +1158,7 @@
 	}
 }
 
-static Base *mouse_select_menu(bContext *C, ViewContext *vc, unsigned int *buffer, int hits, const int mval[2], short extend)
+static Base *object_mouse_select_menu(bContext *C, ViewContext *vc, unsigned int *buffer, int hits, const int mval[2], short extend)
 {
 	short baseCount = 0;
 	short ok;
@@ -1098,9 +1196,6 @@
 	}
 	CTX_DATA_END;
 
-	if(baseCount)
-
-
 	if(baseCount==0) {
 		return NULL;
 	}
@@ -1110,35 +1205,30 @@
 		return base;
 	}
 	else {
-		/* UI */
-		uiPopupMenu *pup= uiPupMenuBegin(C, "Select Object", ICON_NONE);
-		uiLayout *layout= uiPupMenuLayout(pup);
-		uiLayout *split= uiLayoutSplit(layout, 0, 0);
-		uiLayout *column= uiLayoutColumn(split, 0);
+		/* UI, full in static array values that we later use in an enum function */
 		LinkNode *node;
+		int i;
 
-		node= linklist;
-		while(node) {
+		memset(object_mouse_select_menu_data, 0, sizeof(object_mouse_select_menu_data));
+
+		for (node = linklist, i = 0; node; node= node->next, i++) {
 			Base *base=node->link;
 			Object *ob= base->object;
 			char *name= ob->id.name+2;
-			/* annoying!, since we need to set 2 props cant use this. */
-			/* uiItemStringO(column, name, 0, "OBJECT_OT_select_name", "name", name); */
 
-			{
-				PointerRNA ptr;
+			BLI_strncpy(object_mouse_select_menu_data[i].idname, name, MAX_ID_NAME-2);
+			object_mouse_select_menu_data[i].icon = uiIconFromID(&ob->id);
+		}
 
-				WM_operator_properties_create(&ptr, "OBJECT_OT_select_name");
-				RNA_string_set(&ptr, "name", name);
-				RNA_boolean_set(&ptr, "extend", extend);
-				uiItemFullO(column, "OBJECT_OT_select_name", name, uiIconFromID((ID *)ob), ptr.data, WM_OP_EXEC_DEFAULT, 0);
-			}
+		{
+			PointerRNA ptr;
 
-			node= node->next;
+			WM_operator_properties_create(&ptr, "VIEW3D_OT_select_menu");
+			RNA_boolean_set(&ptr, "extend", extend);
+			WM_operator_name_call(C, "VIEW3D_OT_select_menu", WM_OP_INVOKE_DEFAULT, &ptr);
+			WM_operator_properties_free(&ptr);
 		}
 
-		uiPupMenuEnd(C, pup);
-
 		BLI_linklist_free(linklist, NULL);
 		return NULL;
 	}
@@ -1364,7 +1454,7 @@
 		

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-blender-cvs mailing list