2.5/Posemode:
[blender-staging.git] / source / blender / editors / space_outliner / outliner.c
index 431208ad51126b398ae3183bded3265e5fbfa46b..33119317a6da246d837e834fa7dcba6eeea95e90 100644 (file)
@@ -50,7 +50,7 @@
 #include "DNA_modifier_types.h"
 #include "DNA_nla_types.h"
 #include "DNA_object_types.h"
-#include "DNA_oops_types.h"
+#include "DNA_outliner_types.h"
 #include "DNA_particle_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
@@ -64,6 +64,7 @@
 
 #include "IMB_imbuf_types.h"
 
+#include "BKE_animsys.h"
 #include "BKE_constraint.h"
 #include "BKE_context.h"
 #include "BKE_deform.h"
 #include "BKE_material.h"
 #include "BKE_modifier.h"
 #include "BKE_object.h"
+#include "BKE_report.h"
 #include "BKE_screen.h"
 #include "BKE_scene.h"
 #include "BKE_sequence.h"
 #include "BKE_utildefines.h"
 
+#include "ED_armature.h"
+#include "ED_object.h"
 #include "ED_screen.h"
 #include "ED_util.h"
 #include "ED_types.h"
 #include "UI_interface_icons.h"
 #include "UI_resources.h"
 #include "UI_view2d.h"
-#include "UI_text.h"
 
 #include "RNA_access.h"
+#include "RNA_define.h"
 
 #include "ED_armature.h"
+#include "ED_keyframing.h"
 #include "ED_object.h"
+#include "ED_particle.h"
+#include "ED_screen.h"
+#include "ED_view3d.h"
 
 #include "outliner_intern.h"
 
-#ifdef INTERNATIONAL
-#include "FTF_Api.h"
-#endif
-
 #include "PIL_time.h" 
 
 
 
 /* ************* XXX **************** */
 
-static void allqueue() {}
-static void BIF_undo_push() {}
-static void BIF_preview_changed() {}
-static void set_scene() {}
 static void error() {}
-static int pupmenu() {return 0;}
 
 /* ********************************** */
 
 
 /* ******************** PROTOTYPES ***************** */
-static void outliner_draw_tree_element(Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, int startx, int *starty);
-static void outliner_do_object_operation(Scene *scene, SpaceOops *soops, ListBase *lb, 
-                                                                                void (*operation_cb)(TreeElement *, TreeStoreElem *, TreeStoreElem *));
+static void outliner_draw_tree_element(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, int startx, int *starty);
+static void outliner_do_object_operation(bContext *C, Scene *scene, SpaceOops *soops, ListBase *lb, 
+                                                                                void (*operation_cb)(bContext *C, Scene *scene, TreeElement *, TreeStoreElem *, TreeStoreElem *));
 
 
 /* ******************** PERSISTANT DATA ***************** */
@@ -554,16 +553,6 @@ static void outliner_add_scene_contents(SpaceOops *soops, ListBase *lb, Scene *s
        }
        
        outliner_add_element(soops,  lb, sce->world, te, 0, 0);
-       
-       if(sce->scriptlink.scripts) {
-               int a= 0;
-               tenla= outliner_add_element(soops,  lb, sce, te, TSE_SCRIPT_BASE, 0);
-               tenla->name= "Scripts";
-               for (a=0; a<sce->scriptlink.totscript; a++) {
-                       outliner_add_element(soops, &tenla->subtree, sce->scriptlink.scripts[a], tenla, 0, 0);
-               }
-       }
-
 }
 
 static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *idv, 
@@ -572,7 +561,7 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
        TreeElement *te;
        TreeStoreElem *tselem;
        ID *id= idv;
