Outliner: Added recursive select/deselect (CTRL+LMB) and extend (CTRL+SHIFT+LMB)
[blender.git] / source / blender / editors / space_outliner / outliner_edit.c
index 04e9cbf..78346dc 100644 (file)
@@ -35,6 +35,7 @@
 #include "DNA_group_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_object_types.h"
+#include "DNA_material_types.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_utildefines.h"
@@ -48,6 +49,7 @@
 #include "BKE_main.h"
 #include "BKE_report.h"
 #include "BKE_scene.h"
+#include "BKE_material.h"
 
 #include "ED_object.h"
 #include "ED_screen.h"
@@ -79,7 +81,7 @@ static int outliner_open_back(SpaceOops *soops, TreeElement *te)
        
        for (te = te->parent; te; te = te->parent) {
                tselem = TREESTORE(te);
-               if (tselem->flag & TSE_CLOSED) { 
+               if (tselem->flag & TSE_CLOSED) {
                        tselem->flag &= ~TSE_CLOSED;
                        retval = 1;
                }
@@ -181,8 +183,8 @@ void OUTLINER_OT_item_openclose(wmOperatorType *ot)
 
 static void do_item_rename(ARegion *ar, TreeElement *te, TreeStoreElem *tselem, ReportList *reports)
 {
-       /* can't rename rna datablocks entries */
-       if (ELEM3(tselem->type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) {
+       /* can't rename rna datablocks entries or listbases */
+       if (ELEM4(tselem->type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM, TSE_ID_BASE)) {
                /* do nothing */;
        }
        else if (ELEM10(tselem->type, TSE_ANIM_DATA, TSE_NLA, TSE_DEFGROUP_BASE, TSE_CONSTRAINT_BASE, TSE_MODIFIER_BASE,
@@ -195,17 +197,18 @@ static void do_item_rename(ARegion *ar, TreeElement *te, TreeStoreElem *tselem,
        }
        else if (tselem->id->lib) {
                // XXX                                          error_libdata();
-       } 
+       }
        else if (te->idcode == ID_LI && te->parent) {
                BKE_report(reports, RPT_WARNING, "Cannot edit the path of an indirectly linked library");
-       } 
+       }
        else {
                tselem->flag |= TSE_TEXTBUT;
                ED_region_tag_redraw(ar);
        }
 }
 
-void item_rename_cb(bContext *C, Scene *UNUSED(scene), TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
+void item_rename_cb(bContext *C, Scene *UNUSED(scene), TreeElement *te,
+                    TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
        ARegion *ar = CTX_wm_region(C);
        ReportList *reports = CTX_wm_reports(C); // XXX
@@ -219,12 +222,12 @@ static int do_outliner_item_rename(bContext *C, ARegion *ar, SpaceOops *soops, T
        if (mval[1] > te->ys && mval[1] < te->ys + UI_UNIT_Y) {
                TreeStoreElem *tselem = TREESTORE(te);
                
-               /* name and first icon */
-               if (mval[0] > te->xs + UI_UNIT_X && mval[0] < te->xend) {
-                       
+               /* click on name */
+               if (mval[0] > te->xs + UI_UNIT_X * 2 && mval[0] < te->xend) {
                        do_item_rename(ar, te, tselem, reports);
+                       return 1;
                }
-               return 1;
+               return 0;
        }
        
        for (te = te->subtree.first; te; te = te->next) {
@@ -239,14 +242,18 @@ static int outliner_item_rename(bContext *C, wmOperator *UNUSED(op), wmEvent *ev
        SpaceOops *soops = CTX_wm_space_outliner(C);
        TreeElement *te;
        float fmval[2];
+       int any_renamed = FALSE;
        
        UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], fmval, fmval + 1);
        
        for (te = soops->tree.first; te; te = te->next) {
-               if (do_outliner_item_rename(C, ar, soops, te, fmval)) break;
+               if (do_outliner_item_rename(C, ar, soops, te, fmval)) {
+                       any_renamed = TRUE;
+                       break;
+               }
        }
        
-       return OPERATOR_FINISHED;
+       return any_renamed ? OPERATOR_FINISHED : OPERATOR_PASS_THROUGH;
 }
 
 
@@ -340,7 +347,8 @@ int common_restrict_check(bContext *C, Object *ob)
 
 /* Toggle Visibility ---------------------------------------- */
 
-void object_toggle_visibility_cb(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
+void object_toggle_visibility_cb(bContext *C, Scene *scene, TreeElement *te,
+                                 TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
        Base *base = (Base *)te->directdata;
        Object *ob = (Object *)tselem->id;
@@ -355,7 +363,8 @@ void object_toggle_visibility_cb(bContext *C, Scene *scene, TreeElement *te, Tre
        }
 }
 
-void group_toggle_visibility_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
+void group_toggle_visibility_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te),
+                                TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
        Group *group = (Group *)tselem->id;
        restrictbutton_gr_restrict_flag(scene, group, OB_RESTRICT_VIEW);
@@ -363,12 +372,14 @@ void group_toggle_visibility_cb(bContext *UNUSED(C), Scene *scene, TreeElement *
 
 static int outliner_toggle_visibility_exec(bContext *C, wmOperator *UNUSED(op))
 {
+       Main *bmain = CTX_data_main(C);
        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);
        
+       DAG_id_type_tag(bmain, ID_OB);
        WM_event_add_notifier(C, NC_SCENE | ND_OB_VISIBLE, scene);
        ED_region_tag_redraw(ar);
        
@@ -391,7 +402,8 @@ void OUTLINER_OT_visibility_toggle(wmOperatorType *ot)
 
 /* Toggle Selectability ---------------------------------------- */
 
-void object_toggle_selectability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
+void object_toggle_selectability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te,
+                                    TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
        Base *base = (Base *)te->directdata;
        
@@ -401,7 +413,8 @@ void object_toggle_selectability_cb(bContext *UNUSED(C), Scene *scene, TreeEleme
        }
 }
 
-void group_toggle_selectability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
+void group_toggle_selectability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te),
+                                   TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
        Group *group = (Group *)tselem->id;
        restrictbutton_gr_restrict_flag(scene, group, OB_RESTRICT_SELECT);
@@ -437,7 +450,8 @@ void OUTLINER_OT_selectability_toggle(wmOperatorType *ot)
 
 /* Toggle Renderability ---------------------------------------- */
 
-void object_toggle_renderability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
+void object_toggle_renderability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *te,
+                                    TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
        Base *base = (Base *)te->directdata;
        
@@ -447,7 +461,8 @@ void object_toggle_renderability_cb(bContext *UNUSED(C), Scene *scene, TreeEleme
        }
 }
 
-void group_toggle_renderability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te), TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
+void group_toggle_renderability_cb(bContext *UNUSED(C), Scene *scene, TreeElement *UNUSED(te),
+                                   TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
 {
        Group *group = (Group *)tselem->id;
        restrictbutton_gr_restrict_flag(scene, group, OB_RESTRICT_RENDER);
@@ -455,11 +470,13 @@ void group_toggle_renderability_cb(bContext *UNUSED(C), Scene *scene, TreeElemen
 
 static int outliner_toggle_renderability_exec(bContext *C, wmOperator *UNUSED(op))
 {
+       Main *bmain = CTX_data_main(C);
        SpaceOops *soops = CTX_wm_space_outliner(C);
        Scene *scene = CTX_data_scene(C);
        
        outliner_do_object_operation(C, scene, soops, &soops->tree, object_toggle_renderability_cb);
        
+       DAG_id_type_tag(bmain, ID_OB);
        WM_event_add_notifier(C, NC_SCENE | ND_OB_RENDER, scene);
        
        return OPERATOR_FINISHED;
@@ -570,11 +587,11 @@ static int outliner_show_active_exec(bContext *C, wmOperator *UNUSED(op))
        te = outliner_find_id(so, &so->tree, (ID *)OBACT);
        if (te) {
                /* make te->ys center of view */
-               ytop = (int)(te->ys + (v2d->mask.ymax - v2d->mask.ymin) / 2);
+               ytop = (int)(te->ys + BLI_rcti_size_y(&v2d->mask) / 2);
                if (ytop > 0) ytop = 0;
                
                v2d->cur.ymax = (float)ytop;
-               v2d->cur.ymin = (float)(ytop - (v2d->mask.ymax - v2d->mask.ymin));
+               v2d->cur.ymin = (float)(ytop - BLI_rcti_size_y(&v2d->mask));
                
                /* make te->xs ==> te->xend center of view */
                xdelta = (int)(te->xs - v2d->cur.xmin);
@@ -606,7 +623,7 @@ void OUTLINER_OT_show_active(wmOperatorType *ot)
 static int outliner_scroll_page_exec(bContext *C, wmOperator *op)
 {
        ARegion *ar = CTX_wm_region(C);
-       int dy = ar->v2d.mask.ymax - ar->v2d.mask.ymin;
+       int dy = BLI_rcti_size_y(&ar->v2d.mask);
        int up = 0;
        
        if (RNA_boolean_get(op->ptr, "up"))
@@ -674,7 +691,8 @@ static void outliner_set_coordinates(ARegion *ar, SpaceOops *soops)
 }
 
 /* find next element that has this name */
-static TreeElement *outliner_find_name(SpaceOops *soops, ListBase *lb, char *name, int flags, TreeElement *prev, int *prevFound)
+static TreeElement *outliner_find_name(SpaceOops *soops, ListBase *lb, char *name, int flags,
+                                       TreeElement *prev, int *prevFound)
 {
        TreeElement *te, *tes;
        
@@ -716,7 +734,7 @@ static void outliner_find_panel(Scene *UNUSED(scene), ARegion *ar, SpaceOops *so
        
        /* determine which type of search to do */
        if (again && last_find) {
-               /* no popup panel - previous + user wanted to search for next after previous */         
+               /* no popup panel - previous + user wanted to search for next after previous */
                BLI_strncpy(name, soops->search_string, sizeof(name));
                flags = soops->search_flags;
                
@@ -732,7 +750,7 @@ static void outliner_find_panel(Scene *UNUSED(scene), ARegion *ar, SpaceOops *so
                /* pop up panel - no previous, or user didn't want search after previous */
                name[0] = '\0';
 // XXX         if (sbutton(name, 0, sizeof(name)-1, "Find: ") && name[0]) {
-//                     te= outliner_find_name(soops, &soops->tree, name, flags, NULL, &prevFound);
+//                     te = outliner_find_name(soops, &soops->tree, name, flags, NULL, &prevFound);
 //             }
 //             else return; /* XXX RETURN! XXX */
        }
@@ -750,10 +768,10 @@ static void outliner_find_panel(Scene *UNUSED(scene), ARegion *ar, SpaceOops *so
                        tselem->flag |= TSE_SELECTED;
                        
                        /* make te->ys center of view */
-                       ytop = (int)(te->ys + (ar->v2d.mask.ymax - ar->v2d.mask.ymin) / 2);
+                       ytop = (int)(te->ys + BLI_rctf_size_y(&ar->v2d.mask) / 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));
+                       ar->v2d.cur.ymin = (float)(ytop - BLI_rctf_size_y(&ar->v2d.mask));
                        
                        /* make te->xs ==> te->xend center of view */
                        xdelta = (int)(te->xs - ar->v2d.cur.xmin);
@@ -772,7 +790,7 @@ static void outliner_find_panel(Scene *UNUSED(scene), ARegion *ar, SpaceOops *so
        }
        else {
                /* no tree-element found */
-               BKE_report(reports, RPT_WARNING, "Not found: %s", name);
+               BKE_reportf(reports, RPT_WARNING, "Not found: %s", name);
        }
 }
 #endif
@@ -822,6 +840,8 @@ static int outliner_one_level_exec(bContext *C, wmOperator *op)
 
 void OUTLINER_OT_show_one_level(wmOperatorType *ot)
 {
+       PropertyRNA *prop;
+
        /* identifiers */
        ot->name = "Show/Hide One Level";
        ot->idname = "OUTLINER_OT_show_one_level";
@@ -834,7 +854,8 @@ void OUTLINER_OT_show_one_level(wmOperatorType *ot)
        /* no undo or registry, UI option */
        
        /* properties */
-       RNA_def_boolean(ot->srna, "open", 1, "Open", "Expand all entries one level deep");
+       prop = RNA_def_boolean(ot->srna, "open", 1, "Open", "Expand all entries one level deep");
+       RNA_def_property_flag(prop, PROP_SKIP_SAVE);
 }
 
 /* Show Hierarchy ----------------------------------------------- */
@@ -873,9 +894,13 @@ static void tree_element_show_hierarchy(Scene *scene, SpaceOops *soops, ListBase
                                else tselem->flag |= TSE_CLOSED;
                        }
                }
-               else tselem->flag |= TSE_CLOSED;
-               
-               if (TSELEM_OPEN(tselem, soops)) tree_element_show_hierarchy(scene, soops, &te->subtree);
+               else {
+                       tselem->flag |= TSE_CLOSED;
+               }
+
+               if (TSELEM_OPEN(tselem, soops)) {
+                       tree_element_show_hierarchy(scene, soops, &te->subtree);
+               }
        }
 }
 
@@ -961,7 +986,8 @@ static void tree_element_to_path(SpaceOops *soops, TreeElement *te, TreeStoreEle
                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) */
+       /* 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;
@@ -972,7 +998,7 @@ static void tree_element_to_path(SpaceOops *soops, TreeElement *te, TreeStoreEle
                /* 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
+                        * - 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) {
@@ -983,7 +1009,7 @@ static void tree_element_to_path(SpaceOops *soops, TreeElement *te, TreeStoreEle
                                        char buf[128], *name;
                                        
                                        temnext = (TreeElement *)(ld->next->data);
-                                       /* tsenext= TREESTORE(temnext); */ /* UNUSED */
+                                       /* tsenext = TREESTORE(temnext); */ /* UNUSED */
                                        
                                        nextptr = &temnext->rnaptr;
                                        name = RNA_struct_name_get_alloc(nextptr, buf, sizeof(buf), NULL);
@@ -1019,7 +1045,8 @@ static void tree_element_to_path(SpaceOops *soops, TreeElement *te, TreeStoreEle
                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? */
+                               /* 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;
                                        
@@ -1090,7 +1117,9 @@ static void do_outliner_drivers_editop(SpaceOops *soops, ListBase *tree, ReportL
                        short groupmode = KSP_GROUP_KSNAME;
                        
                        /* check if RNA-property described by this selected element is an animatable prop */
-                       if (ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM) && RNA_property_animateable(&te->rnaptr, te->directdata)) {
+                       if (ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM) &&
+                           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);
@@ -1269,7 +1298,9 @@ static void do_outliner_keyingset_editop(SpaceOops *soops, KeyingSet *ks, ListBa
                        short groupmode = KSP_GROUP_KSNAME;
                        
                        /* check if RNA-property described by this selected element is an animatable prop */
-                       if (ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM) && RNA_property_animateable(&te->rnaptr, te->directdata)) {
+                       if (ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM) &&
+                           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);
@@ -1282,11 +1313,12 @@ static void do_outliner_keyingset_editop(SpaceOops *soops, KeyingSet *ks, ListBa
                                        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
+                                               /* 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_path(ks, id, NULL, path, array_index, flag, groupmode);
                                                ks->active_path = BLI_countlist(&ks->paths);
+                                               break;
                                        }
-                                       break;
                                        case KEYINGSET_EDITMODE_REMOVE:
                                        {
                                                /* find the relevant path, then remove it from the KeyingSet */
@@ -1298,8 +1330,8 @@ static void do_outliner_keyingset_editop(SpaceOops *soops, KeyingSet *ks, ListBa
 
                                                        ks->active_path = 0;
                                                }
+                                               break;
                                        }
-                                       break;
                                }
                                
                                /* free path, since it had to be generated */
@@ -1323,7 +1355,7 @@ static int outliner_keyingset_additems_exec(bContext *C, wmOperator *op)
        
        /* check for invalid states */
        if (ks == NULL) {
-               BKE_report(op->reports, RPT_ERROR, "Operation requires an Active Keying Set");
+               BKE_report(op->reports, RPT_ERROR, "Operation requires an active keying set");
                return OPERATOR_CANCELLED;
        }
        if (soutliner == NULL)
@@ -1343,7 +1375,7 @@ void OUTLINER_OT_keyingset_add_selected(wmOperatorType *ot)
        /* identifiers */
        ot->idname = "OUTLINER_OT_keyingset_add_selected";
        ot->name = "Keying Set Add Selected";
-       ot->description = "Add selected items (blue-grey rows) to active Keying Set";
+       ot->description = "Add selected items (blue-gray rows) to active Keying Set";
        
        /* api callbacks */
        ot->exec = outliner_keyingset_additems_exec;
@@ -1380,7 +1412,7 @@ void OUTLINER_OT_keyingset_remove_selected(wmOperatorType *ot)
        /* identifiers */
        ot->idname = "OUTLINER_OT_keyingset_remove_selected";
        ot->name = "Keying Set Remove Selected";
-       ot->description = "Remove selected items (blue-grey rows) from active Keying Set";
+       ot->description = "Remove selected items (blue-gray rows) from active Keying Set";
        
        /* api callbacks */
        ot->exec = outliner_keyingset_removeitems_exec;
@@ -1406,10 +1438,9 @@ static int parent_drop_exec(bContext *C, wmOperator *op)
        RNA_string_get(op->ptr, "child", childname);
        ob = (Object *)BKE_libblock_find_name(ID_OB, childname);
 
-       ED_object_parent_set(op->reports, bmain, scene, ob, par, partype);
+       ED_object_parent_set(op->reports, bmain, scene, ob, par, partype, FALSE, FALSE);
 
-       DAG_scene_sort(bmain, scene);
-       DAG_ids_flush_update(bmain, 0);
+       DAG_relations_tag_update(bmain);
        WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
        WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, NULL);
 
@@ -1426,7 +1457,7 @@ TreeElement *outliner_dropzone_parent(bContext *C, wmEvent *event, TreeElement *
                /* name and first icon */
                if ((fmval[0] > te->xs + UI_UNIT_X) && (fmval[0] < te->xend)) {
                        /* always makes active object */
-                       if (te->idcode == ID_OB) {
+                       if (te->idcode == ID_OB && tselem->type == 0) {
                                return te;
                        }
                        else {
@@ -1453,7 +1484,7 @@ static int parent_drop_invoke(bContext *C, wmOperator *op, wmEvent *event)
        SpaceOops *soops = CTX_wm_space_outliner(C);
        ARegion *ar = CTX_wm_region(C);
        Main *bmain = CTX_data_main(C);
-       Scene *scene = CTX_data_scene(C);
+       Scene *scene = NULL;
        TreeElement *te = NULL;
        TreeElement *te_found = NULL;
        char childname[MAX_ID_NAME];
@@ -1485,14 +1516,20 @@ static int parent_drop_invoke(bContext *C, wmOperator *op, wmEvent *event)
                        return OPERATOR_CANCELLED;
                }
                
-               /* check dragged object (child) is active */
-               if (ob != CTX_data_active_object(C))
-                       ED_base_object_select(BKE_scene_base_find(scene, ob), BA_SELECT);
-               
+               scene = (Scene *)outliner_search_back(soops, te_found, ID_SCE);
+
+               if (scene == NULL) {
+                       /* currently outlier organized in a way, that if there's no parent scene
+                        * element for object it means that all displayed objects belong to
+                        * active scene and parenting them is allowed (sergey)
+                        */
+
+                       scene = CTX_data_scene(C);
+               }
+
                if ((par->type != OB_ARMATURE) && (par->type != OB_CURVE) && (par->type != OB_LATTICE)) {
-                       if (ED_object_parent_set(op->reports, bmain, scene, ob, par, partype)) {
-                               DAG_scene_sort(bmain, scene);
-                               DAG_ids_flush_update(bmain, 0);
+                       if (ED_object_parent_set(op->reports, bmain, scene, ob, par, partype, FALSE, FALSE)) {
+                               DAG_relations_tag_update(bmain);
                                WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
                                WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, NULL);
                        }
@@ -1606,7 +1643,7 @@ void OUTLINER_OT_parent_drop(wmOperatorType *ot)
        ot->poll = ED_operator_outliner_active;
 
        /* flags */
-       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
 
        /* properties */
        RNA_def_string(ot->srna, "child", "Object", MAX_ID_NAME, "Child", "Child Object");
@@ -1635,7 +1672,7 @@ int outliner_dropzone_parent_clear(bContext *C, wmEvent *event, TreeElement *te,
                if ((fmval[0] < (te->xs + UI_UNIT_X)) || (fmval[0] > te->xend)) {
                        return 1;
                }
-               else if (te->idcode != ID_OB) {
+               else if (te->idcode != ID_OB || ELEM(tselem->type, TSE_MODIFIER_BASE, TSE_CONSTRAINT_BASE)) {
                        return 1;
                }
                
@@ -1654,19 +1691,30 @@ int outliner_dropzone_parent_clear(bContext *C, wmEvent *event, TreeElement *te,
 
 static int parent_clear_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
 {
-       Scene *scene = CTX_data_scene(C);
+       Main *bmain = CTX_data_main(C);
+       Scene *scene = NULL;
        Object *ob = NULL;
+       SpaceOops *soops = CTX_wm_space_outliner(C);
+       TreeElement *te;
        char obname[MAX_ID_NAME];
 
        RNA_string_get(op->ptr, "dragged_obj", obname);
        ob = (Object *)BKE_libblock_find_name(ID_OB, obname);
 
-       /* check dragged object (child) is active */
-       if (ob != CTX_data_active_object(C))
-               ED_base_object_select(BKE_scene_base_find(scene, ob), BA_SELECT);
+       /* search forwards to find the object */
+       te = outliner_find_id(soops, &soops->tree, (ID *)ob);
+       /* then search backwards to get the scene */
+       scene = (Scene *)outliner_search_back(soops, te, ID_SCE);
+
+       if (scene == NULL) {
+               return OPERATOR_CANCELLED;
+       }
 
-       ED_object_parent_clear(C, RNA_enum_get(op->ptr, "type"));
+       ED_object_parent_clear(ob, RNA_enum_get(op->ptr, "type"));
 
+       DAG_relations_tag_update(bmain);
+       WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
+       WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, NULL);
        return OPERATOR_FINISHED;
 }
 
@@ -1683,9 +1731,164 @@ void OUTLINER_OT_parent_clear(wmOperatorType *ot)
        ot->poll = ED_operator_outliner_active;
 
        /* flags */
-       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
 
        /* properties */
        RNA_def_string(ot->srna, "dragged_obj", "Object", MAX_ID_NAME, "Child", "Child Object");
        RNA_def_enum(ot->srna, "type", prop_clear_parent_types, 0, "Type", "");
 }
+
+TreeElement *outliner_dropzone_scene(bContext *C, wmEvent *UNUSED(event), TreeElement *te, float *fmval)
+{
+       SpaceOops *soops = CTX_wm_space_outliner(C);
+       TreeStoreElem *tselem = TREESTORE(te);
+
+       if ((fmval[1] > te->ys) && (fmval[1] < (te->ys + UI_UNIT_Y))) {
+               /* name and first icon */
+               if ((fmval[0] > te->xs + UI_UNIT_X) && (fmval[0] < te->xend)) {
+                       if (te->idcode == ID_SCE && tselem->type == 0) {
+                               return te;
+                       }
+               }
+       }
+       return NULL;
+}
+
+static int scene_drop_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       Scene *scene = NULL;
+       Object *ob = NULL;
+       SpaceOops *soops = CTX_wm_space_outliner(C);
+       ARegion *ar = CTX_wm_region(C);
+       Main *bmain = CTX_data_main(C);
+       TreeElement *te = NULL;
+       TreeElement *te_found = NULL;
+       char obname[MAX_ID_NAME];
+       float fmval[2];
+
+       UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]);
+
+       /* Find object hovered over */
+       for (te = soops->tree.first; te; te = te->next) {
+               te_found = outliner_dropzone_scene(C, event, te, fmval);
+               if (te_found)
+                       break;
+       }
+
+       if (te_found) {
+               Base *base;
+
+               RNA_string_set(op->ptr, "scene", te_found->name);
+               scene = (Scene *)BKE_libblock_find_name(ID_SCE, te_found->name);
+
+               RNA_string_get(op->ptr, "object", obname);
+               ob = (Object *)BKE_libblock_find_name(ID_OB, obname);
+
+               if (ELEM(NULL, ob, scene) || scene->id.lib != NULL) {
+                       return OPERATOR_CANCELLED;
+               }
+
+               base = ED_object_scene_link(scene, ob);
+
+               if (base == NULL) {
+                       return OPERATOR_CANCELLED;
+               }
+
+               if (scene == CTX_data_scene(C)) {
+                       /* when linking to an inactive scene don't touch the layer */
+                       ob->lay = base->lay;
+                       ED_base_object_select(base, BA_SELECT);
+               }
+
+               DAG_relations_tag_update(bmain);
+
+               WM_main_add_notifier(NC_SCENE | ND_OB_SELECT, scene);
+
+               return OPERATOR_FINISHED;
+       }
+
+       return OPERATOR_CANCELLED;
+}
+
+void OUTLINER_OT_scene_drop(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Drop Object to Scene";
+       ot->description = "Drag object to scene in Outliner";
+       ot->idname = "OUTLINER_OT_scene_drop";
+
+       /* api callbacks */
+       ot->invoke = scene_drop_invoke;
+
+       ot->poll = ED_operator_outliner_active;
+
+       /* flags */
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
+
+       /* properties */
+       RNA_def_string(ot->srna, "object", "Object", MAX_ID_NAME, "Object", "Target Object");
+       RNA_def_string(ot->srna, "scene", "Scene", MAX_ID_NAME, "Scene", "Target Scene");
+}
+
+static int material_drop_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       Material *ma = NULL;
+       Object *ob = NULL;
+       SpaceOops *soops = CTX_wm_space_outliner(C);
+       ARegion *ar = CTX_wm_region(C);
+       TreeElement *te = NULL;
+       TreeElement *te_found = NULL;
+       char mat_name[MAX_ID_NAME - 2];
+       float fmval[2];
+
+       UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]);
+
+       /* Find object hovered over */
+       for (te = soops->tree.first; te; te = te->next) {
+               te_found = outliner_dropzone_parent(C, event, te, fmval);
+               if (te_found)
+                       break;
+       }
+
+       if (te_found) {
+               RNA_string_set(op->ptr, "object", te_found->name);
+               ob = (Object *)BKE_libblock_find_name(ID_OB, te_found->name);
+
+               RNA_string_get(op->ptr, "material", mat_name);
+               ma = (Material *)BKE_libblock_find_name(ID_MA, mat_name);
+
+               if (ELEM(NULL, ob, ma)) {
+                       return OPERATOR_CANCELLED;
+               }
+
+               assign_material(ob, ma, ob->totcol + 1, BKE_MAT_ASSIGN_USERPREF);
+
+               WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, CTX_wm_view3d(C));
+               WM_event_add_notifier(C, NC_MATERIAL | ND_SHADING_LINKS, ma);
+
+               return OPERATOR_FINISHED;
+       }
+
+       return OPERATOR_CANCELLED;
+}
+
+void OUTLINER_OT_material_drop(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Drop Material on Object";
+       ot->description = "Drag material to object in Outliner";
+       ot->idname = "OUTLINER_OT_material_drop";
+
+       /* api callbacks */
+       ot->invoke = material_drop_invoke;
+
+       ot->poll = ED_operator_outliner_active;
+
+       /* flags */
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
+
+       /* properties */
+       RNA_def_string(ot->srna, "object", "Object", MAX_ID_NAME, "Object", "Target Object");
+       RNA_def_string(ot->srna, "material", "Material", MAX_ID_NAME, "Material", "Target Material");
+}
+