Hi Matt, shouldn't all the operators (with multiple options) have invoke? That way if someone wants to have the operator in the Tool Shelf or to call it with the SPACE menu the options can be selected?
Thanks for the help on that, Dalai 2010/5/24 Matt Ebb <[email protected]>: > Revision: 28971 > > http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28971 > Author: broken > Date: 2010-05-25 08:24:45 +0200 (Tue, 25 May 2010) > > Log Message: > ----------- > Tweaks to copy game properties operator for Dalai > > Modified Paths: > -------------- > trunk/blender/release/scripts/ui/space_view3d.py > trunk/blender/source/blender/editors/object/object_edit.c > > Modified: trunk/blender/release/scripts/ui/space_view3d.py > =================================================================== > --- trunk/blender/release/scripts/ui/space_view3d.py 2010-05-25 05:56:31 > UTC (rev 28970) > +++ trunk/blender/release/scripts/ui/space_view3d.py 2010-05-25 06:24:45 > UTC (rev 28971) > @@ -675,6 +675,7 @@ > layout.menu("VIEW3D_MT_object_track") > layout.menu("VIEW3D_MT_object_group") > layout.menu("VIEW3D_MT_object_constraints") > + layout.menu("VIEW3D_MT_object_game_properties") > > layout.separator() > > @@ -843,6 +844,17 @@ > layout.operator_enums("object.make_links_data", "type") # inline > > > +class VIEW3D_MT_object_game_properties(bpy.types.Menu): > + bl_label = "Game Properties" > + > + def draw(self, context): > + layout = self.layout > + > + layout.operator("object.game_property_copy", > text="Replace").operation="REPLACE" > + layout.operator("object.game_property_copy", > text="Merge").operation="MERGE" > + # layout.operator("object.game_property_copy").operation="CLEAR" > doesn't really belong as part of copy... > + layout.operator_menu_enum("object.game_property_copy", "property", > text="Copy...") > + > # ********** Vertex paint menu ********** > > > @@ -2208,6 +2220,7 @@ > VIEW3D_MT_object_track, > VIEW3D_MT_object_group, > VIEW3D_MT_object_constraints, > + VIEW3D_MT_object_game_properties, > VIEW3D_MT_object_showhide, > VIEW3D_MT_make_single_user, > VIEW3D_MT_make_links, > > Modified: trunk/blender/source/blender/editors/object/object_edit.c > =================================================================== > --- trunk/blender/source/blender/editors/object/object_edit.c 2010-05-25 > 05:56:31 UTC (rev 28970) > +++ trunk/blender/source/blender/editors/object/object_edit.c 2010-05-25 > 06:24:45 UTC (rev 28971) > @@ -2173,13 +2173,11 @@ > { > Object *ob= CTX_data_active_object(C); > bProperty *prop; > - int index; > + int index= RNA_int_get(op->ptr, "index"); > > if(!ob) > return OPERATOR_CANCELLED; > > - index = RNA_int_get(op->ptr, "index"); > - > prop= BLI_findlink(&ob->prop, index); > > if(prop) { > @@ -2207,52 +2205,25 @@ > > RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Property index > to remove ", 0, INT_MAX); > } > -static EnumPropertyItem game_properties_copy_types[] ={ > - {1, "REPLACE", 0, "Replace Properties", ""}, > - {2, "MERGE", 0, "Merge Properties", ""}, > - {3, "CLEAR", 0, "Clear All", ""}, > - {4, "COPY", 0, "Copy a Property", ""}, > - {0, NULL, 0, NULL, NULL}}; > > -static int game_property_copy_invoke(bContext *C, wmOperator *op, wmEvent > *event) > -{ > - Object *ob= CTX_data_active_object(C); > - bProperty *prop; > - int tot=0; > - uiPopupMenu *pup; > - uiLayout *menu; > +#define COPY_PROPERTIES_REPLACE 1 > +#define COPY_PROPERTIES_MERGE 2 > +#define COPY_PROPERTIES_CLEAR 3 > +#define COPY_PROPERTIES_COPY 4 > > - /* count number of available properties */ > - prop= ob->prop.first; > - while(prop) { > - tot++; > - prop= prop->next; > - } > +static EnumPropertyItem game_properties_copy_operations[] ={ > + {COPY_PROPERTIES_REPLACE, "REPLACE", 0, "Replace Properties", ""}, > + {COPY_PROPERTIES_MERGE, "MERGE", 0, "Merge Properties", ""}, > + {COPY_PROPERTIES_CLEAR, "CLEAR", 0, "Clear All", ""}, > + {COPY_PROPERTIES_COPY, "COPY", 0, "Copy a Property", ""}, > + {0, NULL, 0, NULL, NULL}}; > > - /* start building */ > - pup= uiPupMenuBegin(C, op->type->name, 0); > - menu= uiPupMenuLayout(pup); > - uiLayoutSetOperatorContext(menu, WM_OP_EXEC_DEFAULT); > - > - if(!tot) > - uiItemEnumO(menu, "OBJECT_OT_game_property_copy", NULL, 0, > "type", 3);//CLEAR); > - else { > - uiItemEnumO(menu, "OBJECT_OT_game_property_copy", NULL, 0, > "type", 1);//REPLACE); > - uiItemEnumO(menu, "OBJECT_OT_game_property_copy", NULL, 0, > "type", 2);//MERGE); > - uiItemMenuEnumO(menu, "OBJECT_OT_game_property_copy", > "property", "Copy Property", 0);//COPY > - } > - uiPupMenuEnd(C, pup); > - > - /* this operator is only for a menu, not used further */ > - return OPERATOR_CANCELLED; > -} > - > static EnumPropertyItem gameprops_items[]= { > {0, NULL, 0, NULL, NULL}}; > > static EnumPropertyItem *gameprops_itemf(bContext *C, PointerRNA *ptr, int > *free) > { > - Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data; > + Object *ob= ED_object_active_context(C); > EnumPropertyItem tmp = {0, "", 0, "", ""}; > EnumPropertyItem *item= NULL; > bProperty *prop; > @@ -2278,21 +2249,22 @@ > { > Object *ob=ED_object_active_context(C); > bProperty *prop; > - > - int tmp_int; //need an int pointer to pass for the RNA_enum_name > - EnumPropertyItem *dyn_props= NULL; > - const char *prop_name= NULL; > - > - int type = RNA_enum_get(op->ptr, "type"); > + int type = RNA_enum_get(op->ptr, "operation"); > int propid= RNA_enum_get(op->ptr, "property"); > > - // recreate the dynamic enum with the properties > - dyn_props = gameprops_itemf(C, NULL, &tmp_int); > - > - if (propid > 0) > - RNA_enum_name(dyn_props, propid, &prop_name); > - > - if ( type == 1 || type == 2 || type == 3) { > + if(propid > 0) { /* copy */ > + prop = BLI_findlink(&ob->prop, propid-1); > + > + if(prop) { > + CTX_DATA_BEGIN(C, Object*, ob_iter, > selected_editable_objects) { > + if (ob != ob_iter) { > + if (ob->data != ob_iter->data) > + set_ob_property(ob_iter, > prop); > + } > + } CTX_DATA_END; > + } > + } > + else if (ELEM3(type, COPY_PROPERTIES_REPLACE, COPY_PROPERTIES_MERGE, > COPY_PROPERTIES_CLEAR)) { > CTX_DATA_BEGIN(C, Object*, ob_iter, selected_editable_objects) > { > if (ob != ob_iter) { > if (ob->data != ob_iter->data){ > @@ -2307,18 +2279,7 @@ > } > CTX_DATA_END; > } > - else if(prop_name) { /* copy */ > - prop = (bProperty *) BLI_findstring(&ob->prop, prop_name, > offsetof(bProperty, name)); > - > - if(prop) { > - CTX_DATA_BEGIN(C, Object*, ob_iter, > selected_editable_objects) { > - if (ob != ob_iter) { > - if (ob->data != ob_iter->data) > - set_ob_property(ob_iter, > prop); > - } > - } CTX_DATA_END; > - } > - } > + > return OPERATOR_FINISHED; > } > > @@ -2330,14 +2291,13 @@ > ot->idname= "OBJECT_OT_game_property_copy"; > > /* api callbacks */ > - ot->invoke= game_property_copy_invoke; > ot->exec= game_property_copy_exec; > ot->poll= ED_operator_object_active_editable; > > /* flags */ > ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; > > - RNA_def_enum(ot->srna, "type", game_properties_copy_types, 4, > "Operation", ""); > + RNA_def_enum(ot->srna, "operation", game_properties_copy_operations, > 4, "Operation", ""); > prop=RNA_def_enum(ot->srna, "property", gameprops_items, 0, > "Property", "Properties to copy"); > RNA_def_enum_funcs(prop, gameprops_itemf); > ot->prop=prop; > > > _______________________________________________ > Bf-blender-cvs mailing list > [email protected] > http://lists.blender.org/mailman/listinfo/bf-blender-cvs > _______________________________________________ Bf-committers mailing list [email protected] http://lists.blender.org/mailman/listinfo/bf-committers
