2.5: Modifiers & Menus
[blender-staging.git] / source / blender / editors / object / object_edit.c
index 234a1cc0ea40c10eff47bed4f9e3941fd2d1c7b2..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_curve.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;
 }
 
@@ -338,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)
@@ -357,7 +338,7 @@ 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);
@@ -415,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)
@@ -465,7 +446,7 @@ static int object_add_curve_invoke(bContext *C, wmOperator *op, wmEvent *event)
        uiPopupMenu *pup;
        uiLayout *layout;
 
-       pup= uiPupMenuBegin(op->type->name, 0);
+       pup= uiPupMenuBegin(C, op->type->name, 0);
        layout= uiPupMenuLayout(pup);
        if(!obedit || obedit->type == OB_CURVE)
                uiItemsEnumO(layout, op->type->idname, "type");
@@ -496,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)
@@ -553,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);
@@ -631,22 +684,23 @@ void OBJECT_OT_armature_add(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-
 static int object_primitive_add_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
-       uiPopupMenu *pup= uiPupMenuBegin("Add Object", 0);
+       uiPopupMenu *pup= uiPupMenuBegin(C, "Add Object", 0);
        uiLayout *layout= uiPupMenuLayout(pup);
        
-       uiItemMenuEnumO(layout, NULL, /*ICON_OUTLINER_OB_MESH*/0, "OBJECT_OT_mesh_add", "type");
-       uiItemMenuEnumO(layout, NULL, ICON_OUTLINER_OB_CURVE, "OBJECT_OT_curve_add", "type");
-       uiItemMenuEnumO(layout, NULL, ICON_OUTLINER_OB_SURFACE, "OBJECT_OT_surface_add", "type");
-       uiItemO(layout, NULL, ICON_OUTLINER_OB_FONT, "OBJECT_OT_text_add");
-       uiItemEnumO(layout, NULL, ICON_OUTLINER_OB_META, "OBJECT_OT_object_add", "type", OB_MBALL);
+       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);
-       uiItemEnumO(layout, NULL, ICON_OUTLINER_OB_EMPTY, "OBJECT_OT_object_add", "type", OB_EMPTY);
-       uiItemO(layout, NULL, ICON_OUTLINER_OB_ARMATURE, "OBJECT_OT_armature_add");
-       uiItemEnumO(layout, NULL, ICON_OUTLINER_OB_LATTICE, "OBJECT_OT_object_add", "type", OB_LATTICE);
        
        uiPupMenuEnd(C, pup);
        
