2.5: Modifiers & Menus
[blender-staging.git] / source / blender / editors / object / object_edit.c
index e0acb719cf65512f7ac52742f5ac3ca828ae5c56..2fb9835f833b59365ec11e3c1a3adf34d6d4bdc0 100644 (file)
@@ -98,6 +98,7 @@
 #include "BKE_mesh.h"
 #include "BKE_nla.h"
 #include "BKE_object.h"
+#include "BKE_paint.h"
 #include "BKE_particle.h"
 #include "BKE_property.h"
 #include "BKE_report.h"
 #include "ED_anim_api.h"
 #include "ED_armature.h"
 #include "ED_curve.h"
-#include "ED_editparticle.h"
+#include "ED_particle.h"
 #include "ED_mesh.h"
+#include "ED_mball.h"
 #include "ED_object.h"
 #include "ED_screen.h"
+#include "ED_transform.h"
 #include "ED_types.h"
 #include "ED_util.h"
 #include "ED_view3d.h"
 
-#include "BMF_Api.h"
-
-#include "BIF_transform.h"
-
 #include "UI_interface.h"
 
 #include "RNA_access.h"
 #include "RNA_define.h"
+#include "RNA_enum_types.h"
 
 /* for menu/popup icons etc etc*/
 #include "UI_interface.h"
 
 /* ************* XXX **************** */
 static void error() {}
-static void waitcursor() {}
-static int pupmenu() {return 0;}
-static int pupmenu_col() {return 0;}
-static int okee() {return 0;}
+static void waitcursor(int val) {}
+static int pupmenu(const char *msg) {return 0;}
+static int pupmenu_col(const char *msg, int val) {return 0;}
+static int okee(const char *msg) {return 0;}
 
 /* port over here */
 static bContext *C;
@@ -179,10 +179,6 @@ void ED_base_object_activate(bContext *C, Base *base)
        Scene *scene= CTX_data_scene(C);
        Base *tbase;
        
-       /* activating a non-mesh, should end a couple of modes... */
-       if(base && base->object->type!=OB_MESH)
-               ED_view3d_exit_paint_modes(C);
-       
        /* sets scene->basact */
        BASACT= base;
        
@@ -205,21 +201,6 @@ void ED_base_object_activate(bContext *C, Base *base)
 }
 
 
-/*
- * Returns true if the Object data is a from an external blend file (libdata)
- */
-int object_data_is_libdata(Object *ob)
-{
-       if (!ob) return 0;
-       if (ob->proxy) return 0;
-       if (ob->id.lib) return 1;
-       if (!ob->data) return 0;
-       if (((ID *)ob->data)->lib) return 1;
-       return 0;
-}
-
-
-
 /* exported */
 void ED_object_base_init_from_view(bContext *C, Base *base)
 {
@@ -261,17 +242,19 @@ void ED_object_base_init_from_view(bContext *C, Base *base)
 /* ******************* add object operator ****************** */
 
 static EnumPropertyItem prop_object_types[] = {
-       {OB_EMPTY, "EMPTY", "Empty", ""},
-       {OB_MESH, "MESH", "Mesh", ""},
-       {OB_CURVE, "CURVE", "Curve", ""},
-       {OB_SURF, "SURFACE", "Surface", ""},
-       {OB_FONT, "TEXT", "Text", ""},
-       {OB_MBALL, "META", "Meta", ""},
-       {OB_LAMP, "LAMP", "Lamp", ""},
-       {OB_CAMERA, "CAMERA", "Camera", ""},
-       {OB_ARMATURE, "ARMATURE", "Armature", ""},
-       {OB_LATTICE, "LATTICE", "Lattice", ""},
-       {0, NULL, NULL, NULL}
+       {OB_MESH, "MESH", 0, "Mesh", ""},
+       {OB_CURVE, "CURVE", 0, "Curve", ""},
+       {OB_SURF, "SURFACE", 0, "Surface", ""},
+       {OB_MBALL, "META", 0, "Meta", ""},
+       {OB_FONT, "TEXT", 0, "Text", ""},
+       {0, "", 0, NULL, NULL},
+       {OB_ARMATURE, "ARMATURE", 0, "Armature", ""},
+       {OB_LATTICE, "LATTICE", 0, "Lattice", ""},
+       {OB_EMPTY, "EMPTY", 0, "Empty", ""},
+       {0, "", 0, NULL, NULL},
+       {OB_CAMERA, "CAMERA", 0, "Camera", ""},
+       {OB_LAMP, "LAMP", 0, "Lamp", ""},
+       {0, NULL, 0, NULL, NULL}
 };
 
 
@@ -287,9 +270,6 @@ static Object *object_add_type(bContext *C, int type)
        Scene *scene= CTX_data_scene(C);
        Object *ob;
        
-       /* XXX hrms, this is editor level operator, remove? */
-       ED_view3d_exit_paint_modes(C);
-       
        /* for as long scene has editmode... */
        if (CTX_data_edit_object(C)) 
                ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* freedata, and undo */
@@ -298,12 +278,12 @@ static Object *object_add_type(bContext *C, int type)
        ob= add_object(scene, type);
        /* editor level activate, notifiers */
        ED_base_object_activate(C, BASACT);
-       
+
        /* more editor stuff */
        ED_object_base_init_from_view(C, BASACT);
-       
+
        DAG_scene_sort(scene);
-       
+
        return ob;
 }
 
@@ -319,6 +299,7 @@ void OBJECT_OT_object_add(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Add Object";
+       ot->description = "Add an object to the scene.";
        ot->idname= "OBJECT_OT_object_add";
        
        /* api callbacks */
@@ -337,16 +318,17 @@ void OBJECT_OT_object_add(wmOperatorType *ot)
 /* ******  work both in and outside editmode ****** */
 
 static EnumPropertyItem prop_mesh_types[] = {
-       {0, "PLANE", "Plane", ""},
-       {1, "CUBE", "Cube", ""},
-       {2, "CIRCLE", "Circle", ""},
-       {3, "UVSPHERE", "UVsphere", ""},
-       {4, "ICOSPHERE", "Icosphere", ""},
-       {5, "CYLINDER", "Cylinder", ""},
-       {6, "CONE", "Cone", ""},
-       {7, "GRID", "Grid", ""},
-       {8, "MONKEY", "Monkey", ""},
-       {0, NULL, NULL, NULL}
+       {0, "PLANE", ICON_MESH_PLANE, "Plane", ""},
+       {1, "CUBE", ICON_MESH_CUBE, "Cube", ""},
+       {2, "CIRCLE", ICON_MESH_CIRCLE, "Circle", ""},
+       {3, "UVSPHERE", ICON_MESH_UVSPHERE, "UVsphere", ""},
+       {4, "ICOSPHERE", ICON_MESH_ICOSPHERE, "Icosphere", ""},
+       {5, "CYLINDER", ICON_MESH_TUBE, "Cylinder", ""},
+       {6, "CONE", ICON_MESH_CONE, "Cone", ""},
+       {0, "", 0, NULL, NULL},
+       {7, "GRID", ICON_MESH_GRID, "Grid", ""},
+       {8, "MONKEY", ICON_MESH_MONKEY, "Monkey", ""},
+       {0, NULL, 0, NULL, NULL}
 };
 
 static int object_add_mesh_exec(bContext *C, wmOperator *op)
@@ -356,38 +338,38 @@ static int object_add_mesh_exec(bContext *C, wmOperator *op)
        
        if(obedit==NULL || obedit->type!=OB_MESH) {
                object_add_type(C, OB_MESH);
-               ED_object_enter_editmode(C, 0);
+               ED_object_enter_editmode(C, EM_DO_UNDO);
                newob = 1;
        }
        else DAG_object_flush_update(CTX_data_scene(C), obedit, OB_RECALC_DATA);
 
        switch(RNA_enum_get(op->ptr, "type")) {
                case 0:
-                       WM_operator_name_call(C, "MESH_OT_add_primitive_plane", WM_OP_INVOKE_REGION_WIN, NULL);
+                       WM_operator_name_call(C, "MESH_OT_primitive_plane_add", WM_OP_INVOKE_REGION_WIN, NULL);
                        break;
                case 1:
-                       WM_operator_name_call(C, "MESH_OT_add_primitive_cube", WM_OP_INVOKE_REGION_WIN, NULL);
+                       WM_operator_name_call(C, "MESH_OT_primitive_cube_add", WM_OP_INVOKE_REGION_WIN, NULL);
                        break;
                case 2:
-                       WM_operator_name_call(C, "MESH_OT_add_primitive_circle", WM_OP_INVOKE_REGION_WIN, NULL);
+                       WM_operator_name_call(C, "MESH_OT_primitive_circle_add", WM_OP_INVOKE_REGION_WIN, NULL);
                        break;
                case 3:
-                       WM_operator_name_call(C, "MESH_OT_add_primitive_uv_sphere", WM_OP_INVOKE_REGION_WIN, NULL);
+                       WM_operator_name_call(C, "MESH_OT_primitive_uv_sphere_add", WM_OP_INVOKE_REGION_WIN, NULL);
                        break;
                case 4:
-                       WM_operator_name_call(C, "MESH_OT_add_primitive_ico_sphere", WM_OP_INVOKE_REGION_WIN, NULL);
+                       WM_operator_name_call(C, "MESH_OT_primitive_ico_sphere_add", WM_OP_INVOKE_REGION_WIN, NULL);
                        break;
                case 5:
-                       WM_operator_name_call(C, "MESH_OT_add_primitive_cylinder", WM_OP_INVOKE_REGION_WIN, NULL);
+                       WM_operator_name_call(C, "MESH_OT_primitive_cylinder_add", WM_OP_INVOKE_REGION_WIN, NULL);
                        break;
                case 6:
-                       WM_operator_name_call(C, "MESH_OT_add_primitive_cone", WM_OP_INVOKE_REGION_WIN, NULL);
+                       WM_operator_name_call(C, "MESH_OT_primitive_cone_add", WM_OP_INVOKE_REGION_WIN, NULL);
                        break;
                case 7:
-                       WM_operator_name_call(C, "MESH_OT_add_primitive_grid", WM_OP_INVOKE_REGION_WIN, NULL);
+                       WM_operator_name_call(C, "MESH_OT_primitive_grid_add", WM_OP_INVOKE_REGION_WIN, NULL);
                        break;
                case 8:
-                       WM_operator_name_call(C, "MESH_OT_add_primitive_monkey", WM_OP_INVOKE_REGION_WIN, NULL);
+                       WM_operator_name_call(C, "MESH_OT_primitive_monkey_add", WM_OP_INVOKE_REGION_WIN, NULL);
                        break;
        }
        /* userdef */
@@ -405,6 +387,7 @@ void OBJECT_OT_mesh_add(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Add Mesh";
+       ot->description = "Add a mesh object to the scene.";
        ot->idname= "OBJECT_OT_mesh_add";
        
        /* api callbacks */
@@ -413,19 +396,19 @@ void OBJECT_OT_mesh_add(wmOperatorType *ot)
        
        ot->poll= ED_operator_scene_editable;
        
-       /* flags */
-       ot->flag= 0;
+       /* flags: no register or undo, this operator calls operators */
+       ot->flag= 0; //OPTYPE_REGISTER|OPTYPE_UNDO;
        
        RNA_def_enum(ot->srna, "type", prop_mesh_types, 0, "Primitive", "");
 }
 
 static EnumPropertyItem prop_curve_types[] = {
-       {CU_BEZIER|CU_2D|CU_PRIM_CURVE, "BEZIER_CURVE", "Bezier Curve", ""},
-       {CU_BEZIER|CU_2D|CU_PRIM_CIRCLE, "BEZIER_CIRCLE", "Bezier Circle", ""},
-       {CU_NURBS|CU_2D|CU_PRIM_CURVE, "NURBS_CURVE", "NURBS Curve", ""},
-       {CU_NURBS|CU_2D|CU_PRIM_CIRCLE, "NURBS_CIRCLE", "NURBS Circle", ""},
-       {CU_NURBS|CU_2D|CU_PRIM_PATH, "PATH", "Path", ""},
-       {0, NULL, NULL, NULL}
+       {CU_BEZIER|CU_2D|CU_PRIM_CURVE, "BEZIER_CURVE", ICON_CURVE_BEZCURVE, "Bezier Curve", ""},
+       {CU_BEZIER|CU_2D|CU_PRIM_CIRCLE, "BEZIER_CIRCLE", ICON_CURVE_BEZCIRCLE, "Bezier Circle", ""},
+       {CU_NURBS|CU_2D|CU_PRIM_CURVE, "NURBS_CURVE", ICON_CURVE_NCURVE, "NURBS Curve", ""},
+       {CU_NURBS|CU_2D|CU_PRIM_CIRCLE, "NURBS_CIRCLE", ICON_CURVE_NCIRCLE, "NURBS Circle", ""},
+       {CU_NURBS|CU_2D|CU_PRIM_PATH, "PATH", ICON_CURVE_PATH, "Path", ""},
+       {0, NULL, 0, NULL, NULL}
 };
 
 static int object_add_curve_exec(bContext *C, wmOperator *op)
@@ -460,14 +443,16 @@ static int object_add_curve_exec(bContext *C, wmOperator *op)
 static int object_add_curve_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        Object *obedit= CTX_data_edit_object(C);
-       uiMenuItem *head;
+       uiPopupMenu *pup;
+       uiLayout *layout;
 
-       head= uiPupMenuBegin(op->type->name, 0);
+       pup= uiPupMenuBegin(C, op->type->name, 0);
+       layout= uiPupMenuLayout(pup);
        if(!obedit || obedit->type == OB_CURVE)
-               uiMenuItemsEnumO(head, op->type->idname, "type");
+               uiItemsEnumO(layout, op->type->idname, "type");
        else
-               uiMenuItemsEnumO(head, "OBJECT_OT_surface_add", "type");
-       uiPupMenuEnd(C, head);
+               uiItemsEnumO(layout, "OBJECT_OT_surface_add", "type");
+       uiPupMenuEnd(C, pup);
 
        return OPERATOR_CANCELLED;
 }
@@ -476,6 +461,7 @@ void OBJECT_OT_curve_add(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Add Curve";
+       ot->description = "Add a curve object to the scene.";
        ot->idname= "OBJECT_OT_curve_add";
        
        /* api callbacks */
@@ -491,13 +477,13 @@ void OBJECT_OT_curve_add(wmOperatorType *ot)
 }
 
 static EnumPropertyItem prop_surface_types[]= {
-       {CU_PRIM_CURVE|CU_NURBS, "NURBS_CURVE", "NURBS Curve", ""},
-       {CU_PRIM_CIRCLE|CU_NURBS, "NURBS_CIRCLE", "NURBS Circle", ""},
-       {CU_PRIM_PATCH|CU_NURBS, "NURBS_SURFACE", "NURBS Surface", ""},
-       {CU_PRIM_TUBE|CU_NURBS, "NURBS_TUBE", "NURBS Tube", ""},
-       {CU_PRIM_SPHERE|CU_NURBS, "NURBS_SPHERE", "NURBS Sphere", ""},
-       {CU_PRIM_DONUT|CU_NURBS, "NURBS_DONUT", "NURBS Donut", ""},
-       {0, NULL, NULL, NULL}
+       {CU_PRIM_CURVE|CU_NURBS, "NURBS_CURVE", ICON_SURFACE_NCURVE, "NURBS Curve", ""},
+       {CU_PRIM_CIRCLE|CU_NURBS, "NURBS_CIRCLE", ICON_SURFACE_NCIRCLE, "NURBS Circle", ""},
+       {CU_PRIM_PATCH|CU_NURBS, "NURBS_SURFACE", ICON_SURFACE_NSURFACE, "NURBS Surface", ""},
+       {CU_PRIM_TUBE|CU_NURBS, "NURBS_TUBE", ICON_SURFACE_NTUBE, "NURBS Tube", ""},
+       {CU_PRIM_SPHERE|CU_NURBS, "NURBS_SPHERE", ICON_SURFACE_NSPHERE, "NURBS Sphere", ""},
+       {CU_PRIM_DONUT|CU_NURBS, "NURBS_DONUT", ICON_SURFACE_NDONUT, "NURBS Donut", ""},
+       {0, NULL, 0, NULL, NULL}
 };
 
 static int object_add_surface_exec(bContext *C, wmOperator *op)
