Implement operator to select linked data from outliner
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 25 Jul 2012 19:45:34 +0000 (19:45 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 25 Jul 2012 19:45:34 +0000 (19:45 +0000)
Supports selecting using object data, material and library.

Would be nice to hide this menu item from menus appearing for
datablocks which does not support such a selection, but that
could be done separately.

source/blender/editors/include/ED_object.h
source/blender/editors/object/object_select.c
source/blender/editors/space_outliner/outliner_tools.c

index 38f0077c36808da5599f7d329fff59e004be625f..09fb88fd5ac81610284f04200e45bbf420874524 100644 (file)
@@ -41,6 +41,7 @@ struct bContext;
 struct bPoseChannel;
 struct Curve;
 struct EnumPropertyItem;
+struct ID;
 struct KeyBlock;
 struct Lattice;
 struct Main;
@@ -183,6 +184,9 @@ int ED_object_iter_other(struct Main *bmain, struct Object *orig_ob, int include
 
 int ED_object_multires_update_totlevels_cb(struct Object *ob, void *totlevel_v);
 
+/* ibject_select.c */
+void ED_object_select_linked_by_id(struct bContext *C, struct ID *id);
+
 #ifdef __cplusplus
 }
 #endif
index f5f1ba61e8b271775adfd659e916105a128898ff..c83331a8eb76039741b2e4f1f1b0eeb72fdfe107 100644 (file)
@@ -372,6 +372,25 @@ static int object_select_all_by_library_obdata(bContext *C, Library *lib)
        return changed;
 }
 
+void ED_object_select_linked_by_id(bContext *C, ID *id)
+{
+       int gs = GS(id->name);
+       int changed = FALSE;
+
+       if (ELEM8(gs, ID_ME, ID_CU, ID_MB, ID_LT, ID_LA, ID_CA, ID_TXT, ID_SPK)) {
+               changed = object_select_all_by_obdata(C, id);
+       }
+       else if (gs == ID_MA) {
+               changed = object_select_all_by_material_texture(C, FALSE, (Material *)id, NULL);
+       }
+       else if (gs == ID_LI) {
+               changed = object_select_all_by_library(C, (Library *) id);
+       }
+
+       if (changed)
+               WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, CTX_data_scene(C));
+}
+
 static int object_select_linked_exec(bContext *C, wmOperator *op)
 {
        Scene *scene = CTX_data_scene(C);
@@ -1097,5 +1116,3 @@ void OBJECT_OT_select_random(wmOperatorType *ot)
        RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f, "Percent", "Percentage of objects to select randomly", 0.f, 100.0f);
        RNA_def_boolean(ot->srna, "extend", FALSE, "Extend Selection", "Extend selection instead of deselecting everything first");
 }
-
-
index 3d01de1c67a45f685b30f8d1d8511a86ad515def..acfaadb947deec07690a0f0086d869b26b049446 100644 (file)
@@ -324,6 +324,14 @@ static void id_fake_user_clear_cb(bContext *UNUSED(C), Scene *UNUSED(scene), Tre
        }
 }
 
+static void id_select_linked_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te),
+                                TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem)
+{
+       ID *id = tselem->id;
+
+       ED_object_select_linked_by_id(C, id);
+}
+
 static void singleuser_action_cb(bContext *C, Scene *UNUSED(scene), TreeElement *UNUSED(te),
                                  TreeStoreElem *tsep, TreeStoreElem *tselem)
 {
@@ -728,7 +736,9 @@ typedef enum eOutlinerIdOpTypes {
        
        OUTLINER_IDOP_FAKE_ADD,
        OUTLINER_IDOP_FAKE_CLEAR,
-       OUTLINER_IDOP_RENAME
+       OUTLINER_IDOP_RENAME,
+
+       OUTLINER_IDOP_SELECT_LINKED
 } eOutlinerIdOpTypes;
 
 // TODO: implement support for changing the ID-block used
@@ -740,6 +750,7 @@ static EnumPropertyItem prop_id_op_types[] = {
      "Ensure datablock gets saved even if it isn't in use (e.g. for motion and material libraries)"},
        {OUTLINER_IDOP_FAKE_CLEAR, "CLEAR_FAKE", 0, "Clear Fake User", ""},
        {OUTLINER_IDOP_RENAME, "RENAME", 0, "Rename", ""},
+       {OUTLINER_IDOP_SELECT_LINKED, "SELECT_LINKED", 0, "Select Linked", ""},
        {0, NULL, 0, NULL, NULL}
 };
 
@@ -855,6 +866,11 @@ static int outliner_id_operation_exec(bContext *C, wmOperator *op)
                        ED_undo_push(C, "Rename");
                }
                break;
+
+               case OUTLINER_IDOP_SELECT_LINKED:
+                       outliner_do_libdata_operation(C, scene, soops, &soops->tree, id_select_linked_cb);
+                       ED_undo_push(C, "Select");
+                       break;
                        
                default:
                        // invalid - unhandled