@@ -692,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;
@@ -717,8 +769,8 @@ void OBJECT_OT_delete(wmOperatorType *ot)
 {
        
        /* identifiers */
-       ot->name= "Delete Objects";
-       ot->description = "Delete the object.";
+       ot->name= "Delete";
+       ot->description = "Delete selected objects.";
        ot->idname= "OBJECT_OT_delete";
        
        /* api callbacks */
@@ -760,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){
@@ -1098,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;
@@ -1180,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);
@@ -1266,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");
@@ -1329,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 */
@@ -1383,43 +1434,45 @@ 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 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_parent_clear(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Clear parent";
+       ot->name= "Clear Parent";
        ot->description = "Clear the object's parenting.";
        ot->idname= "OBJECT_OT_parent_clear";
        
@@ -1439,14 +1492,16 @@ void OBJECT_OT_parent_clear(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_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;
@@ -1455,9 +1510,8 @@ static int object_track_clear_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;
 
@@ -1488,9 +1542,9 @@ void OBJECT_OT_track_clear(wmOperatorType *ot)
 
 /* *****************Selection Operators******************* */
 static EnumPropertyItem prop_select_types[] = {
-       {0, "EXCLUSIVE", "Exclusive", ""},
-       {1, "EXTEND", "Extend", ""},
-       {0, NULL, NULL, NULL}
+       {0, "EXCLUSIVE", 0, "Exclusive", ""},
+       {1, "EXTEND", 0, "Extend", ""},
+       {0, NULL, 0, NULL, NULL}
 };
 
 /* ****** Select by Type ****** */
@@ -1543,13 +1597,13 @@ void OBJECT_OT_select_by_type(wmOperatorType *ot)
 /* ****** 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)
@@ -1700,6 +1754,308 @@ void OBJECT_OT_select_linked(wmOperatorType *ot)
        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)
@@ -1749,7 +2105,7 @@ void OBJECT_OT_select_by_layer(wmOperatorType *ot)
 }
 
 /* ****** 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)
@@ -1765,16 +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->description = "Invert th select of all visible objects.";
-       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 */
@@ -1882,7 +2238,7 @@ 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)
@@ -1907,7 +2263,7 @@ void OBJECT_OT_location_clear(wmOperatorType *ot)
 {
        
        /* identifiers */
-       ot->name= "Clear Object Location";
+       ot->name= "Clear Location";
        ot->description = "Clear the object's location.";
        ot->idname= "OBJECT_OT_location_clear";
        
@@ -1925,7 +2281,7 @@ 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;
@@ -1951,7 +2307,7 @@ void OBJECT_OT_rotation_clear(wmOperatorType *ot)
 {
        
        /* identifiers */
-       ot->name= "Clear Object Rotation";
+       ot->name= "Clear Rotation";
        ot->description = "Clear the object's rotation.";
        ot->idname= "OBJECT_OT_rotation_clear";
        
@@ -1969,7 +2325,7 @@ 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;
@@ -1999,7 +2355,7 @@ void OBJECT_OT_scale_clear(wmOperatorType *ot)
 {
        
        /* identifiers */
-       ot->name= "Clear Object Scale";
+       ot->name= "Clear Scale";
        ot->description = "Clear the object's scale.";
        ot->idname= "OBJECT_OT_scale_clear";
        
@@ -2045,7 +2401,7 @@ void OBJECT_OT_origin_clear(wmOperatorType *ot)
 {
 
        /* identifiers */
-       ot->name= "Clear Object Origin";
+       ot->name= "Clear Origin";
        ot->description = "Clear the object's origin.";
        ot->idname= "OBJECT_OT_origin_clear";
        
@@ -2088,12 +2444,11 @@ void OBJECT_OT_restrictview_clear(wmOperatorType *ot)
 {
        
        /* identifiers */
-       ot->name= "Clear restrict view";
+       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_restrictview_clear_exec;
        ot->poll= ED_operator_view3d_active;
        
@@ -2101,19 +2456,14 @@ void OBJECT_OT_restrictview_clear(wmOperatorType *ot)
        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_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;
@@ -2124,7 +2474,7 @@ static int object_restrictview_set_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;
@@ -2146,19 +2496,18 @@ static int object_restrictview_set_exec(bContext *C, wmOperator *op)
 void OBJECT_OT_restrictview_set(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Set restrict view";
+       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_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 ******************* */
@@ -2381,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);
@@ -2455,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)
@@ -2501,6 +2946,22 @@ 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 parent_set_exec(bContext *C, wmOperator *op)
 {
@@ -2508,6 +2969,7 @@ static int parent_set_exec(bContext *C, wmOperator *op)
        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;
        
@@ -2579,24 +3041,20 @@ static int parent_set_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 {
@@ -2607,7 +3065,7 @@ static int parent_set_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 */
@@ -2617,7 +3075,8 @@ static int parent_set_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;
 }
@@ -2625,15 +3084,18 @@ static int parent_set_exec(bContext *C, wmOperator *op)
 static int parent_set_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        Object *ob= CTX_data_active_object(C);
-       uiPopupMenu *pup= uiPupMenuBegin("Set Parent To", 0);
+       uiPopupMenu *pup= uiPupMenuBegin(C, "Set Parent To", 0);
        uiLayout *layout= uiPupMenuLayout(pup);
        
-       uiLayoutContext(layout, WM_OP_EXEC_DEFAULT);
+       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) {
                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) {
@@ -2654,7 +3116,7 @@ static int parent_set_invoke(bContext *C, wmOperator *op, wmEvent *event)
 void OBJECT_OT_parent_set(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Make parent";
+       ot->name= "Make Parent";
        ot->description = "Set the object's parenting.";
        ot->idname= "OBJECT_OT_parent_set";
        
@@ -2665,24 +3127,25 @@ void OBJECT_OT_parent_set(wmOperatorType *ot)
        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 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;
 
@@ -2706,7 +3169,7 @@ static int track_set_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;
 
@@ -2730,7 +3193,7 @@ static int track_set_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;
@@ -2808,7 +3271,7 @@ static void make_object_duplilist_real(Scene *scene, View3D *v3d, Base *base)
 }
 
 
-static int object_dupli_set_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);
@@ -2828,17 +3291,17 @@ static int object_dupli_set_real_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void OBJECT_OT_dupli_set_real(wmOperatorType *ot)
+void OBJECT_OT_duplicates_make_real(wmOperatorType *ot)
 {
        
        /* identifiers */
-       ot->name= "Make Dupli Real";
+       ot->name= "Make Duplicates Real";
        ot->description = "Make dupli objects attached to this object real.";
-       ot->idname= "OBJECT_OT_dupli_set_real";
+       ot->idname= "OBJECT_OT_duplicates_make_real";
        
        /* api callbacks */
        ot->invoke= WM_operator_confirm;
-       ot->exec= object_dupli_set_real_exec;
+       ot->exec= object_duplicates_make_real_exec;
        
        ot->poll= ED_operator_scene_editable;
        
@@ -2848,10 +3311,10 @@ void OBJECT_OT_dupli_set_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 */
@@ -3223,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) {   
@@ -3246,11 +3713,10 @@ 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 */
@@ -3265,6 +3731,9 @@ void ED_object_exit_editmode(bContext *C, int flag)
        
                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);
 }
 
 
@@ -3272,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;
@@ -3280,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)) {
@@ -3294,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;
@@ -3334,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
@@ -3366,6 +3843,7 @@ 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);
 }
 
@@ -3380,6 +3858,16 @@ static int editmode_toggle_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)
 {
        
@@ -3391,7 +3879,7 @@ void OBJECT_OT_editmode_toggle(wmOperatorType *ot)
        /* api callbacks */
        ot->exec= editmode_toggle_exec;
        
-       ot->poll= ED_operator_object_active;
+       ot->poll= editmode_toggle_poll;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -3399,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)
 {
@@ -3589,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=0;
-       short randfac;
        
        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;
@@ -3646,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;
@@ -3659,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);
@@ -3678,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");
@@ -3780,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");
@@ -5347,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;
@@ -5470,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;
@@ -5493,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;
@@ -5679,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);
                }
                
                