@@ -533,6 +519,7 @@ void OBJECT_OT_surface_add(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Add Surface";
+       ot->description = "Add a surface object to the scene.";
        ot->idname= "OBJECT_OT_surface_add";
        
        /* api callbacks */
@@ -547,6 +534,78 @@ void OBJECT_OT_surface_add(wmOperatorType *ot)
        RNA_def_enum(ot->srna, "type", prop_surface_types, 0, "Primitive", "");
 }
 
+static EnumPropertyItem prop_metaball_types[]= {
+       {MB_BALL, "MBALL_BALL", ICON_META_BALL, "Meta Ball", ""},
+       {MB_TUBE, "MBALL_TUBE", ICON_META_TUBE, "Meta Tube", ""},
+       {MB_PLANE, "MBALL_PLANE", ICON_META_PLANE, "Meta Plane", ""},
+       {MB_CUBE, "MBALL_CUBE", ICON_META_CUBE, "Meta Cube", ""},
+       {MB_ELIPSOID, "MBALL_ELLIPSOID", ICON_META_ELLIPSOID, "Meta Ellipsoid", ""},
+       {0, NULL, 0, NULL, NULL}
+};
+
+static int object_metaball_add_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       MetaBall *mball;
+       MetaElem *elem;
+       int newob= 0;
+       
+       if(obedit==NULL || obedit->type!=OB_MBALL) {
+               object_add_type(C, OB_MBALL);
+               ED_object_enter_editmode(C, 0);
+               newob = 1;
+       }
+       else DAG_object_flush_update(CTX_data_scene(C), obedit, OB_RECALC_DATA);
+       
+       obedit= CTX_data_edit_object(C);
+       elem= (MetaElem*)add_metaball_primitive(C, RNA_enum_get(op->ptr, "type"), newob);
+       mball= (MetaBall*)obedit->data;
+       BLI_addtail(mball->editelems, elem);
+       
+       /* userdef */
+       if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
+               ED_object_exit_editmode(C, EM_FREEDATA);
+       }
+       
+       WM_event_add_notifier(C, NC_OBJECT|ND_GEOM_SELECT, obedit);
+       
+       return OPERATOR_FINISHED;
+}
+
+static int object_metaball_add_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       uiPopupMenu *pup;
+       uiLayout *layout;
+
+       pup= uiPupMenuBegin(C, op->type->name, 0);
+       layout= uiPupMenuLayout(pup);
+       if(!obedit || obedit->type == OB_MBALL)
+               uiItemsEnumO(layout, op->type->idname, "type");
+       else
+               uiItemsEnumO(layout, "OBJECT_OT_metaball_add", "type");
+       uiPupMenuEnd(C, pup);
+
+       return OPERATOR_CANCELLED;
+}
+
+void OBJECT_OT_metaball_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Metaball";
+       ot->description= "Add an metaball object to the scene.";
+       ot->idname= "OBJECT_OT_metaball_add";
+
+       /* api callbacks */
+       ot->invoke= object_metaball_add_invoke;
+       ot->exec= object_metaball_add_exec;
+       ot->poll= ED_operator_scene_editable;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       RNA_def_enum(ot->srna, "type", prop_metaball_types, 0, "Primitive", "");
+}
 static int object_add_text_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