-       int a;
+       int a = 0;
        
        if(ELEM3(type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) {
                id= ((PointerRNA*)idv)->id.data;
@@ -616,6 +605,7 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
                                Object *ob= (Object *)id;
                                
                                outliner_add_element(soops, &te->subtree, ob->adt, te, TSE_ANIM_DATA, 0);
+                               outliner_add_element(soops, &te->subtree, ob->poselib, te, 0, 0); // XXX FIXME.. add a special type for this
                                
                                if(ob->proxy && ob->id.lib==NULL)
                                        outliner_add_element(soops, &te->subtree, ob->proxy, te, TSE_PROXY, 0);
@@ -630,7 +620,7 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
                                        
                                        tenla->name= "Pose";
                                        
-                                       if(arm->edbo==NULL && (ob->flag & OB_POSEMODE)) {       // channels undefined in editmode, but we want the 'tenla' pose icon itself
+                                       if(arm->edbo==NULL && (ob->mode & OB_MODE_POSE)) {      // channels undefined in editmode, but we want the 'tenla' pose icon itself
                                                int a= 0, const_index= 1000;    /* ensure unique id for bone constraints */
                                                
                                                for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next, a++) {
@@ -769,15 +759,6 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
                                                ten->directdata= defgroup;
                                        }
                                }
-                               if(ob->scriptlink.scripts) {
-                                       TreeElement *tenla= outliner_add_element(soops, &te->subtree, ob, te, TSE_SCRIPT_BASE, 0);
-                                       int a= 0;
-                                       
-                                       tenla->name= "Scripts";
-                                       for (a=0; a<ob->scriptlink.totscript; a++) {                                                    /*  ** */
-                                               outliner_add_element(soops, &tenla->subtree, ob->scriptlink.scripts[a], te, 0, 0);
-                                       }
-                               }
                                
                                if(ob->dup_group)
                                        outliner_add_element(soops, &te->subtree, ob->dup_group, te, 0, 0);     
@@ -906,7 +887,7 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
                                else {
                                        /* do not extend Armature when we have posemode */
                                        tselem= TREESTORE(te->parent);
-                                       if( GS(tselem->id->name)==ID_OB && ((Object *)tselem->id)->flag & OB_POSEMODE);
+                                       if( GS(tselem->id->name)==ID_OB && ((Object *)tselem->id)->mode & OB_MODE_POSE);
                                        else {
                                                Bone *curBone;
                                                for (curBone=arm->bonebase.first; curBone; curBone=curBone->next){
@@ -932,14 +913,18 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
                        TreeElement *ted= outliner_add_element(soops, &te->subtree, adt, te, TSE_DRIVER_BASE, 0);
                        ID *lastadded= NULL;
                        FCurve *fcu;
+                       DriverTarget *dtar;
                        
                        ted->name= "Drivers";
                
                        for (fcu= adt->drivers.first; fcu; fcu= fcu->next) {
-                               if (fcu->driver && fcu->driver->id) {
-                                       if (lastadded != fcu->driver->id) {
-                                               outliner_add_element(soops, &ted->subtree, fcu->driver->id, ted, TSE_LINKED_OB, 0);
-                                               lastadded= fcu->driver->id;
+                               if (fcu->driver && fcu->driver->targets.first)  {
+                                       for (dtar= fcu->driver->targets.first; dtar; dtar= dtar->next) {
+                                               if (lastadded != dtar->id) {
+                                                       // XXX this lastadded check is rather lame, and also fails quite badly...
+                                                       outliner_add_element(soops, &ted->subtree, dtar->id, ted, TSE_LINKED_OB, 0);
+                                                       lastadded= dtar->id;
+                                               }
                                        }
                                }
                        }
@@ -947,7 +932,6 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
                
                /* NLA Data */
                if (adt->nla_tracks.first) {
-#if 0
                        TreeElement *tenla= outliner_add_element(soops, &te->subtree, adt, te, TSE_NLA, 0);
                        NlaTrack *nlt;
                        int a= 0;
@@ -955,17 +939,18 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
                        tenla->name= "NLA Tracks";
                        
                        for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next) {
-                               TreeElement *tenlt= outliner_add_element(soops, &te->subtree, nlt, te, TSE_NLA_TRACK, a);
-                               bActionStrip *strip;
+                               TreeElement *tenlt= outliner_add_element(soops, &tenla->subtree, nlt, tenla, TSE_NLA_TRACK, a);
+                               NlaStrip *strip;
                                TreeElement *ten;
                                int b= 0;
                                
-                               for (strip=nlt->strips.first; strip; strip=strip->next, a++) {
-                                       ten= outliner_add_element(soops, &tenla->subtree, strip->act, tenla, TSE_NLA_ACTION, a);
+                               tenlt->name= nlt->name;
+                               
+                               for (strip=nlt->strips.first; strip; strip=strip->next, b++) {
+                                       ten= outliner_add_element(soops, &tenlt->subtree, strip->act, tenlt, TSE_NLA_ACTION, b);
                                        if(ten) ten->directdata= strip;
                                }
                        }
-#endif
                }
        }
        else if(type==TSE_SEQUENCE) {
@@ -1029,9 +1014,8 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
        }
        else if(ELEM3(type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) {
                PointerRNA pptr, propptr, *ptr= (PointerRNA*)idv;
-               PropertyRNA *prop, *iterprop, *nameprop;
+               PropertyRNA *prop, *iterprop;
                PropertyType proptype;
-               PropertySubType propsubtype;
                int a, tot;
 
                /* we do lazy build, for speed and to avoid infinite recusion */
@@ -1041,20 +1025,18 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
                }
                else if(type == TSE_RNA_STRUCT) {
                        /* struct */
-                       nameprop= RNA_struct_name_property(ptr);
+                       te->name= RNA_struct_name_get_alloc(ptr, NULL, 0);
 
-                       if(nameprop) {
-                               te->name= RNA_property_string_get_alloc(ptr, nameprop, NULL, 0);
+                       if(te->name)
                                te->flag |= TE_FREE_NAME;
-                       }
                        else
-                               te->name= (char*)RNA_struct_ui_name(ptr);
+                               te->name= (char*)RNA_struct_ui_name(ptr->type);
 
-                       iterprop= RNA_struct_iterator_property(ptr);
+                       iterprop= RNA_struct_iterator_property(ptr->type);
                        tot= RNA_property_collection_length(ptr, iterprop);
 
                        /* auto open these cases */
-                       if(!parent || (RNA_property_type(&parent->rnaptr, parent->directdata)) == PROP_POINTER)
+                       if(!parent || (RNA_property_type(parent->directdata)) == PROP_POINTER)
                                if(!tselem->used)
                                        tselem->flag &= ~TSE_CLOSED;
 
@@ -1069,18 +1051,18 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
                }
                else if(type == TSE_RNA_PROPERTY) {
                        /* property */
-                       iterprop= RNA_struct_iterator_property(ptr);
+                       iterprop= RNA_struct_iterator_property(ptr->type);
                        RNA_property_collection_lookup_int(ptr, iterprop, index, &propptr);
 
                        prop= propptr.data;
-                       proptype= RNA_property_type(ptr, prop);
+                       proptype= RNA_property_type(prop);
 
-                       te->name= (char*)RNA_property_ui_name(ptr, prop);
+                       te->name= (char*)RNA_property_ui_name(prop);
                        te->directdata= prop;
                        te->rnaptr= *ptr;
 
                        if(proptype == PROP_POINTER) {
-                               RNA_property_pointer_get(ptr, prop, &pptr);
+                               pptr= RNA_property_pointer_get(ptr, prop);
 
                                if(pptr.data) {
                                        if(!(tselem->flag & TSE_CLOSED))
@@ -1102,7 +1084,7 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
                                        te->flag |= TE_LAZY_CLOSED;
                        }
                        else if(ELEM3(proptype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) {
-                               tot= RNA_property_array_length(ptr, prop);
+                               tot= RNA_property_array_length(prop);
 
                                if(!(tselem->flag & TSE_CLOSED)) {
                                        for(a=0; a<tot; a++)
@@ -1113,32 +1095,61 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
                        }
                }
                else if(type == TSE_RNA_ARRAY_ELEM) {
-                       /* array property element */
-                       static char *vectoritem[4]= {"  x", "  y", "  z", "  w"};
-                       static char *quatitem[4]= {"  w", "  x", "  y", "  z"};
-                       static char *coloritem[4]= {"  r", "  g", "  b", "  a"};
+                       char c;
 
                        prop= parent->directdata;
-                       proptype= RNA_property_type(ptr, prop);
-                       propsubtype= RNA_property_subtype(ptr, prop);
-                       tot= RNA_property_array_length(ptr, prop);
 
                        te->directdata= prop;
                        te->rnaptr= *ptr;
                        te->index= index;
 
-                       if(tot == 4 && propsubtype == PROP_ROTATION)
-                               te->name= quatitem[index];
-                       else if(tot <= 4 && (propsubtype == PROP_VECTOR || propsubtype == PROP_ROTATION))
-                               te->name= vectoritem[index];
-                       else if(tot <= 4 && propsubtype == PROP_COLOR)
-                               te->name= coloritem[index];
-                       else {
-                               te->name= MEM_callocN(sizeof(char)*20, "OutlinerRNAArrayName");
-                               sprintf(te->name, "  %d", index+1);
-                               te->flag |= TE_FREE_NAME;
+                       c= RNA_property_array_item_char(prop, index);
+
+                       te->name= MEM_callocN(sizeof(char)*20, "OutlinerRNAArrayName");
+                       if(c) sprintf(te->name, "  %c", c);
+                       else sprintf(te->name, "  %d", index+1);
+                       te->flag |= TE_FREE_NAME;
+               }
+       }
+       else if(type == TSE_KEYMAP) {
+               wmKeyMap *km= (wmKeyMap *)idv;
+               wmKeymapItem *kmi;
+               char opname[OP_MAX_TYPENAME];
+               
+               te->directdata= idv;
+               te->name= km->nameid;
+               
+               if(!(tselem->flag & TSE_CLOSED)) {
+                       a= 0;
+                       
+                       for (kmi= km->keymap.first; kmi; kmi= kmi->next, a++) {
+                               const char *key= WM_key_event_string(kmi->type);
+                               
+                               if(key[0]) {
+                                       wmOperatorType *ot= NULL;
+                                       
+                                       if(kmi->propvalue);
+                                       else ot= WM_operatortype_find(kmi->idname, 0);
+                                       
+                                       if(ot || kmi->propvalue) {
+                                               TreeElement *ten= outliner_add_element(soops, &te->subtree, kmi, te, TSE_KEYMAP_ITEM, a);
+                                               
+                                               ten->directdata= kmi;
+                                               
+                                               if(kmi->propvalue) {
+                                                       ten->name= "Modal map, not yet";
+                                               }
+                                               else {
+                                                       WM_operator_py_idname(opname, ot->idname);
+                                                       ten->name= BLI_strdup(opname);
+                                                       ten->flag |= TE_FREE_NAME;
+                                               }
+                                       }
+                               }
                        }
                }
+               else 
+                       te->flag |= TE_LAZY_CLOSED;
        }
 
        return te;
@@ -1393,6 +1404,14 @@ static void outliner_build_tree(Main *mainvar, Scene *scene, SpaceOops *soops)
                        tselem->flag &= ~TSE_CLOSED;
                }
        }
+       else if(soops->outlinevis==SO_KEYMAP) {
+               wmWindowManager *wm= mainvar->wm.first;
+               wmKeyMap *km;
+               
+               for(km= wm->keymaps.first; km; km= km->next) {
+                       ten= outliner_add_element(soops, &soops->tree, (void*)km, NULL, TSE_KEYMAP, 0);
+               }
+       }
        else {
                ten= outliner_add_element(soops, &soops->tree, OBACT, NULL, 0, 0);
                if(ten) ten->directdata= BASACT;
@@ -1445,9 +1464,10 @@ static void outliner_set_flag(SpaceOops *soops, ListBase *lb, short flag, short
        }
 }
 
-void object_toggle_visibility_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+/* --- */
+
+void object_toggle_visibility_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
 {
-       Scene *scene= NULL;             // XXX
        Base *base= (Base *)te->directdata;
        
        if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
@@ -1456,21 +1476,37 @@ void object_toggle_visibility_cb(TreeElement *te, TreeStoreElem *tsep, TreeStore
        }
 }
 
-void outliner_toggle_visibility(Scene *scene, SpaceOops *soops)
+static int outliner_toggle_visibility_exec(bContext *C, wmOperator *op)
 {
-
-       outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_visibility_cb);
+       SpaceOops *soops= CTX_wm_space_outliner(C);
+       Scene *scene= CTX_data_scene(C);
+       ARegion *ar= CTX_wm_region(C);
+       
+       outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_visibility_cb);
        
-       BIF_undo_push("Outliner toggle selectability");
+       ED_region_tag_redraw(ar);
+       
+       return OPERATOR_FINISHED;
+}
 
-       allqueue(REDRAWVIEW3D, 1);
-       allqueue(REDRAWOOPS, 0);
-       allqueue(REDRAWINFO, 1);
+void OUTLINER_OT_visibility_toggle(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Toggle Visability";
+       ot->idname= "OUTLINER_OT_visibility_toggle";
+       ot->description= "Toggle the visibility of selected items.";
+       
+       /* callbacks */
+       ot->exec= outliner_toggle_visibility_exec;
+       ot->poll= ED_operator_outliner_active;
+       
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-static void object_toggle_selectability_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+/* --- */
+
+static void object_toggle_selectability_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
 {
-       Scene *scene= NULL; // XXX
        Base *base= (Base *)te->directdata;
        
        if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
@@ -1479,21 +1515,37 @@ static void object_toggle_selectability_cb(TreeElement *te, TreeStoreElem *tsep,
        }
 }
 
-void outliner_toggle_selectability(Scene *scene, SpaceOops *soops)
+static int outliner_toggle_selectability_exec(bContext *C, wmOperator *op)
 {
+       SpaceOops *soops= CTX_wm_space_outliner(C);
+       Scene *scene= CTX_data_scene(C);
+       ARegion *ar= CTX_wm_region(C);
+       
+       outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_selectability_cb);
        
-       outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_selectability_cb);
+       ED_region_tag_redraw(ar);
        
-       BIF_undo_push("Outliner toggle selectability");
+       return OPERATOR_FINISHED;
+}
 
-       allqueue(REDRAWVIEW3D, 1);
-       allqueue(REDRAWOOPS, 0);
-       allqueue(REDRAWINFO, 1);
+void OUTLINER_OT_selectability_toggle(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Toggle Selectability";
+       ot->idname= "OUTLINER_OT_selectability_toggle";
+       ot->description= "Toggle the selectability";
+       
+       /* callbacks */
+       ot->exec= outliner_toggle_selectability_exec;
+       ot->poll= ED_operator_outliner_active;
+       
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-void object_toggle_renderability_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+/* --- */
+
+void object_toggle_renderability_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
 {
-       Scene *scene= NULL;     // XXX
        Base *base= (Base *)te->directdata;
        
        if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
@@ -1502,42 +1554,100 @@ void object_toggle_renderability_cb(TreeElement *te, TreeStoreElem *tsep, TreeSt
        }
 }
 
-void outliner_toggle_renderability(Scene *scene, SpaceOops *soops)
+static int outliner_toggle_renderability_exec(bContext *C, wmOperator *op)
 {
-
-       outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_renderability_cb);
+       SpaceOops *soops= CTX_wm_space_outliner(C);
+       Scene *scene= CTX_data_scene(C);
+       ARegion *ar= CTX_wm_region(C);
+       
+       outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_renderability_cb);
        
-       BIF_undo_push("Outliner toggle renderability");
+       ED_region_tag_redraw(ar);
+       
+       return OPERATOR_FINISHED;
+}
 
-       allqueue(REDRAWVIEW3D, 1);
-       allqueue(REDRAWOOPS, 0);
-       allqueue(REDRAWINFO, 1);
+void OUTLINER_OT_renderability_toggle(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Toggle Renderability";
+       ot->idname= "OUTLINER_OT_renderability_toggle";
+       ot->description= "Toggle the renderbility of selected items.";
+       
+       /* callbacks */
+       ot->exec= outliner_toggle_renderability_exec;
+       ot->poll= ED_operator_outliner_active;
+       
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-void outliner_toggle_visible(SpaceOops *soops)
+/* --- */
+
+static int outliner_toggle_expanded_exec(bContext *C, wmOperator *op)
 {
+       SpaceOops *soops= CTX_wm_space_outliner(C);
+       ARegion *ar= CTX_wm_region(C);
        
-       ifoutliner_has_one_flag(soops, &soops->tree, TSE_CLOSED, 1))
+       if (outliner_has_one_flag(soops, &soops->tree, TSE_CLOSED, 1))
                outliner_set_flag(soops, &soops->tree, TSE_CLOSED, 0);
        else 
                outliner_set_flag(soops, &soops->tree, TSE_CLOSED, 1);
+       
+       ED_region_tag_redraw(ar);
+       
+       return OPERATOR_FINISHED;
+}
 
-       BIF_undo_push("Outliner toggle visible");
+void OUTLINER_OT_expanded_toggle(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Expand/Collapse All";
+       ot->idname= "OUTLINER_OT_expanded_toggle";
+       ot->description= "Expand/Collapse all items.";
+       
+       /* callbacks */
+       ot->exec= outliner_toggle_expanded_exec;
+       ot->poll= ED_operator_outliner_active;
+       
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-void outliner_toggle_selected(ARegion *ar, SpaceOops *soops)
+/* --- */
+
+static int outliner_toggle_selected_exec(bContext *C, wmOperator *op)
 {
+       SpaceOops *soops= CTX_wm_space_outliner(C);
+       ARegion *ar= CTX_wm_region(C);
        
-       ifoutliner_has_one_flag(soops, &soops->tree, TSE_SELECTED, 1))
+       if (outliner_has_one_flag(soops, &soops->tree, TSE_SELECTED, 1))
                outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
        else 
                outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 1);
        
-       BIF_undo_push("Outliner toggle selected");
        soops->storeflag |= SO_TREESTORE_REDRAW;
+       
+       ED_region_tag_redraw(ar);
+       
+       return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_selected_toggle(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Toggle Selected";
+       ot->idname= "OUTLINER_OT_selected_toggle";
+       ot->description= "Toggle the Outliner selection of items.";
+       
+       /* callbacks */
+       ot->exec= outliner_toggle_selected_exec;
+       ot->poll= ED_operator_outliner_active;
+       
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+/* --- */
 
+/* helper function for Show/Hide one level operator */
 static void outliner_openclose_level(SpaceOops *soops, ListBase *lb, int curlevel, int level, int open)
 {
        TreeElement *te;
@@ -1557,6 +1667,43 @@ static void outliner_openclose_level(SpaceOops *soops, ListBase *lb, int curleve
        }
 }
 
+static int outliner_one_level_exec(bContext *C, wmOperator *op)
+{
+       SpaceOops *soops= CTX_wm_space_outliner(C);
+       ARegion *ar= CTX_wm_region(C);
+       int add= RNA_boolean_get(op->ptr, "open");
+       int level;
+       
+       level= outliner_has_one_flag(soops, &soops->tree, TSE_CLOSED, 1);
+       if(add==1) {
+               if(level) outliner_openclose_level(soops, &soops->tree, 1, level, 1);
+       }
+       else {
+               if(level==0) level= outliner_count_levels(soops, &soops->tree, 0);
+               if(level) outliner_openclose_level(soops, &soops->tree, 1, level-1, 0);
+       }
+       
+       ED_region_tag_redraw(ar);
+       
+       return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_show_one_level(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Show/Hide One Level";
+       ot->idname= "OUTLINER_OT_show_one_level";
+       
+       /* callbacks */
+       ot->exec= outliner_one_level_exec;
+       ot->poll= ED_operator_outliner_active;
+       
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* properties */
+       RNA_def_boolean(ot->srna, "open", 1, "Open", "Expand all entries one level deep.");
+}
+
 /* return 1 when levels were opened */
 static int outliner_open_back(SpaceOops *soops, TreeElement *te)
 {
@@ -1599,22 +1746,7 @@ static void outliner_open_reveal(SpaceOops *soops, ListBase *lb, TreeElement *te
 }
 #endif
 
-void outliner_one_level(SpaceOops *soops, int add)
-{
-       int level;
-       
-       level= outliner_has_one_flag(soops, &soops->tree, TSE_CLOSED, 1);
-       if(add==1) {
-               if(level) outliner_openclose_level(soops, &soops->tree, 1, level, 1);
-       }
-       else {
-               if(level==0) level= outliner_count_levels(soops, &soops->tree, 0);
-               if(level) outliner_openclose_level(soops, &soops->tree, 1, level-1, 0);
-       }
-       
-       BIF_undo_push("Outliner show/hide one level");
-}
-
+// XXX just use View2D ops for this?
 void outliner_page_up_down(Scene *scene, ARegion *ar, SpaceOops *soops, int up)
 {
        int dy= ar->v2d.mask.ymax-ar->v2d.mask.ymin;
@@ -1628,7 +1760,7 @@ void outliner_page_up_down(Scene *scene, ARegion *ar, SpaceOops *soops, int up)
 
 /* **** do clicks on items ******* */
 
-static int tree_element_active_renderlayer(TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_renderlayer(bContext *C, TreeElement *te, TreeStoreElem *tselem, int set)
 {
        Scene *sce;
        
@@ -1639,7 +1771,7 @@ static int tree_element_active_renderlayer(TreeElement *te, TreeStoreElem *tsele
        
        if(set) {
                sce->r.actlay= tselem->nr;
-               allqueue(REDRAWBUTSSCENE, 0);
+               WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, sce);
        }
        else {
                return sce->r.actlay==tselem->nr;
@@ -1647,13 +1779,12 @@ static int tree_element_active_renderlayer(TreeElement *te, TreeStoreElem *tsele
        return 0;
 }
 
-static void tree_element_set_active_object(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te)
+static void tree_element_set_active_object(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
 {
        TreeStoreElem *tselem= TREESTORE(te);
        Scene *sce;
        Base *base;
        Object *ob= NULL;
-       int shift= 0; // XXX
        
        /* if id is not object, we search back */
        if(te->idcode==ID_OB) ob= (Object *)tselem->id;
@@ -1665,15 +1796,14 @@ static void tree_element_set_active_object(bContext *C, Scene *scene, SpaceOops
        
        sce= (Scene *)outliner_search_back(soops, te, ID_SCE);
        if(sce && scene != sce) {
-// XXX         if(obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
-               set_scene(sce);
+               ED_screen_set_scene(C, sce);
        }
        
        /* find associated base in current scene */
        for(base= FIRSTBASE; base; base= base->next) 
                if(base->object==ob) break;
        if(base) {
-               if(shift) {
+               if(set==2) {
                        /* swap select */
                        if(base->flag & SELECT)
                                ED_base_object_select(base, BA_DESELECT);
@@ -1693,11 +1823,14 @@ static void tree_element_set_active_object(bContext *C, Scene *scene, SpaceOops
                        ED_base_object_activate(C, base); /* adds notifier */
        }
        
-// XXX if(ob!=obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
-//     else countall(); /* exit_editmode calls f() */
+       if(ob!=scene->obedit) 
+               ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
+       
+       WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
+
 }
 
-static int tree_element_active_material(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
+static int tree_element_active_material(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
 {
        TreeElement *tes;
        Object *ob;
@@ -1711,36 +1844,33 @@ static int tree_element_active_material(Scene *scene, SpaceOops *soops, TreeElem
        if(tes->idcode==ID_OB) {
                if(set) {
                        ob->actcol= te->index+1;
-                       ob->colbits |= (1<<te->index);  // make ob material active too
+                       ob->matbits[te->index]= 1;      // make ob material active too
+                       ob->colbits |= (1<<te->index);
                }
                else {
                        if(ob->actcol == te->index+1) 
-                               if(ob->colbits & (1<<te->index)) return 1;
+                               if(ob->matbits[te->index]) return 1;
                }
        }
        /* or we search for obdata material */
        else {
                if(set) {
                        ob->actcol= te->index+1;
-                       ob->colbits &= ~(1<<te->index); // make obdata material active too
+                       ob->matbits[te->index]= 0;      // make obdata material active too
+                       ob->colbits &= ~(1<<te->index);
                }
                else {
                        if(ob->actcol == te->index+1)
-                               if( (ob->colbits & (1<<te->index))==0 ) return 1;
+                               if(ob->matbits[te->index]==0) return 1;
                }
        }
        if(set) {
-// XXX         extern_set_butspace(F5KEY, 0);  // force shading buttons
-               BIF_preview_changed(ID_MA);
-               allqueue(REDRAWBUTSSHADING, 1);
-               allqueue(REDRAWNODE, 0);
-               allqueue(REDRAWOOPS, 0);
-               allqueue(REDRAWIPO, 0);
+               WM_event_add_notifier(C, NC_MATERIAL|ND_SHADING, NULL);
        }
        return 0;
 }
 
-static int tree_element_active_texture(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
+static int tree_element_active_texture(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
 {
        TreeElement *tep;
        TreeStoreElem *tselem, *tselemp;
@@ -1763,8 +1893,8 @@ static int tree_element_active_texture(Scene *scene, SpaceOops *soops, TreeEleme
 
                if(set) {
                        if(sbuts) {
-                               sbuts->tabo= TAB_SHADING_TEX;   // hack from header_buttonswin.c
-                               sbuts->texfrom= 1;
+                               // XXX sbuts->tabo= TAB_SHADING_TEX;    // hack from header_buttonswin.c
+                               // XXX sbuts->texfrom= 1;
                        }
 // XXX                 extern_set_butspace(F6KEY, 0);  // force shading buttons texture
                        wrld->texact= te->index;
@@ -1777,8 +1907,8 @@ static int tree_element_active_texture(Scene *scene, SpaceOops *soops, TreeEleme
                Lamp *la= (Lamp *)tselemp->id;
                if(set) {
                        if(sbuts) {
-                               sbuts->tabo= TAB_SHADING_TEX;   // hack from header_buttonswin.c
-                               sbuts->texfrom= 2;
+                               // XXX sbuts->tabo= TAB_SHADING_TEX;    // hack from header_buttonswin.c
+                               // XXX sbuts->texfrom= 2;
                        }
 // XXX                 extern_set_butspace(F6KEY, 0);  // force shading buttons texture
                        la->texact= te->index;
@@ -1794,7 +1924,7 @@ static int tree_element_active_texture(Scene *scene, SpaceOops *soops, TreeEleme
                if(set) {
                        if(sbuts) {
                                //sbuts->tabo= TAB_SHADING_TEX; // hack from header_buttonswin.c
-                               sbuts->texfrom= 0;
+                               // XXX sbuts->texfrom= 0;
                        }
 // XXX                 extern_set_butspace(F6KEY, 0);  // force shading buttons texture
                        ma->texact= (char)te->index;
@@ -1811,7 +1941,7 @@ static int tree_element_active_texture(Scene *scene, SpaceOops *soops, TreeEleme
 }
 
 
-static int tree_element_active_lamp(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
+static int tree_element_active_lamp(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
 {
        Object *ob;
        
@@ -1821,17 +1951,13 @@ static int tree_element_active_lamp(Scene *scene, SpaceOops *soops, TreeElement
        
        if(set) {
 // XXX         extern_set_butspace(F5KEY, 0);
-               BIF_preview_changed(ID_LA);
-               allqueue(REDRAWBUTSSHADING, 1);
-               allqueue(REDRAWOOPS, 0);
-               allqueue(REDRAWIPO, 0);
        }
        else return 1;
        
        return 0;
 }
 
-static int tree_element_active_world(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
+static int tree_element_active_world(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
 {
        TreeElement *tep;
        TreeStoreElem *tselem=NULL;
@@ -1845,8 +1971,7 @@ static int tree_element_active_world(Scene *scene, SpaceOops *soops, TreeElement
        
        if(set) {       // make new scene active
                if(sce && scene != sce) {
-// XXX                 if(obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
-                       set_scene(sce);
+                       ED_screen_set_scene(C, sce);
                }
        }
        
@@ -1861,7 +1986,7 @@ static int tree_element_active_world(Scene *scene, SpaceOops *soops, TreeElement
        return 0;
 }
 
-static int tree_element_active_defgroup(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_defgroup(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
 {
        Object *ob;
        
@@ -1870,7 +1995,7 @@ static int tree_element_active_defgroup(Scene *scene, TreeElement *te, TreeStore
        if(set) {
                ob->actdef= te->index+1;
                DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
-               allqueue(REDRAWVIEW3D, ob->ipowin);
+               WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
        }
        else {
                if(ob==OBACT)
@@ -1879,14 +2004,14 @@ static int tree_element_active_defgroup(Scene *scene, TreeElement *te, TreeStore
        return 0;
 }
 
-static int tree_element_active_posegroup(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_posegroup(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
 {
        Object *ob= (Object *)tselem->id;
        
        if(set) {
                if (ob->pose) {
                        ob->pose->active_group= te->index+1;
-                       allqueue(REDRAWBUTSEDIT, 0);
+                       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
                }
        }
        else {
@@ -1897,7 +2022,7 @@ static int tree_element_active_posegroup(Scene *scene, TreeElement *te, TreeStor
        return 0;
 }
 
-static int tree_element_active_posechannel(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_posechannel(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
 {
        Object *ob= (Object *)tselem->id;
        bPoseChannel *pchan= te->directdata;
@@ -1905,13 +2030,16 @@ static int tree_element_active_posechannel(Scene *scene, TreeElement *te, TreeSt
        if(set) {
                if(!(pchan->bone->flag & BONE_HIDDEN_P)) {
                        
-// XXX                 if(G.qual & LR_SHIFTKEY) deselectall_posearmature(ob, 2, 0);    // 2 = clear active tag
-//                     else deselectall_posearmature(ob, 0, 0);        // 0 = deselect 
-                       pchan->bone->flag |= BONE_SELECTED|BONE_ACTIVE;
+                       if(set==2) ED_pose_deselectall(ob, 2, 0);       // 2 = clear active tag
+                       else ED_pose_deselectall(ob, 0, 0);     // 0 = deselect 
                        
-                       allqueue(REDRAWVIEW3D, 0);
-                       allqueue(REDRAWOOPS, 0);
-                       allqueue(REDRAWACTION, 0);
+                       if(set==2 && (pchan->bone->flag & BONE_SELECTED))
+                               pchan->bone->flag &= ~(BONE_SELECTED|BONE_ACTIVE);
+                       else
+                               pchan->bone->flag |= BONE_SELECTED|BONE_ACTIVE;
+                       
+                       WM_event_add_notifier(C, NC_OBJECT|ND_BONE_ACTIVE, ob);
+
                }
        }
        else {
@@ -1922,20 +2050,22 @@ static int tree_element_active_posechannel(Scene *scene, TreeElement *te, TreeSt
        return 0;
 }
 
-static int tree_element_active_bone(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_bone(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
 {
        bArmature *arm= (bArmature *)tselem->id;
        Bone *bone= te->directdata;
        
        if(set) {
                if(!(bone->flag & BONE_HIDDEN_P)) {
-// XXX                 if(G.qual & LR_SHIFTKEY) deselectall_posearmature(OBACT, 2, 0); // 2 is clear active tag
-//                     else deselectall_posearmature(OBACT, 0, 0);
-                       bone->flag |= BONE_SELECTED|BONE_ACTIVE;
+                       if(set==2) ED_pose_deselectall(OBACT, 2, 0);    // 2 is clear active tag
+                       else ED_pose_deselectall(OBACT, 0, 0);
+                       
+                       if(set==2 && (bone->flag & BONE_SELECTED))
+                               bone->flag &= ~(BONE_SELECTED|BONE_ACTIVE);
+                       else
+                               bone->flag |= BONE_SELECTED|BONE_ACTIVE;
                        
-                       allqueue(REDRAWVIEW3D, 0);
-                       allqueue(REDRAWOOPS, 0);
-                       allqueue(REDRAWACTION, 0);
+                       WM_event_add_notifier(C, NC_OBJECT|ND_BONE_ACTIVE, OBACT);
                }
        }
        else {
@@ -1950,24 +2080,21 @@ static int tree_element_active_bone(Scene *scene, TreeElement *te, TreeStoreElem
 
 
 /* ebones only draw in editmode armature */
-static int tree_element_active_ebone(TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_ebone(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
 {
        EditBone *ebone= te->directdata;
-//     int shift= 0; // XXX
        
        if(set) {
                if(!(ebone->flag & BONE_HIDDEN_A)) {
                        
-// XXX                 if(shift) deselectall_armature(2, 0);   // only clear active tag
-//                     else deselectall_armature(0, 0);        // deselect
+                       if(set==2) ED_armature_deselectall(scene->obedit, 2, 0);        // only clear active tag
+                       else ED_armature_deselectall(scene->obedit, 0, 0);      // deselect
 
                        ebone->flag |= BONE_SELECTED|BONE_ROOTSEL|BONE_TIPSEL|BONE_ACTIVE;
                        // flush to parent?
                        if(ebone->parent && (ebone->flag & BONE_CONNECTED)) ebone->parent->flag |= BONE_TIPSEL;
                        
-                       allqueue(REDRAWVIEW3D, 0);
-                       allqueue(REDRAWOOPS, 0);
-                       allqueue(REDRAWACTION, 0);
+                       WM_event_add_notifier(C, NC_OBJECT|ND_BONE_ACTIVE, scene->obedit);
                }
        }
        else {
@@ -1976,84 +2103,97 @@ static int tree_element_active_ebone(TreeElement *te, TreeStoreElem *tselem, int
        return 0;
 }
 
-static int tree_element_active_modifier(TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_modifier(bContext *C, TreeElement *te, TreeStoreElem *tselem, int set)
 {
        if(set) {
+               Object *ob= (Object *)tselem->id;
+               
+               WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
+
 // XXX         extern_set_butspace(F9KEY, 0);
        }
        
        return 0;
 }
 
-static int tree_element_active_psys(TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_psys(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
 {
        if(set) {
-//             Object *ob= (Object *)tselem->id;
-//             ParticleSystem *psys= te->directdata;
+               Object *ob= (Object *)tselem->id;
+               ParticleSystem *psys= te->directdata;
+               
+               PE_change_act_psys(scene, ob, psys);
+               WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE, ob);
                
-// XXX         PE_change_act_psys(ob, psys);
 // XXX         extern_set_butspace(F7KEY, 0);
        }
        
        return 0;
 }
 
-static int tree_element_active_constraint(TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_constraint(bContext *C, TreeElement *te, TreeStoreElem *tselem, int set)
 {
        if(set) {
+               Object *ob= (Object *)tselem->id;
+               
+               WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, ob);
 // XXX         extern_set_butspace(F7KEY, 0);
        }
        
        return 0;
 }
 
-static int tree_element_active_text(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
+static int tree_element_active_text(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
 {
        // XXX removed
        return 0;
 }
 
 /* generic call for ID data check or make/check active in UI */
-static int tree_element_active(Scene *scene, SpaceOops *soops, TreeElement *te, int set)
+static int tree_element_active(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, int set)
 {
 
        switch(te->idcode) {
                case ID_MA:
-                       return tree_element_active_material(scene, soops, te, set);
+                       return tree_element_active_material(C, scene, soops, te, set);
                case ID_WO:
-                       return tree_element_active_world(scene, soops, te, set);
+                       return tree_element_active_world(C, scene, soops, te, set);
                case ID_LA:
-                       return tree_element_active_lamp(scene, soops, te, set);
+                       return tree_element_active_lamp(C, scene, soops, te, set);
                case ID_TE:
-                       return tree_element_active_texture(scene, soops, te, set);
+                       return tree_element_active_texture(C, scene, soops, te, set);
                case ID_TXT:
-                       return tree_element_active_text(scene, soops, te, set);
+                       return tree_element_active_text(C, scene, soops, te, set);
        }
        return 0;
 }
 
-static int tree_element_active_pose(TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_pose(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
 {
        Object *ob= (Object *)tselem->id;
+       Base *base= object_in_scene(ob, scene);
        
        if(set) {
-// XXX         if(obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
-//             if(ob->flag & OB_POSEMODE) exit_posemode();
-//             else enter_posemode();
+               if(scene->obedit) 
+                       ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
+               
+               if(ob->mode & OB_MODE_POSE) 
+                       ED_armature_exit_posemode(C, base);
+               else 
+                       ED_armature_enter_posemode(C, base);
        }
        else {
-               if(ob->flag & OB_POSEMODE) return 1;
+               if(ob->mode & OB_MODE_POSE) return 1;
        }
        return 0;
 }
 
-static int tree_element_active_sequence(TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_sequence(bContext *C, TreeElement *te, TreeStoreElem *tselem, int set)
 {
        Sequence *seq= (Sequence*) te->directdata;
 
        if(set) {
 // XXX         select_single_seq(seq, 1);
-               allqueue(REDRAWSEQ, 0);
        }
        else {
                if(seq->flag & SELECT)
@@ -2062,7 +2202,7 @@ static int tree_element_active_sequence(TreeElement *te, TreeStoreElem *tselem,
        return(0);
 }
 
-static int tree_element_active_sequence_dup(Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_sequence_dup(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
 {
        Sequence *seq, *p;
        Editing *ed= seq_give_editing(scene, FALSE);
@@ -2086,10 +2226,24 @@ static int tree_element_active_sequence_dup(Scene *scene, TreeElement *te, TreeS
 // XXX                 select_single_seq(p, 0);
                p= p->next;
        }
-       allqueue(REDRAWSEQ, 0);
        return(0);
 }
 
+static int tree_element_active_keymap_item(bContext *C, TreeElement *te, TreeStoreElem *tselem, int set)
+{
+       wmKeymapItem *kmi= te->directdata;
+       
+       if(set==0) {
+               if(kmi->inactive) return 0;
+               return 1;
+       }
+       else {
+               kmi->inactive= !kmi->inactive;
+       }
+       return 0;
+}
+
+
 /* generic call for non-id data to make/check active in UI */
 /* Context can be NULL when set==0 */
 static int tree_element_type_active(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te, TreeStoreElem *tselem, int set)
@@ -2097,59 +2251,56 @@ static int tree_element_type_active(bContext *C, Scene *scene, SpaceOops *soops,
        
        switch(tselem->type) {
                case TSE_DEFGROUP:
-                       return tree_element_active_defgroup(scene, te, tselem, set);
+                       return tree_element_active_defgroup(C, scene, te, tselem, set);
                case TSE_BONE:
-                       return tree_element_active_bone(scene, te, tselem, set);
+                       return tree_element_active_bone(C, scene, te, tselem, set);
                case TSE_EBONE:
-                       return tree_element_active_ebone(te, tselem, set);
+                       return tree_element_active_ebone(C, scene, te, tselem, set);
                case TSE_MODIFIER:
-                       return tree_element_active_modifier(te, tselem, set);
+                       return tree_element_active_modifier(C, te, tselem, set);
                case TSE_LINKED_OB:
-                       if(set) tree_element_set_active_object(C, scene, soops, te);
+                       if(set) tree_element_set_active_object(C, scene, soops, te, set);
                        else if(tselem->id==(ID *)OBACT) return 1;
                        break;
                case TSE_LINKED_PSYS:
-                       return tree_element_active_psys(te, tselem, set);
-                       break;
+                       return tree_element_active_psys(C, scene, te, tselem, set);
                case TSE_POSE_BASE:
-                       return tree_element_active_pose(te, tselem, set);
-                       break;
+                       return tree_element_active_pose(C, scene, te, tselem, set);
                case TSE_POSE_CHANNEL:
-                       return tree_element_active_posechannel(scene, te, tselem, set);
+                       return tree_element_active_posechannel(C, scene, te, tselem, set);
                case TSE_CONSTRAINT:
-                       return tree_element_active_constraint(te, tselem, set);
+                       return tree_element_active_constraint(C, te, tselem, set);
                case TSE_R_LAYER:
-                       return tree_element_active_renderlayer(te, tselem, set);
+                       return tree_element_active_renderlayer(C, te, tselem, set);
                case TSE_POSEGRP:
-                       return tree_element_active_posegroup(scene, te, tselem, set);
+                       return tree_element_active_posegroup(C, scene, te, tselem, set);
                case TSE_SEQUENCE:
-                       return tree_element_active_sequence(te, tselem, set);
-                       break;
+                       return tree_element_active_sequence(C, te, tselem, set);
                case TSE_SEQUENCE_DUP:
-                       return tree_element_active_sequence_dup(scene, te, tselem, set);
-                       break;
+                       return tree_element_active_sequence_dup(C, scene, te, tselem, set);
+               case TSE_KEYMAP_ITEM:
+                       return tree_element_active_keymap_item(C, te, tselem, set);
+                       
        }
        return 0;
 }
 
-static int do_outliner_mouse_event(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, short event, float *mval)
+static int do_outliner_item_activate(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, int extend, float *mval)
 {
-       int shift= 0, ctrl= 0; // XXX
        
        if(mval[1]>te->ys && mval[1]<te->ys+OL_H) {
                TreeStoreElem *tselem= TREESTORE(te);
                int openclose= 0;
 
-               /* open close icon, three things to check */
-               if(event==RETKEY || event==PADENTER) openclose= 1; // enter opens/closes always
-               else if((te->flag & TE_ICONROW)==0) {                           // hidden icon, no open/close
-                       if( mval[0]>te->xs && mval[0]<te->xs+OL_X) openclose= 1;
+               /* open close icon */
+               if((te->flag & TE_ICONROW)==0) {                                // hidden icon, no open/close
+                       if( mval[0]>te->xs && mval[0]<te->xs+OL_X) 
+                               openclose= 1;
                }
 
                if(openclose) {
-                       
                        /* all below close/open? */
-                       if(shift) {
+                       if(extend) {
                                tselem->flag &= ~TSE_CLOSED;
                                outliner_set_flag(soops, &te->subtree, TSE_CLOSED, !outliner_has_one_flag(soops, &te->subtree, TSE_CLOSED, 1));
                        }
@@ -2158,213 +2309,325 @@ static int do_outliner_mouse_event(bContext *C, Scene *scene, ARegion *ar, Space
                                else tselem->flag |= TSE_CLOSED;
                                
                        }
-                       
+
                        return 1;
                }
                /* name and first icon */
                else if(mval[0]>te->xs && mval[0]<te->xend) {
                        
-                       /* activate a name button? */
-                       if(event==LEFTMOUSE) {
+                       /* always makes active object */
+                       if(tselem->type!=TSE_SEQUENCE && tselem->type!=TSE_SEQ_STRIP && tselem->type!=TSE_SEQUENCE_DUP)
+                               tree_element_set_active_object(C, scene, soops, te, 1 + (extend!=0 && tselem->type==0));
                        
-                               if (ctrl) {
-                                       if(ELEM10(tselem->type, TSE_ANIM_DATA, TSE_NLA, TSE_DEFGROUP_BASE, TSE_CONSTRAINT_BASE, TSE_MODIFIER_BASE, TSE_SCRIPT_BASE, TSE_POSE_BASE, TSE_POSEGRP_BASE, TSE_R_LAYER_BASE, TSE_R_PASS)) 
-                                               error("Cannot edit builtin name");
-                                       else if(ELEM3(tselem->type, TSE_SEQUENCE, TSE_SEQ_STRIP, TSE_SEQUENCE_DUP))
-                                               error("Cannot edit sequence name");
-                                       else if(tselem->id->lib) {
-// XXX                                         error_libdata();
-                                       } else if(te->idcode == ID_LI && te->parent) {
-                                               error("Cannot edit the path of an indirectly linked library");
-                                       } else {
-                                               tselem->flag |= TSE_TEXTBUT;
-                                       }
-                               } else {
-                                       /* always makes active object */
-                                       if(tselem->type!=TSE_SEQUENCE && tselem->type!=TSE_SEQ_STRIP && tselem->type!=TSE_SEQUENCE_DUP)
-                                               tree_element_set_active_object(C, scene, soops, te);
-                                       
-                                       if(tselem->type==0) { // the lib blocks
-                                               /* editmode? */
-                                               if(te->idcode==ID_SCE) {
-                                                       if(scene!=(Scene *)tselem->id) {
-// XXX                                                         if(obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
-                                                               set_scene((Scene *)tselem->id);
-                                                       }
-                                               }
-                                               else if(ELEM5(te->idcode, ID_ME, ID_CU, ID_MB, ID_LT, ID_AR)) {
-// XXX                                                 if(obedit) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
-//                                                     else {
-//                                                             enter_editmode(EM_WAITCURSOR);
-//                                                             extern_set_butspace(F9KEY, 0);
-//                                             }
-                                               } else {        // rest of types
-                                                       tree_element_active(scene, soops, te, 1);
-                                               }
-                                               
+                       if(tselem->type==0) { // the lib blocks
+                               /* editmode? */
+                               if(te->idcode==ID_SCE) {
+                                       if(scene!=(Scene *)tselem->id) {
+                                               ED_screen_set_scene(C, (Scene *)tselem->id);
                                        }
-                                       else tree_element_type_active(C, scene, soops, te, tselem, 1);
                                }
-                       }
-                       else if(event==RIGHTMOUSE) {
-                               /* select object that's clicked on and popup context menu */
-                               if (!(tselem->flag & TSE_SELECTED)) {
-                               
-                                       if ( outliner_has_one_flag(soops, &soops->tree, TSE_SELECTED, 1) )
-                                               outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
-                               
-                                       tselem->flag |= TSE_SELECTED;
-                                       /* redraw, same as outliner_select function */
-                                       soops->storeflag |= SO_TREESTORE_REDRAW;
-// XXX                                 screen_swapbuffers();
+                               else if(ELEM5(te->idcode, ID_ME, ID_CU, ID_MB, ID_LT, ID_AR)) {
+                                       Object *obedit= CTX_data_edit_object(C);
+                                       if(obedit) 
+                                               ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
+                                       else {
+                                               ED_object_enter_editmode(C, EM_WAITCURSOR);
+                                               // XXX extern_set_butspace(F9KEY, 0);
+                                       }
+                               } else {        // rest of types
+                                       tree_element_active(C, scene, soops, te, 1);
                                }
                                
-                               outliner_operation_menu(scene, ar, soops);
                        }
+                       else tree_element_type_active(C, scene, soops, te, tselem, 1+(extend!=0));
+
                        return 1;
                }
        }
        
        for(te= te->subtree.first; te; te= te->next) {
-               if(do_outliner_mouse_event(C, scene, ar, soops, te, event, mval)) return 1;
+               if(do_outliner_item_activate(C, scene, ar, soops, te, extend, mval)) return 1;
        }
        return 0;
 }
 
 /* event can enterkey, then it opens/closes */
-static int outliner_activate_click(bContext *C, wmOperator *op, wmEvent *event)
+static int outliner_item_activate(bContext *C, wmOperator *op, wmEvent *event)
 {
        Scene *scene= CTX_data_scene(C);
        ARegion *ar= CTX_wm_region(C);
-       SpaceOops *soops= (SpaceOops*)CTX_wm_space_data(C);
+       SpaceOops *soops= CTX_wm_space_outliner(C);
        TreeElement *te;
        float fmval[2];
+       int extend= RNA_boolean_get(op->ptr, "extend");
        
        UI_view2d_region_to_view(&ar->v2d, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin, fmval, fmval+1);
        
        for(te= soops->tree.first; te; te= te->next) {
-               if(do_outliner_mouse_event(C, scene, ar, soops, te, event->type, fmval)) break;
+               if(do_outliner_item_activate(C, scene, ar, soops, te, extend, fmval)) break;
        }
        
        if(te) {
-               BIF_undo_push("Outliner click event");
+               ED_undo_push(C, "Outliner click event");
+       }
+       else {
+               short selecting= -1;
+               int row;
+               
+               /* get row number - 100 here is just a dummy value since we don't need the column */
+               UI_view2d_listview_view_to_cell(&ar->v2d, 1000, OL_H, 0.0f, 0.0f, 
+                                               fmval[0], fmval[1], NULL, &row);
+               
+               /* select relevant row */
+               outliner_select(soops, &soops->tree, &row, &selecting);
+               
+               soops->storeflag |= SO_TREESTORE_REDRAW;
+               
+               ED_undo_push(C, "Outliner selection event");
        }
-       else 
-               outliner_select(ar, soops);
        
        ED_region_tag_redraw(ar);
 
        return OPERATOR_FINISHED;
 }
 
-void OUTLINER_OT_activate_click(wmOperatorType *ot)
+void OUTLINER_OT_item_activate(wmOperatorType *ot)
 {
-       ot->name= "Activate Click";
-       ot->idname= "OUTLINER_OT_activate_click";
+       ot->name= "Activate Item";
+       ot->idname= "OUTLINER_OT_item_activate";
        
-       ot->invoke= outliner_activate_click;
+       ot->invoke= outliner_item_activate;
        
        ot->poll= ED_operator_outliner_active;
+       
+       RNA_def_boolean(ot->srna, "extend", 1, "Extend", "Extend selection for activation.");
 }
 
+/* *********** */
 
-
-/* recursive helper for function below */
-static void outliner_set_coordinates_element(SpaceOops *soops, TreeElement *te, int startx, int *starty)
+static int do_outliner_item_openclose(bContext *C, SpaceOops *soops, TreeElement *te, int all, float *mval)
 {
-       TreeStoreElem *tselem= TREESTORE(te);
-       
-       /* store coord and continue, we need coordinates for elements outside view too */
-       te->xs= (float)startx;
-       te->ys= (float)(*starty);
-       *starty-= OL_H;
        
-       if((tselem->flag & TSE_CLOSED)==0) {
-               TreeElement *ten;
-               for(ten= te->subtree.first; ten; ten= ten->next) {
-                       outliner_set_coordinates_element(soops, ten, startx+OL_X, starty);
+       if(mval[1]>te->ys && mval[1]<te->ys+OL_H) {
+               TreeStoreElem *tselem= TREESTORE(te);
+
+               /* all below close/open? */
+               if(all) {
+                       tselem->flag &= ~TSE_CLOSED;
+                       outliner_set_flag(soops, &te->subtree, TSE_CLOSED, !outliner_has_one_flag(soops, &te->subtree, TSE_CLOSED, 1));
+               }
+               else {
+                       if(tselem->flag & TSE_CLOSED) tselem->flag &= ~TSE_CLOSED;
+                       else tselem->flag |= TSE_CLOSED;
                }
+
+               return 1;
+       }
+       
+       for(te= te->subtree.first; te; te= te->next) {
+               if(do_outliner_item_openclose(C, soops, te, all, mval)) 
+                       return 1;
        }
+       return 0;
        
 }
 
-/* to retrieve coordinates with redrawing the entire tree */
-static void outliner_set_coordinates(ARegion *ar, SpaceOops *soops)
+/* event can enterkey, then it opens/closes */
+static int outliner_item_openclose(bContext *C, wmOperator *op, wmEvent *event)
 {
+       ARegion *ar= CTX_wm_region(C);
+       SpaceOops *soops= CTX_wm_space_outliner(C);
        TreeElement *te;
-       int starty= (int)(ar->v2d.tot.ymax)-OL_H;
-       int startx= 0;
+       float fmval[2];
+       int all= RNA_boolean_get(op->ptr, "all");
+       
+       UI_view2d_region_to_view(&ar->v2d, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin, fmval, fmval+1);
        
        for(te= soops->tree.first; te; te= te->next) {
-               outliner_set_coordinates_element(soops, te, startx, &starty);
+               if(do_outliner_item_openclose(C, soops, te, all, fmval)) 
+                       break;
        }
+
+       ED_region_tag_redraw(ar);
+       
+       return OPERATOR_FINISHED;
 }
 
-static TreeElement *outliner_find_id(SpaceOops *soops, ListBase *lb, ID *id)
+void OUTLINER_OT_item_openclose(wmOperatorType *ot)
 {
-       TreeElement *te, *tes;
-       TreeStoreElem *tselem;
+       ot->name= "Open/Close Item";
+       ot->idname= "OUTLINER_OT_item_openclose";
        
-       for(te= lb->first; te; te= te->next) {
-               tselem= TREESTORE(te);
-               if(tselem->type==0) {
-                       if(tselem->id==id) return te;
-                       /* only deeper on scene or object */
-                       if( te->idcode==ID_OB || te->idcode==ID_SCE) { 
-                               tes= outliner_find_id(soops, &te->subtree, id);
-                               if(tes) return tes;
-                       }
-               }
-       }
-       return NULL;
+       ot->invoke= outliner_item_openclose;
+       
+       ot->poll= ED_operator_outliner_active;
+       
+       RNA_def_boolean(ot->srna, "all", 1, "All", "Close or open all items.");
+
 }
 
-void outliner_show_active(Scene *scene, ARegion *ar, SpaceOops *so)
+
+/* ********************************************** */
+
+static int do_outliner_item_rename(bContext *C, ARegion *ar, SpaceOops *soops, TreeElement *te, float *mval)
 {
-       TreeElement *te;
-       int xdelta, ytop;
-       
-       if(OBACT == NULL) return;
        
-       te= outliner_find_id(so, &so->tree, (ID *)OBACT);
-       if(te) {
-               /* make te->ys center of view */
-               ytop= (int)(te->ys + (ar->v2d.mask.ymax-ar->v2d.mask.ymin)/2);
-               if(ytop>0) ytop= 0;
-               ar->v2d.cur.ymax= (float)ytop;
-               ar->v2d.cur.ymin= (float)(ytop-(ar->v2d.mask.ymax-ar->v2d.mask.ymin));
-               
-               /* make te->xs ==> te->xend center of view */
-               xdelta = (int)(te->xs - ar->v2d.cur.xmin);
-               ar->v2d.cur.xmin += xdelta;
-               ar->v2d.cur.xmax += xdelta;
+       if(mval[1]>te->ys && mval[1]<te->ys+OL_H) {
+               TreeStoreElem *tselem= TREESTORE(te);
                
-               so->storeflag |= SO_TREESTORE_REDRAW;
+               /* name and first icon */
+               if(mval[0]>te->xs && mval[0]<te->xend) {
+
+                       if(ELEM10(tselem->type, TSE_ANIM_DATA, TSE_NLA, TSE_DEFGROUP_BASE, TSE_CONSTRAINT_BASE, TSE_MODIFIER_BASE, TSE_SCRIPT_BASE, TSE_POSE_BASE, TSE_POSEGRP_BASE, TSE_R_LAYER_BASE, TSE_R_PASS)) 
+                                       error("Cannot edit builtin name");
+                       else if(ELEM3(tselem->type, TSE_SEQUENCE, TSE_SEQ_STRIP, TSE_SEQUENCE_DUP))
+                               error("Cannot edit sequence name");
+                       else if(tselem->id->lib) {
+                               // XXX                                          error_libdata();
+                       } else if(te->idcode == ID_LI && te->parent) {
+                               error("Cannot edit the path of an indirectly linked library");
+                       } else {
+                               tselem->flag |= TSE_TEXTBUT;
+                               ED_region_tag_redraw(ar);
+                       }
+               }
+               return 1;
+       }
+       
+       for(te= te->subtree.first; te; te= te->next) {
+               if(do_outliner_item_rename(C, ar, soops, te, mval)) return 1;
+       }
+       return 0;
+}
+
+static int outliner_item_rename(bContext *C, wmOperator *op, wmEvent *event)
+{
+       ARegion *ar= CTX_wm_region(C);
+       SpaceOops *soops= CTX_wm_space_outliner(C);
+       TreeElement *te;
+       float fmval[2];
+       
+       UI_view2d_region_to_view(&ar->v2d, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin, fmval, fmval+1);
+       
+       for(te= soops->tree.first; te; te= te->next) {
+               if(do_outliner_item_rename(C, ar, soops, te, fmval)) break;
+       }
+       
+       return OPERATOR_FINISHED;
+}
+
+
+void OUTLINER_OT_item_rename(wmOperatorType *ot)
+{
+       ot->name= "Rename Item";
+       ot->idname= "OUTLINER_OT_item_rename";
+       
+       ot->invoke= outliner_item_rename;
+       
+       ot->poll= ED_operator_outliner_active;
+}
+
+
+
+/* recursive helper for function below */
+static void outliner_set_coordinates_element(SpaceOops *soops, TreeElement *te, int startx, int *starty)
+{
+       TreeStoreElem *tselem= TREESTORE(te);
+       
+       /* store coord and continue, we need coordinates for elements outside view too */
+       te->xs= (float)startx;
+       te->ys= (float)(*starty);
+       *starty-= OL_H;
+       
+       if((tselem->flag & TSE_CLOSED)==0) {
+               TreeElement *ten;
+               for(ten= te->subtree.first; ten; ten= ten->next) {
+                       outliner_set_coordinates_element(soops, ten, startx+OL_X, starty);
+               }
+       }
+       
+}
+
+/* to retrieve coordinates with redrawing the entire tree */
+static void outliner_set_coordinates(ARegion *ar, SpaceOops *soops)
+{
+       TreeElement *te;
+       int starty= (int)(ar->v2d.tot.ymax)-OL_H;
+       int startx= 0;
+       
+       for(te= soops->tree.first; te; te= te->next) {
+               outliner_set_coordinates_element(soops, te, startx, &starty);
+       }
+}
+
+static TreeElement *outliner_find_id(SpaceOops *soops, ListBase *lb, ID *id)
+{
+       TreeElement *te, *tes;
+       TreeStoreElem *tselem;
+       
+       for(te= lb->first; te; te= te->next) {
+               tselem= TREESTORE(te);
+               if(tselem->type==0) {
+                       if(tselem->id==id) return te;
+                       /* only deeper on scene or object */
+                       if( te->idcode==ID_OB || te->idcode==ID_SCE) { 
+                               tes= outliner_find_id(soops, &te->subtree, id);
+                               if(tes) return tes;
+                       }
+               }
        }
+       return NULL;
 }
 
-void outliner_show_selected(Scene *scene, ARegion *ar, SpaceOops *so)
+static int outliner_show_active_exec(bContext *C, wmOperator *op)
 {
+       SpaceOops *so= CTX_wm_space_outliner(C);
+       Scene *scene= CTX_data_scene(C);
+       ARegion *ar= CTX_wm_region(C);
+       View2D *v2d= &ar->v2d;
+       
        TreeElement *te;
        int xdelta, ytop;
        
+       // TODO: make this get this info from context instead...
+       if (OBACT == NULL) 
+               return OPERATOR_CANCELLED;
+       
        te= outliner_find_id(so, &so->tree, (ID *)OBACT);
-       if(te) {
+       if (te) {
                /* make te->ys center of view */
-               ytop= (int)(te->ys + (ar->v2d.mask.ymax-ar->v2d.mask.ymin)/2);
-               if(ytop>0) ytop= 0;
-               ar->v2d.cur.ymax= (float)ytop;
-               ar->v2d.cur.ymin= (float)(ytop-(ar->v2d.mask.ymax-ar->v2d.mask.ymin));
+               ytop= (int)(te->ys + (v2d->mask.ymax - v2d->mask.ymin)/2);
+               if (ytop>0) ytop= 0;
+               
+               v2d->cur.ymax= (float)ytop;
+               v2d->cur.ymin= (float)(ytop-(v2d->mask.ymax - v2d->mask.ymin));
                
                /* make te->xs ==> te->xend center of view */
-               xdelta = (int)(te->xs - ar->v2d.cur.xmin);
-               ar->v2d.cur.xmin += xdelta;
-               ar->v2d.cur.xmax += xdelta;
+               xdelta = (int)(te->xs - v2d->cur.xmin);
+               v2d->cur.xmin += xdelta;
+               v2d->cur.xmax += xdelta;
                
                so->storeflag |= SO_TREESTORE_REDRAW;
        }
+       
+       ED_region_tag_redraw(ar);
+       
+       return OPERATOR_FINISHED;
 }
 
+void OUTLINER_OT_show_active(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Show Active";
+       ot->idname= "OUTLINER_OT_show_active";
+       ot->description= "Adjust the view so that the active Object is shown centered.";
+       
+       /* callbacks */
+       ot->exec= outliner_show_active_exec;
+       ot->poll= ED_operator_outliner_active;
+       
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
 
 /* find next element that has this name */
 static TreeElement *outliner_find_named(SpaceOops *soops, ListBase *lb, char *name, int flags, TreeElement *prev, int *prevFound)
@@ -2466,7 +2729,7 @@ void outliner_find_panel(Scene *scene, ARegion *ar, SpaceOops *soops, int again,
 //             else return; /* XXX RETURN! XXX */
        }
 
-       /* do selection and reveil */
+       /* do selection and reveal */
        if (te) {
                tselem= TREESTORE(te);
                if (tselem) {
@@ -2505,6 +2768,7 @@ void outliner_find_panel(Scene *scene, ARegion *ar, SpaceOops *soops, int again,
        }
 }
 
+/* helper function for tree_element_shwo_hierarchy() - recursively checks whether subtrees have any objects*/
 static int subtree_has_objects(SpaceOops *soops, ListBase *lb)
 {
        TreeElement *te;
@@ -2518,6 +2782,7 @@ static int subtree_has_objects(SpaceOops *soops, ListBase *lb)
        return 0;
 }
 
+/* recursive helper function for Show Hierarchy operator */
 static void tree_element_show_hierarchy(Scene *scene, SpaceOops *soops, ListBase *lb)
 {
        TreeElement *te;
@@ -2538,79 +2803,80 @@ static void tree_element_show_hierarchy(Scene *scene, SpaceOops *soops, ListBase
                        }
                }
                else tselem->flag |= TSE_CLOSED;
-
+               
                if(tselem->flag & TSE_CLOSED); else tree_element_show_hierarchy(scene, soops, &te->subtree);
        }
-       
 }
 
 /* show entire object level hierarchy */
-void outliner_show_hierarchy(Scene *scene, SpaceOops *soops)
+static int outliner_show_hierarchy_exec(bContext *C, wmOperator *op)
 {
+       SpaceOops *soops= CTX_wm_space_outliner(C);
+       ARegion *ar= CTX_wm_region(C);
+       Scene *scene= CTX_data_scene(C);
        
+       /* recursively open/close levels */
        tree_element_show_hierarchy(scene, soops, &soops->tree);
        
-       BIF_undo_push("Outliner show hierarchy");
+       ED_region_tag_redraw(ar);
+       
+       return OPERATOR_FINISHED;
 }
 
-#if 0
-static void do_outliner_select(SpaceOops *soops, ListBase *lb, float y1, float y2, short *selecting)
+void OUTLINER_OT_show_hierarchy(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Show Hierarchy";
+       ot->idname= "OUTLINER_OT_show_hierarchy";
+       ot->description= "Open all object entries and close all others.";
+       
+       /* callbacks */
+       ot->exec= outliner_show_hierarchy_exec;
+       ot->poll= ED_operator_outliner_active; //  TODO: shouldn't be allowed in RNA views...
+       
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+void outliner_select(SpaceOops *soops, ListBase *lb, int *index, short *selecting)
 {
        TreeElement *te;
        TreeStoreElem *tselem;
        
-       if(y1>y2) SWAP(float, y1, y2);
-       
-       for(te= lb->first; te; te= te->next) {
+       for (te= lb->first; te && *index >= 0; te=te->next, (*index)--) {
                tselem= TREESTORE(te);
                
-               if(te->ys + OL_H < y1) return;
-               if(te->ys < y2) {
-                       if((te->flag & TE_ICONROW)==0) {
-                               if(*selecting == -1) {
-                                       if( tselem->flag & TSE_SELECTED) *selecting= 0;
-                                       else *selecting= 1;
+               /* if we've encountered the right item, set its 'Outliner' selection status */
+               if (*index == 0) {
+                       /* this should be the last one, so no need to do anything with index */
+                       if ((te->flag & TE_ICONROW)==0) {
+                               /* -1 value means toggle testing for now... */
+                               if (*selecting == -1) {
+                                       if (tselem->flag & TSE_SELECTED) 
+                                               *selecting= 0;
+                                       else 
+                                               *selecting= 1;
                                }
-                               if(*selecting) tselem->flag |= TSE_SELECTED;
-                               else tselem->flag &= ~TSE_SELECTED;
+                               
+                               /* set selection */
+                               if (*selecting) 
+                                       tselem->flag |= TSE_SELECTED;
+                               else 
+                                       tselem->flag &= ~TSE_SELECTED;
                        }
                }
-               if((tselem->flag & TSE_CLOSED)==0) do_outliner_select(soops, &te->subtree, y1, y2, selecting);
-       }
-}
-#endif
-
-/* its own redraw loop... urm */
-void outliner_select(ARegion *ar, SpaceOops *so)
-{
-#if 0
-       XXX
-       float fmval[2], y1, y2;
-       short yo=-1, selecting= -1;
-       
-       UI_view2d_region_to_view(&ar->v2d, event->x, event->y, fmval, fmval+1);
-       
-       y1= fmval[1];
-
-       while (get_mbut() & (L_MOUSE|R_MOUSE)) {
-               UI_view2d_region_to_view(&ar->v2d, event->x, event->y, fmval, fmval+1);
-               y2= fmval[1];
-               
-               if(yo!=mval[1]) {
-                       /* select the 'ouliner row' */
-                       do_outliner_select(so, &so->tree, y1, y2, &selecting);
-                       yo= mval[1];
-                       
-                       so->storeflag |= SO_TREESTORE_REDRAW;
-// XXX                 screen_swapbuffers();
-               
-                       y1= y2;
+               else if ((tselem->flag & TSE_CLOSED)==0) {
+                       /* Only try selecting sub-elements if we haven't hit the right element yet
+                        *
+                        * Hack warning:
+                        *      Index must be reduced before supplying it to the sub-tree to try to do
+                        *      selection, however, we need to increment it again for the next loop to 
+                        *      function correctly
+                        */
+                       (*index)--;
+                       outliner_select(soops, &te->subtree, index, selecting);
+                       (*index)++;
                }
-               else PIL_sleep_ms(30);
        }
-       
-       BIF_undo_push("Outliner selection");
-#endif
 }
 
 /* ************ SELECTION OPERATIONS ********* */
@@ -2628,13 +2894,10 @@ static void set_operation_types(SpaceOops *soops, ListBase *lb,
                tselem= TREESTORE(te);
                if(tselem->flag & TSE_SELECTED) {
                        if(tselem->type) {
-                               if(tselem->type==TSE_SEQUENCE)
-                                       *datalevel= TSE_SEQUENCE;
-                               else if(tselem->type==TSE_SEQ_STRIP)
-                                       *datalevel= TSE_SEQ_STRIP;
-                               else if(tselem->type==TSE_SEQUENCE_DUP)
-                                       *datalevel= TSE_SEQUENCE_DUP;
-                               else if(*datalevel!=tselem->type) *datalevel= -1;
+                               if(*datalevel==0) 
+                                       *datalevel= tselem->type;
+                               else if(*datalevel!=tselem->type) 
+                                       *datalevel= -1;
                        }
                        else {
                                int idcode= GS(tselem->id->name);
@@ -2664,7 +2927,7 @@ static void set_operation_types(SpaceOops *soops, ListBase *lb,
        }
 }
 
-static void unlink_material_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+static void unlink_material_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
 {
        Material **matar=NULL;
        int a, totcol=0;
@@ -2698,7 +2961,7 @@ static void unlink_material_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreEl
        }
 }
 
-static void unlink_texture_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+static void unlink_texture_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
 {
        MTex **mtex= NULL;
        int a;
@@ -2727,7 +2990,7 @@ static void unlink_texture_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreEle
        }
 }
 
-static void unlink_group_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+static void unlink_group_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
 {
        Group *group= (Group *)tselem->id;
        
@@ -2743,8 +3006,8 @@ static void unlink_group_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem
        }
 }
 
-static void outliner_do_libdata_operation(SpaceOops *soops, ListBase *lb, 
-                                                                                void (*operation_cb)(TreeElement *, TreeStoreElem *, TreeStoreElem *))
+static void outliner_do_libdata_operation(bContext *C, Scene *scene, SpaceOops *soops, ListBase *lb, 
+                                                                                void (*operation_cb)(bContext *C, Scene *scene, TreeElement *, TreeStoreElem *, TreeStoreElem *))
 {
        TreeElement *te;
        TreeStoreElem *tselem;
@@ -2754,20 +3017,19 @@ static void outliner_do_libdata_operation(SpaceOops *soops, ListBase *lb,
                if(tselem->flag & TSE_SELECTED) {
                        if(tselem->type==0) {
                                TreeStoreElem *tsep= TREESTORE(te->parent);
-                               operation_cb(te, tsep, tselem);
+                               operation_cb(C, scene, te, tsep, tselem);
                        }
                }
                if((tselem->flag & TSE_CLOSED)==0) {
-                       outliner_do_libdata_operation(soops, &te->subtree, operation_cb);
+                       outliner_do_libdata_operation(C, scene, soops, &te->subtree, operation_cb);
                }
        }
 }
 
 /* */
 
-static void object_select_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+static void object_select_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
 {
-       Scene *scene= NULL;     // XXX
        Base *base= (Base *)te->directdata;
        
        if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
@@ -2777,9 +3039,8 @@ static void object_select_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem
        }
 }
 
-static void object_deselect_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+static void object_deselect_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
 {
-       Scene *scene= NULL;
        Base *base= (Base *)te->directdata;
        
        if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
@@ -2789,28 +3050,27 @@ static void object_deselect_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreEl
        }
 }
 
-static void object_delete_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+static void object_delete_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
 {
-       Scene *scene= NULL;
        Base *base= (Base *)te->directdata;
        
-       if(base==NULL) base= object_in_scene((Object *)tselem->id, scene);
+       if(base==NULL) 
+               base= object_in_scene((Object *)tselem->id, scene);
        if(base) {
                // check also library later
-// XXX         if(obedit==base->object) exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
+               if(scene->obedit==base->object) 
+                       ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
                
-               if(base==BASACT) {
-                       G.f &= ~(G_VERTEXPAINT+G_TEXTUREPAINT+G_WEIGHTPAINT+G_SCULPTMODE);
-// XXX                 setcursor_space(SPACE_VIEW3D, CURSOR_STD);
-               }
-               
-// XXX         free_and_unlink_base(base);
+               ED_base_object_free_and_unlink(scene, base);
                te->directdata= NULL;
                tselem->id= NULL;
        }
+       
+       WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
+
 }
 
-static void id_local_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+static void id_local_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
 {
        if(tselem->id->lib && (tselem->id->flag & LIB_EXTERN)) {
                tselem->id->lib= NULL;
@@ -2819,9 +3079,8 @@ static void id_local_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tse
        }
 }
 
-static void group_linkobs2scene_cb(TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
+static void group_linkobs2scene_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tsep, TreeStoreElem *tselem)
 {
-       Scene *scene= NULL;
        Group *group= (Group *)tselem->id;
        GroupObject *gob;
        Base *base;
@@ -2844,8 +3103,8 @@ static void group_linkobs2scene_cb(TreeElement *te, TreeStoreElem *tsep, TreeSto
        }
 }
 
-static void outliner_do_object_operation(Scene *scene, SpaceOops *soops, ListBase *lb, 
-                                                                                void (*operation_cb)(TreeElement *, TreeStoreElem *, TreeStoreElem *))
+static void outliner_do_object_operation(bContext *C, Scene *scene, SpaceOops *soops, ListBase *lb, 
+                                                                                void (*operation_cb)(bContext *C, Scene *scene, TreeElement *, TreeStoreElem *, TreeStoreElem *))
 {
        TreeElement *te;
        TreeStoreElem *tselem;
@@ -2857,18 +3116,20 @@ static void outliner_do_object_operation(Scene *scene, SpaceOops *soops, ListBas
                                // when objects selected in other scenes... dunno if that should be allowed
                                Scene *sce= (Scene *)outliner_search_back(soops, te, ID_SCE);
                                if(sce && scene != sce) {
-                                       set_scene(sce);
+                                       ED_screen_set_scene(C, sce);
                                }
                                
-                               operation_cb(te, NULL, tselem);
+                               operation_cb(C, scene, te, NULL, tselem);
                        }
                }
                if((tselem->flag & TSE_CLOSED)==0) {
-                       outliner_do_object_operation(scene, soops, &te->subtree, operation_cb);
+                       outliner_do_object_operation(C, scene, soops, &te->subtree, operation_cb);
                }
        }
 }
 
+/* ******************************************** */
+
 static void pchan_cb(int event, TreeElement *te, TreeStoreElem *tselem)
 {
        bPoseChannel *pchan= (bPoseChannel *)te->directdata;
@@ -2917,361 +3178,901 @@ static void ebone_cb(int event, TreeElement *te, TreeStoreElem *tselem)
                ebone->flag &= ~BONE_HIDDEN_A;
 }
 
-static void sequence_cb(int event, TreeElement *te, TreeStoreElem *tselem)
+static void sequence_cb(int event, TreeElement *te, TreeStoreElem *tselem)
+{
+//     Sequence *seq= (Sequence*) te->directdata;
+       if(event==1) {
+// XXX         select_single_seq(seq, 1);
+       }
+}
+
+static void outliner_do_data_operation(SpaceOops *soops, int type, int event, ListBase *lb, 
+                                                                                void (*operation_cb)(int, TreeElement *, TreeStoreElem *))
+{
+       TreeElement *te;
+       TreeStoreElem *tselem;
+       
+       for(te=lb->first; te; te= te->next) {
+               tselem= TREESTORE(te);
+               if(tselem->flag & TSE_SELECTED) {
+                       if(tselem->type==type) {
+                               operation_cb(event, te, tselem);
+                       }
+               }
+               if((tselem->flag & TSE_CLOSED)==0) {
+                       outliner_do_data_operation(soops, type, event, &te->subtree, operation_cb);
+               }
+       }
+}
+
+void outliner_del(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops)
+{
+       
+       if(soops->outlinevis==SO_SEQUENCE)
+               ;//             del_seq();
+       else {
+               outliner_do_object_operation(C, scene, soops, &soops->tree, object_delete_cb);
+               DAG_scene_sort(scene);
+               ED_undo_push(C, "Delete Objects");
+       }
+}
+
+/* **************************************** */
+
+static EnumPropertyItem prop_object_op_types[] = {
+       {1, "SELECT", 0, "Select", ""},
+       {2, "DESELECT", 0, "Deselect", ""},
+       {4, "DELETE", 0, "Delete", ""},
+       {6, "TOGVIS", 0, "Toggle Visible", ""},
+       {7, "TOGSEL", 0, "Toggle Selectable", ""},
+       {8, "TOGREN", 0, "Toggle Renderable", ""},
+       {0, NULL, 0, NULL, NULL}
+};
+
+static int outliner_object_operation_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       SpaceOops *soops= CTX_wm_space_outliner(C);
+       int event;
+       char *str;
+       
+       /* check for invalid states */
+       if (soops == NULL)
+               return OPERATOR_CANCELLED;
+       
+       event= RNA_enum_get(op->ptr, "type");
+
+       if(event==1) {
+               Scene *sce= scene;      // to be able to delete, scenes are set...
+               outliner_do_object_operation(C, scene, soops, &soops->tree, object_select_cb);
+               if(scene != sce) {
+                       ED_screen_set_scene(C, sce);
+               }
+               
+               str= "Select Objects";
+       }
+       else if(event==2) {
+               outliner_do_object_operation(C, scene, soops, &soops->tree, object_deselect_cb);
+               str= "Deselect Objects";
+       }
+       else if(event==4) {
+               outliner_do_object_operation(C, scene, soops, &soops->tree, object_delete_cb);
+               DAG_scene_sort(scene);
+               str= "Delete Objects";
+       }
+       else if(event==5) {     /* disabled, see above (ton) */
+               outliner_do_object_operation(C, scene, soops, &soops->tree, id_local_cb);
+               str= "Localized Objects";
+       }
+       else if(event==6) {
+               outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_visibility_cb);
+               str= "Toggle Visibility";
+       }
+       else if(event==7) {
+               outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_selectability_cb);
+               str= "Toggle Selectability";
+       }
+       else if(event==8) {
+               outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_renderability_cb);
+               str= "Toggle Renderability";
+       }
+       
+       WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
+
+       ED_undo_push(C, str);
+       
+       return OPERATOR_FINISHED;
+}
+
+
+void OUTLINER_OT_object_operation(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Outliner Object Operation";
+       ot->idname= "OUTLINER_OT_object_operation";
+       ot->description= "";
+       
+       /* callbacks */
+       ot->invoke= WM_menu_invoke;
+       ot->exec= outliner_object_operation_exec;
+       ot->poll= ED_operator_outliner_active;
+       
+       ot->flag= 0;
+
+       RNA_def_enum(ot->srna, "type", prop_object_op_types, 0, "Object Operation", "");
+}
+
+/* **************************************** */
+
+static EnumPropertyItem prop_group_op_types[] = {
+       {1, "UNLINK", 0, "Unlink", ""},
+       {2, "LOCAL", 0, "Make Local", ""},
+       {3, "LINK", 0, "Link Group Objects to Scene", ""},
+       {0, NULL, 0, NULL, NULL}
+};
+
+static int outliner_group_operation_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       SpaceOops *soops= CTX_wm_space_outliner(C);
+       int event;
+       
+       /* check for invalid states */
+       if (soops == NULL)
+               return OPERATOR_CANCELLED;
+       
+       event= RNA_enum_get(op->ptr, "type");
+       
+       if(event==1) {
+               outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_group_cb);
+               ED_undo_push(C, "Unlink group");
+       }
+       else if(event==2) {
+               outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_local_cb);
+               ED_undo_push(C, "Localized Data");
+       }
+       else if(event==3) {
+               outliner_do_libdata_operation(C, scene, soops, &soops->tree, group_linkobs2scene_cb);
+               ED_undo_push(C, "Link Group Objects to Scene");
+       }
+       
+       
+       WM_event_add_notifier(C, NC_GROUP, NULL);
+       
+       return OPERATOR_FINISHED;
+}
+
+
+void OUTLINER_OT_group_operation(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Outliner Group Operation";
+       ot->idname= "OUTLINER_OT_group_operation";
+       ot->description= "";
+       
+       /* callbacks */
+       ot->invoke= WM_menu_invoke;
+       ot->exec= outliner_group_operation_exec;
+       ot->poll= ED_operator_outliner_active;
+       
+       ot->flag= 0;
+       
+       RNA_def_enum(ot->srna, "type", prop_group_op_types, 0, "Group Operation", "");
+}
+
+/* **************************************** */
+
+static EnumPropertyItem prop_id_op_types[] = {
+       {1, "UNLINK", 0, "Unlink", ""},
+       {2, "LOCAL", 0, "Make Local", ""},
+       {0, NULL, 0, NULL, NULL}
+};
+
+static int outliner_id_operation_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       SpaceOops *soops= CTX_wm_space_outliner(C);
+       int scenelevel=0, objectlevel=0, idlevel=0, datalevel=0;
+       int event;
+       
+       /* check for invalid states */
+       if (soops == NULL)
+               return OPERATOR_CANCELLED;
+       
+       set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
+       
+       event= RNA_enum_get(op->ptr, "type");
+       
+       if(event==1) {
+               switch(idlevel) {
+                       case ID_MA:
+                               outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_material_cb);
+                               ED_undo_push(C, "Unlink material");
+                               break;
+                       case ID_TE:
+                               outliner_do_libdata_operation(C, scene, soops, &soops->tree, unlink_texture_cb);
+                               ED_undo_push(C, "Unlink texture");
+                               break;
+                       default:
+                               BKE_report(op->reports, RPT_WARNING, "Not Yet");
+               }
+       }
+       else if(event==2) {
+               outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_local_cb);
+               ED_undo_push(C, "Localized Data");
+       }
+       
+       /* wrong notifier still... */
+       WM_event_add_notifier(C, NC_OBJECT, NULL);
+       
+       return OPERATOR_FINISHED;
+}
+
+
+void OUTLINER_OT_id_operation(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Outliner ID data Operation";
+       ot->idname= "OUTLINER_OT_id_operation";
+       ot->description= "";
+       
+       /* callbacks */
+       ot->invoke= WM_menu_invoke;
+       ot->exec= outliner_id_operation_exec;
+       ot->poll= ED_operator_outliner_active;
+       
+       ot->flag= 0;
+       
+       RNA_def_enum(ot->srna, "type", prop_id_op_types, 0, "ID data Operation", "");
+}
+
+/* **************************************** */
+
+static EnumPropertyItem prop_data_op_types[] = {
+       {1, "SELECT", 0, "Select", ""},
+       {2, "DESELECT", 0, "Deselect", ""},
+       {3, "HIDE", 0, "Hide", ""},
+       {4, "UNHIDE", 0, "Unhide", ""},
+       {0, NULL, 0, NULL, NULL}
+};
+
+static int outliner_data_operation_exec(bContext *C, wmOperator *op)
+{
+       SpaceOops *soops= CTX_wm_space_outliner(C);
+       int scenelevel=0, objectlevel=0, idlevel=0, datalevel=0;
+       int event;
+       
+       /* check for invalid states */
+       if (soops == NULL)
+               return OPERATOR_CANCELLED;
+       
+       event= RNA_enum_get(op->ptr, "type");
+       set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
+       
+       if(datalevel==TSE_POSE_CHANNEL) {
+               if(event>0) {
+                       outliner_do_data_operation(soops, datalevel, event, &soops->tree, pchan_cb);
+                       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
+                       ED_undo_push(C, "PoseChannel operation");
+               }
+       }
+       else if(datalevel==TSE_BONE) {
+               if(event>0) {
+                       outliner_do_data_operation(soops, datalevel, event, &soops->tree, bone_cb);
+                       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
+                       ED_undo_push(C, "Bone operation");
+               }
+       }
+       else if(datalevel==TSE_EBONE) {
+               if(event>0) {
+                       outliner_do_data_operation(soops, datalevel, event, &soops->tree, ebone_cb);
+                       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
+                       ED_undo_push(C, "EditBone operation");
+               }
+       }
+       else if(datalevel==TSE_SEQUENCE) {
+               if(event>0) {
+                       outliner_do_data_operation(soops, datalevel, event, &soops->tree, sequence_cb);
+               }
+       }
+       
+       return OPERATOR_FINISHED;
+}
+
+
+void OUTLINER_OT_data_operation(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Outliner Data Operation";
+       ot->idname= "OUTLINER_OT_data_operation";
+       ot->description= "";
+       
+       /* callbacks */
+       ot->invoke= WM_menu_invoke;
+       ot->exec= outliner_data_operation_exec;
+       ot->poll= ED_operator_outliner_active;
+       
+       ot->flag= 0;
+       
+       RNA_def_enum(ot->srna, "type", prop_data_op_types, 0, "Data Operation", "");
+}
+
+
+/* ******************** */
+
+
+static int do_outliner_operation_event(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, wmEvent *event, float *mval)
+{
+       
+       if(mval[1]>te->ys && mval[1]<te->ys+OL_H) {
+               int scenelevel=0, objectlevel=0, idlevel=0, datalevel=0;
+               TreeStoreElem *tselem= TREESTORE(te);
+               
+               /* select object that's clicked on and popup context menu */
+               if (!(tselem->flag & TSE_SELECTED)) {
+                       
+                       if ( outliner_has_one_flag(soops, &soops->tree, TSE_SELECTED, 1) )
+                               outliner_set_flag(soops, &soops->tree, TSE_SELECTED, 0);
+                       
+                       tselem->flag |= TSE_SELECTED;
+                       /* redraw, same as outliner_select function */
+                       soops->storeflag |= SO_TREESTORE_REDRAW;
+                       ED_region_tag_redraw(ar);
+               }
+               
+               set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
+               
+               if(scenelevel) {
+                       //if(objectlevel || datalevel || idlevel) error("Mixed selection");
+                       //else pupmenu("Scene Operations%t|Delete");
+               }
+               else if(objectlevel) {
+                       WM_operator_name_call(C, "OUTLINER_OT_object_operation", WM_OP_INVOKE_REGION_WIN, NULL);
+               }
+               else if(idlevel) {
+                       if(idlevel==-1 || datalevel) error("Mixed selection");
+                       else {
+                               if (idlevel==ID_GR)
+                                       WM_operator_name_call(C, "OUTLINER_OT_group_operation", WM_OP_INVOKE_REGION_WIN, NULL);
+                               else
+                                       WM_operator_name_call(C, "OUTLINER_OT_id_operation", WM_OP_INVOKE_REGION_WIN, NULL);
+                       }
+               }
+               else if(datalevel) {
+                       if(datalevel==-1) error("Mixed selection");
+                       else {
+                               WM_operator_name_call(C, "OUTLINER_OT_data_operation", WM_OP_INVOKE_REGION_WIN, NULL);
+                       }
+               }
+               
+               return 1;
+       }
+       
+       for(te= te->subtree.first; te; te= te->next) {
+               if(do_outliner_operation_event(C, scene, ar, soops, te, event, mval)) 
+                       return 1;
+       }
+       return 0;
+}
+
+
+static int outliner_operation(bContext *C, wmOperator *op, wmEvent *event)
+{
+       Scene *scene= CTX_data_scene(C);
+       ARegion *ar= CTX_wm_region(C);
+       SpaceOops *soops= CTX_wm_space_outliner(C);
+       TreeElement *te;
+       float fmval[2];
+       
+       UI_view2d_region_to_view(&ar->v2d, event->x - ar->winrct.xmin, event->y - ar->winrct.ymin, fmval, fmval+1);
+       
+       for(te= soops->tree.first; te; te= te->next) {
+               if(do_outliner_operation_event(C, scene, ar, soops, te, event, fmval)) break;
+       }
+       
+       return OPERATOR_FINISHED;
+}
+
+/* Menu only! Calls other operators */
+void OUTLINER_OT_operation(wmOperatorType *ot)
+{
+       ot->name= "Execute Operation";
+       ot->idname= "OUTLINER_OT_operation";
+       
+       ot->invoke= outliner_operation;
+       
+       ot->poll= ED_operator_outliner_active;
+}
+
+
+
+/* ***************** ANIMATO OPERATIONS ********************************** */
+/* KeyingSet and Driver Creation - Helper functions */
+
+/* specialised poll callback for these operators to work in Datablocks view only */
+static int ed_operator_outliner_datablocks_active(bContext *C)
+{
+       ScrArea *sa= CTX_wm_area(C);
+       if ((sa) && (sa->spacetype==SPACE_OUTLINER)) {
+               SpaceOops *so= CTX_wm_space_outliner(C);
+               return (so->outlinevis == SO_DATABLOCKS);
+       }
+       return 0;
+}
+
+
+/* Helper func to extract an RNA path from selected tree element 
+ * NOTE: the caller must zero-out all values of the pointers that it passes here first, as
+ * this function does not do that yet 
+ */
+static void tree_element_to_path(SpaceOops *soops, TreeElement *te, TreeStoreElem *tselem, 
+                                                       ID **id, char **path, int *array_index, short *flag, short *groupmode)
+{
+       ListBase hierarchy = {NULL, NULL};
+       LinkData *ld;
+       TreeElement *tem, *temnext, *temsub;
+       TreeStoreElem *tse, *tsenext;
+       PointerRNA *ptr, *nextptr;
+       PropertyRNA *prop;
+       char *newpath=NULL;
+       
+       /* optimise tricks:
+        *      - Don't do anything if the selected item is a 'struct', but arrays are allowed
+        */
+       if (tselem->type == TSE_RNA_STRUCT)
+               return;
+       
+       /* Overview of Algorithm:
+        *      1. Go up the chain of parents until we find the 'root', taking note of the 
+        *         levels encountered in reverse-order (i.e. items are added to the start of the list
+        *      for more convenient looping later)
+        *      2. Walk down the chain, adding from the first ID encountered 
+        *         (which will become the 'ID' for the KeyingSet Path), and build a  
+        *              path as we step through the chain
+        */
+        
+       /* step 1: flatten out hierarchy of parents into a flat chain */
+       for (tem= te->parent; tem; tem= tem->parent) {
+               ld= MEM_callocN(sizeof(LinkData), "LinkData for tree_element_to_path()");
+               ld->data= tem;
+               BLI_addhead(&hierarchy, ld);
+       }
+       
+       /* step 2: step down hierarchy building the path (NOTE: addhead in previous loop was needed so that we can loop like this) */
+       for (ld= hierarchy.first; ld; ld= ld->next) {
+               /* get data */
+               tem= (TreeElement *)ld->data;
+               tse= TREESTORE(tem);
+               ptr= &tem->rnaptr;
+               prop= tem->directdata;
+               
+               /* check if we're looking for first ID, or appending to path */
+               if (*id) {
+                       /* just 'append' property to path 
+                        *      - to prevent memory leaks, we must write to newpath not path, then free old path + swap them
+                        */
+                       if(tse->type == TSE_RNA_PROPERTY) {
+                               if(RNA_property_type(prop) == PROP_POINTER) {
+                                       /* for pointer we just append property name */
+                                       newpath= RNA_path_append(*path, ptr, prop, 0, NULL);
+                               }
+                               else if(RNA_property_type(prop) == PROP_COLLECTION) {
+                                       char buf[128], *name;
+                                       
+                                       temnext= (TreeElement*)(ld->next->data);
+                                       tsenext= TREESTORE(temnext);
+                                       
+                                       nextptr= &temnext->rnaptr;
+                                       name= RNA_struct_name_get_alloc(nextptr, buf, sizeof(buf));
+                                       
+                                       if(name) {
+                                               /* if possible, use name as a key in the path */
+                                               newpath= RNA_path_append(*path, NULL, prop, 0, name);
+                                               
+                                               if(name != buf)
+                                                       MEM_freeN(name);
+                                       }
+                                       else {
+                                               /* otherwise use index */
+                                               int index= 0;
+                                               
+                                               for(temsub=tem->subtree.first; temsub; temsub=temsub->next, index++)
+                                                       if(temsub == temnext)
+                                                               break;
+                                               
+                                               newpath= RNA_path_append(*path, NULL, prop, index, NULL);
+                                       }
+                                       
+                                       ld= ld->next;
+                               }
+                       }
+                       
+                       if(newpath) {
+                               if (*path) MEM_freeN(*path);
+                               *path= newpath;
+                               newpath= NULL;
+                       }
+               }
+               else {
+                       /* no ID, so check if entry is RNA-struct, and if that RNA-struct is an ID datablock to extract info from */
+                       if (tse->type == TSE_RNA_STRUCT) {
+                               /* ptr->data not ptr->id.data seems to be the one we want, since ptr->data is sometimes the owner of this ID? */
+                               if(RNA_struct_is_ID(ptr->type)) {
+                                       *id= (ID *)ptr->data;
+                                       
+                                       /* clear path */
+                                       if(*path) {
+                                               MEM_freeN(*path);
+                                               path= NULL;
+                                       }
+                               }
+                       }
+               }
+       }
+
+       /* step 3: if we've got an ID, add the current item to the path */
+       if (*id) {
+               /* add the active property to the path */
+               ptr= &te->rnaptr;
+               prop= te->directdata;
+               
+               /* array checks */
+               if (tselem->type == TSE_RNA_ARRAY_ELEM) {
+                       /* item is part of an array, so must set the array_index */
+                       *array_index= te->index;
+               }
+               else if (RNA_property_array_length(prop)) {
+                       /* entire array was selected, so keyframe all */
+                       *flag |= KSP_FLAG_WHOLE_ARRAY;
+               }
+               
+               /* path */
+               newpath= RNA_path_append(*path, NULL, prop, 0, NULL);
+               if (*path) MEM_freeN(*path);
+               *path= newpath;
+       }
+
+       /* free temp data */
+       BLI_freelistN(&hierarchy);
+}
+
+/* ***************** KEYINGSET OPERATIONS *************** */
+
+/* These operators are only available in databrowser mode for now, as
+ * they depend on having RNA paths and/or hierarchies available.
+ */
+enum {
+       DRIVERS_EDITMODE_ADD    = 0,
+       DRIVERS_EDITMODE_REMOVE,
+} eDrivers_EditModes;
+
+/* Utilities ---------------------------------- */ 
+
+/* Recursively iterate over tree, finding and working on selected items */
+static void do_outliner_drivers_editop(SpaceOops *soops, ListBase *tree, short mode)
+{
+       TreeElement *te;
+       TreeStoreElem *tselem;
+       
+       for (te= tree->first; te; te=te->next) {
+               tselem= TREESTORE(te);
+               
+               /* if item is selected, perform operation */
+               if (tselem->flag & TSE_SELECTED) {
+                       ID *id= NULL;
+                       char *path= NULL;
+                       int array_index= 0;
+                       short flag= 0;
+                       short groupmode= KSP_GROUP_KSNAME;
+                       
+                       /* check if RNA-property described by this selected element is an animateable prop */
+                       if ((tselem->type == TSE_RNA_PROPERTY) && RNA_property_animateable(&te->rnaptr, te->directdata)) {
+                               /* get id + path + index info from the selected element */
+                               tree_element_to_path(soops, te, tselem, 
+                                               &id, &path, &array_index, &flag, &groupmode);
+                       }
+                       
+                       /* only if ID and path were set, should we perform any actions */
+                       if (id && path) {
+                               /* action depends on mode */
+                               switch (mode) {
+                                       case DRIVERS_EDITMODE_ADD:
+                                       {
+                                               /* add a new driver with the information obtained (only if valid) */
+                                               ANIM_add_driver(id, path, array_index, flag, DRIVER_TYPE_AVERAGE);
+                                       }
+                                               break;
+                                       case DRIVERS_EDITMODE_REMOVE:
+                                       {
+                                               /* remove driver matching the information obtained (only if valid) */
+                                               ANIM_remove_driver(id, path, array_index, flag);
+                                       }
+                                               break;
+                               }
+                               
+                               /* free path, since it had to be generated */
+                               MEM_freeN(path);
+                       }
+                       
+                       
+               }
+               
+               /* go over sub-tree */
+               if ((tselem->flag & TSE_CLOSED)==0)
+                       do_outliner_drivers_editop(soops, &te->subtree, mode);
+       }
+}
+
+/* Add Operator ---------------------------------- */
+
+static int outliner_drivers_addsel_exec(bContext *C, wmOperator *op)
+{
+       SpaceOops *soutliner= CTX_wm_space_outliner(C);
+       
+       /* check for invalid states */
+       if (soutliner == NULL)
+               return OPERATOR_CANCELLED;
+       
+       /* recursively go into tree, adding selected items */
+       do_outliner_drivers_editop(soutliner, &soutliner->tree, DRIVERS_EDITMODE_ADD);
+       
+       /* send notifiers */
+       WM_event_add_notifier(C, NC_SCENE|ND_KEYINGSET, NULL);
+       
+       return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_drivers_add(wmOperatorType *ot)
 {
-//     Sequence *seq= (Sequence*) te->directdata;
-       if(event==1) {
-// XXX         select_single_seq(seq, 1);
-               allqueue(REDRAWSEQ, 0);
-       }
+       /* api callbacks */
+       ot->idname= "OUTLINER_OT_drivers_add";
+       ot->name= "Add Drivers";
+       ot->description= "Add drivers to selected items.";
+       
+       /* api callbacks */
+       ot->exec= outliner_drivers_addsel_exec;
+       ot->poll= ed_operator_outliner_datablocks_active;
+       
+       /* flags */
+       ot->flag = OPTYPE_UNDO;
 }
 
-static void outliner_do_data_operation(SpaceOops *soops, int type, int event, ListBase *lb, 
-                                                                                void (*operation_cb)(int, TreeElement *, TreeStoreElem *))
+
+/* Remove Operator ---------------------------------- */
+
+static int outliner_drivers_deletesel_exec(bContext *C, wmOperator *op)
 {
-       TreeElement *te;
-       TreeStoreElem *tselem;
+       SpaceOops *soutliner= CTX_wm_space_outliner(C);
        
-       for(te=lb->first; te; te= te->next) {
-               tselem= TREESTORE(te);
-               if(tselem->flag & TSE_SELECTED) {
-                       if(tselem->type==type) {
-                               operation_cb(event, te, tselem);
-                       }
-               }
-               if((tselem->flag & TSE_CLOSED)==0) {
-                       outliner_do_data_operation(soops, type, event, &te->subtree, operation_cb);
-               }
-       }
+       /* check for invalid states */
+       if (soutliner == NULL)
+               return OPERATOR_CANCELLED;
+       
+       /* recursively go into tree, adding selected items */
+       do_outliner_drivers_editop(soutliner, &soutliner->tree, DRIVERS_EDITMODE_REMOVE);
+       
+       /* send notifiers */
+       WM_event_add_notifier(C, NC_SCENE|ND_KEYINGSET, NULL);
+       
+       return OPERATOR_FINISHED;
 }
 
-void outliner_del(Scene *scene, ARegion *ar, SpaceOops *soops)
+void OUTLINER_OT_drivers_delete(wmOperatorType *ot)
 {
+       /* identifiers */
+       ot->idname= "OUTLINER_OT_drivers_delete";
+       ot->name= "Delete Drivers";
+       ot->description= "Delete drivers assigned to selected items.";
+       
+       /* api callbacks */
+       ot->exec= outliner_drivers_deletesel_exec;
+       ot->poll= ed_operator_outliner_datablocks_active;
        
-// XXX if(soops->outlinevis==SO_SEQUENCE)
-//             del_seq();
-//     else {
-//             outliner_do_object_operation(scene, soops, &soops->tree, object_delete_cb);
-//             DAG_scene_sort(scene);
-//             BIF_undo_push("Delete Objects");
-//     }
-//     allqueue(REDRAWALL, 0); 
+       /* flags */
+       ot->flag = OPTYPE_UNDO;
 }
 
+/* ***************** KEYINGSET OPERATIONS *************** */
 
-void outliner_operation_menu(Scene *scene, ARegion *ar, SpaceOops *soops)
+/* These operators are only available in databrowser mode for now, as
+ * they depend on having RNA paths and/or hierarchies available.
+ */
+enum {
+       KEYINGSET_EDITMODE_ADD  = 0,
+       KEYINGSET_EDITMODE_REMOVE,
+} eKeyingSet_EditModes;
+
+/* Utilities ---------------------------------- */ 
+/* find the 'active' KeyingSet, and add if not found (if adding is allowed) */
+// TODO: should this be an API func?
+static KeyingSet *verify_active_keyingset(Scene *scene, short add)
 {
-       int scenelevel=0, objectlevel=0, idlevel=0, datalevel=0;
+       KeyingSet *ks= NULL;
        
-       set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
+       /* sanity check */
+       if (scene == NULL)
+               return NULL;
        
-       if(scenelevel) {
-               if(objectlevel || datalevel || idlevel) error("Mixed selection");
-               else pupmenu("Scene Operations%t|Delete");
+       /* try to find one from scene */
+       if (scene->active_keyingset > 0)
+               ks= BLI_findlink(&scene->keyingsets, scene->active_keyingset-1);
+               
+       /* add if none found */
+       // XXX the default settings have yet to evolve
+       if ((add) && (ks==NULL)) {
+               ks= BKE_keyingset_add(&scene->keyingsets, "Keying Set", KEYINGSET_ABSOLUTE, 0);
+               scene->active_keyingset= BLI_countlist(&scene->keyingsets);
        }
-       else if(objectlevel) {
-               short event= pupmenu("Select%x1|Deselect%x2|Delete%x4|Toggle Visible%x6|Toggle Selectable%x7|Toggle Renderable%x8");    /* make local: does not work... it doesn't set lib_extern flags... so data gets lost */
-               if(event>0) {
-                       char *str="";
+       
+       return ks;
+}
+
+/* Recursively iterate over tree, finding and working on selected items */
+static void do_outliner_keyingset_editop(SpaceOops *soops, KeyingSet *ks, ListBase *tree, short mode)
+{
+       TreeElement *te;
+       TreeStoreElem *tselem;
+       
+       for (te= tree->first; te; te=te->next) {
+               tselem= TREESTORE(te);
+               
+               /* if item is selected, perform operation */
+               if (tselem->flag & TSE_SELECTED) {
+                       ID *id= NULL;
+                       char *path= NULL;
+                       int array_index= 0;
+                       short flag= 0;
+                       short groupmode= KSP_GROUP_KSNAME;
                        
-                       if(event==1) {
-                               Scene *sce= scene;      // to be able to delete, scenes are set...
-                               outliner_do_object_operation(scene, soops, &soops->tree, object_select_cb);
-                               if(scene != sce) {
-                                       set_scene(sce);
-                               }
-                               
-                               str= "Select Objects";
-                       }
-                       else if(event==2) {
-                               outliner_do_object_operation(scene, soops, &soops->tree, object_deselect_cb);
-                               str= "Deselect Objects";
-                       }
-                       else if(event==4) {
-                               outliner_do_object_operation(scene, soops, &soops->tree, object_delete_cb);
-                               DAG_scene_sort(scene);
-                               str= "Delete Objects";
-                       }
-                       else if(event==5) {     /* disabled, see above (ton) */
-                               outliner_do_object_operation(scene, soops, &soops->tree, id_local_cb);
-                               str= "Localized Objects";
-                       }
-                       else if(event==6) {
-                               outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_visibility_cb);
-                               str= "Toggle Visibility";
+                       /* check if RNA-property described by this selected element is an animateable prop */
+                       if ((tselem->type == TSE_RNA_PROPERTY) && RNA_property_animateable(&te->rnaptr, te->directdata)) {
+                               /* get id + path + index info from the selected element */
+                               tree_element_to_path(soops, te, tselem, 
+                                               &id, &path, &array_index, &flag, &groupmode);
                        }
-                       else if(event==7) {
-                               outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_selectability_cb);
-                               str= "Toggle Selectability";
-                       }
-                       else if(event==8) {
-                               outliner_do_object_operation(scene, soops, &soops->tree, object_toggle_renderability_cb);
-                               str= "Toggle Renderability";
-                       }
-                       
-                       BIF_undo_push(str);
-                       allqueue(REDRAWALL, 0);
-               }
-       }
-       else if(idlevel) {
-               if(idlevel==-1 || datalevel) error("Mixed selection");
-               else {
-                       short event;
-                       if (idlevel==ID_GR)
-                               event = pupmenu("Unlink %x1|Make Local %x2|Link Group Objects to Scene%x3");
-                       else
-                               event = pupmenu("Unlink %x1|Make Local %x2");
-                       
                        
-                       if(event==1) {
-                               switch(idlevel) {
-                                       case ID_MA:
-                                               outliner_do_libdata_operation(soops, &soops->tree, unlink_material_cb);
-                                               BIF_undo_push("Unlink material");
-                                               allqueue(REDRAWBUTSSHADING, 1);
-                                               break;
-                                       case ID_TE:
-                                               outliner_do_libdata_operation(soops, &soops->tree, unlink_texture_cb);
-                                               allqueue(REDRAWBUTSSHADING, 1);
-                                               BIF_undo_push("Unlink texture");
+                       /* only if ID and path were set, should we perform any actions */
+                       if (id && path) {
+                               /* action depends on mode */
+                               switch (mode) {
+                                       case KEYINGSET_EDITMODE_ADD:
+                                       {
+                                               /* add a new path with the information obtained (only if valid) */
+                                               // TODO: what do we do with group name? for now, we don't supply one, and just let this use the KeyingSet name
+                                               BKE_keyingset_add_destination(ks, id, NULL, path, array_index, flag, groupmode);
+                                       }
                                                break;
-                                       case ID_GR:
-                                               outliner_do_libdata_operation(soops, &soops->tree, unlink_group_cb);
-                                               BIF_undo_push("Unlink group");
+                                       case KEYINGSET_EDITMODE_REMOVE:
+                                       {
+                                               /* find the relevant path, then remove it from the KeyingSet */
+                                               KS_Path *ksp= BKE_keyingset_find_destination(ks, id, NULL, path, array_index, groupmode);
+                                               
+                                               if (ksp) {
+                                                       /* free path's data */
+                                                       // TODO: we probably need an API method for this 
+                                                       if (ksp->rna_path) MEM_freeN(ksp->rna_path);
+                                                       
+                                                       /* remove path from set */
+                                                       BLI_freelinkN(&ks->paths, ksp);
+                                               }
+                                       }
                                                break;
-                                       default:
-                                               error("Not yet...");
                                }
-                               allqueue(REDRAWALL, 0);
-                       }
-                       else if(event==2) {
-                               outliner_do_libdata_operation(soops, &soops->tree, id_local_cb);
-                               BIF_undo_push("Localized Data");
-                               allqueue(REDRAWALL, 0); 
-                       }
-                       else if(event==3 && idlevel==ID_GR) {
-                               outliner_do_libdata_operation(soops, &soops->tree, group_linkobs2scene_cb);
-                               BIF_undo_push("Link Group Objects to Scene");
+                               
+                               /* free path, since it had to be generated */
+                               MEM_freeN(path);
                        }
+                       
+                       
                }
+               
+               /* go over sub-tree */
+               if ((tselem->flag & TSE_CLOSED)==0)
+                       do_outliner_keyingset_editop(soops, ks, &te->subtree, mode);
        }
-       else if(datalevel) {
-               if(datalevel==-1) error("Mixed selection");
-               else {
-                       if(datalevel==TSE_POSE_CHANNEL) {
-                               short event= pupmenu("PoseChannel Operations%t|Select%x1|Deselect%x2|Hide%x3|Unhide%x4");
-                               if(event>0) {
-                                       outliner_do_data_operation(soops, datalevel, event, &soops->tree, pchan_cb);
-                                       BIF_undo_push("PoseChannel operation");
-                               }
-                       }
-                       else if(datalevel==TSE_BONE) {
-                               short event= pupmenu("Bone Operations%t|Select%x1|Deselect%x2|Hide%x3|Unhide%x4");
-                               if(event>0) {
-                                       outliner_do_data_operation(soops, datalevel, event, &soops->tree, bone_cb);
-                                       BIF_undo_push("Bone operation");
-                               }
-                       }
-                       else if(datalevel==TSE_EBONE) {
-                               short event= pupmenu("EditBone Operations%t|Select%x1|Deselect%x2|Hide%x3|Unhide%x4");
-                               if(event>0) {
-                                       outliner_do_data_operation(soops, datalevel, event, &soops->tree, ebone_cb);
-                                       BIF_undo_push("EditBone operation");
-                               }
-                       }
-                       else if(datalevel==TSE_SEQUENCE) {
-                               short event= pupmenu("Sequence Operations %t|Select %x1");
-                               if(event>0) {
-                                       outliner_do_data_operation(soops, datalevel, event, &soops->tree, sequence_cb);
-                               }
-                       }
+}
 
-                       allqueue(REDRAWOOPS, 0);
-                       allqueue(REDRAWBUTSALL, 0);
-                       allqueue(REDRAWVIEW3D, 0);
-               }
+/* Add Operator ---------------------------------- */
+
+static int outliner_keyingset_additems_exec(bContext *C, wmOperator *op)
+{
+       SpaceOops *soutliner= CTX_wm_space_outliner(C);
+       Scene *scene= CTX_data_scene(C);
+       KeyingSet *ks= verify_active_keyingset(scene, 1);
+       
+       /* check for invalid states */
+       if (ks == NULL) {
+               BKE_report(op->reports, RPT_ERROR, "Operation requires an Active Keying Set");
+               return OPERATOR_CANCELLED;
        }
+       if (soutliner == NULL)
+               return OPERATOR_CANCELLED;
+       
+       /* recursively go into tree, adding selected items */
+       do_outliner_keyingset_editop(soutliner, ks, &soutliner->tree, KEYINGSET_EDITMODE_ADD);
+       
+       /* send notifiers */
+       WM_event_add_notifier(C, NC_SCENE|ND_KEYINGSET, NULL);
+       
+       return OPERATOR_FINISHED;
 }
 
+void OUTLINER_OT_keyingset_add_selected(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->idname= "OUTLINER_OT_keyingset_add_selected";
+       ot->name= "Keyingset Add Selected";
+       
+       /* api callbacks */
+       ot->exec= outliner_keyingset_additems_exec;
+       ot->poll= ed_operator_outliner_datablocks_active;
+       
+       /* flags */
+       ot->flag = OPTYPE_UNDO;
+}
 
-/* ***************** DRAW *************** */
 
-static int tselem_rna_icon(PointerRNA *ptr)
-{
-       StructRNA *rnatype= ptr->type;
-
-       if(rnatype == &RNA_Scene)
-               return ICON_SCENE_DEHLT;
-       else if(rnatype == &RNA_World)
-               return ICON_WORLD;
-       else if(rnatype == &RNA_Object)
-               return ICON_OBJECT;
-       else if(rnatype == &RNA_Mesh)
-               return ICON_MESH;
-       else if(rnatype == &RNA_MeshVertex)
-               return ICON_VERTEXSEL;
-       else if(rnatype == &RNA_MeshEdge)
-               return ICON_EDGESEL;
-       else if(rnatype == &RNA_MeshFace)
-               return ICON_FACESEL;
-       else if(rnatype == &RNA_MeshTextureFace)
-               return ICON_FACESEL_HLT;
-       else if(rnatype == &RNA_VertexGroup)
-               return ICON_VGROUP;
-       else if(rnatype == &RNA_VertexGroupElement)
-               return ICON_VGROUP;
-       else if(rnatype == &RNA_Curve)
-               return ICON_CURVE;
-       else if(rnatype == &RNA_MetaBall)
-               return ICON_MBALL;
-       else if(rnatype == &RNA_MetaElement)
-               return ICON_OUTLINER_DATA_META;
-       else if(rnatype == &RNA_Lattice)
-               return ICON_LATTICE;
-       else if(rnatype == &RNA_Armature)
-               return ICON_ARMATURE;
-       else if(rnatype == &RNA_Bone)
-               return ICON_BONE_DEHLT;
-       else if(rnatype == &RNA_Camera)
-               return ICON_CAMERA;
-       else if(rnatype == &RNA_LocalLamp)
-               return ICON_LAMP;
-       else if(rnatype == &RNA_AreaLamp)
-               return ICON_LAMP;
-       else if(rnatype == &RNA_SpotLamp)
-               return ICON_LAMP;
-       else if(rnatype == &RNA_SunLamp)
-               return ICON_LAMP;
-       else if(rnatype == &RNA_HemiLamp)
-               return ICON_LAMP;
-       else if(rnatype == &RNA_Lamp)
-               return ICON_LAMP;
-       else if(rnatype == &RNA_Group)
-               return ICON_GROUP;
-       else if(rnatype == &RNA_ParticleSystem)
-               return ICON_PARTICLES;
-       else if(rnatype == &RNA_ParticleSettings)
-               return ICON_PARTICLES;
-       else if(rnatype == &RNA_Material)
-               return ICON_MATERIAL;
-       else if(rnatype == &RNA_Texture)
-               return ICON_TEXTURE;
-       else if(rnatype == &RNA_TextureSlot)
-               return ICON_TEXTURE;
-       else if(rnatype == &RNA_WorldTextureSlot)
-               return ICON_TEXTURE;
-       else if(rnatype == &RNA_MaterialTextureSlot)
-               return ICON_TEXTURE;
-       else if(rnatype == &RNA_Image)
-               return ICON_TEXTURE;
-       else if(rnatype == &RNA_Screen)
-               return ICON_SPLITSCREEN;
-       else if(rnatype == &RNA_NodeTree)
-               return ICON_NODE;
-       else if(rnatype == &RNA_Text)
-               return ICON_TEXT;
-       else if(rnatype == &RNA_Sound)
-               return ICON_SOUND;
-       else if(rnatype == &RNA_Brush)
-               return ICON_TPAINT_HLT;
-       else if(rnatype == &RNA_Library)
-               return ICON_LIBRARY_DEHLT;
-       else if(rnatype == &RNA_Action)
-               return ICON_ACTION;
-       else if(rnatype == &RNA_FCurve)
-               return ICON_IPO_DEHLT;
-       //else if(rnatype == &RNA_Ipo)
-       //      return ICON_IPO_DEHLT;
-       else if(rnatype == &RNA_Key)
-               return ICON_SHAPEKEY;
-       else if(rnatype == &RNA_Main)
-               return ICON_BLENDER;
-       else if(rnatype == &RNA_Struct)
-               return ICON_RNA;
-       else if(rnatype == &RNA_Property)
-               return ICON_RNA;
-       else if(rnatype == &RNA_BooleanProperty)
-               return ICON_RNA;
-       else if(rnatype == &RNA_IntProperty)
-               return ICON_RNA;
-       else if(rnatype == &RNA_FloatProperty)
-               return ICON_RNA;
-       else if(rnatype == &RNA_StringProperty)
-               return ICON_RNA;
-       else if(rnatype == &RNA_EnumProperty)
-               return ICON_RNA;
-       else if(rnatype == &RNA_EnumPropertyItem)
-               return ICON_RNA;
-       else if(rnatype == &RNA_PointerProperty)
-               return ICON_RNA;
-       else if(rnatype == &RNA_CollectionProperty)
-               return ICON_RNA;
-       else if(rnatype == &RNA_GameObjectSettings)
-               return ICON_GAME;
-       else if(rnatype == &RNA_ScriptLink)
-               return ICON_PYTHON;
-       
-       /* modifiers */
-       else if(rnatype == &RNA_SubsurfModifier)
-               return ICON_MOD_SUBSURF;
-       else if(rnatype == &RNA_ArmatureModifier)
-               return ICON_ARMATURE;
-       else if(rnatype == &RNA_LatticeModifier)
-               return ICON_LATTICE;
-       else if(rnatype == &RNA_CurveModifier)
-               return ICON_CURVE;
-       else if(rnatype == &RNA_BuildModifier)
-               return ICON_MOD_BUILD;
-       else if(rnatype == &RNA_MirrorModifier)
-               return ICON_MOD_MIRROR;
-       else if(rnatype == &RNA_DecimateModifier)
-               return ICON_MOD_DECIM;
-       else if(rnatype == &RNA_WaveModifier)
-               return ICON_MOD_WAVE;
-       else if(rnatype == &RNA_HookModifier)
-               return ICON_HOOK;
-       else if(rnatype == &RNA_SoftbodyModifier)
-               return ICON_MOD_SOFT;
-       else if(rnatype == &RNA_BooleanModifier)
-               return ICON_MOD_BOOLEAN;
-       else if(rnatype == &RNA_ParticleInstanceModifier)
-               return ICON_MOD_PARTICLEINSTANCE;
-       else if(rnatype == &RNA_ParticleSystemModifier)
-               return ICON_MOD_PARTICLES;
-       else if(rnatype == &RNA_EdgeSplitModifier)
-               return ICON_MOD_EDGESPLIT;
-       else if(rnatype == &RNA_ArrayModifier)
-               return ICON_MOD_ARRAY;
-       else if(rnatype == &RNA_UVProjectModifier)
-               return ICON_MOD_UVPROJECT;
-       else if(rnatype == &RNA_DisplaceModifier)
-               return ICON_MOD_DISPLACE;
-       
-       else
-               return ICON_DOT;
+/* Remove Operator ---------------------------------- */
+
+static int outliner_keyingset_removeitems_exec(bContext *C, wmOperator *op)
+{
+       SpaceOops *soutliner= CTX_wm_space_outliner(C);
+       Scene *scene= CTX_data_scene(C);
+       KeyingSet *ks= verify_active_keyingset(scene, 1);
+       
+       /* check for invalid states */
+       if (soutliner == NULL)
+               return OPERATOR_CANCELLED;
+       
+       /* recursively go into tree, adding selected items */
+       do_outliner_keyingset_editop(soutliner, ks, &soutliner->tree, KEYINGSET_EDITMODE_REMOVE);
+       
+       /* send notifiers */
+       WM_event_add_notifier(C, NC_SCENE|ND_KEYINGSET, NULL);
+       
+       return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_keyingset_remove_selected(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->idname= "OUTLINER_OT_keyingset_remove_selected";
+       ot->name= "Keyingset Remove Selected";
+       
+       /* api callbacks */
+       ot->exec= outliner_keyingset_removeitems_exec;
+       ot->poll= ed_operator_outliner_datablocks_active;
+       
+       /* flags */
+       ot->flag = OPTYPE_UNDO;
 }
 
+/* ***************** DRAW *************** */
+
 static void tselem_draw_icon(float x, float y, TreeStoreElem *tselem, TreeElement *te)
 {
        if(tselem->type) {
                switch( tselem->type) {
                        case TSE_ANIM_DATA:
-                               UI_icon_draw(x, y, ICON_IPO_DEHLT); break; // xxx
+                               UI_icon_draw(x, y, ICON_ANIM_DATA); break; // xxx
                        case TSE_NLA:
                                UI_icon_draw(x, y, ICON_NLA); break;
+                       case TSE_NLA_TRACK:
+                               UI_icon_draw(x, y, ICON_NLA); break; // XXX
                        case TSE_NLA_ACTION:
                                UI_icon_draw(x, y, ICON_ACTION); break;
                        case TSE_DEFGROUP_BASE:
-                               UI_icon_draw(x, y, ICON_VGROUP); break;
+                               UI_icon_draw(x, y, ICON_GROUP_VERTEX); break;
                        case TSE_BONE:
                        case TSE_EBONE:
-                               UI_icon_draw(x, y, ICON_BONE_DEHLT); break;
+                               UI_icon_draw(x, y, ICON_BONE_DATA); break;
                        case TSE_CONSTRAINT_BASE:
                                UI_icon_draw(x, y, ICON_CONSTRAINT); break;
                        case TSE_MODIFIER_BASE:
                                UI_icon_draw(x, y, ICON_MODIFIER); break;
                        case TSE_LINKED_OB:
-                               UI_icon_draw(x, y, ICON_OBJECT); break;
+                               UI_icon_draw(x, y, ICON_OBJECT_DATA); break;
                        case TSE_LINKED_PSYS:
                                UI_icon_draw(x, y, ICON_PARTICLES); break;
                        case TSE_MODIFIER:
@@ -3282,11 +4083,11 @@ static void tselem_draw_icon(float x, float y, TreeStoreElem *tselem, TreeElemen
                                        case eModifierType_Subsurf: 
                                                UI_icon_draw(x, y, ICON_MOD_SUBSURF); break;
                                        case eModifierType_Armature: 
-                                               UI_icon_draw(x, y, ICON_ARMATURE); break;
+                                               UI_icon_draw(x, y, ICON_MOD_ARMATURE); break;
                                        case eModifierType_Lattice: 
-                                               UI_icon_draw(x, y, ICON_LATTICE); break;
+                                               UI_icon_draw(x, y, ICON_MOD_LATTICE); break;
                                        case eModifierType_Curve: 
-                                               UI_icon_draw(x, y, ICON_CURVE); break;
+                                               UI_icon_draw(x, y, ICON_MOD_CURVE); break;
                                        case eModifierType_Build: 
                                                UI_icon_draw(x, y, ICON_MOD_BUILD); break;
                                        case eModifierType_Mirror: 
@@ -3302,7 +4103,7 @@ static void tselem_draw_icon(float x, float y, TreeStoreElem *tselem, TreeElemen
                                        case eModifierType_Boolean: 
                                                UI_icon_draw(x, y, ICON_MOD_BOOLEAN); break;
                                        case eModifierType_ParticleSystem: 
-                                               UI_icon_draw(x, y, ICON_MOD_PARTICLEINSTANCE); break;
+                                               UI_icon_draw(x, y, ICON_MOD_PARTICLES); break;
                                        case eModifierType_ParticleInstance:
                                                UI_icon_draw(x, y, ICON_MOD_PARTICLES); break;
                                        case eModifierType_EdgeSplit:
@@ -3313,6 +4114,30 @@ static void tselem_draw_icon(float x, float y, TreeStoreElem *tselem, TreeElemen
                                                UI_icon_draw(x, y, ICON_MOD_UVPROJECT); break;
                                        case eModifierType_Displace:
                                                UI_icon_draw(x, y, ICON_MOD_DISPLACE); break;
+                                       case eModifierType_Shrinkwrap:
+                                               UI_icon_draw(x, y, ICON_MOD_SHRINKWRAP); break;
+                                       case eModifierType_Cast:
+                                               UI_icon_draw(x, y, ICON_MOD_CAST); break;
+                                       case eModifierType_MeshDeform:
+                                               UI_icon_draw(x, y, ICON_MOD_MESHDEFORM); break;
+                                       case eModifierType_Bevel:
+                                               UI_icon_draw(x, y, ICON_MOD_BEVEL); break;
+                                       case eModifierType_Smooth:
+                                               UI_icon_draw(x, y, ICON_MOD_SMOOTH); break;
+                                       case eModifierType_SimpleDeform:
+                                               UI_icon_draw(x, y, ICON_MOD_SIMPLEDEFORM); break;
+                                       case eModifierType_Mask:
+                                               UI_icon_draw(x, y, ICON_MOD_MASK); break;
+                                       case eModifierType_Cloth:
+                                               UI_icon_draw(x, y, ICON_MOD_CLOTH); break;
+                                       case eModifierType_Explode:
+                                               UI_icon_draw(x, y, ICON_MOD_EXPLODE); break;
+                                       case eModifierType_Collision:
+                                               UI_icon_draw(x, y, ICON_MOD_PHYSICS); break;
+                                       case eModifierType_Fluidsim:
+                                               UI_icon_draw(x, y, ICON_MOD_FLUIDSIM); break;
+                                       case eModifierType_Multires:
+                                               UI_icon_draw(x, y, ICON_MOD_MULTIRES); break;
                                        default:
                                                UI_icon_draw(x, y, ICON_DOT); break;
                                }
@@ -3321,29 +4146,29 @@ static void tselem_draw_icon(float x, float y, TreeStoreElem *tselem, TreeElemen
                        case TSE_SCRIPT_BASE:
                                UI_icon_draw(x, y, ICON_TEXT); break;
                        case TSE_POSE_BASE:
-                               UI_icon_draw(x, y, ICON_ARMATURE); break;
+                               UI_icon_draw(x, y, ICON_ARMATURE_DATA); break;
                        case TSE_POSE_CHANNEL:
-                               UI_icon_draw(x, y, ICON_BONE_DEHLT); break;
+                               UI_icon_draw(x, y, ICON_BONE_DATA); break;
                        case TSE_PROXY:
                                UI_icon_draw(x, y, ICON_GHOST); break;
                        case TSE_R_LAYER_BASE:
-                               UI_icon_draw(x, y, ICON_RESTRICT_RENDER_OFF); break;
+                               UI_icon_draw(x, y, ICON_RENDERLAYERS); break;
                        case TSE_R_LAYER:
-                               UI_icon_draw(x, y, ICON_IMAGE_DEHLT); break;
+                               UI_icon_draw(x, y, ICON_RENDER_RESULT); break;
                        case TSE_LINKED_LAMP:
-                               UI_icon_draw(x, y, ICON_LAMP_DEHLT); break;
+                               UI_icon_draw(x, y, ICON_LAMP_DATA); break;
                        case TSE_LINKED_MAT:
-                               UI_icon_draw(x, y, ICON_MATERIAL_DEHLT); break;
+                               UI_icon_draw(x, y, ICON_MATERIAL_DATA); break;
                        case TSE_POSEGRP_BASE:
                                UI_icon_draw(x, y, ICON_VERTEXSEL); break;
                        case TSE_SEQUENCE:
-                               if((te->idcode==SEQ_MOVIE) || (te->idcode==SEQ_MOVIE_AND_HD_SOUND))
+                               if(te->idcode==SEQ_MOVIE)
                                        UI_icon_draw(x, y, ICON_SEQUENCE);
                                else if(te->idcode==SEQ_META)
                                        UI_icon_draw(x, y, ICON_DOT);
                                else if(te->idcode==SEQ_SCENE)
                                        UI_icon_draw(x, y, ICON_SCENE);
-                               else if((te->idcode==SEQ_RAM_SOUND) || (te->idcode==SEQ_HD_SOUND))
+                               else if(te->idcode==SEQ_SOUND)
                                        UI_icon_draw(x, y, ICON_SOUND);
                                else if(te->idcode==SEQ_IMAGE)
                                        UI_icon_draw(x, y, ICON_IMAGE_COL);
@@ -3351,13 +4176,13 @@ static void tselem_draw_icon(float x, float y, TreeStoreElem *tselem, TreeElemen
                                        UI_icon_draw(x, y, ICON_PARTICLES);
                                break;
                        case TSE_SEQ_STRIP:
-                               UI_icon_draw(x, y, ICON_LIBRARY_DEHLT);
+                               UI_icon_draw(x, y, ICON_LIBRARY_DATA_DIRECT);
                                break;
                        case TSE_SEQUENCE_DUP:
-                               UI_icon_draw(x, y, ICON_OBJECT);
+                               UI_icon_draw(x, y, ICON_OBJECT_DATA);
                                break;
                        case TSE_RNA_STRUCT:
-                               UI_icon_draw(x, y, tselem_rna_icon(&te->rnaptr));
+                               UI_icon_draw(x, y, RNA_struct_ui_icon(te->rnaptr.type));
                                break;
                        default:
                                UI_icon_draw(x, y, ICON_DOT); break;
@@ -3380,6 +4205,10 @@ static void tselem_draw_icon(float x, float y, TreeStoreElem *tselem, TreeElemen
                                UI_icon_draw(x, y, ICON_OUTLINER_OB_LATTICE); break;
                        case OB_ARMATURE: 
                                UI_icon_draw(x, y, ICON_OUTLINER_OB_ARMATURE); break;
+                       case OB_FONT: 
+                               UI_icon_draw(x, y, ICON_OUTLINER_OB_FONT); break;
+                       case OB_SURF: 
+                               UI_icon_draw(x, y, ICON_OUTLINER_OB_SURFACE); break;
                        case OB_EMPTY: 
                                UI_icon_draw(x, y, ICON_OUTLINER_OB_EMPTY); break;
                
@@ -3388,7 +4217,7 @@ static void tselem_draw_icon(float x, float y, TreeStoreElem *tselem, TreeElemen
        else {
                switch( GS(tselem->id->name)) {
                        case ID_SCE:
-                               UI_icon_draw(x, y, ICON_SCENE_DEHLT); break;
+                               UI_icon_draw(x, y, ICON_SCENE_DATA); break;
                        case ID_ME:
                                UI_icon_draw(x, y, ICON_OUTLINER_DATA_MESH); break;
                        case ID_CU:
@@ -3398,13 +4227,31 @@ static void tselem_draw_icon(float x, float y, TreeStoreElem *tselem, TreeElemen
                        case ID_LT:
                                UI_icon_draw(x, y, ICON_OUTLINER_DATA_LATTICE); break;
                        case ID_LA:
-                               UI_icon_draw(x, y, ICON_OUTLINER_DATA_LAMP); break;
+                       {
+                               Lamp *la= (Lamp *)tselem->id;
+                               
+                               switch(la->type) {
+                                       case LA_LOCAL:
+                                               UI_icon_draw(x, y, ICON_LAMP_POINT); break;
+                                       case LA_SUN:
+                                               UI_icon_draw(x, y, ICON_LAMP_SUN); break;
+                                       case LA_SPOT:
+                                               UI_icon_draw(x, y, ICON_LAMP_SPOT); break;
+                                       case LA_HEMI:
+                                               UI_icon_draw(x, y, ICON_LAMP_HEMI); break;
+                                       case LA_AREA:
+                                               UI_icon_draw(x, y, ICON_LAMP_AREA); break;
+                                       default:
+                                               UI_icon_draw(x, y, ICON_OUTLINER_DATA_LAMP); break;
+                               }
+                               break;
+                       }
                        case ID_MA:
-                               UI_icon_draw(x, y, ICON_MATERIAL_DEHLT); break;
+                               UI_icon_draw(x, y, ICON_MATERIAL_DATA); break;
                        case ID_TE:
-                               UI_icon_draw(x, y, ICON_TEXTURE_DEHLT); break;
+                               UI_icon_draw(x, y, ICON_TEXTURE_DATA); break;
                        case ID_IM:
-                               UI_icon_draw(x, y, ICON_IMAGE_DEHLT); break;
+                               UI_icon_draw(x, y, ICON_IMAGE_DATA); break;
                        case ID_SO:
                                UI_icon_draw(x, y, ICON_SPEAKER); break;
                        case ID_AR:
@@ -3412,9 +4259,9 @@ static void tselem_draw_icon(float x, float y, TreeStoreElem *tselem, TreeElemen
                        case ID_CA:
                                UI_icon_draw(x, y, ICON_OUTLINER_DATA_CAMERA); break;
                        case ID_KE:
-                               UI_icon_draw(x, y, ICON_SHAPEKEY); break;
+                               UI_icon_draw(x, y, ICON_SHAPEKEY_DATA); break;
                        case ID_WO:
-                               UI_icon_draw(x, y, ICON_WORLD_DEHLT); break;
+                               UI_icon_draw(x, y, ICON_WORLD_DATA); break;
                        case ID_AC:
                                UI_icon_draw(x, y, ICON_ACTION); break;
                        case ID_NLA:
@@ -3424,12 +4271,12 @@ static void tselem_draw_icon(float x, float y, TreeStoreElem *tselem, TreeElemen
                        case ID_GR:
                                UI_icon_draw(x, y, ICON_GROUP); break;
                        case ID_LI:
-                               UI_icon_draw(x, y, ICON_LIBRARY_DEHLT); break;
+                               UI_icon_draw(x, y, ICON_LIBRARY_DATA_DIRECT); break;
                }
        }
 }
 
-static void outliner_draw_iconrow(Scene *scene, SpaceOops *soops, ListBase *lb, int level, int *offsx, int ys)
+static void outliner_draw_iconrow(bContext *C, Scene *scene, SpaceOops *soops, ListBase *lb, int level, int *offsx, int ys)
 {
        TreeElement *te;
        TreeStoreElem *tselem;
@@ -3446,7 +4293,7 @@ static void outliner_draw_iconrow(Scene *scene, SpaceOops *soops, ListBase *lb,
                        if(tselem->type==0) {
                                if(te->idcode==ID_OB) active= (OBACT==(Object *)tselem->id);
                                else if(scene->obedit && scene->obedit->data==tselem->id) active= 1;    // XXX use context?
-                               else active= tree_element_active(scene, soops, te, 0);
+                               else active= tree_element_active(C, scene, soops, te, 0);
                        }
                        else active= tree_element_type_active(NULL, scene, soops, te, tselem, 0);
                        
@@ -3468,12 +4315,12 @@ static void outliner_draw_iconrow(Scene *scene, SpaceOops *soops, ListBase *lb,
                
                /* this tree element always has same amount of branches, so dont draw */
                if(tselem->type!=TSE_R_LAYER)
-                       outliner_draw_iconrow(scene, soops, &te->subtree, level+1, offsx, ys);
+                       outliner_draw_iconrow(C, scene, soops, &te->subtree, level+1, offsx, ys);
        }
        
 }
 
-static void outliner_draw_tree_element(Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, int startx, int *starty)
+static void outliner_draw_tree_element(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement *te, int startx, int *starty)
 {
        TreeElement *ten;
        TreeStoreElem *tselem;
@@ -3511,12 +4358,12 @@ static void outliner_draw_tree_element(Scene *scene, ARegion *ar, SpaceOops *soo
                                }
 
                        }
-// XXX context?                        else if(obedit && obedit->data==tselem->id) {
-//                             glColor4ub(255, 255, 255, 100);
-//                             active= 2;
-//                     }
+                       else if(scene->obedit && scene->obedit->data==tselem->id) {
+                               glColor4ub(255, 255, 255, 100);
+                               active= 2;
+                       }
                        else {
-                               if(tree_element_active(scene, soops, te, 0)) {
+                               if(tree_element_active(C, scene, soops, te, 0)) {
                                        glColor4ub(220, 220, 255, 100);
                                        active= 2;
                                }
@@ -3565,9 +4412,9 @@ static void outliner_draw_tree_element(Scene *scene, ARegion *ar, SpaceOops *soo
                if(tselem->type==0 && tselem->id->lib) {
                        glPixelTransferf(GL_ALPHA_SCALE, 0.5f);
                        if(tselem->id->flag & LIB_INDIRECT)
-                               UI_icon_draw((float)startx+offsx, (float)*starty+2, ICON_LIBRARY_HLT);
+                               UI_icon_draw((float)startx+offsx, (float)*starty+2, ICON_LIBRARY_DATA_INDIRECT);
                        else
-                               UI_icon_draw((float)startx+offsx, (float)*starty+2, ICON_LIBRARY_DEHLT);
+                               UI_icon_draw((float)startx+offsx, (float)*starty+2, ICON_LIBRARY_DATA_DIRECT);
                        glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
                        offsx+= OL_X;
                }               
@@ -3577,10 +4424,10 @@ static void outliner_draw_tree_element(Scene *scene, ARegion *ar, SpaceOops *soo
                if(active==1) UI_ThemeColor(TH_TEXT_HI);
                else if(ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) UI_ThemeColorBlend(TH_BACK, TH_TEXT, 0.75f);
                else UI_ThemeColor(TH_TEXT);
-               glRasterPos2i(startx+offsx, *starty+5);
-               UI_RasterPos((float)startx+offsx, (float)*starty+5);
-               UI_DrawString(G.font, te->name, 0);
-               offsx+= (int)(OL_X + UI_GetStringWidth(G.font, te->name, 0));
+               
+               UI_DrawString(startx+offsx, *starty+5, te->name);
+               
+               offsx+= (int)(OL_X + UI_GetStringWidth(te->name));
                
                /* closed item, we draw the icons, not when it's a scene, or master-server list though */
                if(tselem->flag & TSE_CLOSED) {
@@ -3595,7 +4442,7 @@ static void outliner_draw_tree_element(Scene *scene, ARegion *ar, SpaceOops *soo
                                        glEnable(GL_BLEND);
                                        glPixelTransferf(GL_ALPHA_SCALE, 0.5);
 
-                                       outliner_draw_iconrow(scene, soops, &te->subtree, 0, &tempx, *starty+2);
+                                       outliner_draw_iconrow(C, scene, soops, &te->subtree, 0, &tempx, *starty+2);
                                        
                                        glPixelTransferf(GL_ALPHA_SCALE, 1.0);
                                        glDisable(GL_BLEND);
@@ -3612,7 +4459,7 @@ static void outliner_draw_tree_element(Scene *scene, ARegion *ar, SpaceOops *soo
 
        if((tselem->flag & TSE_CLOSED)==0) {
                for(ten= te->subtree.first; ten; ten= ten->next) {
-                       outliner_draw_tree_element(scene, ar, soops, ten, startx+OL_X, starty);
+                       outliner_draw_tree_element(C, scene, ar, soops, ten, startx+OL_X, starty);
                }
        }       
 }
@@ -3668,7 +4515,7 @@ static void outliner_draw_struct_marks(ARegion *ar, SpaceOops *soops, ListBase *
                if((tselem->flag & TSE_CLOSED)==0) {
                        outliner_draw_struct_marks(ar, soops, &te->subtree, starty);
                        if(tselem->type == TSE_RNA_STRUCT)
-                               fdrawline(0, *starty+OL_H-1, (int)ar->v2d.cur.xmax, *starty+OL_H-1);
+                               fdrawline(0, (float)*starty+OL_H-1, ar->v2d.cur.xmax, (float)*starty+OL_H-1);
                }
        }
 }
@@ -3691,33 +4538,27 @@ static void outliner_draw_selection(ARegion *ar, SpaceOops *soops, ListBase *lb,
 }
 
 
-static void outliner_draw_tree(Scene *scene, ARegion *ar, SpaceOops *soops)
+static void outliner_draw_tree(bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops)
 {
        TreeElement *te;
        int starty, startx;
        float col[4];
-       
-#if 0 // XXX was #ifdef INTERNATIONAL
-       FTF_SetFontSize('l');
-       BIF_SetScale(1.0);
-#endif
-       
+               
        glBlendFunc(GL_SRC_ALPHA,  GL_ONE_MINUS_SRC_ALPHA); // only once
        
-       if(ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) {
-               // struct marks
+       if (ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) {
+               /* struct marks */
                UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
                //UI_ThemeColorShade(TH_BACK, -20);
                starty= (int)ar->v2d.tot.ymax-OL_H;
                outliner_draw_struct_marks(ar, soops, &soops->tree, &starty);
        }
-       else {
-               // selection first
-               UI_GetThemeColor3fv(TH_BACK, col);
-               glColor3f(col[0]+0.06f, col[1]+0.08f, col[2]+0.10f);
-               starty= (int)ar->v2d.tot.ymax-OL_H;
-               outliner_draw_selection(ar, soops, &soops->tree, &starty);
-       }
+       
+       /* always draw selection fill before hierarchy */
+       UI_GetThemeColor3fv(TH_BACK, col);
+       glColor3f(col[0]+0.06f, col[1]+0.08f, col[2]+0.10f);
+       starty= (int)ar->v2d.tot.ymax-OL_H;
+       outliner_draw_selection(ar, soops, &soops->tree, &starty);
        
        // grey hierarchy lines
        UI_ThemeColorBlend(TH_BACK, TH_TEXT, 0.2f);
@@ -3729,7 +4570,7 @@ static void outliner_draw_tree(Scene *scene, ARegion *ar, SpaceOops *soops)
        starty= (int)ar->v2d.tot.ymax-OL_H;
        startx= 0;
        for(te= soops->tree.first; te; te= te->next) {
-               outliner_draw_tree_element(scene, ar, soops, te, startx, &starty);
+               outliner_draw_tree_element(C, scene, ar, soops, te, startx, &starty);
        }
 }
 
@@ -3804,9 +4645,8 @@ static void restrictbutton_view_cb(bContext *C, void *poin, void *poin2)
                        }
                }
        }
+       WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
 
-       allqueue(REDRAWOOPS, 0);
-       allqueue(REDRAWVIEW3D, 0);
 }
 
 static void restrictbutton_sel_cb(bContext *C, void *poin, void *poin2)
@@ -3827,22 +4667,18 @@ static void restrictbutton_sel_cb(bContext *C, void *poin, void *poin2)
                        }
                }
        }
+       WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, scene);
 
-       allqueue(REDRAWOOPS, 0);
-       allqueue(REDRAWVIEW3D, 0);
 }
 
 static void restrictbutton_rend_cb(bContext *C, void *poin, void *poin2)
 {
-       allqueue(REDRAWOOPS, 0);
-       allqueue(REDRAWVIEW3D, 0);
+       WM_event_add_notifier(C, NC_SCENE|ND_OB_SELECT, poin);
 }
 
 static void restrictbutton_r_lay_cb(bContext *C, void *poin, void *poin2)
 {
-       allqueue(REDRAWOOPS, 0);
-       allqueue(REDRAWNODE, 0);
-       allqueue(REDRAWBUTSSCENE, 0);
+       WM_event_add_notifier(C, NC_SCENE|ND_RENDER_OPTIONS, poin);
 }
 
 static void restrictbutton_modifier_cb(bContext *C, void *poin, void *poin2)
@@ -3853,32 +4689,40 @@ static void restrictbutton_modifier_cb(bContext *C, void *poin, void *poin2)
        DAG_object_flush_update(scene, ob, OB_RECALC_DATA);
        object_handle_update(scene, ob);
 
-       allqueue(REDRAWOOPS, 0);
-       allqueue(REDRAWVIEW3D, 0);
-       allqueue(REDRAWBUTSEDIT, 0);
-       allqueue(REDRAWBUTSOBJECT, 0);
+       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, ob);
 }
 
 static void restrictbutton_bone_cb(bContext *C, void *poin, void *poin2)
 {
-       allqueue(REDRAWOOPS, 0);
-       allqueue(REDRAWVIEW3D, 0);
-       allqueue(REDRAWBUTSEDIT, 0);
+       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, NULL);
 }
 
-static void namebutton_cb(bContext *C, void *tep, void *oldnamep)
+static void namebutton_cb(bContext *C, void *tsep, char *oldname)
 {
-       SpaceOops *soops= NULL; // XXXcurarea->spacedata.first;
-       Scene *scene= NULL;     // XXX
+       SpaceOops *soops= CTX_wm_space_outliner(C);
+       Scene *scene= CTX_data_scene(C);
+       Object *obedit= CTX_data_edit_object(C);
        TreeStore *ts= soops->treestore;
-       TreeElement *te= tep;
+       TreeStoreElem *tselem= tsep;
        
-       if(ts && te) {
-               TreeStoreElem *tselem= TREESTORE(te);
+       if(ts && tselem) {
+               TreeElement *te= outliner_find_tse(soops, tselem);
                
                if(tselem->type==0) {
                        test_idbutton(tselem->id->name+2);      // library.c, unique name and alpha sort
                        
+                       switch(GS(tselem->id->name)) {
+                               case ID_MA:
+                                       WM_event_add_notifier(C, NC_MATERIAL, NULL); break;
+                               case ID_TE:
+                                       WM_event_add_notifier(C, NC_TEXTURE, NULL); break;
+                               case ID_IM:
+                                       WM_event_add_notifier(C, NC_IMAGE, NULL); break;
+                               case ID_SCE:
+                                       WM_event_add_notifier(C, NC_SCENE, NULL); break;
+                               default:
+                                       WM_event_add_notifier(C, NC_MATERIAL, NULL); break;
+                       }                                       
                        /* Check the library target exists */
                        if (te->idcode == ID_LI) {
                                char expanded[FILE_MAXDIR + FILE_MAXFILE];
@@ -3893,7 +4737,6 @@ static void namebutton_cb(bContext *C, void *tep, void *oldnamep)
                        switch(tselem->type) {
                        case TSE_DEFGROUP:
                                unique_vertexgroup_name(te->directdata, (Object *)tselem->id); //       id = object
-                               allqueue(REDRAWBUTSEDIT, 0);
                                break;
                        case TSE_NLA_ACTION:
                                test_idbutton(tselem->id->name+2);
@@ -3907,12 +4750,10 @@ static void namebutton_cb(bContext *C, void *tep, void *oldnamep)
                                        
                                        /* restore bone name */
                                        BLI_strncpy(newname, ebone->name, 32);
-                                       BLI_strncpy(ebone->name, oldnamep, 32);
-// XXX                                 armature_bone_rename(obedit->data, oldnamep, newname);
+                                       BLI_strncpy(ebone->name, oldname, 32);
+                                       ED_armature_bone_rename(obedit->data, oldname, newname);
+                                       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, OBACT);
                                }
-                               allqueue(REDRAWOOPS, 0);
-                               allqueue(REDRAWVIEW3D, 1);
-                               allqueue(REDRAWBUTSEDIT, 0);
                        }
                                break;
 
@@ -3923,17 +4764,15 @@ static void namebutton_cb(bContext *C, void *tep, void *oldnamep)
                                        char newname[32];
                                        
                                        // always make current object active
-                                       tree_element_set_active_object(C, scene, soops, te);
+                                       tree_element_set_active_object(C, scene, soops, te, 1);
                                        ob= OBACT;
                                        
                                        /* restore bone name */
                                        BLI_strncpy(newname, bone->name, 32);
-                                       BLI_strncpy(bone->name, oldnamep, 32);
-// XXX                                 armature_bone_rename(ob->data, oldnamep, newname);
+                                       BLI_strncpy(bone->name, oldname, 32);
+                                       ED_armature_bone_rename(ob->data, oldname, newname);
+                                       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
                                }
-                               allqueue(REDRAWOOPS, 0);
-                               allqueue(REDRAWVIEW3D, 1);
-                               allqueue(REDRAWBUTSEDIT, 0);
                                break;
                        case TSE_POSE_CHANNEL:
                                {
@@ -3942,30 +4781,26 @@ static void namebutton_cb(bContext *C, void *tep, void *oldnamep)
                                        char newname[32];
                                        
                                        // always make current object active
-                                       tree_element_set_active_object(C, scene, soops, te);
+                                       tree_element_set_active_object(C, scene, soops, te, 1);
                                        ob= OBACT;
                                        
                                        /* restore bone name */
                                        BLI_strncpy(newname, pchan->name, 32);
-                                       BLI_strncpy(pchan->name, oldnamep, 32);
-// XXX                                 armature_bone_rename(ob->data, oldnamep, newname);
+                                       BLI_strncpy(pchan->name, oldname, 32);
+                                       ED_armature_bone_rename(ob->data, oldname, newname);
+                                       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
                                }
-                               allqueue(REDRAWOOPS, 0);
-                               allqueue(REDRAWVIEW3D, 1);
-                               allqueue(REDRAWBUTSEDIT, 0);
                                break;
                        case TSE_POSEGRP:
                                {
                                        Object *ob= (Object *)tselem->id; // id = object
                                        bActionGroup *grp= te->directdata;
                                        
-                                       BLI_uniquename(&ob->pose->agroups, grp, "Group", offsetof(bActionGroup, name), 32);
-                                       allqueue(REDRAWBUTSEDIT, 0);
+                                       BLI_uniquename(&ob->pose->agroups, grp, "Group", '.', offsetof(bActionGroup, name), 32);
+                                       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
                                }
                                break;
                        case TSE_R_LAYER:
-                               allqueue(REDRAWOOPS, 0);
-                               allqueue(REDRAWBUTSSCENE, 0);
                                break;
                        }
                }
@@ -3978,7 +4813,7 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
        TreeElement *te;
        TreeStoreElem *tselem;
        Object *ob = NULL;
-       
+
        for(te= lb->first; te; te= te->next) {
                tselem= TREESTORE(te);
                if(te->ys >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {  
@@ -3987,20 +4822,17 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
                                ob = (Object *)tselem->id;
                                
                                uiBlockSetEmboss(block, UI_EMBOSSN);
-                               bt= uiDefIconButBitS(block, ICONTOG, OB_RESTRICT_VIEW, REDRAWALL, ICON_RESTRICT_VIEW_OFF, 
+                               bt= uiDefIconButBitS(block, ICONTOG, OB_RESTRICT_VIEW, 0, ICON_RESTRICT_VIEW_OFF, 
                                                (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, (short)te->ys, 17, OL_H-1, &(ob->restrictflag), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View");
                                uiButSetFunc(bt, restrictbutton_view_cb, scene, ob);
-                               uiButSetFlag(bt, UI_NO_HILITE);
                                
-                               bt= uiDefIconButBitS(block, ICONTOG, OB_RESTRICT_SELECT, REDRAWALL, ICON_RESTRICT_SELECT_OFF, 
+                               bt= uiDefIconButBitS(block, ICONTOG, OB_RESTRICT_SELECT, 0, ICON_RESTRICT_SELECT_OFF, 
                                                (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_SELECTX, (short)te->ys, 17, OL_H-1, &(ob->restrictflag), 0, 0, 0, 0, "Restrict/Allow selection in the 3D View");
                                uiButSetFunc(bt, restrictbutton_sel_cb, scene, ob);
-                               uiButSetFlag(bt, UI_NO_HILITE);
                                
-                               bt= uiDefIconButBitS(block, ICONTOG, OB_RESTRICT_RENDER, REDRAWALL, ICON_RESTRICT_RENDER_OFF, 
+                               bt= uiDefIconButBitS(block, ICONTOG, OB_RESTRICT_RENDER, 0, ICON_RESTRICT_RENDER_OFF, 
                                                (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_RENDERX, (short)te->ys, 17, OL_H-1, &(ob->restrictflag), 0, 0, 0, 0, "Restrict/Allow renderability");
-                               uiButSetFunc(bt, restrictbutton_rend_cb, NULL, NULL);
-                               uiButSetFlag(bt, UI_NO_HILITE);
+                               uiButSetFunc(bt, restrictbutton_rend_cb, scene, ob);
                                
                                uiBlockSetEmboss(block, UI_EMBOSS);
                        }
@@ -4008,9 +4840,9 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
                        else if(tselem->type==TSE_R_LAYER) {
                                uiBlockSetEmboss(block, UI_EMBOSSN);
                                
-                               bt= uiDefIconButBitI(block, ICONTOGN, SCE_LAY_DISABLE, REDRAWBUTSSCENE, ICON_CHECKBOX_HLT-1, 
+                               bt= uiDefIconButBitI(block, ICONTOGN, SCE_LAY_DISABLE, 0, ICON_CHECKBOX_HLT-1, 
                                                                         (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, (short)te->ys, 17, OL_H-1, te->directdata, 0, 0, 0, 0, "Render this RenderLayer");
-                               uiButSetFunc(bt, restrictbutton_r_lay_cb, NULL, NULL);
+                               uiButSetFunc(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
                                
                                uiBlockSetEmboss(block, UI_EMBOSS);
                        }
@@ -4019,15 +4851,15 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
                                uiBlockSetEmboss(block, UI_EMBOSSN);
                                
                                /* NOTE: tselem->nr is short! */
-                               bt= uiDefIconButBitI(block, ICONTOG, tselem->nr, REDRAWBUTSSCENE, ICON_CHECKBOX_HLT-1, 
+                               bt= uiDefIconButBitI(block, ICONTOG, tselem->nr, 0, ICON_CHECKBOX_HLT-1, 
                                                                         (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, (short)te->ys, 17, OL_H-1, layflag, 0, 0, 0, 0, "Render this Pass");
-                               uiButSetFunc(bt, restrictbutton_r_lay_cb, NULL, NULL);
+                               uiButSetFunc(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
                                
                                layflag++;      /* is lay_xor */
                                if(ELEM6(tselem->nr, SCE_PASS_SPEC, SCE_PASS_SHADOW, SCE_PASS_AO, SCE_PASS_REFLECT, SCE_PASS_REFRACT, SCE_PASS_RADIO))
-                                       bt= uiDefIconButBitI(block, TOG, tselem->nr, REDRAWBUTSSCENE, (*layflag & tselem->nr)?ICON_DOT:ICON_BLANK1, 
+                                       bt= uiDefIconButBitI(block, TOG, tselem->nr, 0, (*layflag & tselem->nr)?ICON_DOT:ICON_BLANK1, 
                                                                         (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_SELECTX, (short)te->ys, 17, OL_H-1, layflag, 0, 0, 0, 0, "Exclude this Pass from Combined");
-                               uiButSetFunc(bt, restrictbutton_r_lay_cb, NULL, NULL);
+                               uiButSetFunc(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
                                
                                uiBlockSetEmboss(block, UI_EMBOSS);
                        }
@@ -4036,34 +4868,30 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
                                ob = (Object *)tselem->id;
                                
                                uiBlockSetEmboss(block, UI_EMBOSSN);
-                               bt= uiDefIconButBitI(block, ICONTOGN, eModifierMode_Realtime, REDRAWALL, ICON_RESTRICT_VIEW_OFF, 
+                               bt= uiDefIconButBitI(block, ICONTOGN, eModifierMode_Realtime, 0, ICON_RESTRICT_VIEW_OFF, 
                                                (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, (short)te->ys, 17, OL_H-1, &(md->mode), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View");
                                uiButSetFunc(bt, restrictbutton_modifier_cb, scene, ob);
-                               uiButSetFlag(bt, UI_NO_HILITE);
                                
-                               bt= uiDefIconButBitI(block, ICONTOGN, eModifierMode_Render, REDRAWALL, ICON_RESTRICT_RENDER_OFF, 
+                               bt= uiDefIconButBitI(block, ICONTOGN, eModifierMode_Render, 0, ICON_RESTRICT_RENDER_OFF, 
                                                (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_RENDERX, (short)te->ys, 17, OL_H-1, &(md->mode), 0, 0, 0, 0, "Restrict/Allow renderability");
                                uiButSetFunc(bt, restrictbutton_modifier_cb, scene, ob);
-                               uiButSetFlag(bt, UI_NO_HILITE);
                        }
                        else if(tselem->type==TSE_POSE_CHANNEL)  {
                                bPoseChannel *pchan= (bPoseChannel *)te->directdata;
                                Bone *bone = pchan->bone;
 
                                uiBlockSetEmboss(block, UI_EMBOSSN);
-                               bt= uiDefIconButBitI(block, ICONTOG, BONE_HIDDEN_P, REDRAWALL, ICON_RESTRICT_VIEW_OFF, 
+                               bt= uiDefIconButBitI(block, ICONTOG, BONE_HIDDEN_P, 0, ICON_RESTRICT_VIEW_OFF, 
                                                (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, (short)te->ys, 17, OL_H-1, &(bone->flag), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View");
                                uiButSetFunc(bt, restrictbutton_bone_cb, NULL, NULL);
-                               uiButSetFlag(bt, UI_NO_HILITE);
                        }
                        else if(tselem->type==TSE_EBONE)  {
                                EditBone *ebone= (EditBone *)te->directdata;
 
                                uiBlockSetEmboss(block, UI_EMBOSSN);
-                               bt= uiDefIconButBitI(block, ICONTOG, BONE_HIDDEN_A, REDRAWALL, ICON_RESTRICT_VIEW_OFF, 
+                               bt= uiDefIconButBitI(block, ICONTOG, BONE_HIDDEN_A, 0, ICON_RESTRICT_VIEW_OFF, 
                                                (int)ar->v2d.cur.xmax-OL_TOG_RESTRICT_VIEWX, (short)te->ys, 17, OL_H-1, &(ebone->flag), 0, 0, 0, 0, "Restrict/Allow visibility in the 3D View");
                                uiButSetFunc(bt, restrictbutton_bone_cb, NULL, NULL);
-                               uiButSetFlag(bt, UI_NO_HILITE);
                        }
                }
                
@@ -4078,90 +4906,17 @@ static void outliner_draw_rnacols(ARegion *ar, SpaceOops *soops, int sizex)
        UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
 
        /* draw column separator lines */
-       fdrawline(sizex,
+       fdrawline((float)sizex,
                v2d->cur.ymax,
-               sizex,
+               (float)sizex,
                v2d->cur.ymin);
 
-       fdrawline(sizex+OL_RNA_COL_SIZEX,
+       fdrawline((float)sizex+OL_RNA_COL_SIZEX,
                v2d->cur.ymax,
-               sizex+OL_RNA_COL_SIZEX,
+               (float)sizex+OL_RNA_COL_SIZEX,
                v2d->cur.ymin);
 }
 
-static uiBut *outliner_draw_rnabut(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int index, int x1, int y1, int x2, int y2)
-{
-       uiBut *but=NULL;
-       const char *propname= RNA_property_identifier(ptr, prop);
-       int arraylen= RNA_property_array_length(ptr, prop);
-
-       switch(RNA_property_type(ptr, prop)) {
-               case PROP_BOOLEAN: {
-                       int value, length;
-
-                       if(arraylen && index == -1)
-                               return NULL;
-
-                       length= RNA_property_array_length(ptr, prop);
-
-                       if(length)
-                               value= RNA_property_boolean_get_array(ptr, prop, index);
-                       else
-                               value= RNA_property_boolean_get(ptr, prop);
-
-                       but= uiDefButR(block, TOG, 0, (value)? "True": "False", x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
-                       break;
-               }
-               case PROP_INT:
-               case PROP_FLOAT:
-                       if(arraylen && index == -1) {
-                               if(RNA_property_subtype(ptr, prop) == PROP_COLOR)
-                                       but= uiDefButR(block, COL, 0, "", x1, y1, x2, y2, ptr, propname, 0, 0, 0, -1, -1, NULL);
-                       }
-                       else
-                               but= uiDefButR(block, NUM, 0, "", x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
-                       break;
-               case PROP_ENUM:
-                       but= uiDefButR(block, MENU, 0, NULL, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
-                       break;
-               case PROP_STRING:
-                       but= uiDefButR(block, TEX, 0, "", x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
-                       break;
-               case PROP_POINTER: {
-                       PointerRNA pptr;
-                       PropertyRNA *nameprop;
-                       char *text, *descr, textbuf[256];
-                       int icon;
-
-                       RNA_property_pointer_get(ptr, prop, &pptr);
-
-                       if(!pptr.data)
-                               return NULL;
-
-                       icon= tselem_rna_icon(&pptr);
-                       nameprop= RNA_struct_name_property(&pptr);
-
-                       if(nameprop) {
-                               text= RNA_property_string_get_alloc(&pptr, nameprop, textbuf, sizeof(textbuf));
-                               descr= (char*)RNA_property_ui_description(&pptr, prop);
-                               but= uiDefIconTextBut(block, LABEL, 0, icon, text, x1, y1, x2, y2, NULL, 0, 0, 0, 0, descr);
-                               if(text != textbuf)
-                                       MEM_freeN(text);
-                       }
-                       else {
-                               text= (char*)RNA_struct_ui_name(&pptr);
-                               descr= (char*)RNA_property_ui_description(&pptr, prop);
-                               but= uiDefIconTextBut(block, LABEL, 0, icon, text, x1, y1, x2, y2, NULL, 0, 0, 0, 0, descr);
-                       }
-               }
-               default:
-                       but= NULL;
-                       break;
-       }
-
-       return but;
-}
-
 static void outliner_draw_rnabuts(uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops, int sizex, ListBase *lb)
 {      
        TreeElement *te;
@@ -4177,15 +4932,15 @@ static void outliner_draw_rnabuts(uiBlock *block, Scene *scene, ARegion *ar, Spa
                        if(tselem->type == TSE_RNA_PROPERTY) {
                                ptr= &te->rnaptr;
                                prop= te->directdata;
-
-                               if(!(RNA_property_type(ptr, prop) == PROP_POINTER && (tselem->flag & TSE_CLOSED)==0))
-                                       outliner_draw_rnabut(block, ptr, prop, -1, sizex, te->ys, OL_RNA_COL_SIZEX, OL_H-1);
+                               
+                               if(!(RNA_property_type(prop) == PROP_POINTER && (tselem->flag & TSE_CLOSED)==0))
+                                       uiDefAutoButR(block, ptr, prop, -1, "", 0, sizex, (int)te->ys, OL_RNA_COL_SIZEX, OL_H-1);
                        }
                        else if(tselem->type == TSE_RNA_ARRAY_ELEM) {
                                ptr= &te->rnaptr;
                                prop= te->directdata;
-
-                               outliner_draw_rnabut(block, ptr, prop, te->index, sizex, te->ys, OL_RNA_COL_SIZEX, OL_H-1);
+                               
+                               uiDefAutoButR(block, ptr, prop, te->index, "", 0, sizex, (int)te->ys, OL_RNA_COL_SIZEX, OL_H-1);
                        }
                }
                
@@ -4193,7 +4948,242 @@ static void outliner_draw_rnabuts(uiBlock *block, Scene *scene, ARegion *ar, Spa
        }
 }
 
-static void outliner_buttons(uiBlock *block, ARegion *ar, SpaceOops *soops, ListBase *lb)
+static void operator_call_cb(struct bContext *C, void *arg_kmi, void *arg2)
+{
+       wmOperatorType *ot= arg2;
+       wmKeymapItem *kmi= arg_kmi;
+       
+       if(ot)
+               BLI_strncpy(kmi->idname, ot->idname, OP_MAX_TYPENAME);
+}
+
+static void operator_search_cb(const struct bContext *C, void *arg_kmi, char *str, uiSearchItems *items)
+{
+       wmOperatorType *ot = WM_operatortype_first();
+       
+       for(; ot; ot= ot->next) {
+               
+               if(BLI_strcasestr(ot->idname, str)) {
+                       char name[OP_MAX_TYPENAME];
+                       
+                       /* display name for menu */
+                       WM_operator_py_idname(name, ot->idname);
+                       
+                       if(0==uiSearchItemAdd(items, name, ot, 0))
+                               break;
+               }
+       }
+}
+
+/* operator Search browse menu, open */
+static uiBlock *operator_search_menu(bContext *C, ARegion *ar, void *arg_kmi)
+{
+       static char search[OP_MAX_TYPENAME];
+       wmEvent event;
+       wmWindow *win= CTX_wm_window(C);
+       wmKeymapItem *kmi= arg_kmi;
+       wmOperatorType *ot= WM_operatortype_find(kmi->idname, 0);
+       uiBlock *block;
+       uiBut *but;
+       
+       /* clear initial search string, then all items show */
+       search[0]= 0;
+       
+       block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
+       uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1);
+       
+       /* fake button, it holds space for search items */
+       uiDefBut(block, LABEL, 0, "", 10, 15, 150, uiSearchBoxhHeight(), NULL, 0, 0, 0, 0, NULL);
+       
+       but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 10, 0, 150, 19, "");
+       uiButSetSearchFunc(but, operator_search_cb, arg_kmi, operator_call_cb, ot);
+       
+       uiBoundsBlock(block, 6);
+       uiBlockSetDirection(block, UI_DOWN);    
+       uiEndBlock(C, block);
+       
+       event= *(win->eventstate);      /* XXX huh huh? make api call */
+       event.type= EVT_BUT_OPEN;
+       event.val= KM_PRESS;
+       event.customdata= but;
+       event.customdatafree= FALSE;
+       wm_event_add(win, &event);
+       
+       return block;
+}
+
+#define OL_KM_KEYBOARD         0
+#define OL_KM_MOUSE                    1
+#define OL_KM_TWEAK                    2
+#define OL_KM_SPECIALS         3
+
+static short keymap_menu_type(short type)
+{
+       if(ISKEYBOARD(type)) return OL_KM_KEYBOARD;
+       if(WM_key_event_is_tweak(type)) return OL_KM_TWEAK;
+       if(type >= LEFTMOUSE && type <= WHEELOUTMOUSE) return OL_KM_MOUSE;
+//     return OL_KM_SPECIALS;
+       return 0;
+}
+
+static char *keymap_type_menu(void)
+{
+       static char string[500];
+       static char formatstr[] = "|%s %%x%d";
+       char *str= string;
+       
+       str += sprintf(str, "Event Type %%t");
+       
+       str += sprintf(str, formatstr, "Keyboard", OL_KM_KEYBOARD);
+       str += sprintf(str, formatstr, "Mouse", OL_KM_MOUSE);
+       str += sprintf(str, formatstr, "Tweak", OL_KM_TWEAK);
+//     str += sprintf(str, formatstr, "Specials", OL_KM_SPECIALS);
+       
+       return string;
+}      
+
+static char *keymap_mouse_menu(void)
+{
+       static char string[500];
+       static char formatstr[] = "|%s %%x%d";
+       char *str= string;
+       
+       str += sprintf(str, "Mouse Event %%t");
+       
+       str += sprintf(str, formatstr, "Left Mouse", LEFTMOUSE);
+       str += sprintf(str, formatstr, "Middle Mouse", MIDDLEMOUSE);
+       str += sprintf(str, formatstr, "Right Mouse", RIGHTMOUSE);
+       str += sprintf(str, formatstr, "Action Mouse", ACTIONMOUSE);
+       str += sprintf(str, formatstr, "Select Mouse", SELECTMOUSE);
+       str += sprintf(str, formatstr, "Mouse Move", MOUSEMOVE);
+       str += sprintf(str, formatstr, "Wheel Up", WHEELUPMOUSE);
+       str += sprintf(str, formatstr, "Wheel Down", WHEELDOWNMOUSE);
+       str += sprintf(str, formatstr, "Wheel In", WHEELINMOUSE);
+       str += sprintf(str, formatstr, "Wheel Out", WHEELOUTMOUSE);
+       
+       return string;
+}
+
+static char *keymap_tweak_menu(void)
+{
+       static char string[500];
+       static char formatstr[] = "|%s %%x%d";
+       char *str= string;
+       
+       str += sprintf(str, "Tweak Event %%t");
+       
+       str += sprintf(str, formatstr, "Left Mouse", EVT_TWEAK_L);
+       str += sprintf(str, formatstr, "Middle Mouse", EVT_TWEAK_M);
+       str += sprintf(str, formatstr, "Right Mouse", EVT_TWEAK_R);
+       str += sprintf(str, formatstr, "Action Mouse", EVT_TWEAK_A);
+       str += sprintf(str, formatstr, "Select Mouse", EVT_TWEAK_S);
+       
+       return string;
+}
+
+static void keymap_type_cb(bContext *C, void *kmi_v, void *unused_v)
+{
+       wmKeymapItem *kmi= kmi_v;
+       short maptype= keymap_menu_type(kmi->type);
+       
+       if(maptype!=kmi->maptype) {
+               switch(kmi->maptype) {
+                       case OL_KM_KEYBOARD:
+                               kmi->type= AKEY;
+                               kmi->val= KM_PRESS;
+                               break;
+                       case OL_KM_MOUSE:
+                               kmi->type= LEFTMOUSE;
+                               kmi->val= KM_PRESS;
+                               break;
+                       case OL_KM_TWEAK:
+                               kmi->type= EVT_TWEAK_L;
+                               kmi->val= KM_ANY;
+                               break;
+                       case OL_KM_SPECIALS:
+                               kmi->type= AKEY;
+                               kmi->val= KM_PRESS;
+               }
+               ED_region_tag_redraw(CTX_wm_region(C));
+       }
+}
+
+static void outliner_draw_keymapbuts(uiBlock *block, ARegion *ar, SpaceOops *soops, ListBase *lb)
+{
+       TreeElement *te;
+       TreeStoreElem *tselem;
+       
+       uiBlockSetEmboss(block, UI_EMBOSST);
+       
+       for(te= lb->first; te; te= te->next) {
+               tselem= TREESTORE(te);
+               if(te->ys >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {
+                       uiBut *but;
+                       char *str;
+                       int xstart= 240;
+                       int butw1= 20; /* operator */
+                       int butw2= 90; /* event type, menus */
+                       int butw3= 43; /* modifiers */
+
+                       if(tselem->type == TSE_KEYMAP_ITEM) {
+                               wmKeymapItem *kmi= te->directdata;
+                               
+                               /* modal map? */
+                               if(kmi->propvalue);
+                               else {
+                                       uiDefBlockBut(block, operator_search_menu, kmi, "", xstart, (int)te->ys+1, butw1, OL_H-1, "Assign new Operator");
+                               }
+                               xstart+= butw1+10;
+                               
+                               /* map type button */
+                               kmi->maptype= keymap_menu_type(kmi->type);
+                               
+                               str= keymap_type_menu();
+                               but= uiDefButS(block, MENU, 0, str,     xstart, (int)te->ys+1, butw2, OL_H-1, &kmi->maptype, 0, 0, 0, 0, "Event type");
+                               uiButSetFunc(but, keymap_type_cb, kmi, NULL);
+                               xstart+= butw2+5;
+                               
+                               /* edit actual event */
+                               switch(kmi->maptype) {
+                                       case OL_KM_KEYBOARD:
+                                               uiDefKeyevtButS(block, 0, "", xstart, (int)te->ys+1, butw2, OL_H-1, &kmi->type, "Key code");
+                                               xstart+= butw2+5;
+                                               break;
+                                       case OL_KM_MOUSE:
+                                               str= keymap_mouse_menu();
+                                               uiDefButS(block, MENU, 0, str, xstart,(int)te->ys+1, butw2, OL_H-1, &kmi->type, 0, 0, 0, 0,  "Mouse button");   
+                                               xstart+= butw2+5;
+                                               break;
+                                       case OL_KM_TWEAK:
+                                               str= keymap_tweak_menu();
+                                               uiDefButS(block, MENU, 0, str, xstart, (int)te->ys+1, butw2, OL_H-1, &kmi->type, 0, 0, 0, 0,  "Tweak gesture"); 
+                                               xstart+= butw2+5;
+                                               break;
+                               }
+                               
+                               /* modifiers */
+                               uiBlockBeginAlign(block);
+                               uiDefButS(block, OPTION, 0, "Shift",    xstart, (int)te->ys+1, butw3+5, OL_H-1, &kmi->shift, 0, 0, 0, 0, "Modifier"); xstart+= butw3+5;
+                               uiDefButS(block, OPTION, 0, "Ctrl",     xstart, (int)te->ys+1, butw3, OL_H-1, &kmi->ctrl, 0, 0, 0, 0, "Modifier"); xstart+= butw3;
+                               uiDefButS(block, OPTION, 0, "Alt",      xstart, (int)te->ys+1, butw3, OL_H-1, &kmi->alt, 0, 0, 0, 0, "Modifier"); xstart+= butw3;
+                               uiDefButS(block, OPTION, 0, "Cmd",      xstart, (int)te->ys+1, butw3, OL_H-1, &kmi->oskey, 0, 0, 0, 0, "Modifier"); xstart+= butw3;
+                               xstart+= 5;
+                               uiBlockEndAlign(block);
+                               
+                               /* rna property */
+                               if(kmi->ptr && kmi->ptr->data)
+                                       uiDefBut(block, LABEL, 0, "(RNA property)",     xstart, (int)te->ys+1, butw2, OL_H-1, &kmi->oskey, 0, 0, 0, 0, ""); xstart+= butw2;
+                                       
+                               
+                       }
+               }
+               
+               if((tselem->flag & TSE_CLOSED)==0) outliner_draw_keymapbuts(block, ar, soops, &te->subtree);
+       }
+}
+
+
+static void outliner_buttons(const bContext *C, uiBlock *block, ARegion *ar, SpaceOops *soops, ListBase *lb)
 {
        uiBut *bt;
        TreeElement *te;
@@ -4205,6 +5195,7 @@ static void outliner_buttons(uiBlock *block, ARegion *ar, SpaceOops *soops, List
                if(te->ys >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {
                        
                        if(tselem->flag & TSE_TEXTBUT) {
+                               
                                /* If we add support to rename Sequence.
                                 * need change this.
                                 */
@@ -4215,21 +5206,19 @@ static void outliner_buttons(uiBlock *block, ARegion *ar, SpaceOops *soops, List
                                else if(tselem->id && GS(tselem->id->name)==ID_LI) len = sizeof(((Library*) 0)->name);
                                else len= sizeof(((ID*) 0)->name)-2;
                                
-                               dx= (int)UI_GetStringWidth(G.font, te->name, 0);
+                               dx= (int)UI_GetStringWidth(te->name);
                                if(dx<50) dx= 50;
                                
                                bt= uiDefBut(block, TEX, OL_NAMEBUTTON, "",  (short)te->xs+2*OL_X-4, (short)te->ys, dx+10, OL_H-1, te->name, 1.0, (float)len-1, 0, 0, "");
-                               uiButSetFunc(bt, namebutton_cb, te, NULL);
-
-                               // signal for button to open
-// XXX                         addqueue(curarea->win, BUT_ACTIVATE, OL_NAMEBUTTON);
+                               uiButSetRenameFunc(bt, namebutton_cb, tselem);
                                
-                               /* otherwise keeps open on ESC */
-                               tselem->flag &= ~TSE_TEXTBUT;
+                               /* returns false if button got removed */
+                               if( 0 == uiButActiveOnly(C, block, bt) )
+                                       tselem->flag &= ~TSE_TEXTBUT;
                        }
                }
                
-               if((tselem->flag & TSE_CLOSED)==0) outliner_buttons(block, ar, soops, &te->subtree);
+               if((tselem->flag & TSE_CLOSED)==0) outliner_buttons(C, block, ar, soops, &te->subtree);
        }
 }
 
@@ -4239,7 +5228,7 @@ void draw_outliner(const bContext *C)
        Scene *scene= CTX_data_scene(C);
        ARegion *ar= CTX_wm_region(C);
        View2D *v2d= &ar->v2d;
-       SpaceOops *soops= (SpaceOops*)CTX_wm_space_data(C);
+       SpaceOops *soops= CTX_wm_space_outliner(C);
        uiBlock *block;
        int sizey= 0, sizex= 0, sizex_rna= 0;
        
@@ -4248,7 +5237,7 @@ void draw_outliner(const bContext *C)
        /* get extents of data */
        outliner_height(soops, &soops->tree, &sizey);
 
-       if (ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) {
+       if (ELEM3(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF, SO_KEYMAP)) {
                /* RNA has two columns:
                 *      - column 1 is (max_width + OL_RNA_COL_SPACEX) or
                 *                               (OL_RNA_COL_X), whichever is wider...
@@ -4283,17 +5272,20 @@ void draw_outliner(const bContext *C)
 
        /* draw outliner stuff (background and hierachy lines) */
        outliner_back(ar, soops);
-       outliner_draw_tree(scene, ar, soops);
+       outliner_draw_tree((bContext *)C, scene, ar, soops);
 
        /* draw icons and names */
-       block= uiBeginBlock(C, ar, "outliner buttons", UI_EMBOSS, UI_HELV);
-       outliner_buttons(block, ar, soops, &soops->tree);
+       block= uiBeginBlock(C, ar, "outliner buttons", UI_EMBOSS);
+       outliner_buttons(C, block, ar, soops, &soops->tree);
        
        if(ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) {
                /* draw rna buttons */
                outliner_draw_rnacols(ar, soops, sizex_rna);
                outliner_draw_rnabuts(block, scene, ar, soops, sizex_rna, &soops->tree);
        }
+       else if(soops->outlinevis == SO_KEYMAP) {
+               outliner_draw_keymapbuts(block, ar, soops, &soops->tree);
+       }
        else if (!(soops->flag & SO_HIDE_RESTRICTCOLS)) {
                /* draw restriction columns */
                outliner_draw_restrictcols(ar, soops);