@@ -5700,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 */
@@ -5904,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 {
@@ -6085,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 */
@@ -6103,11 +6502,12 @@ Base *ED_object_add_duplicate(Scene *scene, Base *base, int usedupflag)
 }
 
 /* contextual operator dupli */
-static int duplicate_add_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 */
@@ -6135,27 +6535,27 @@ static int duplicate_add_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-static int duplicate_add_invoke(bContext *C, wmOperator *op, wmEvent *event)
+static int duplicate_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
-       duplicate_add_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_duplicate_add(wmOperatorType *ot)
+void OBJECT_OT_duplicate(wmOperatorType *ot)
 {
        
        /* identifiers */
-       ot->name= "Add Duplicate";
-       ot->description = "Duplicate the object.";
-       ot->idname= "OBJECT_OT_duplicate_add";
+       ot->name= "Duplicate";
+       ot->description = "Duplicate selected objects.";
+       ot->idname= "OBJECT_OT_duplicate";
        
        /* api callbacks */
-       ot->invoke= duplicate_add_invoke;
-       ot->exec= duplicate_add_exec;
+       ot->invoke= duplicate_invoke;
+       ot->exec= duplicate_exec;
        
        ot->poll= ED_operator_scene_editable;
        
@@ -6163,9 +6563,127 @@ void OBJECT_OT_duplicate_add(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)
@@ -6522,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);
+}