Bring back the pupmenu for "select object in the same group"
authorDiego Borghetti <bdiego@gmail.com>
Wed, 12 May 2010 22:29:32 +0000 (22:29 +0000)
committerDiego Borghetti <bdiego@gmail.com>
Wed, 12 May 2010 22:29:32 +0000 (22:29 +0000)
when the object have more that one group.

I put a XXX because the selection function use G.main to
get the group, probably we need a CTX_DATA_BEGIN for
groups ? Brecht ? Campbell ?

I make a new operator for the pupmenu, it's only for the
selection menu, so don't have any key binding.

Matt, can you check ?

source/blender/editors/object/object_intern.h
source/blender/editors/object/object_ops.c
source/blender/editors/object/object_select.c

index 21a4f30..7e1f2cb 100644 (file)
@@ -95,6 +95,7 @@ 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 */
 void OBJECT_OT_add(struct wmOperatorType *ot);
index 1a15b66..759e13b 100644 (file)
@@ -98,6 +98,7 @@ void ED_operatortypes_object(void)
        WM_operatortype_append(OBJECT_OT_select_inverse);
        WM_operatortype_append(OBJECT_OT_select_random);
        WM_operatortype_append(OBJECT_OT_select_all);
+       WM_operatortype_append(OBJECT_OT_select_same_group);
        WM_operatortype_append(OBJECT_OT_select_by_type);
        WM_operatortype_append(OBJECT_OT_select_by_layer);
        WM_operatortype_append(OBJECT_OT_select_linked);
index 0182161..47168d2 100644 (file)
@@ -60,6 +60,8 @@
 
 #include "ED_screen.h"
 
+#include "UI_interface.h"
+
 #include "RNA_access.h"
 #include "RNA_define.h"
 #include "RNA_enum_types.h"
@@ -403,14 +405,12 @@ static short select_grouped_group(bContext *C, Object *ob)        /* Select objects in
 {
        short changed = 0;
        Group *group, *ob_groups[GROUP_MENU_MAX];
-       //char str[10 + (24*GROUP_MENU_MAX)];
-       //char *p = str;
-       int group_count=0; //, menu, i;
-
-       for (   group=G.main->group.first;
-                       group && group_count < GROUP_MENU_MAX;
-                       group=group->id.next
-               ) {
+       int group_count=0, i;
+       uiPopupMenu *pup;
+       uiLayout *layout;
+
+       // XXX G.main ?
+       for (group=G.main->group.first; group && group_count < GROUP_MENU_MAX; group=group->id.next) {
                if (object_in_group (ob, group)) {
                        ob_groups[group_count] = group;
                        group_count++;
@@ -419,7 +419,6 @@ static short select_grouped_group(bContext *C, Object *ob)  /* Select objects in
 
        if (!group_count)
                return 0;
-
        else if (group_count == 1) {
                group = ob_groups[0];
                CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
@@ -431,27 +430,18 @@ static short select_grouped_group(bContext *C, Object *ob)        /* Select objects in
                CTX_DATA_END;
                return changed;
        }
-#if 0 // XXX hows this work in 2.5?
+
        /* build the menu. */
-       p += sprintf(str, "Groups%%t");
+       pup= uiPupMenuBegin(C, "Select Group", 0);
+       layout= uiPupMenuLayout(pup);
+
        for (i=0; i<group_count; i++) {
                group = ob_groups[i];
-               p += sprintf (p, "|%s%%x%i", group->id.name+2, i);
+               uiItemStringO(layout, group->id.name+2, 0, "OBJECT_OT_select_same_group", "group", group->id.name);
        }
 
-       menu = pupmenu (str);
-       if (menu == -1)
-               return 0;
-
-       group = ob_groups[menu];
-       for (base= FIRSTBASE; base; base= base->next) {
-               if (!(base->flag & SELECT) && object_in_group(base->object, group)) {
-                       ED_base_object_select(base, BA_SELECT);
-                       changed = 1;
-               }
-       }
-#endif
-       return changed;
+       uiPupMenuEnd(C, pup);
+       return changed; // The operator already handle this!
 }
 
 static short select_grouped_object_hooks(bContext *C, Object *ob)
@@ -786,6 +776,56 @@ void OBJECT_OT_select_all(wmOperatorType *ot)
        WM_operator_properties_select_all(ot);
 }
 
+/**************************** Select In The Same Group ****************************/
+
+static int object_select_same_group_exec(bContext *C, wmOperator *op)
+{
+       Group *group;
+       char group_name[32];
+
+       /* passthrough if no objects are visible */
+       if (CTX_DATA_COUNT(C, visible_bases) == 0) return OPERATOR_PASS_THROUGH;
+
+       RNA_string_get(op->ptr, "group", group_name);
+
+       // XXX G.main ?
+       for (group=G.main->group.first; group; group=group->id.next) {
+               if (!strcmp(group->id.name, group_name))
+                       break;
+       }
+
+       if (!group)
+               return OPERATOR_PASS_THROUGH;
+
+       CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
+               if (!(base->flag & SELECT) && object_in_group(base->object, group))
+                       ED_base_object_select(base, BA_SELECT);
+       }
+       CTX_DATA_END;
+
+       WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
+       
+       return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_select_same_group(wmOperatorType *ot)
+{
+       
+       /* identifiers */
+       ot->name= "select same group";
+       ot->description = "Select object in the same group";
+       ot->idname= "OBJECT_OT_select_same_group";
+       
+       /* api callbacks */
+       ot->exec= object_select_same_group_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       RNA_def_string(ot->srna, "group", "", 32, "Group", "Name of the group to select.");
+}
+
 /**************************** Select Mirror ****************************/
 
 /* finds the best possible flipped name. For renaming; check for unique names afterwards */