[Bf-blender-cvs] [e59db98688c] soc-2020-outliner: Outliner: Add type options for new collections

Nathan Craddock noreply at git.blender.org
Thu Jul 9 05:31:02 CEST 2020


Commit: e59db98688c3ed7fa451382dc7805a3f4575c4ce
Author: Nathan Craddock
Date:   Wed Jul 8 21:23:24 2020 -0600
Branches: soc-2020-outliner
https://developer.blender.org/rBe59db98688c3ed7fa451382dc7805a3f4575c4ce

Outliner: Add type options for new collections

Add options to move or link objects into the new collection from the
context menu.

===================================================================

M	release/scripts/startup/bl_ui/space_outliner.py
M	source/blender/editors/space_outliner/outliner_collections.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_outliner.py b/release/scripts/startup/bl_ui/space_outliner.py
index a57ef2b5691..56c28ea6d69 100644
--- a/release/scripts/startup/bl_ui/space_outliner.py
+++ b/release/scripts/startup/bl_ui/space_outliner.py
@@ -68,7 +68,7 @@ class OUTLINER_HT_header(Header):
             sub.prop(space, "filter_id_type", text="", icon_only=True)
 
         if display_mode == 'VIEW_LAYER':
-            layout.operator("outliner.collection_new", text="", icon='COLLECTION_NEW').nested = True
+            layout.operator("outliner.collection_new", text="", icon='COLLECTION_NEW')
 
         elif display_mode == 'ORPHAN_DATA':
             layout.operator("outliner.orphans_purge", text="Purge")
@@ -204,7 +204,7 @@ class OUTLINER_MT_collection(Menu):
 
         space = context.space_data
 
-        layout.operator("outliner.collection_new", text="New").nested = True
+        layout.operator("outliner.collection_new", text="New")
         layout.operator("outliner.collection_duplicate", text="Duplicate Collection")
         layout.operator("outliner.collection_duplicate_linked", text="Duplicate Linked")
         layout.operator("outliner.id_copy", text="Copy", icon='COPYDOWN')
@@ -260,7 +260,7 @@ class OUTLINER_MT_collection_new(Menu):
 
     @staticmethod
     def draw_without_context_menu(context, layout):
-        layout.operator("outliner.collection_new", text="New Collection").nested = False
+        layout.operator_menu_enum("outliner.collection_new", "type", text="New Collection")
         layout.operator("outliner.id_paste", text="Paste Data-Blocks", icon='PASTEDOWN')
 
     def draw(self, context):
diff --git a/source/blender/editors/space_outliner/outliner_collections.c b/source/blender/editors/space_outliner/outliner_collections.c
index 4ea700b2786..9d9ba709288 100644
--- a/source/blender/editors/space_outliner/outliner_collections.c
+++ b/source/blender/editors/space_outliner/outliner_collections.c
@@ -200,17 +200,11 @@ static int collection_new_exec(bContext *C, wmOperator *op)
   SpaceOutliner *soops = CTX_wm_space_outliner(C);
   Main *bmain = CTX_data_main(C);
   Scene *scene = CTX_data_scene(C);
-
   Collection *collection;
+  const short type = RNA_enum_get(op->ptr, "type");
 
-  if (RNA_boolean_get(op->ptr, "nested")) {
-    /* Make new collection a child of the active collection */
-    collection = CTX_data_layer_collection(C)->collection;
-  }
-  else {
-    collection = scene->master_collection;
-  }
-
+  /* Make new collection a child of the active collection */
+  collection = CTX_data_layer_collection(C)->collection;
   if (ID_IS_LINKED(collection)) {
     collection = scene->master_collection;
   }
@@ -222,20 +216,27 @@ static int collection_new_exec(bContext *C, wmOperator *op)
 
   Collection *collection_new = BKE_collection_add(bmain, collection, NULL);
 
-  /* Move selected objects into new collection */
-  struct IDsSelectedData data = {{NULL}};
-  outliner_tree_traverse(
-      soops, &soops->tree, 0, TSE_SELECTED, outliner_find_selected_objects, &data);
+  if (type != COLLECTION_NEW_EMPTY) {
+    /* Move selected objects into new collection */
+    struct IDsSelectedData data = {{NULL}};
+    outliner_tree_traverse(
+        soops, &soops->tree, 0, TSE_SELECTED, outliner_find_selected_objects, &data);
 
-  LISTBASE_FOREACH (LinkData *, link, &data.selected_array) {
-    TreeElement *te = (TreeElement *)link->data;
-    TreeStoreElem *tselem = TREESTORE(te);
-    Collection *parent = find_parent_collection(te);
-    Object *ob = (Object *)tselem->id;
+    LISTBASE_FOREACH (LinkData *, link, &data.selected_array) {
+      TreeElement *te = (TreeElement *)link->data;
+      TreeStoreElem *tselem = TREESTORE(te);
+      Collection *parent = find_parent_collection(te);
+      Object *ob = (Object *)tselem->id;
 
-    BKE_collection_object_move(bmain, scene, collection_new, parent, ob);
+      if (type == COLLECTION_NEW_FROM_SELECTION) {
+        BKE_collection_object_move(bmain, scene, collection_new, parent, ob);
+      }
+      else {
+        BKE_collection_object_add(bmain, collection_new, ob);
+      }
+    }
+    BLI_freelistN(&data.selected_array);
   }
-  BLI_freelistN(&data.selected_array);
 
   DEG_id_tag_update(&collection->id, ID_RECALC_COPY_ON_WRITE);
   DEG_relations_tag_update(bmain);
@@ -256,12 +257,12 @@ void OUTLINER_OT_collection_new(wmOperatorType *ot)
       {COLLECTION_NEW_FROM_SELECTION,
        "SELECTION",
        0,
-       "Move Selection",
+       "Move Objects",
        "Move the selected objects to a new collection"},
       {COLLECTION_NEW_FROM_SELECTION_LINKED,
        "SELECTION_LINKED",
        0,
-       "Link Selection",
+       "Link Objects",
        "Link the selected objects to a new collection"},
       {0, NULL, 0, NULL, NULL},
   };
@@ -279,11 +280,7 @@ void OUTLINER_OT_collection_new(wmOperatorType *ot)
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
   /* properties */
-  PropertyRNA *prop = RNA_def_boolean(
-      ot->srna, "nested", true, "Nested", "Add as child of selected collection");
-  RNA_def_property_flag(prop, PROP_SKIP_SAVE);
-
-  ot->prop = RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
+  ot->prop = RNA_def_enum(ot->srna, "type", type_items, COLLECTION_NEW_FROM_SELECTION, "Type", "");
 }
 
 /** \} */



More information about the Bf-blender-cvs mailing list