@@ -569,6 +628,7 @@ void OBJECT_OT_text_add(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Add Text";
+       ot->description = "Add a text object to the scene";
        ot->idname= "OBJECT_OT_text_add";
        
        /* api callbacks */
@@ -579,9 +639,11 @@ void OBJECT_OT_text_add(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-static int object_add_armature_exec(bContext *C, wmOperator *op)
+static int object_armature_add_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
+       View3D *v3d= CTX_wm_view3d(C);
+       RegionView3D *rv3d= NULL;
        int newob= 0;
        
        if ((obedit==NULL) || (obedit->type != OB_ARMATURE)) {
@@ -591,10 +653,12 @@ static int object_add_armature_exec(bContext *C, wmOperator *op)
        }
        else DAG_object_flush_update(CTX_data_scene(C), obedit, OB_RECALC_DATA);
        
-       //nu= add_nurbs_primitive(C, RNA_enum_get(op->ptr, "type"), newob);
-       //editnurb= curve_get_editcurve(CTX_data_edit_object(C));
-       //BLI_addtail(editnurb, nu);
+       if(v3d) 
+               rv3d= CTX_wm_region(C)->regiondata;
        
+       /* v3d and rv3d are allowed to be NULL */
+       add_primitive_bone(CTX_data_scene(C), v3d, rv3d);
+
        /* userdef */
        if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
                ED_object_exit_editmode(C, EM_FREEDATA);
@@ -609,33 +673,36 @@ void OBJECT_OT_armature_add(wmOperatorType *ot)
 {      
        /* identifiers */
        ot->name= "Add Armature";
+       ot->description = "Add an armature object to the scene.";
        ot->idname= "OBJECT_OT_armature_add";
        
        /* api callbacks */
-       ot->exec= object_add_armature_exec;
+       ot->exec= object_armature_add_exec;
        ot->poll= ED_operator_scene_editable;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-
-static int object_add_primitive_invoke(bContext *C, wmOperator *op, wmEvent *event)
+static int object_primitive_add_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
-       uiMenuItem *head= uiPupMenuBegin("Add Object", 0);
+       uiPopupMenu *pup= uiPupMenuBegin(C, "Add Object", 0);
+       uiLayout *layout= uiPupMenuLayout(pup);
        
-       uiMenuLevelEnumO(head, "OBJECT_OT_mesh_add", "type");
-       uiMenuLevelEnumO(head, "OBJECT_OT_curve_add", "type");
-       uiMenuLevelEnumO(head, "OBJECT_OT_surface_add", "type");
-       uiMenuItemO(head, 0, "OBJECT_OT_text_add");
-       uiMenuItemEnumO(head, "", 0, "OBJECT_OT_object_add", "type", OB_MBALL);
-       uiMenuItemEnumO(head, "", 0, "OBJECT_OT_object_add", "type", OB_CAMERA);
-       uiMenuItemEnumO(head, "", 0, "OBJECT_OT_object_add", "type", OB_LAMP);
-       uiMenuItemEnumO(head, "", 0, "OBJECT_OT_object_add", "type", OB_EMPTY);
-       uiMenuItemO(head, 0, "OBJECT_OT_armature_add");
-       uiMenuItemEnumO(head, "", 0, "OBJECT_OT_object_add", "type", OB_LATTICE);
+       uiItemMenuEnumO(layout, "Mesh", ICON_OUTLINER_OB_MESH, "OBJECT_OT_mesh_add", "type");
+       uiItemMenuEnumO(layout, "Curve", ICON_OUTLINER_OB_CURVE, "OBJECT_OT_curve_add", "type");
+       uiItemMenuEnumO(layout, "Surface", ICON_OUTLINER_OB_SURFACE, "OBJECT_OT_surface_add", "type");
+       uiItemMenuEnumO(layout, NULL, ICON_OUTLINER_OB_META, "OBJECT_OT_metaball_add", "type");
+       uiItemO(layout, "Text", ICON_OUTLINER_OB_FONT, "OBJECT_OT_text_add");
+       uiItemS(layout);
+       uiItemO(layout, "Armature", ICON_OUTLINER_OB_ARMATURE, "OBJECT_OT_armature_add");
+       uiItemEnumO(layout, NULL, ICON_OUTLINER_OB_LATTICE, "OBJECT_OT_object_add", "type", OB_LATTICE);
+       uiItemEnumO(layout, NULL, ICON_OUTLINER_OB_EMPTY, "OBJECT_OT_object_add", "type", OB_EMPTY);
+       uiItemS(layout);
+       uiItemEnumO(layout, NULL, ICON_OUTLINER_OB_CAMERA, "OBJECT_OT_object_add", "type", OB_CAMERA);
+       uiItemEnumO(layout, NULL, ICON_OUTLINER_OB_LAMP, "OBJECT_OT_object_add", "type", OB_LAMP);
        
-       uiPupMenuEnd(C, head);
+       uiPupMenuEnd(C, pup);
        
        /* this operator is only for a menu, not used further */
        return OPERATOR_CANCELLED;
@@ -646,10 +713,11 @@ void OBJECT_OT_primitive_add(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Add Primitive";
+       ot->description = "Add a primitive object.";
        ot->idname= "OBJECT_OT_primitive_add";
        
        /* api callbacks */
-       ot->invoke= object_add_primitive_invoke;
+       ot->invoke= object_primitive_add_invoke;
        
        ot->poll= ED_operator_scene_editable;
        
@@ -678,8 +746,6 @@ static int object_delete_exec(bContext *C, wmOperator *op)
        if(CTX_data_edit_object(C)) 
                return OPERATOR_CANCELLED;
        
-       ED_view3d_exit_paint_modes(C);
-
        CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
 
                if(base->object->type==OB_LAMP) islamp= 1;
@@ -703,7 +769,8 @@ void OBJECT_OT_delete(wmOperatorType *ot)
 {
        
        /* identifiers */
-       ot->name= "Delete Objects";
+       ot->name= "Delete";
+       ot->description = "Delete selected objects.";
        ot->idname= "OBJECT_OT_delete";
        
        /* api callbacks */
@@ -745,7 +812,7 @@ static void copy_object_set_idnew(Scene *scene, View3D *v3d, int dupflag)
        
        /* XXX check object pointers */
        for(base= FIRSTBASE; base; base= base->next) {
-               if(TESTBASELIB(v3d, base)) {
+               if(TESTBASELIB_BGMODE(v3d, base)) {
                        ob= base->object;
                        relink_constraints(&ob->constraints);
                        if (ob->pose){
@@ -908,7 +975,7 @@ static int return_editmesh_vgroup(Object *obedit, EditMesh *em, char *name, floa
 static void select_editmesh_hook(Object *ob, HookModifierData *hmd)
 {
        Mesh *me= ob->data;
-       EditMesh *em= me->edit_mesh;
+       EditMesh *em= BKE_mesh_get_editmesh(me);
        EditVert *eve;
        int index=0, nr=0;
        
@@ -919,6 +986,8 @@ static void select_editmesh_hook(Object *ob, HookModifierData *hmd)
                }
        }
        EM_select_flush(em);
+
+       BKE_mesh_end_editmesh(me, em);
 }
 
 static int return_editlattice_indexar(Lattice *editlatt, int *tot, int **indexar, float *cent)
@@ -1081,7 +1150,7 @@ void ED_object_apply_obmat(Object *ob)
        
 }
 
-int hook_getIndexArray(Object *obedit, int *tot, int **indexar, char *name, float *cent_r)
+int object_hook_index_array(Object *obedit, int *tot, int **indexar, char *name, float *cent_r)
 {
        *indexar= NULL;
        *tot= 0;
@@ -1091,9 +1160,17 @@ int hook_getIndexArray(Object *obedit, int *tot, int **indexar, char *name, floa
                case OB_MESH:
                {
                        Mesh *me= obedit->data;
+                       EditMesh *em = BKE_mesh_get_editmesh(me);
+
                        /* check selected vertices first */
-                       if( return_editmesh_indexar(me->edit_mesh, tot, indexar, cent_r)) return 1;
-                       else return return_editmesh_vgroup(obedit, me->edit_mesh, name, cent_r);
+                       if( return_editmesh_indexar(em, tot, indexar, cent_r)) {
+                               BKE_mesh_end_editmesh(me, em);
+                               return 1;
+                       } else {
+                               int ret = return_editmesh_vgroup(obedit, em, name, cent_r);
+                               BKE_mesh_end_editmesh(me, em);
+                               return ret;
+                       }
                }
                case OB_CURVE:
                case OB_SURF:
@@ -1155,9 +1232,8 @@ static void select_editcurve_hook(Object *obedit, HookModifierData *hmd)
        }
 }
 
-void obedit_hook_select(Object *ob, HookModifierData *hmd) 
+void object_hook_select(Object *ob, HookModifierData *hmd) 
 {
-       
        if(ob->type==OB_MESH) select_editmesh_hook(ob, hmd);
        else if(ob->type==OB_LATTICE) select_editlattice_hook(ob, hmd);
        else if(ob->type==OB_CURVE) select_editcurve_hook(ob, hmd);
@@ -1241,7 +1317,7 @@ void add_hook(Scene *scene, View3D *v3d, int mode)
                int tot, ok, *indexar;
                char name[32];
                
-               ok = hook_getIndexArray(obedit, &tot, &indexar, name, cent);
+               ok = object_hook_index_array(obedit, &tot, &indexar, name, cent);
                
                if(ok==0) {
                        error("Requires selected vertices or active Vertex Group");
@@ -1304,7 +1380,7 @@ void add_hook(Scene *scene, View3D *v3d, int mode)
                modifier_free(md);
        }
        else if(mode==5) { /* select */
-               obedit_hook_select(obedit, hmd);
+               object_hook_select(obedit, hmd);
        }
        else if(mode==6) { /* clear offset */
                where_is_object(scene, ob);     /* ob is hook->parent */
@@ -1358,48 +1434,51 @@ void add_hook_menu(Scene *scene, View3D *v3d)
 /* ******************** clear parent operator ******************* */
 
 static EnumPropertyItem prop_clear_parent_types[] = {
-       {0, "CLEAR", "Clear Parent", ""},
-       {1, "CLEAR_KEEP_TRANSFORM", "Clear and Keep Transformation (Clear Track)", ""},
-       {2, "CLEAR_INVERSE", "Clear Parent Inverse", ""},
-       {0, NULL, NULL, NULL}
+       {0, "CLEAR", 0, "Clear Parent", ""},
+       {1, "CLEAR_KEEP_TRANSFORM", 0, "Clear and Keep Transformation (Clear Track)", ""},
+       {2, "CLEAR_INVERSE", 0, "Clear Parent Inverse", ""},
+       {0, NULL, 0, NULL, NULL}
 };
 
 /* note, poll should check for editable scene */
-static int clear_parent_exec(bContext *C, wmOperator *op)
+static int parent_clear_exec(bContext *C, wmOperator *op)
 {
+       int type= RNA_enum_get(op->ptr, "type");
        
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
 
-               if(RNA_enum_is_equal(op->ptr, "type", "CLEAR")) {
+               if(type == 0) {
                        ob->parent= NULL;
                }                       
-               if(RNA_enum_is_equal(op->ptr, "type", "CLEAR_KEEP_TRANSFORM")) {
+               else if(type == 1) {
                        ob->parent= NULL;
                        ob->track= NULL;
                        ED_object_apply_obmat(ob);
                }
-               if(RNA_enum_is_equal(op->ptr, "type", "CLEAR_INVERSE")) {
+               else if(type == 2)
                        Mat4One(ob->parentinv);
-               }
+
                ob->recalc |= OB_RECALC;
        }
        CTX_DATA_END;
        
        DAG_scene_sort(CTX_data_scene(C));
        ED_anim_dag_flush_update(C);
-       
+       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
+
        return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_clear_parent(wmOperatorType *ot)
+void OBJECT_OT_parent_clear(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Clear parent";
-       ot->idname= "OBJECT_OT_clear_parent";
+       ot->name= "Clear Parent";
+       ot->description = "Clear the object's parenting.";
+       ot->idname= "OBJECT_OT_parent_clear";
        
        /* api callbacks */
        ot->invoke= WM_menu_invoke;
-       ot->exec= clear_parent_exec;
+       ot->exec= parent_clear_exec;
        
        ot->poll= ED_operator_object_active;
        
@@ -1413,14 +1492,16 @@ void OBJECT_OT_clear_parent(wmOperatorType *ot)
 
 
 static EnumPropertyItem prop_clear_track_types[] = {
-       {0, "CLEAR", "Clear Track", ""},
-       {1, "CLEAR_KEEP_TRANSFORM", "Clear and Keep Transformation (Clear Track)", ""},
-       {0, NULL, NULL, NULL}
+       {0, "CLEAR", 0, "Clear Track", ""},
+       {1, "CLEAR_KEEP_TRANSFORM", 0, "Clear and Keep Transformation (Clear Track)", ""},
+       {0, NULL, 0, NULL, NULL}
 };
 
 /* note, poll should check for editable scene */
-static int object_clear_track_exec(bContext *C, wmOperator *op)
+static int object_track_clear_exec(bContext *C, wmOperator *op)
 {
+       int type= RNA_enum_get(op->ptr, "type");
+
        if(CTX_data_edit_object(C)) {
                BKE_report(op->reports, RPT_ERROR, "Operation cannot be performed in EditMode");
                return OPERATOR_CANCELLED;
@@ -1429,9 +1510,8 @@ static int object_clear_track_exec(bContext *C, wmOperator *op)
                ob->track= NULL;
                ob->recalc |= OB_RECALC;
                
-               if(RNA_enum_is_equal(op->ptr, "type", "CLEAR_KEEP_TRANSFORM")) {
+               if(type == 1)
                        ED_object_apply_obmat(ob);
-               }                       
        }
        CTX_DATA_END;
 
@@ -1441,15 +1521,16 @@ static int object_clear_track_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_clear_track(wmOperatorType *ot)
+void OBJECT_OT_track_clear(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Clear track";
-       ot->idname= "OBJECT_OT_clear_track";
+       ot->description = "Clear tracking constraint or flag from object.";
+       ot->idname= "OBJECT_OT_track_clear";
        
        /* api callbacks */
        ot->invoke= WM_menu_invoke;
-       ot->exec= object_clear_track_exec;
+       ot->exec= object_track_clear_exec;
        
        ot->poll= ED_operator_scene_editable;
        
@@ -1459,16 +1540,29 @@ void OBJECT_OT_clear_track(wmOperatorType *ot)
        RNA_def_enum(ot->srna, "type", prop_clear_track_types, 0, "Type", "");
 }
 
+/* *****************Selection Operators******************* */
+static EnumPropertyItem prop_select_types[] = {
+       {0, "EXCLUSIVE", 0, "Exclusive", ""},
+       {1, "EXTEND", 0, "Extend", ""},
+       {0, NULL, 0, NULL, NULL}
+};
 
-/* ***************************** */
 /* ****** Select by Type ****** */
 
 static int object_select_by_type_exec(bContext *C, wmOperator *op)
 {
-       short obtype;
+       short obtype, seltype;
        
        obtype = RNA_enum_get(op->ptr, "type");
+       seltype = RNA_enum_get(op->ptr, "seltype");
                
+       if (seltype == 0) {
+               CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
+                       ED_base_object_select(base, BA_DESELECT);
+               }
+               CTX_DATA_END;
+       }
+       
        CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
                if(base->object->type==obtype) {
                        ED_base_object_select(base, BA_SELECT);
@@ -1485,6 +1579,7 @@ void OBJECT_OT_select_by_type(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Select By Type";
+       ot->description = "Select all visible objects that are of a type.";
        ot->idname= "OBJECT_OT_select_by_type";
        
        /* api callbacks */
@@ -1495,19 +1590,20 @@ void OBJECT_OT_select_by_type(wmOperatorType *ot)
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
-       RNA_def_enum(ot->srna, "type", prop_object_types, 0, "Type", "");
+       RNA_def_enum(ot->srna, "seltype", prop_select_types, 0, "Selection", "Extend selection or clear selection then select");
+       RNA_def_enum(ot->srna, "type", prop_object_types, 1, "Type", "");
 
 }
 /* ****** selection by links *******/
 
 static EnumPropertyItem prop_select_linked_types[] = {
-       {1, "IPO", "Object IPO", ""}, // XXX depreceated animation system stuff...
-       {2, "OBDATA", "Ob Data", ""},
-       {3, "MATERIAL", "Material", ""},
-       {4, "TEXTURE", "Texture", ""},
-       {5, "DUPGROUP", "Dupligroup", ""},
-       {6, "PARTICLE", "Particle System", ""},
-       {0, NULL, NULL, NULL}
+       {1, "IPO", 0, "Object IPO", ""}, // XXX depreceated animation system stuff...
+       {2, "OBDATA", 0, "Ob Data", ""},
+       {3, "MATERIAL", 0, "Material", ""},
+       {4, "TEXTURE", 0, "Texture", ""},
+       {5, "DUPGROUP", 0, "Dupligroup", ""},
+       {6, "PARTICLE", 0, "Particle System", ""},
+       {0, NULL, 0, NULL, NULL}
 };
 
 static int object_select_linked_exec(bContext *C, wmOperator *op)
@@ -1519,7 +1615,7 @@ static int object_select_linked_exec(bContext *C, wmOperator *op)
        Tex *tex=0;
        int a, b;
        int nr = RNA_enum_get(op->ptr, "type");
-       short changed = 0;
+       short changed = 0, seltype;
        /* events (nr):
         * Object Ipo: 1
         * ObData: 2
@@ -1528,7 +1624,15 @@ static int object_select_linked_exec(bContext *C, wmOperator *op)
         * DupliGroup: 5
         * PSys: 6
         */
+
+       seltype = RNA_enum_get(op->ptr, "seltype");
        
+       if (seltype == 0) {
+               CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
+                       ED_base_object_select(base, BA_DESELECT);
+               }
+               CTX_DATA_END;
+       }
        
        ob= OBACT;
        if(ob==0){ 
@@ -1563,65 +1667,63 @@ static int object_select_linked_exec(bContext *C, wmOperator *op)
        else return OPERATOR_CANCELLED;
        
        CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
-               if (!(base->flag & SELECT)) {
-                       if(nr==1) {
-                                       // XXX old animation system
-                               //if(base->object->ipo==ipo) base->flag |= SELECT;
-                               //changed = 1;
-                       }
-                       else if(nr==2) {
-                               if(base->object->data==obdata) base->flag |= SELECT;
-                               changed = 1;
-                       }
-                       else if(nr==3 || nr==4) {
-                               ob= base->object;
-                               
-                               for(a=1; a<=ob->totcol; a++) {
-                                       mat1= give_current_material(ob, a);
-                                       if(nr==3) {
-                                               if(mat1==mat) base->flag |= SELECT;
-                                               changed = 1;
-                                       }
-                                       else if(mat1 && nr==4) {
-                                               for(b=0; b<MAX_MTEX; b++) {
-                                                       if(mat1->mtex[b]) {
-                                                               if(tex==mat1->mtex[b]->tex) {
-                                                                       base->flag |= SELECT;
-                                                                       changed = 1;
-                                                                       break;
-                                                               }
+               if(nr==1) {
+                               // XXX old animation system
+                       //if(base->object->ipo==ipo) base->flag |= SELECT;
+                       //changed = 1;
+               }
+               else if(nr==2) {
+                       if(base->object->data==obdata) base->flag |= SELECT;
+                       changed = 1;
+               }
+               else if(nr==3 || nr==4) {
+                       ob= base->object;
+                       
+                       for(a=1; a<=ob->totcol; a++) {
+                               mat1= give_current_material(ob, a);
+                               if(nr==3) {
+                                       if(mat1==mat) base->flag |= SELECT;
+                                       changed = 1;
+                               }
+                               else if(mat1 && nr==4) {
+                                       for(b=0; b<MAX_MTEX; b++) {
+                                               if(mat1->mtex[b]) {
+                                                       if(tex==mat1->mtex[b]->tex) {
+                                                               base->flag |= SELECT;
+                                                               changed = 1;
+                                                               break;
                                                        }
                                                }
                                        }
                                }
                        }
-                       else if(nr==5) {
-                               if(base->object->dup_group==ob->dup_group) {
-                                        base->flag |= SELECT;
-                                        changed = 1;
-                               }
+               }
+               else if(nr==5) {
+                       if(base->object->dup_group==ob->dup_group) {
+                                base->flag |= SELECT;
+                                changed = 1;
                        }
-                       else if(nr==6) {
-                               /* loop through other, then actives particles*/
-                               ParticleSystem *psys;
-                               ParticleSystem *psys_act;
-                               
-                               for(psys=base->object->particlesystem.first; psys; psys=psys->next) {
-                                       for(psys_act=ob->particlesystem.first; psys_act; psys_act=psys_act->next) {
-                                               if (psys->part == psys_act->part) {
-                                                       base->flag |= SELECT;
-                                                       changed = 1;
-                                                       break;
-                                               }
-                                       }
-                                       
-                                       if (base->flag & SELECT) {
+               }
+               else if(nr==6) {
+                       /* loop through other, then actives particles*/
+                       ParticleSystem *psys;
+                       ParticleSystem *psys_act;
+                       
+                       for(psys=base->object->particlesystem.first; psys; psys=psys->next) {
+                               for(psys_act=ob->particlesystem.first; psys_act; psys_act=psys_act->next) {
+                                       if (psys->part == psys_act->part) {
+                                               base->flag |= SELECT;
+                                               changed = 1;
                                                break;
                                        }
                                }
+                               
+                               if (base->flag & SELECT) {
+                                       break;
+                               }
                        }
-                       base->object->flag= base->flag;
                }
+               base->object->flag= base->flag;
        }
        CTX_DATA_END;
        
@@ -1637,6 +1739,7 @@ void OBJECT_OT_select_linked(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Select Linked";
+       ot->description = "Select all visible objects that are linked.";
        ot->idname= "OBJECT_OT_select_linked";
        
        /* api callbacks */
@@ -1648,15 +1751,327 @@ void OBJECT_OT_select_linked(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        RNA_def_enum(ot->srna, "type", prop_select_linked_types, 0, "Type", "");
+       RNA_def_enum(ot->srna, "seltype", prop_select_types, 1, "Selection", "Extend selection or clear selection then select");
+
+}
+
+/* ****** selection grouped *******/
+
+static EnumPropertyItem prop_select_grouped_types[] = {
+       {1, "CHILDREN_RECURSIVE", 0, "Children", ""}, // XXX depreceated animation system stuff...
+       {2, "CHILDREN", 0, "Immediate Children", ""},
+       {3, "PARENT", 0, "Parent", ""},
+       {4, "SIBLINGS", 0, "Siblings", "Shared Parent"},
+       {5, "TYPE", 0, "Type", "Shared object type"},
+       {6, "LAYER", 0, "Layer", "Shared layers"},
+       {7, "GROUP", 0, "Group", "Shared group"},
+       {8, "HOOK", 0, "Hook", ""},
+       {9, "PASS", 0, "Pass", "Render pass Index"},
+       {10, "COLOR", 0, "Color", "Object Color"},
+       {11, "PROPERTIES", 0, "Properties", "Game Properties"},
+       {0, NULL, 0, NULL, NULL}
+};
+
+
+static short select_grouped_children(bContext *C, Object *ob, int recursive)
+{
+       short changed = 0;
+
+       CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
+               if (ob == base->object->parent) {
+                       if (!(base->flag & SELECT)) {
+                               ED_base_object_select(base, BA_SELECT);
+                               changed = 1;
+                       }
+
+                       if (recursive)
+                               changed |= select_grouped_children(C, base->object, 1);
+               }
+       }
+       CTX_DATA_END;
+       return changed;
+}
+
+static short select_grouped_parent(bContext *C)        /* Makes parent active and de-selected OBACT */
+{
+       Scene *scene= CTX_data_scene(C);
+       View3D *v3d= CTX_wm_view3d(C);
+
+       short changed = 0;
+       Base *baspar, *basact= CTX_data_active_base(C);
+
+       if (!basact || !(basact->object->parent)) return 0; /* we know OBACT is valid */
+
+       baspar= object_in_scene(basact->object->parent, scene);
+
+       /* can be NULL if parent in other scene */
+       if(baspar && BASE_SELECTABLE(v3d, baspar)) {
+               ED_base_object_select(basact, BA_DESELECT);
+               ED_base_object_select(baspar, BA_SELECT);
+               ED_base_object_activate(C, baspar);
+               changed = 1;
+       }
+       return changed;
+}
+
+
+#define GROUP_MENU_MAX 24
+static short select_grouped_group(bContext *C, Object *ob)     /* Select objects in the same group as the active */
+{
+       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
+               ) {
+               if (object_in_group (ob, group)) {
+                       ob_groups[group_count] = group;
+                       group_count++;
+               }
+       }
+
+       if (!group_count)
+               return 0;
+
+       else if (group_count == 1) {
+               group = ob_groups[0];
+               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);
+                               changed = 1;
+                       }
+               }
+               CTX_DATA_END;
+               return changed;
+       }
+#if 0 // XXX hows this work in 2.5?
+       /* build the menu. */
+       p += sprintf(str, "Groups%%t");
+       for (i=0; i<group_count; i++) {
+               group = ob_groups[i];
+               p += sprintf (p, "|%s%%x%i", group->id.name+2, i);
+       }
+
+       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;
+}
+
+static short select_grouped_object_hooks(bContext *C, Object *ob)
+{
+       Scene *scene= CTX_data_scene(C);
+       View3D *v3d= CTX_wm_view3d(C);
+
+       short changed = 0;
+       Base *base;
+       ModifierData *md;
+       HookModifierData *hmd;
+
+       for (md = ob->modifiers.first; md; md=md->next) {
+               if (md->type==eModifierType_Hook) {
+                       hmd= (HookModifierData*) md;
+                       if (hmd->object && !(hmd->object->flag & SELECT)) {
+                               base= object_in_scene(hmd->object, scene);
+                               if (base && (BASE_SELECTABLE(v3d, base))) {
+                                       ED_base_object_select(base, BA_SELECT);
+                                       changed = 1;
+                               }
+                       }
+               }
+       }
+       return changed;
+}
+
+/* Select objects woth the same parent as the active (siblings),
+ * parent can be NULL also */
+static short select_grouped_siblings(bContext *C, Object *ob)
+{
+       short changed = 0;
+
+       CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
+               if ((base->object->parent==ob->parent)  && !(base->flag & SELECT)) {
+                       ED_base_object_select(base, BA_SELECT);
+                       changed = 1;
+               }
+       }
+       CTX_DATA_END;
+       return changed;
+}
+
+static short select_grouped_type(bContext *C, Object *ob)
+{
+       short changed = 0;
+
+       CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
+               if ((base->object->type == ob->type) && !(base->flag & SELECT)) {
+                       ED_base_object_select(base, BA_SELECT);
+                       changed = 1;
+               }
+       }
+       CTX_DATA_END;
+       return changed;
+}
 
+static short select_grouped_layer(bContext *C, Object *ob)
+{
+       char changed = 0;
+
+       CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
+               if ((base->lay & ob->lay) && !(base->flag & SELECT)) {
+                       ED_base_object_select(base, BA_SELECT);
+                       changed = 1;
+               }
+       }
+       CTX_DATA_END;
+       return changed;
+}
+
+static short select_grouped_index_object(bContext *C, Object *ob)
+{
+       char changed = 0;
+
+       CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
+               if ((base->object->index == ob->index) && !(base->flag & SELECT)) {
+                       ED_base_object_select(base, BA_SELECT);
+                       changed = 1;
+               }
+       }
+       CTX_DATA_END;
+       return changed;
 }
+
+static short select_grouped_color(bContext *C, Object *ob)
+{
+       char changed = 0;
+
+       CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
+               if (!(base->flag & SELECT) && (FloatCompare(base->object->col, ob->col, 0.005f))) {
+                       ED_base_object_select(base, BA_SELECT);
+                       changed = 1;
+               }
+       }
+       CTX_DATA_END;
+       return changed;
+}
+
+static short objects_share_gameprop(Object *a, Object *b)
+{
+       bProperty *prop;
+       /*make a copy of all its properties*/
+
+       for( prop= a->prop.first; prop; prop = prop->next ) {
+               if ( get_ob_property(b, prop->name) )
+                       return 1;
+       }
+       return 0;
+}
+
+static short select_grouped_gameprops(bContext *C, Object *ob)
+{
+       char changed = 0;
+
+       CTX_DATA_BEGIN(C, Base*, base, selectable_bases) {
+               if (!(base->flag & SELECT) && (objects_share_gameprop(base->object, ob))) {
+                       ED_base_object_select(base, BA_SELECT);
+                       changed = 1;
+               }
+       }
+       CTX_DATA_END;
+       return changed;
+}
+
+static int object_select_grouped_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       Object *ob;
+       int nr = RNA_enum_get(op->ptr, "type");
+       short changed = 0, seltype;
+
+       seltype = RNA_enum_get(op->ptr, "seltype");
+       
+       if (seltype == 0) {
+               CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
+                       ED_base_object_select(base, BA_DESELECT);
+               }
+               CTX_DATA_END;
+       }
+       
+       ob= OBACT;
+       if(ob==0){ 
+               BKE_report(op->reports, RPT_ERROR, "No Active Object");
+               return OPERATOR_CANCELLED;
+       }
+       
+       if(nr==1)               changed = select_grouped_children(C, ob, 1);
+       else if(nr==2)  changed = select_grouped_children(C, ob, 0);
+       else if(nr==3)  changed = select_grouped_parent(C);
+       else if(nr==4)  changed = select_grouped_siblings(C, ob);
+       else if(nr==5)  changed = select_grouped_type(C, ob);
+       else if(nr==6)  changed = select_grouped_layer(C, ob);
+       else if(nr==7)  changed = select_grouped_group(C, ob);
+       else if(nr==8)  changed = select_grouped_object_hooks(C, ob);
+       else if(nr==9)  changed = select_grouped_index_object(C, ob);
+       else if(nr==10) changed = select_grouped_color(C, ob);
+       else if(nr==11) changed = select_grouped_gameprops(C, ob);
+       
+       if (changed) {
+               WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, CTX_data_scene(C));
+               return OPERATOR_FINISHED;
+       }
+       
+       return OPERATOR_CANCELLED;
+}
+
+void OBJECT_OT_select_grouped(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Select Grouped";
+       ot->description = "Select all visible objects grouped by various properties.";
+       ot->idname= "OBJECT_OT_select_grouped";
+       
+       /* api callbacks */
+       ot->invoke= WM_menu_invoke;
+       ot->exec= object_select_grouped_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       RNA_def_enum(ot->srna, "type", prop_select_grouped_types, 0, "Type", "");
+       RNA_def_enum(ot->srna, "seltype", prop_select_types, 1, "Selection", "Extend selection or clear selection then select");
+
+}
+
 /* ****** selection by layer *******/
 
 static int object_select_by_layer_exec(bContext *C, wmOperator *op)
 {
        unsigned int layernum;
+       short seltype;
        
+       seltype = RNA_enum_get(op->ptr, "seltype");
        layernum = RNA_int_get(op->ptr, "layer");
+       
+       if (seltype == 0) {
+               CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
+                       ED_base_object_select(base, BA_DESELECT);
+               }
+               CTX_DATA_END;
+       }
                
        CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
                if(base->lay == (1<< (layernum -1)))
@@ -1673,7 +2088,8 @@ static int object_select_by_layer_exec(bContext *C, wmOperator *op)
 void OBJECT_OT_select_by_layer(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Selection by layer";
+       ot->name= "select by layer";
+       ot->description = "Select all visible objects on a layer.";
        ot->idname= "OBJECT_OT_select_by_layer";
        
        /* api callbacks */
@@ -1685,10 +2101,11 @@ void OBJECT_OT_select_by_layer(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        RNA_def_int(ot->srna, "layer", 1, 1, 20, "Layer", "", 1, 20);
+       RNA_def_enum(ot->srna, "seltype", prop_select_types, 1, "Selection", "Extend selection or clear selection then select");
 }
 
 /* ****** invert selection *******/
-static int object_select_invert_exec(bContext *C, wmOperator *op)
+static int object_select_inverse_exec(bContext *C, wmOperator *op)
 {
        CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
                if (base->flag & SELECT)
@@ -1704,15 +2121,16 @@ static int object_select_invert_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_select_invert(wmOperatorType *ot)
+void OBJECT_OT_select_inverse(wmOperatorType *ot)
 {
        
        /* identifiers */
-       ot->name= "Invert selection";
-       ot->idname= "OBJECT_OT_select_invert";
+       ot->name= "Select Inverse";
+       ot->description = "Invert selection of all visible objects.";
+       ot->idname= "OBJECT_OT_select_inverse";
        
        /* api callbacks */
-       ot->exec= object_select_invert_exec;
+       ot->exec= object_select_inverse_exec;
        ot->poll= ED_operator_scene_editable;
        
        /* flags */
@@ -1721,7 +2139,7 @@ void OBJECT_OT_select_invert(wmOperatorType *ot)
 }
 /* ****** (de)select All *******/
 
-static int object_de_select_all_exec(bContext *C, wmOperator *op)
+static int object_select_de_select_all_exec(bContext *C, wmOperator *op)
 {
        
        int a=0, ok=0; 
@@ -1749,15 +2167,16 @@ static int object_de_select_all_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_de_select_all(wmOperatorType *ot)
+void OBJECT_OT_select_all_toggle(wmOperatorType *ot)
 {
        
        /* identifiers */
        ot->name= "deselect all";
-       ot->idname= "OBJECT_OT_de_select_all";
+       ot->description = "(de)select all visible objects in scene.";
+       ot->idname= "OBJECT_OT_select_all_toggle";
        
        /* api callbacks */
-       ot->exec= object_de_select_all_exec;
+       ot->exec= object_select_de_select_all_exec;
        ot->poll= ED_operator_scene_editable;
        
        /* flags */
@@ -1769,11 +2188,20 @@ void OBJECT_OT_de_select_all(wmOperatorType *ot)
 static int object_select_random_exec(bContext *C, wmOperator *op)
 {      
        float percent;
+       short seltype;
+       
+       seltype = RNA_enum_get(op->ptr, "seltype");
        
+       if (seltype == 0) {
+               CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
+                       ED_base_object_select(base, BA_DESELECT);
+               }
+               CTX_DATA_END;
+       }
        percent = RNA_float_get(op->ptr, "percent");
                
        CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
-               if ((!base->flag & SELECT && BLI_frand() < percent)) {
+               if (BLI_frand() < percent) {
                                ED_base_object_select(base, BA_SELECT);
                }
        }
@@ -1787,7 +2215,8 @@ static int object_select_random_exec(bContext *C, wmOperator *op)
 void OBJECT_OT_select_random(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Random selection";
+       ot->name= "Random select";
+       ot->description = "Set select on random visible objects.";
        ot->idname= "OBJECT_OT_select_random";
        
        /* api callbacks */
@@ -1799,16 +2228,17 @@ void OBJECT_OT_select_random(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        RNA_def_float_percentage(ot->srna, "percent", 0.5f, 0.0f, 1.0f, "Percent", "percentage of objects to randomly select", 0.0001f, 1.0f);
+       RNA_def_enum(ot->srna, "seltype", prop_select_types, 1, "Selection", "Extend selection or clear selection then select");
 }
 
 /* ******** Clear object Translation *********** */
 
-static int object_clear_location_exec(bContext *C, wmOperator *op)
+static int object_location_clear_exec(bContext *C, wmOperator *op)
 {
        int armature_clear= 0;
 
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
-               if((G.f & G_WEIGHTPAINT)==0) {
+               if(!(ob->mode & OB_MODE_WEIGHT_PAINT)) {
                        if ((ob->protectflag & OB_LOCK_LOCX)==0)
                                ob->loc[0]= ob->dloc[0]= 0.0f;
                        if ((ob->protectflag & OB_LOCK_LOCY)==0)
@@ -1829,28 +2259,29 @@ static int object_clear_location_exec(bContext *C, wmOperator *op)
 }
 
 
-void OBJECT_OT_clear_location(wmOperatorType *ot)
+void OBJECT_OT_location_clear(wmOperatorType *ot)
 {
        
        /* identifiers */
-       ot->name= "Clear Object Location";
-       ot->idname= "OBJECT_OT_clear_location";
+       ot->name= "Clear Location";
+       ot->description = "Clear the object's location.";
+       ot->idname= "OBJECT_OT_location_clear";
        
        /* api callbacks */
        ot->invoke= WM_operator_confirm;
-       ot->exec= object_clear_location_exec;
+       ot->exec= object_location_clear_exec;
        ot->poll= ED_operator_object_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-static int object_clear_rotation_exec(bContext *C, wmOperator *op)
+static int object_rotation_clear_exec(bContext *C, wmOperator *op)
 {
        int armature_clear= 0;
 
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
-               if((G.f & G_WEIGHTPAINT)==0) {
+               if(!(ob->mode & OB_MODE_WEIGHT_PAINT)) {
                        /* eulers can only get cleared if they are not protected */
                        if ((ob->protectflag & OB_LOCK_ROTX)==0)
                                ob->rot[0]= ob->drot[0]= 0.0f;
@@ -1872,28 +2303,29 @@ static int object_clear_rotation_exec(bContext *C, wmOperator *op)
 }
 
 
-void OBJECT_OT_clear_rotation(wmOperatorType *ot)
+void OBJECT_OT_rotation_clear(wmOperatorType *ot)
 {
        
        /* identifiers */
-       ot->name= "Clear Object Rotation";
-       ot->idname= "OBJECT_OT_clear_rotation";
+       ot->name= "Clear Rotation";
+       ot->description = "Clear the object's rotation.";
+       ot->idname= "OBJECT_OT_rotation_clear";
        
        /* api callbacks */
        ot->invoke= WM_operator_confirm;
-       ot->exec= object_clear_rotation_exec;
+       ot->exec= object_rotation_clear_exec;
        ot->poll= ED_operator_object_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-static int object_clear_scale_exec(bContext *C, wmOperator *op)
+static int object_scale_clear_exec(bContext *C, wmOperator *op)
 {
        int armature_clear= 0;
 
        CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) {
-               if((G.f & G_WEIGHTPAINT)==0) {
+               if(!(ob->mode & OB_MODE_WEIGHT_PAINT)) {
                        if ((ob->protectflag & OB_LOCK_SCALEX)==0) {
                                ob->dsize[0]= 0.0f;
                                ob->size[0]= 1.0f;
@@ -1919,23 +2351,24 @@ static int object_clear_scale_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_clear_scale(wmOperatorType *ot)
+void OBJECT_OT_scale_clear(wmOperatorType *ot)
 {
        
        /* identifiers */
-       ot->name= "Clear Object Scale";
-       ot->idname= "OBJECT_OT_clear_scale";
+       ot->name= "Clear Scale";
+       ot->description = "Clear the object's scale.";
+       ot->idname= "OBJECT_OT_scale_clear";
        
        /* api callbacks */
        ot->invoke= WM_operator_confirm;
-       ot->exec= object_clear_scale_exec;
+       ot->exec= object_scale_clear_exec;
        ot->poll= ED_operator_object_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-static int object_clear_origin_exec(bContext *C, wmOperator *op)
+static int object_origin_clear_exec(bContext *C, wmOperator *op)
 {
        float *v1, *v3, mat[3][3];
        int armature_clear= 0;
@@ -1964,16 +2397,17 @@ static int object_clear_origin_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_clear_origin(wmOperatorType *ot)
+void OBJECT_OT_origin_clear(wmOperatorType *ot)
 {
 
        /* identifiers */
-       ot->name= "Clear Object Origin";
-       ot->idname= "OBJECT_OT_clear_origin";
+       ot->name= "Clear Origin";
+       ot->description = "Clear the object's origin.";
+       ot->idname= "OBJECT_OT_origin_clear";
        
        /* api callbacks */
        ot->invoke= WM_operator_confirm;
-       ot->exec= object_clear_origin_exec;
+       ot->exec= object_origin_clear_exec;
        ot->poll= ED_operator_object_active;
        
        /* flags */
@@ -1981,7 +2415,7 @@ void OBJECT_OT_clear_origin(wmOperatorType *ot)
 }
 
 /* ********* clear/set restrict view *********/
-static int object_clear_restrictview_exec(bContext *C, wmOperator *op)
+static int object_restrictview_clear_exec(bContext *C, wmOperator *op)
 {
        ScrArea *sa= CTX_wm_area(C);
        View3D *v3d= sa->spacedata.first;
@@ -2006,35 +2440,30 @@ static int object_clear_restrictview_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_clear_restrictview(wmOperatorType *ot)
+void OBJECT_OT_restrictview_clear(wmOperatorType *ot)
 {
        
        /* identifiers */
-       ot->name= "Clear restrict view";
-       ot->idname= "OBJECT_OT_clear_restrictview";
+       ot->name= "Clear Restrict View";
+       ot->description = "Reveal the object by setting the restrictview flag.";
+       ot->idname= "OBJECT_OT_restrictview_clear";
        
        /* api callbacks */
-       ot->invoke= WM_operator_confirm;
-       ot->exec= object_clear_restrictview_exec;
+       ot->exec= object_restrictview_clear_exec;
        ot->poll= ED_operator_view3d_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-static EnumPropertyItem prop_set_restrictview_types[] = {
-       {0, "SELECTED", "Selected", ""},
-       {1, "UNSELECTED", "Unselected ", ""},
-       {0, NULL, NULL, NULL}
-};
-
-static int object_set_restrictview_exec(bContext *C, wmOperator *op)
+static int object_restrictview_set_exec(bContext *C, wmOperator *op)
 {
        Scene *scene= CTX_data_scene(C);
        short changed = 0;
+       int unselected= RNA_boolean_get(op->ptr, "unselected");
        
        CTX_DATA_BEGIN(C, Base*, base, visible_bases) {
-               if(RNA_enum_is_equal(op->ptr, "type", "SELECTED")){
+               if(!unselected) {
                        if (base->flag & SELECT){
                                base->flag &= ~SELECT;
                                base->object->flag = base->flag;
@@ -2045,7 +2474,7 @@ static int object_set_restrictview_exec(bContext *C, wmOperator *op)
                                }
                        }
                }
-               else if (RNA_enum_is_equal(op->ptr, "type", "UNSELECTED")){
+               else {
                        if (!(base->flag & SELECT)){
                                base->object->restrictflag |= OB_RESTRICT_VIEW;
                                changed = 1;
@@ -2064,25 +2493,25 @@ static int object_set_restrictview_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_set_restrictview(wmOperatorType *ot)
+void OBJECT_OT_restrictview_set(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Set restrict view";
-       ot->idname= "OBJECT_OT_set_restrictview";
+       ot->name= "Set Restrict View";
+       ot->description = "Hide the object by setting the restrictview flag.";
+       ot->idname= "OBJECT_OT_restrictview_set";
        
        /* api callbacks */
-       ot->invoke= WM_menu_invoke;
-       ot->exec= object_set_restrictview_exec;
+       ot->exec= object_restrictview_set_exec;
        ot->poll= ED_operator_view3d_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
-       RNA_def_enum(ot->srna, "type", prop_set_restrictview_types, 0, "Type", "");
+       RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected objects.");
        
 }
 /* ************* Slow Parent ******************* */
-static int object_set_slowparent_exec(bContext *C, wmOperator *op)
+static int object_slowparent_set_exec(bContext *C, wmOperator *op)
 {
 
        CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
@@ -2100,23 +2529,24 @@ static int object_set_slowparent_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_set_slowparent(wmOperatorType *ot)
+void OBJECT_OT_slowparent_set(wmOperatorType *ot)
 {
        
        /* identifiers */
        ot->name= "Set Slow Parent";
-       ot->idname= "OBJECT_OT_set_slow_parent";
+       ot->description = "Set the object's slow parent.";
+       ot->idname= "OBJECT_OT_slow_parent_set";
        
        /* api callbacks */
        ot->invoke= WM_operator_confirm;
-       ot->exec= object_set_slowparent_exec;
+       ot->exec= object_slowparent_set_exec;
        ot->poll= ED_operator_view3d_active;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-static int object_clear_slowparent_exec(bContext *C, wmOperator *op)
+static int object_slowparent_clear_exec(bContext *C, wmOperator *op)
 {
        Scene *scene= CTX_data_scene(C);
 
@@ -2140,16 +2570,17 @@ static int object_clear_slowparent_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_clear_slowparent(wmOperatorType *ot)
+void OBJECT_OT_slowparent_clear(wmOperatorType *ot)
 {
        
        /* identifiers */
        ot->name= "Clear Slow Parent";
-       ot->idname= "OBJECT_OT_clear_slow_parent";
+       ot->description = "Clear the object's slow parent.";
+       ot->idname= "OBJECT_OT_slow_parent_clear";
        
        /* api callbacks */
        ot->invoke= WM_operator_confirm;
-       ot->exec= object_clear_slowparent_exec;
+       ot->exec= object_slowparent_clear_exec;
        ot->poll= ED_operator_view3d_active;
        
        /* flags */
@@ -2174,8 +2605,9 @@ void make_vertex_parent(Scene *scene, Object *obedit, View3D *v3d)
        
        if(obedit->type==OB_MESH) {
                Mesh *me= obedit->data;
-               
-               eve= me->edit_mesh->verts.first;
+               EditMesh *em = BKE_mesh_get_editmesh(me);
+
+               eve= em->verts.first;
                while(eve) {
                        if(eve->f & 1) {
                                if(v1==0) v1= nr;
@@ -2187,6 +2619,8 @@ void make_vertex_parent(Scene *scene, Object *obedit, View3D *v3d)
                        nr++;
                        eve= eve->next;
                }
+
+               BKE_mesh_end_editmesh(me, em);
        }
        else if(ELEM(obedit->type, OB_SURF, OB_CURVE)) {
                ListBase *editnurb= curve_get_editcurve(obedit);
@@ -2296,68 +2730,128 @@ void make_vertex_parent(Scene *scene, Object *obedit, View3D *v3d)
        DAG_scene_sort(scene);
 }
 
-static Object *group_objects_menu(Group *group)
+
+/* ******************** make proxy operator *********************** */
+
+/* present menu listing the possible objects within the group to proxify */
+static void proxy_group_objects_menu (bContext *C, wmOperator *op, Object *ob, Group *group)
 {
+       uiPopupMenu *pup;
+       uiLayout *layout;
        GroupObject *go;
-       int len= 0;
-       short a, nr;
-       char *str;
-               
-       for(go= group->gobject.first; go; go= go->next) {
-               if(go->ob)
-                       len++;
+       int len=0;
+       
+       /* check if there are any objects within the group to assign for */
+       for (go= group->gobject.first; go; go= go->next) {
+               if (go->ob) len++;
        }
-       if(len==0) return NULL;
+       if (len==0) return;
        
-       str= MEM_callocN(40+32*len, "menu");
+       /* now create the menu to draw */
+       pup= uiPupMenuBegin(C, "Make Proxy For:", 0);
+       layout= uiPupMenuLayout(pup);
        
-       strcpy(str, "Make Proxy for: %t");
-       a= strlen(str);
-       for(nr=1, go= group->gobject.first; go; go= go->next, nr++) {
-               a+= sprintf(str+a, "|%s %%x%d", go->ob->id.name+2, nr);
+       for (go= group->gobject.first; go; go= go->next) {
+               if (go->ob) {
+                       PointerRNA props_ptr;
+                       
+                       /* create operator properties, and assign the relevant pointers to that, 
+                        * and add a menu entry which uses these props 
+                        */
+                       WM_operator_properties_create(&props_ptr, op->idname);
+                               RNA_string_set(&props_ptr, "object", go->ob->id.name+2);
+                               RNA_string_set(&props_ptr, "group_object", go->ob->id.name+2);
+                       uiItemFullO(layout, go->ob->id.name+2, 0, op->idname, props_ptr.data, WM_OP_EXEC_REGION_WIN);
+               }
        }
        
-       a= pupmenu_col(str, 20);
-       MEM_freeN(str);
-       if(a>0) {
-               go= BLI_findlink(&group->gobject, a-1);
-               return go->ob;
-       }
-       return NULL;
+       /* display the menu, and be done */
+       uiPupMenuEnd(C, pup);
 }
 
-
-/* adds empty object to become local replacement data of a library-linked object */
-void make_proxy(Scene *scene)
+/* set the object to proxify */
+static int make_proxy_invoke (bContext *C, wmOperator *op, wmEvent *evt)
 {
-       Object *ob= OBACT;
-       Object *gob= NULL;
-       
-       if(scene->id.lib) return;
-       if(ob==NULL) return;
-       
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= CTX_data_active_object(C);
        
-       if(ob->dup_group && ob->dup_group->id.lib) {
-               gob= ob;
+       /* sanity checks */
+       if (!scene || scene->id.lib || !ob)
+               return OPERATOR_CANCELLED;
+               
+       /* Get object to work on - use a menu if we need to... */
+       if (ob->dup_group && ob->dup_group->id.lib) {
                /* gives menu with list of objects in group */
-               ob= group_objects_menu(ob->dup_group);
+               proxy_group_objects_menu(C, op, ob, ob->dup_group);
        }
-       else if(ob->id.lib) {
-               if(okee("Make Proxy Object")==0)
-               return;
+       else if (ob->id.lib) {
+               uiPopupMenu *pup= uiPupMenuBegin(C, "OK?", ICON_QUESTION);
+               uiLayout *layout= uiPupMenuLayout(pup);
+               PointerRNA props_ptr;
+               
+               /* create operator properties, and assign the relevant pointers to that, 
+                * and add a menu entry which uses these props 
+                */
+               WM_operator_properties_create(&props_ptr, op->idname);
+                       RNA_string_set(&props_ptr, "object", ob->id.name+2);
+               uiItemFullO(layout, op->type->name, 0, op->idname, props_ptr.data, WM_OP_EXEC_REGION_WIN);
+               
+               /* present the menu and be done... */
+               uiPupMenuEnd(C, pup);
        }
        else {
-               error("Can only make proxy for a referenced object or group");
-               return;
+               /* error.. cannot continue */
+               BKE_report(op->reports, RPT_ERROR, "Can only make proxy for a referenced object or group");
        }
        
-       if(ob) {
+       /* this invoke just calls another instance of this operator... */
+       return OPERATOR_CANCELLED;
+}
+
+static int make_proxy_exec (bContext *C, wmOperator *op)
+{
+       Object *ob=NULL, *gob=NULL;
+       Scene *scene= CTX_data_scene(C);
+       char ob_name[21], gob_name[21];
+       
+       /* get object and group object
+        *      - firstly names
+        *      - then pointers from context 
+        */
+       RNA_string_get(op->ptr, "object", ob_name);
+       RNA_string_get(op->ptr, "group_object", gob_name);
+       
+       if (gob_name[0]) {
+               Group *group;
+               GroupObject *go;
+               
+               /* active object is group object... */
+               // FIXME: we should get the nominated name instead
+               gob= CTX_data_active_object(C);
+               group= gob->dup_group;
+               
+               /* find the object to affect */
+               for (go= group->gobject.first; go; go= go->next) {
+                       if ((go->ob) && strcmp(go->ob->id.name+2, gob_name)==0) {
+                               ob= go->ob;
+                               break;
+                       }
+               }
+       }
+       else {
+               /* just use the active object for now */
+               // FIXME: we should get the nominated name instead
+               ob= CTX_data_active_object(C);
+       }
+       
+       if (ob) {
                Object *newob;
                Base *newbase, *oldbase= BASACT;
                char name[32];
                
+               /* Add new object for the proxy */
                newob= add_object(scene, OB_EMPTY);
-               if(gob)
+               if (gob)
                        strcpy(name, gob->id.name+2);
                else
                        strcpy(name, ob->id.name+2);
@@ -2370,40 +2864,76 @@ void make_proxy(Scene *scene)
                newob->lay= newbase->lay;
                
                /* remove base, leave user count of object, it gets linked in object_make_proxy */
-               if(gob==NULL) {
+               if (gob==NULL) {
                        BLI_remlink(&scene->base, oldbase);
                        MEM_freeN(oldbase);
-               }               
+               }
+               
                object_make_proxy(newob, ob, gob);
                
+               /* depsgraph flushes are needed for the new data */
                DAG_scene_sort(scene);
                DAG_object_flush_update(scene, newob, OB_RECALC);
+               
+               WM_event_add_notifier(C, NC_OBJECT, NULL);
+       }
+       else {
+               BKE_report(op->reports, RPT_ERROR, "No object to make proxy for");
+               return OPERATOR_CANCELLED;
        }
+       
+       return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_proxy_make (wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Make Proxy";
+       ot->idname= "OBJECT_OT_proxy_make";
+       ot->description= "Add empty object to become local replacement data of a library-linked object";
+       
+       /* callbacks */
+       ot->invoke= make_proxy_invoke;
+       ot->exec= make_proxy_exec;
+       ot->poll= ED_operator_object_active;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* properties */
+       RNA_def_string(ot->srna, "object", "", 19, "Proxy Object", "Name of lib-linked/grouped object to make a proxy for.");
+       RNA_def_string(ot->srna, "group_object", "", 19, "Group Object", "Name of group instancer (if applicable).");
 }
 
 /* ******************** make parent operator *********************** */
 
-#define PAR_OBJECT             0
-#define PAR_ARMATURE   1
-#define PAR_BONE               2
-#define PAR_CURVE              3
-#define PAR_FOLLOW             4
-#define PAR_PATH_CONST 5
-#define PAR_LATTICE            6
-#define PAR_VERTEX             7
-#define PAR_TRIA               8
+#define PAR_OBJECT                             0
+#define PAR_ARMATURE                   1
+#define PAR_ARMATURE_NAME              2
+#define PAR_ARMATURE_ENVELOPE  3
+#define PAR_ARMATURE_AUTO              4
+#define PAR_BONE                               5
+#define PAR_CURVE                              6
+#define PAR_FOLLOW                             7
+#define PAR_PATH_CONST                 8
+#define PAR_LATTICE                            9
+#define PAR_VERTEX                             10
+#define PAR_TRIA                               11
 
 static EnumPropertyItem prop_make_parent_types[] = {
-       {PAR_OBJECT, "OBJECT", "Object", ""},
-       {PAR_ARMATURE, "ARMATURE", "Armature Deform", ""},
-       {PAR_BONE, "BONE", "Bone", ""},
-       {PAR_CURVE, "CURVE", "Curve Deform", ""},
-       {PAR_FOLLOW, "FOLLOW", "Follow Path", ""},
-       {PAR_PATH_CONST, "PATH_CONST", "Path Constraint", ""},
-       {PAR_LATTICE, "LATTICE", "Lattice Deform", ""},
-       {PAR_VERTEX, "VERTEX", "Vertex", ""},
-       {PAR_TRIA, "TRIA", "Triangle", ""},
-       {0, NULL, NULL, NULL}
+       {PAR_OBJECT, "OBJECT", 0, "Object", ""},
+       {PAR_ARMATURE, "ARMATURE", 0, "Armature Deform", ""},
+       {PAR_ARMATURE_NAME, "ARMATURE_NAME", 0, "   With Empty Groups", ""},
+       {PAR_ARMATURE_AUTO, "ARMATURE_AUTO", 0, "   With Automatic Weights", ""},
+       {PAR_ARMATURE_ENVELOPE, "ARMATURE_ENVELOPE", 0, "   With Envelope Weights", ""},
+       {PAR_BONE, "BONE", 0, "Bone", ""},
+       {PAR_CURVE, "CURVE", 0, "Curve Deform", ""},
+       {PAR_FOLLOW, "FOLLOW", 0, "Follow Path", ""},
+       {PAR_PATH_CONST, "PATH_CONST", 0, "Path Constraint", ""},
+       {PAR_LATTICE, "LATTICE", 0, "Lattice Deform", ""},
+       {PAR_VERTEX, "VERTEX", 0, "Vertex", ""},
+       {PAR_TRIA, "TRIA", 0, "Triangle", ""},
+       {0, NULL, 0, NULL, NULL}
 };
 
 static int test_parent_loop(Object *par, Object *ob)
@@ -2416,13 +2946,30 @@ static int test_parent_loop(Object *par, Object *ob)
        return test_parent_loop(par->parent, ob);
 }
 
+void ED_object_parent(Object *ob, Object *par, int type, const char *substr)
+{
+       if(!par || test_parent_loop(par, ob)) {
+               ob->parent= NULL;
+               ob->partype= PAROBJECT;
+               ob->parsubstr[0]= 0;
+               return;
+       }
+
+       /* this could use some more checks */
+
+       ob->parent= par;
+       ob->partype &= ~PARTYPE;
+       ob->partype |= type;
+       BLI_strncpy(ob->parsubstr, substr, sizeof(ob->parsubstr));
+}
 
-static int make_parent_exec(bContext *C, wmOperator *op)
+static int parent_set_exec(bContext *C, wmOperator *op)
 {
        Scene *scene= CTX_data_scene(C);
        Object *par= CTX_data_active_object(C);
        bPoseChannel *pchan= NULL;
        int partype= RNA_enum_get(op->ptr, "type");
+       int pararm= ELEM4(partype, PAR_ARMATURE, PAR_ARMATURE_NAME, PAR_ARMATURE_ENVELOPE, PAR_ARMATURE_AUTO);
        
        par->recalc |= OB_RECALC_OB;
        
@@ -2494,24 +3041,20 @@ static int make_parent_exec(bContext *C, wmOperator *op)
                                        ob->loc[0] = vec[0];
                                        ob->loc[1] = vec[1];
                                }
-                               else if(partype==PAR_ARMATURE && ob->type==OB_MESH && par->type == OB_ARMATURE) {
+                               else if(pararm && ob->type==OB_MESH && par->type == OB_ARMATURE) {
+                                       if(partype == PAR_ARMATURE_NAME)
+                                               create_vgroups_from_armature(scene, ob, par, ARM_GROUPS_NAME);
+                                       else if(partype == PAR_ARMATURE_ENVELOPE)
+                                               create_vgroups_from_armature(scene, ob, par, ARM_GROUPS_ENVELOPE);
+                                       else if(partype == PAR_ARMATURE_AUTO)
+                                               create_vgroups_from_armature(scene, ob, par, ARM_GROUPS_AUTO);
                                        
-                                       if(1) {
-                                               /* Prompt the user as to whether he wants to
-                                               * add some vertex groups based on the bones
-                                               * in the parent armature.
-                                               */
-                                               create_vgroups_from_armature(scene, ob, par);
-                                               
-                                               /* get corrected inverse */
-                                               ob->partype= PAROBJECT;
-                                               what_does_parent(scene, ob, &workob);
-                                               
-                                               ob->partype= PARSKEL;
-                                       }
-                                       else
-                                               what_does_parent(scene, ob, &workob);
+                                       /* get corrected inverse */
+                                       ob->partype= PAROBJECT;
+                                       what_does_parent(scene, ob, &workob);
                                        
+                                       ob->partype= PARSKEL;
+
                                        Mat4Invert(ob->parentinv, workob.obmat);
                                }
                                else {
@@ -2522,7 +3065,7 @@ static int make_parent_exec(bContext *C, wmOperator *op)
                                
                                ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA;
                                
-                               if( ELEM3(partype, PAR_CURVE, PAR_ARMATURE, PAR_LATTICE) )
+                               if( ELEM(partype, PAR_CURVE, PAR_LATTICE) || pararm )
                                        ob->partype= PARSKEL; /* note, dna define, not operator property */
                                else
                                        ob->partype= PAROBJECT; /* note, dna define, not operator property */
@@ -2532,70 +3075,77 @@ static int make_parent_exec(bContext *C, wmOperator *op)
        CTX_DATA_END;
        
        DAG_scene_sort(CTX_data_scene(C));
-       ED_anim_dag_flush_update(C);    
+       ED_anim_dag_flush_update(C);
+       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
        
        return OPERATOR_FINISHED;
 }
 
-static int make_parent_invoke(bContext *C, wmOperator *op, wmEvent *event)
+static int parent_set_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        Object *ob= CTX_data_active_object(C);
-       uiMenuItem *head= uiPupMenuBegin("Make Parent To", 0);
+       uiPopupMenu *pup= uiPupMenuBegin(C, "Set Parent To", 0);
+       uiLayout *layout= uiPupMenuLayout(pup);
        
-       uiMenuContext(head, WM_OP_EXEC_DEFAULT);
-       uiMenuItemEnumO(head, "", 0, "OBJECT_OT_make_parent", "type", PAR_OBJECT);
+       uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT);
+       uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_OBJECT);
        
        /* ob becomes parent, make the associated menus */
        if(ob->type==OB_ARMATURE) {
-               uiMenuItemEnumO(head, "", 0, "OBJECT_OT_make_parent", "type", PAR_ARMATURE);
-               uiMenuItemEnumO(head, "", 0, "OBJECT_OT_make_parent", "type", PAR_BONE);
+               uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_ARMATURE);
+               uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_ARMATURE_NAME);
+               uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_ARMATURE_ENVELOPE);
+               uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_ARMATURE_AUTO);
+               uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_BONE);
        }
        else if(ob->type==OB_CURVE) {
-               uiMenuItemEnumO(head, "", 0, "OBJECT_OT_make_parent", "type", PAR_CURVE);
-               uiMenuItemEnumO(head, "", 0, "OBJECT_OT_make_parent", "type", PAR_FOLLOW);
-               uiMenuItemEnumO(head, "", 0, "OBJECT_OT_make_parent", "type", PAR_PATH_CONST);
+               uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_CURVE);
+               uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_FOLLOW);
+               uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_PATH_CONST);
        }
        else if(ob->type == OB_LATTICE) {
-               uiMenuItemEnumO(head, "", 0, "OBJECT_OT_make_parent", "type", PAR_LATTICE);
+               uiItemEnumO(layout, NULL, 0, "OBJECT_OT_parent_set", "type", PAR_LATTICE);
        }
        
-       uiPupMenuEnd(C, head);
+       uiPupMenuEnd(C, pup);
        
        return OPERATOR_CANCELLED;
 }
 
 
-void OBJECT_OT_make_parent(wmOperatorType *ot)
+void OBJECT_OT_parent_set(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Make parent";
-       ot->idname= "OBJECT_OT_make_parent";
+       ot->name= "Make Parent";
+       ot->description = "Set the object's parenting.";
+       ot->idname= "OBJECT_OT_parent_set";
        
        /* api callbacks */
-       ot->invoke= make_parent_invoke;
-       ot->exec= make_parent_exec;
+       ot->invoke= parent_set_invoke;
+       ot->exec= parent_set_exec;
        
        ot->poll= ED_operator_object_active;
        
        /* flags */
-       ot->flag= 0;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        RNA_def_enum(ot->srna, "type", prop_make_parent_types, 0, "Type", "");
 }
 
 /* *** make track ***** */
 static EnumPropertyItem prop_make_track_types[] = {
-       {1, "TRACKTO", "TrackTo Constraint", ""},
-       {2, "LOCKTRACK", "LockTrack Constraint", ""},
-       {3, "OLDTRACK", "Old Track", ""},
-       {0, NULL, NULL, NULL}
+       {1, "TRACKTO", 0, "TrackTo Constraint", ""},
+       {2, "LOCKTRACK", 0, "LockTrack Constraint", ""},
+       {3, "OLDTRACK", 0, "Old Track", ""},
+       {0, NULL, 0, NULL, NULL}
 };
 
-static int make_track_exec(bContext *C, wmOperator *op)
+static int track_set_exec(bContext *C, wmOperator *op)
 {
        Scene *scene= CTX_data_scene(C);
+       int type= RNA_enum_get(op->ptr, "type");
                
-       if(RNA_enum_is_equal(op->ptr, "type", "TRACKTO")){
+       if(type == 1) {
                bConstraint *con;
                bTrackToConstraint *data;
 
@@ -2619,7 +3169,7 @@ static int make_track_exec(bContext *C, wmOperator *op)
                }
                CTX_DATA_END;
        }
-       else if(RNA_enum_is_equal(op->ptr, "type", "LOCKTRACK")){
+       else if(type == 2) {
                bConstraint *con;
                bLockTrackConstraint *data;
 
@@ -2643,7 +3193,7 @@ static int make_track_exec(bContext *C, wmOperator *op)
                }
                CTX_DATA_END;
        }
-       else if(RNA_enum_is_equal(op->ptr, "type", "OLDTRACK")){
+       else {
                CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
                        if(base!=BASACT) {
                                base->object->track= BASACT->object;
@@ -2658,15 +3208,16 @@ static int make_track_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_make_track(wmOperatorType *ot)
+void OBJECT_OT_track_set(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Make Track";
-       ot->idname= "OBJECT_OT_make_track";
+       ot->description = "Make the object track another object, either by constraint or old way or locked track.";
+       ot->idname= "OBJECT_OT_track_set";
        
        /* api callbacks */
        ot->invoke= WM_menu_invoke;
-       ot->exec= make_track_exec;
+       ot->exec= track_set_exec;
        
        ot->poll= ED_operator_scene_editable;
        
@@ -2720,7 +3271,7 @@ static void make_object_duplilist_real(Scene *scene, View3D *v3d, Base *base)
 }
 
 
-static int object_make_dupli_real_exec(bContext *C, wmOperator *op)
+static int object_duplicates_make_real_exec(bContext *C, wmOperator *op)
 {
        Scene *scene= CTX_data_scene(C);
        ScrArea *sa= CTX_wm_area(C);
@@ -2740,16 +3291,17 @@ static int object_make_dupli_real_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_make_dupli_real(wmOperatorType *ot)
+void OBJECT_OT_duplicates_make_real(wmOperatorType *ot)
 {
        
        /* identifiers */
-       ot->name= "Make Dupli Real";
-       ot->idname= "OBJECT_OT_make_dupli_real";
+       ot->name= "Make Duplicates Real";
+       ot->description = "Make dupli objects attached to this object real.";
+       ot->idname= "OBJECT_OT_duplicates_make_real";
        
        /* api callbacks */
        ot->invoke= WM_operator_confirm;
-       ot->exec= object_make_dupli_real_exec;
+       ot->exec= object_duplicates_make_real_exec;
        
        ot->poll= ED_operator_scene_editable;
        
@@ -2759,14 +3311,14 @@ void OBJECT_OT_make_dupli_real(wmOperatorType *ot)
 /* ******************* Set Object Center ********************** */
 
 static EnumPropertyItem prop_set_center_types[] = {
-       {0, "CENTER", "ObData to Center", "Move object data around Object center"},
-       {1, "CENTERNEW", "Center New", "Move Object center to center of object data"},
-       {2, "CENTERCURSOR", "Center Cursor", "Move Object Center to position of the 3d cursor"},
-       {0, NULL, NULL, NULL}
+       {0, "CENTER", 0, "ObData to Center", "Move object data around Object center"},
+       {1, "CENTERNEW", 0, "Center New", "Move Object center to center of object data"},
+       {2, "CENTERCURSOR", 0, "Center Cursor", "Move Object Center to position of the 3d cursor"},
+       {0, NULL, 0, NULL, NULL}
 };
 
 /* 0 == do center, 1 == center new, 2 == center cursor */
-static int object_set_center_exec(bContext *C, wmOperator *op)
+static int object_center_set_exec(bContext *C, wmOperator *op)
 {
        Scene *scene= CTX_data_scene(C);
        ScrArea *sa= CTX_wm_area(C);
@@ -2803,8 +3355,9 @@ static int object_set_center_exec(bContext *C, wmOperator *op)
        
                if(obedit->type==OB_MESH) {
                        Mesh *me= obedit->data;
-                       
-                       for(eve= me->edit_mesh->verts.first; eve; eve= eve->next) {
+                       EditMesh *em = BKE_mesh_get_editmesh(me);
+
+                       for(eve= em->verts.first; eve; eve= eve->next) {
                                if(v3d->around==V3D_CENTROID) {
                                        total++;
                                        VECADD(cent, cent, eve->co);
@@ -2823,13 +3376,14 @@ static int object_set_center_exec(bContext *C, wmOperator *op)
                                cent[2]= (min[2]+max[2])/2.0f;
                        }
                        
-                       for(eve= me->edit_mesh->verts.first; eve; eve= eve->next) {
+                       for(eve= em->verts.first; eve; eve= eve->next) {
                                VecSubf(eve->co, eve->co, cent);                        
                        }
                        
-                       recalc_editnormals(me->edit_mesh);
+                       recalc_editnormals(em);
                        tot_change++;
                        DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
+                       BKE_mesh_end_editmesh(me, em);
                }
        }
        
@@ -2989,7 +3543,7 @@ static int object_set_center_exec(bContext *C, wmOperator *op)
                                        
                                        nu= nu1;
                                        while(nu) {
-                                               if( (nu->type & 7)==1) {
+                                               if( (nu->type & 7)==CU_BEZIER) {
                                                        a= nu->pntsu;
                                                        while (a--) {
                                                                VecSubf(nu->bezt[a].vec[0], nu->bezt[a].vec[0], cent);
@@ -3089,15 +3643,16 @@ static int object_set_center_exec(bContext *C, wmOperator *op)
        
        return OPERATOR_FINISHED;
 }
-void OBJECT_OT_set_center(wmOperatorType *ot)
+void OBJECT_OT_center_set(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Set Center";
-       ot->idname= "OBJECT_OT_set_center";
+       ot->description = "Set the object's center, by either moving the data, or set to center of data, or use 3d cursor";
+       ot->idname= "OBJECT_OT_center_set";
        
        /* api callbacks */
        ot->invoke= WM_menu_invoke;
-       ot->exec= object_set_center_exec;
+       ot->exec= object_center_set_exec;
        
        ot->poll= ED_operator_view3d_active;
        
@@ -3112,7 +3667,6 @@ void ED_object_exit_editmode(bContext *C, int flag)
 {
        Scene *scene= CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
-       Object *ob;
        int freedata = flag & EM_FREEDATA;
        
        if(obedit==NULL) return;
@@ -3132,9 +3686,13 @@ void ED_object_exit_editmode(bContext *C, int flag)
                }
                load_editMesh(scene, obedit);
                
-               if(freedata) free_editMesh(me->edit_mesh);
+               if(freedata) {
+                       free_editMesh(me->edit_mesh);
+                       MEM_freeN(me->edit_mesh);
+                       me->edit_mesh= NULL;
+               }
                
-               if(G.f & G_WEIGHTPAINT)
+               if(obedit->restore_mode & OB_MODE_WEIGHT_PAINT)
                        mesh_octree_table(obedit, NULL, NULL, 'e');
        }
        else if (obedit->type==OB_ARMATURE) {   
@@ -3155,27 +3713,27 @@ void ED_object_exit_editmode(bContext *C, int flag)
                if(freedata) free_editLatt(obedit);
        }
        else if(obedit->type==OB_MBALL) {
-//             extern ListBase editelems;
-//             load_editMball();
-//             if(freedata) BLI_freelistN(&editelems);
+               load_editMball(obedit);
+               if(freedata) free_editMball(obedit);
        }
+
+       /* freedata only 0 now on file saves */
+       if(freedata) {
+               /* for example; displist make is different in editmode */
+               scene->obedit= NULL; // XXX for context
+               
+               /* also flush ob recalc, doesn't take much overhead, but used for particles */
+               DAG_object_flush_update(scene, obedit, OB_RECALC_OB|OB_RECALC_DATA);
        
-       ob= obedit;
-       
-       /* for example; displist make is different in editmode */
-       if(freedata) obedit= NULL;
-       scene->obedit= obedit; // XXX for context
-       
-       /* also flush ob recalc, doesn't take much overhead, but used for particles */
-       DAG_object_flush_update(scene, ob, OB_RECALC_OB|OB_RECALC_DATA);
-       
-       if(obedit==NULL) // XXX && (flag & EM_FREEUNDO)) 
                ED_undo_push(C, "Editmode");
        
-       if(flag & EM_WAITCURSOR) waitcursor(0);
+               if(flag & EM_WAITCURSOR) waitcursor(0);
        
-       WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, scene);
+               WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, scene);
+       }
 
+       obedit->mode &= ~OB_MODE_EDIT;
+       ED_object_toggle_modes(C, obedit->restore_mode);
 }
 
 
@@ -3183,7 +3741,7 @@ void ED_object_enter_editmode(bContext *C, int flag)
 {
        Scene *scene= CTX_data_scene(C);
        Base *base= CTX_data_active_base(C);
-       Object *ob= base->object;
+       Object *ob;
        ScrArea *sa= CTX_wm_area(C);
        View3D *v3d= NULL;
        int ok= 0;
@@ -3191,11 +3749,15 @@ void ED_object_enter_editmode(bContext *C, int flag)
        if(scene->id.lib) return;
        if(base==NULL) return;
        
-       if(sa->spacetype==SPACE_VIEW3D)
+       if(sa && sa->spacetype==SPACE_VIEW3D)
                v3d= sa->spacedata.first;
        
-       if((v3d==NULL || (base->lay & v3d->lay))==0) return;
-       
+       if(v3d && (base->lay & v3d->lay)==0) return;
+       else if(!v3d && (base->lay & scene->lay)==0) return;
+
+       ob = base->object;
+
+       if(ob==NULL) return;
        if(ob->data==NULL) return;
        
        if (object_data_is_libdata(ob)) {
@@ -3205,7 +3767,10 @@ void ED_object_enter_editmode(bContext *C, int flag)
        
        if(flag & EM_WAITCURSOR) waitcursor(1);
 
-       ED_view3d_exit_paint_modes(C);
+       ob->restore_mode = ob->mode;
+       ED_object_toggle_modes(C, ob->mode);
+
+       ob->mode |= OB_MODE_EDIT;
        
        if(ob->type==OB_MESH) {
                Mesh *me= ob->data;
@@ -3245,14 +3810,15 @@ void ED_object_enter_editmode(bContext *C, int flag)
                scene->obedit= ob; // XXX for context
                ok= 1;
                make_editText(ob);
+
                WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_TEXT, scene);
        }
        else if(ob->type==OB_MBALL) {
                scene->obedit= ob; // XXX for context
-//             ok= 1;
-// XXX         make_editMball();
+               ok= 1;
+               make_editMball(ob);
+
                WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_EDITMODE_MBALL, scene);
-               
        }
        else if(ob->type==OB_LATTICE) {
                scene->obedit= ob; // XXX for context
@@ -3277,10 +3843,11 @@ void ED_object_enter_editmode(bContext *C, int flag)
                WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, scene);
        }
        
+       if(flag & EM_DO_UNDO) ED_undo_push(C, "Enter Editmode");
        if(flag & EM_WAITCURSOR) waitcursor(0);
 }
 
-static int toggle_editmode_exec(bContext *C, wmOperator *op)
+static int editmode_toggle_exec(bContext *C, wmOperator *op)
 {
        
        if(!CTX_data_edit_object(C))
@@ -3291,17 +3858,28 @@ static int toggle_editmode_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
+static int editmode_toggle_poll(bContext *C)
+{
+       Object *ob = CTX_data_active_object(C);
+
+       return ob && (ob->type == OB_MESH || ob->type == OB_ARMATURE ||
+                     ob->type == OB_FONT || ob->type == OB_MBALL ||
+                     ob->type == OB_LATTICE || ob->type == OB_SURF ||
+                     ob->type == OB_CURVE);
+}
+
 void OBJECT_OT_editmode_toggle(wmOperatorType *ot)
 {
        
        /* identifiers */
        ot->name= "Toggle Editmode";
+       ot->description = "Toggle object's editmode.";
        ot->idname= "OBJECT_OT_editmode_toggle";
        
        /* api callbacks */
-       ot->exec= toggle_editmode_exec;
+       ot->exec= editmode_toggle_exec;
        
-       ot->poll= ED_operator_object_active;
+       ot->poll= editmode_toggle_poll;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -3309,6 +3887,42 @@ void OBJECT_OT_editmode_toggle(wmOperatorType *ot)
 
 /* *************************** */
 
+static int posemode_exec(bContext *C, wmOperator *op)
+{
+       Base *base= CTX_data_active_base(C);
+       
+       if(base->object->type==OB_ARMATURE) {
+               if(base->object==CTX_data_edit_object(C)) {
+                       ED_object_exit_editmode(C, EM_FREEDATA);
+                       ED_armature_enter_posemode(C, base);
+               }
+               else if(base->object->mode & OB_MODE_POSE)
+                       ED_armature_exit_posemode(C, base);
+               else
+                       ED_armature_enter_posemode(C, base);
+               
+               return OPERATOR_FINISHED;
+       }
+       
+       return OPERATOR_PASS_THROUGH;
+}
+
+void OBJECT_OT_posemode_toggle(wmOperatorType *ot) 
+{
+       /* identifiers */
+       ot->name= "Toggle Pose Mode";
+       ot->idname= "OBJECT_OT_posemode_toggle";
+       ot->description= "Enables or disables posing/selecting bones";
+       
+       /* api callbacks */
+       ot->exec= posemode_exec;
+       ot->poll= ED_operator_object_active;
+       
+       /* flag */
+       ot->flag= OPTYPE_REGISTER;
+}
+
+/* *********************** */
 
 void check_editmode(int type)
 {
@@ -3499,18 +4113,16 @@ void special_editmenu(Scene *scene, View3D *v3d)
 // XXX static short numcuts= 2;
        Object *ob= OBACT;
        Object *obedit= NULL; // XXX
-       float fac;
-       int nr,ret;
-       short randfac;
+       int nr,ret=0;
        
        if(ob==NULL) return;
        
        if(obedit==NULL) {
                
-               if(ob->flag & OB_POSEMODE) {
+               if(ob->mode & OB_MODE_POSE) {
 // XXX                 pose_special_editmenu();
                }
-               else if(FACESEL_PAINT_TEST) {
+               else if(paint_facesel_test(ob)) {
                        Mesh *me= get_mesh(ob);
                        MTFace *tface;
                        MFace *mface;
@@ -3556,7 +4168,7 @@ void special_editmenu(Scene *scene, View3D *v3d)
                        }
                        DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
                }
-               else if(G.f & G_VERTEXPAINT) {
+               else if(ob->mode & OB_MODE_VERTEX_PAINT) {
                        Mesh *me= get_mesh(ob);
                        
                        if(me==0 || (me->mcol==NULL && me->mtface==NULL) ) return;
@@ -3569,17 +4181,17 @@ void special_editmenu(Scene *scene, View3D *v3d)
                                DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
                        }
                }
-               else if(G.f & G_WEIGHTPAINT) {
+               else if(ob->mode & OB_MODE_WEIGHT_PAINT) {
                        Object *par= modifiers_isDeformedByArmature(ob);
 
-                       if(par && (par->flag & OB_POSEMODE)) {
+                       if(par && (par->mode & OB_MODE_POSE)) {
                                nr= pupmenu("Specials%t|Apply Bone Envelopes to Vertex Groups %x1|Apply Bone Heat Weights to Vertex Groups %x2");
 
 // XXX                         if(nr==1 || nr==2)
 // XXX                                 pose_adds_vgroups(ob, (nr == 2));
                        }
                }
-               else if(G.f & G_PARTICLEEDIT) {
+               else if(ob->mode & OB_MODE_PARTICLE_EDIT) {
 #if 0
                        // XXX
                        ParticleSystem *psys = PE_get_current(ob);
@@ -3588,7 +4200,7 @@ void special_editmenu(Scene *scene, View3D *v3d)
                        if(!psys)
                                return;
 
-                       if(scene->selectmode & SCE_SELECT_POINT)
+                       if(pset->selectmode & SCE_SELECT_POINT)
                                nr= pupmenu("Specials%t|Rekey%x1|Subdivide%x2|Select First%x3|Select Last%x4|Remove Doubles%x5");
                        else
                                nr= pupmenu("Specials%t|Rekey%x1|Remove Doubles%x5");
@@ -3690,144 +4302,8 @@ void special_editmenu(Scene *scene, View3D *v3d)
                }
        }
        else if(obedit->type==OB_MESH) {
-               /* This is all that is needed, since all other functionality is in Ctrl+ V/E/F but some users didnt like, so for now have the old/big menu */
-               /*
-               nr= pupmenu("Subdivide Mesh%t|Subdivide%x1|Subdivide Multi%x2|Subdivide Multi Fractal%x3|Subdivide Smooth%x4");
-               switch(nr) {
-               case 1:
-                       waitcursor(1);
-                       esubdivideflag(1, 0.0, scene->toolsettings->editbutflag, 1, 0);
-                       
-                       break;
-               case 2:
-                       if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
-                       waitcursor(1);
-                       esubdivideflag(1, 0.0, scene->toolsettings->editbutflag, numcuts, 0);
-                       break;
-               case 3:
-                       if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
-                       randfac= 10;
-                       if(button(&randfac, 1, 100, "Rand fac:")==0) return;
-                       waitcursor(1);                  
-                       fac= -( (float)randfac )/100;
-                       esubdivideflag(1, fac, scene->toolsettings->editbutflag, numcuts, 0);
-                       break;
-                       
-               case 4:
-                       fac= 1.0f;
-                       if(fbutton(&fac, 0.0f, 5.0f, 10, 10, "Smooth:")==0) return;
-                               fac= 0.292f*fac;
-                       
-                       waitcursor(1);
-                       esubdivideflag(1, fac, scene->toolsettings->editbutflag | B_SMOOTH, 1, 0);
-                       break;          
-               }
-               */
-               
-               nr= pupmenu("Specials%t|Subdivide%x1|Subdivide Multi%x2|Subdivide Multi Fractal%x3|Subdivide Smooth%x12|Merge%x4|Remove Doubles%x5|Hide%x6|Reveal%x7|Select Swap%x8|Flip Normals %x9|Smooth %x10|Bevel %x11|Set Smooth %x14|Set Solid %x15|Blend From Shape%x16|Propagate To All Shapes%x17|Select Vertex Path%x18");
-               
-               switch(nr) {
-               case 1:
-                       waitcursor(1);
-// XXX                 esubdivideflag(1, 0.0, scene->toolsettings->editbutflag, 1, 0);
-                       
-                       break;
-               case 2:
-// XXX                 if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
-                       waitcursor(1);
-// XXX                 esubdivideflag(1, 0.0, scene->toolsettings->editbutflag, numcuts, 0);
-                       break;
-               case 3:
-// XXX                 if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return;
-                       randfac= 10;
-// XXX                 if(button(&randfac, 1, 100, "Rand fac:")==0) return;
-                       waitcursor(1);                  
-                       fac= -( (float)randfac )/100;
-// XXX                 esubdivideflag(1, fac, scene->toolsettings->editbutflag, numcuts, 0);
-                       break;
-                       
-               case 12:        /* smooth */
-                       /* if(button(&numcuts, 1, 128, "Number of Cuts:")==0) return; */
-                       fac= 1.0f;
-// XXX                 if(fbutton(&fac, 0.0f, 5.0f, 10, 10, "Smooth:")==0) return;
-// XXX                         fac= 0.292f*fac;
-                       
-                       waitcursor(1);
-// XXX                 esubdivideflag(1, fac, scene->toolsettings->editbutflag | B_SMOOTH, 1, 0);
-                       break;          
-
-               case 4:
-// XXX                 mergemenu();
-                       break;
-               case 5:
-// XXX                 notice("Removed %d Vertices", removedoublesflag(1, 0, scene->toolsettings->doublimit));
-                       break;
-               case 6:
-// XXX                 hide_mesh(0);
-                       break;
-               case 7:
-// XXX                 reveal_mesh();
-                       break;
-               case 8:
-// XXX                 selectswap_mesh();
-                       break;
-               case 9:
-// XXX                 flip_editnormals();
-                       break;
-               case 10:
-// XXX                 vertexsmooth();
-                       break;
-               case 11:
-// XXX                 bevel_menu();
-                       break;
-               case 14:
-// XXX                 mesh_set_smooth_faces(1);
-                       break;
-               case 15: 
-// XXX                 mesh_set_smooth_faces(0);
-                       break;
-               case 16: 
-// XXX                 shape_copy_select_from();
-                       break;
-               case 17: 
-// XXX                 shape_propagate();
-                       break;
-               case 18:
-// XXX                 pathselect();
-                       break;
-               }
-               
-               
-               DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
-               
-               if(nr>0) waitcursor(0);
-               
        }
        else if(ELEM(obedit->type, OB_CURVE, OB_SURF)) {
-
-               nr= pupmenu("Specials%t|Subdivide%x1|Switch Direction%x2|Set Goal Weight%x3|Set Radius%x4|Smooth%x5|Smooth Radius%x6");
-               
-               switch(nr) {
-               case 1:
-// XXX                 subdivideNurb();
-                       break;
-               case 2:
-// XXX                 switchdirectionNurb2();
-                       break;
-               case 3:
-// XXX                 setweightNurb();
-                       break;
-               case 4:
-// XXX                 setradiusNurb();
-                       break;
-               case 5:
-// XXX                 smoothNurb();
-                       break;
-               case 6:
-// XXX                 smoothradiusNurb();
-                       break;
-               }
-               DAG_object_flush_update(scene, obedit, OB_RECALC_DATA);
        }
        else if(obedit->type==OB_ARMATURE) {
                nr= pupmenu("Specials%t|Subdivide %x1|Subdivide Multi%x2|Switch Direction%x7|Flip Left-Right Names%x3|%l|AutoName Left-Right%x4|AutoName Front-Back%x5|AutoName Top-Bottom%x6");
@@ -4249,14 +4725,12 @@ static void copymenu_properties(Scene *scene, View3D *v3d, Object *ob)
                prop= prop->next;
        }
        
-       if(tot==0) {
-               error("No properties in the active object to copy");
-               return;
-       }
-       
        str= MEM_callocN(50 + 33*tot, "copymenu prop");
        
-       strcpy(str, "Copy Property %t|Replace All|Merge All|%l");
+       if (tot)
+               strcpy(str, "Copy Property %t|Replace All|Merge All|%l");
+       else
+               strcpy(str, "Copy Property %t|Clear All (no properties on active)");
        
        tot= 0; 
        prop= ob->prop.first;
@@ -4559,7 +5033,8 @@ void copy_attr(Scene *scene, View3D *v3d, short event)
                                        base->object->formfactor = ob->formfactor;
                                        base->object->damping= ob->damping;
                                        base->object->rdamping= ob->rdamping;
-                                       base->object->mass= ob->mass;
+                                       base->object->min_vel= ob->min_vel;
+                                       base->object->max_vel= ob->max_vel;
                                        if (ob->gameflag & OB_BOUNDS) {
                                                base->object->boundtype = ob->boundtype;
                                        }
@@ -5103,7 +5578,7 @@ static void apply_objects_internal(Scene *scene, View3D *v3d, int apply_scale, i
                                
                                nu= cu->nurb.first;
                                while(nu) {
-                                       if( (nu->type & 7)==1) {
+                                       if( (nu->type & 7)==CU_BEZIER) {
                                                a= nu->pntsu;
                                                bezt= nu->bezt;
                                                while(a--) {
@@ -5258,7 +5733,7 @@ void new_id_matar(Material **matar, int totcol)
        }
 }
 
-void single_obdata_users(Scene *scene, View3D *v3d, int flag)
+void single_obdata_users(Scene *scene, int flag)
 {
        Object *ob;
        Lamp *la;
@@ -5381,7 +5856,7 @@ void single_obdata_users(Scene *scene, View3D *v3d, int flag)
        }
 }
 
-void single_ipo_users(Scene *scene, View3D *v3d, int flag)
+void single_ipo_users(Scene *scene, int flag)
 {
 #if 0 // XXX old animation system
        Object *ob;
@@ -5404,7 +5879,7 @@ void single_ipo_users(Scene *scene, View3D *v3d, int flag)
 #endif // XXX old animation system
 }
 
-void single_mat_users(Scene *scene, View3D *v3d, int flag)
+void single_mat_users(Scene *scene, int flag)
 {
        Object *ob;
        Base *base;
@@ -5590,19 +6065,19 @@ void single_user(Scene *scene, View3D *v3d)
        
                else if(nr==2) {
                        single_object_users(scene, v3d, 1);
-                       single_obdata_users(scene, v3d, 1);
+                       single_obdata_users(scene, 1);
                }
                else if(nr==3) {
                        single_object_users(scene, v3d, 1);
-                       single_obdata_users(scene, v3d, 1);
-                       single_mat_users(scene, v3d, 1); /* also tex */
+                       single_obdata_users(scene, 1);
+                       single_mat_users(scene, 1); /* also tex */
                        
                }
                else if(nr==4) {
-                       single_mat_users(scene, v3d, 1);
+                       single_mat_users(scene, 1);
                }
                else if(nr==5) {
-                       single_ipo_users(scene, v3d, 1);
+                       single_ipo_users(scene, 1);
                }
                
                
@@ -5611,6 +6086,20 @@ void single_user(Scene *scene, View3D *v3d)
        }
 }
 
+/* used for copying scenes */
+void ED_object_single_users(Scene *scene, int full)
+{
+    single_object_users(scene, NULL, 0);
+
+    if(full) {
+        single_obdata_users(scene, 0);
+        single_mat_users_expand();
+        single_tex_users_expand();
+    }
+
+       clear_id_newpoins();
+}
+
 /* ************************************************************* */
 
 /* helper for below, ma was checked to be not NULL */
@@ -5815,7 +6304,7 @@ static Base *object_add_duplicate_internal(Scene *scene, Base *base, int dupflag
        int a, didit;
 
        ob= base->object;
-       if(ob->flag & OB_POSEMODE) {
+       if(ob->mode & OB_MODE_POSE) {
                ; /* nothing? */
        }
        else {
@@ -5996,12 +6485,11 @@ static Base *object_add_duplicate_internal(Scene *scene, Base *base, int dupflag
        return basen;
 }
 
-/* single object duplicate, if dupflag==0, fully linked, else it uses U.dupflag */
+/* single object duplicate, if dupflag==0, fully linked, else it uses the flags given */
 /* leaves selection of base/object unaltered */
-Base *ED_object_add_duplicate(Scene *scene, Base *base, int usedupflag)
+Base *ED_object_add_duplicate(Scene *scene, Base *base, int dupflag)
 {
        Base *basen;
-       int dupflag= usedupflag?U.dupflag:0;
 
        clear_id_newpoins();
        clear_sca_new_poins();  /* sensor/contr/act */
@@ -6014,11 +6502,12 @@ Base *ED_object_add_duplicate(Scene *scene, Base *base, int usedupflag)
 }
 
 /* contextual operator dupli */
-static int add_duplicate_exec(bContext *C, wmOperator *op)
+static int duplicate_exec(bContext *C, wmOperator *op)
 {
        Scene *scene= CTX_data_scene(C);
        View3D *v3d= CTX_wm_view3d(C);
-       int dupflag= U.dupflag;
+       int linked= RNA_boolean_get(op->ptr, "linked");
+       int dupflag= (linked)? 0: U.dupflag;
        
        clear_id_newpoins();
        clear_sca_new_poins();  /* sensor/contr/act */
@@ -6046,26 +6535,27 @@ static int add_duplicate_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-static int add_duplicate_invoke(bContext *C, wmOperator *op, wmEvent *event)
+static int duplicate_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
-       add_duplicate_exec(C, op);
+       duplicate_exec(C, op);
        
-       RNA_int_set(op->ptr, "mode", TFM_TRANSLATION);
-       WM_operator_name_call(C, "TFM_OT_transform", WM_OP_INVOKE_REGION_WIN, op->ptr);
+//     RNA_int_set(op->ptr, "mode", TFM_TRANSLATION);
+//     WM_operator_name_call(C, "TFM_OT_transform", WM_OP_INVOKE_REGION_WIN, op->ptr);
 
        return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_add_duplicate(wmOperatorType *ot)
+void OBJECT_OT_duplicate(wmOperatorType *ot)
 {
        
        /* identifiers */
-       ot->name= "Add Duplicate";
-       ot->idname= "OBJECT_OT_add_duplicate";
+       ot->name= "Duplicate";
+       ot->description = "Duplicate selected objects.";
+       ot->idname= "OBJECT_OT_duplicate";
        
        /* api callbacks */
-       ot->invoke= add_duplicate_invoke;
-       ot->exec= add_duplicate_exec;
+       ot->invoke= duplicate_invoke;
+       ot->exec= duplicate_exec;
        
        ot->poll= ED_operator_scene_editable;
        
@@ -6073,9 +6563,127 @@ void OBJECT_OT_add_duplicate(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* to give to transform */
+       RNA_def_boolean(ot->srna, "linked", 0, "Linked", "Duplicate object but not object data, linking to the original data.");
        RNA_def_int(ot->srna, "mode", TFM_TRANSLATION, 0, INT_MAX, "Mode", "", 0, INT_MAX);
 }
 
+/* ************************** JOIN *********************** */
+
+static int join_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= CTX_data_active_object(C);
+
+       if(scene->obedit) {
+               BKE_report(op->reports, RPT_ERROR, "This data does not support joining in editmode.");
+               return OPERATOR_CANCELLED;
+       }
+       else if(!ob) {
+               BKE_report(op->reports, RPT_ERROR, "Can't join unless there is an active object.");
+               return OPERATOR_CANCELLED;
+       }
+       else if(object_data_is_libdata(ob)) {
+               BKE_report(op->reports, RPT_ERROR, "Can't edit external libdata.");
+               return OPERATOR_CANCELLED;
+       }
+
+       if(ob->type == OB_MESH)
+               return join_mesh_exec(C, op);
+       else if(ELEM(ob->type, OB_CURVE, OB_SURF))
+               return join_curve_exec(C, op);
+       else if(ob->type == OB_ARMATURE)
+               return join_armature_exec(C, op);
+
+       BKE_report(op->reports, RPT_ERROR, "This object type doesn't support joining.");
+
+       return OPERATOR_CANCELLED;
+}
+
+void OBJECT_OT_join(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Join";
+       ot->description = "Join selected objects into active object.";
+       ot->idname= "OBJECT_OT_join";
+       
+       /* api callbacks */
+       ot->exec= join_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+/********************** Smooth/Flat *********************/
+
+static int shade_smooth_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       Object *ob;
+       Curve *cu;
+       Nurb *nu;
+       int clear= (strcmp(op->idname, "OBJECT_OT_shade_flat") == 0);
+       int done= 0;
+
+       CTX_DATA_BEGIN(C, Base*, base, selected_editable_bases) {
+               ob= base->object;
+
+               if(ob->type==OB_MESH) {
+                       mesh_set_smooth_flag(ob, !clear);
+
+                       DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+                       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
+
+                       done= 1;
+               }
+               else if ELEM(ob->type, OB_SURF, OB_CURVE) {
+                       cu= ob->data;
+
+                       for(nu=cu->nurb.first; nu; nu=nu->next) {
+                               if(!clear) nu->flag |= ME_SMOOTH;
+                               else nu->flag &= ~ME_SMOOTH;
+                               nu= nu->next;
+                       }
+
+                       DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
+                       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
+
+                       done= 1;
+               }
+       }
+       CTX_DATA_END;
+
+       return (done)? OPERATOR_FINISHED: OPERATOR_CANCELLED;
+}
+
+void OBJECT_OT_shade_flat(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Shade Flat";
+       ot->idname= "OBJECT_OT_shade_flat";
+       
+       /* api callbacks */
+       ot->exec= shade_smooth_exec;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+void OBJECT_OT_shade_smooth(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Shade Smooth";
+       ot->idname= "OBJECT_OT_shade_smooth";
+       
+       /* api callbacks */
+       ot->exec= shade_smooth_exec;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+
+
 /* ********************** */
 
 void image_aspect(Scene *scene, View3D *v3d)
@@ -6366,15 +6974,8 @@ void texspace_edit(Scene *scene, View3D *v3d)
 
 void mirrormenu(void)
 {
-       Scene *scene= NULL; // XXX
-       
-       if(G.f & G_PARTICLEEDIT) {
-               PE_mirror_x(scene, 0);
-       }
-       else {
 // XXX         initTransform(TFM_MIRROR, CTX_NO_PET);
 // XXX         Transform();
-       }
 }
 
 void hookmenu(Scene *scene, View3D *v3d)
@@ -6439,3 +7040,109 @@ void hookmenu(Scene *scene, View3D *v3d)
        if (changed) {
        }       
 }
+
+static EnumPropertyItem *object_mode_set_itemsf(bContext *C, PointerRNA *ptr, int *free)
+{      
+       EnumPropertyItem *input = object_mode_items;
+       EnumPropertyItem *item= NULL;
+       Object *ob;
+       int totitem= 0;
+       
+       if(!C) /* needed for docs */
+               return object_mode_items;
+
+       ob = CTX_data_active_object(C);
+       while(ob && input->identifier) {
+               if((input->value == OB_MODE_EDIT && ((ob->type == OB_MESH) || (ob->type == OB_ARMATURE) ||
+                                                   (ob->type == OB_CURVE) || (ob->type == OB_SURF) ||
+                                                    (ob->type == OB_FONT) || (ob->type == OB_MBALL) || (ob->type == OB_LATTICE))) ||
+                  (input->value == OB_MODE_POSE && (ob->type == OB_ARMATURE)) ||
+                  (input->value == OB_MODE_PARTICLE_EDIT && ob->particlesystem.first) ||
+                  ((input->value == OB_MODE_SCULPT || input->value == OB_MODE_VERTEX_PAINT ||
+                    input->value == OB_MODE_WEIGHT_PAINT || input->value == OB_MODE_TEXTURE_PAINT) && (ob->type == OB_MESH)) ||
+                  (input->value == OB_MODE_OBJECT))
+                       RNA_enum_item_add(&item, &totitem, input);
+               ++input;
+       }
+
+       RNA_enum_item_end(&item, &totitem);
+
+       *free= 1;
+
+       return item;
+}
+
+static const char *object_mode_op_string(int mode)
+{
+       if(mode == OB_MODE_EDIT)
+               return "OBJECT_OT_editmode_toggle";
+       if(mode == OB_MODE_SCULPT)
+               return "SCULPT_OT_sculptmode_toggle";
+       if(mode == OB_MODE_VERTEX_PAINT)
+               return "PAINT_OT_vertex_paint_toggle";
+       if(mode == OB_MODE_WEIGHT_PAINT)
+               return "PAINT_OT_weight_paint_toggle";
+       if(mode == OB_MODE_TEXTURE_PAINT)
+               return "PAINT_OT_texture_paint_toggle";
+       if(mode == OB_MODE_PARTICLE_EDIT)
+               return "PARTICLE_OT_particle_edit_toggle";
+       if(mode == OB_MODE_POSE)
+               return "OBJECT_OT_posemode_toggle";
+       return NULL;
+}
+
+static int object_mode_set_exec(bContext *C, wmOperator *op)
+{
+       Object *ob= CTX_data_active_object(C);
+       int mode = RNA_enum_get(op->ptr, "mode");
+
+       if(!ob)
+               return OPERATOR_CANCELLED;
+
+       /* Exit off current mode */
+       if(ob->mode != OB_MODE_OBJECT)
+               WM_operator_name_call(C, object_mode_op_string(ob->mode), WM_OP_EXEC_REGION_WIN, NULL);
+
+       /* Enter new mode */
+       if(mode != OB_MODE_OBJECT)
+               WM_operator_name_call(C, object_mode_op_string(mode), WM_OP_EXEC_REGION_WIN, NULL);
+
+       return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_mode_set(wmOperatorType *ot)
+{
+       PropertyRNA *prop;
+
+       /* identifiers */
+       ot->name= "Set Object Mode";
+       ot->description = "Sets the object interaction mode.";
+       ot->idname= "OBJECT_OT_mode_set";
+       
+       /* api callbacks */
+       ot->exec= object_mode_set_exec;
+       
+       ot->poll= ED_operator_object_active;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       prop= RNA_def_enum(ot->srna, "mode", object_mode_items, 0, "Mode", "");
+       RNA_def_enum_funcs(prop, object_mode_set_itemsf);
+}
+
+
+
+void ED_object_toggle_modes(bContext *C, int mode)
+{
+       if(mode & OB_MODE_SCULPT)
+               WM_operator_name_call(C, "SCULPT_OT_sculptmode_toggle", WM_OP_EXEC_REGION_WIN, NULL);
+       if(mode & OB_MODE_VERTEX_PAINT)
+               WM_operator_name_call(C, "PAINT_OT_vertex_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL);
+       if(mode & OB_MODE_WEIGHT_PAINT)
+               WM_operator_name_call(C, "PAINT_OT_weight_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL);
+       if(mode & OB_MODE_TEXTURE_PAINT)
+               WM_operator_name_call(C, "PAINT_OT_texture_paint_toggle", WM_OP_EXEC_REGION_WIN, NULL);
+       if(mode & OB_MODE_PARTICLE_EDIT)
+               WM_operator_name_call(C, "PARTICLE_OT_particle_edit_toggle", WM_OP_EXEC_REGION_WIN, NULL);
+}