Fix T66955: Cannot delete data from file in outliner.
authorBastien Montagne <montagne29@wanadoo.fr>
Mon, 15 Jul 2019 16:06:32 +0000 (18:06 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Mon, 15 Jul 2019 16:10:26 +0000 (18:10 +0200)
That switch on ID types had not been updated since quiet some time it’d
seem... Using the ID_Type enum type now, so this should not happen again
(compiler will yell at you if you forget to add here any new ID type ;) ).

Also had to change a bit the code layout then, to deal with fake NLA ID
type...

Note that for now, Screen IDs remain excluded from the ID menu usage,
due to T67004.

source/blender/editors/space_outliner/outliner_tools.c

index a618f8ef4c2d54b3dc053d371a394f9dbedd51f6..89eb3b9d95395e1ee44eabda71ea17e98a1e1e4f 100644 (file)
@@ -109,8 +109,9 @@ static void set_operation_types(SpaceOutliner *soops,
         }
       }
       else {
-        int idcode = GS(tselem->id->name);
-        switch (idcode) {
+        const int idcode = (int)GS(tselem->id->name);
+        bool is_standard_id = false;
+        switch ((ID_Type)idcode) {
           case ID_SCE:
             *scenelevel = 1;
             break;
@@ -134,21 +135,47 @@ static void set_operation_types(SpaceOutliner *soops,
           case ID_KE:
           case ID_WO:
           case ID_AC:
-          case ID_NLA:
           case ID_TXT:
           case ID_GR:
           case ID_LS:
           case ID_LI:
-            if (*idlevel == 0) {
-              *idlevel = idcode;
-            }
-            else if (*idlevel != idcode) {
-              *idlevel = -1;
-            }
-            if (ELEM(*datalevel, TSE_VIEW_COLLECTION_BASE, TSE_SCENE_COLLECTION_BASE)) {
-              *datalevel = 0;
-            }
+          case ID_VF:
+          case ID_NT:
+          case ID_BR:
+          case ID_PA:
+          case ID_GD:
+          case ID_MC:
+          case ID_MSK:
+          case ID_PAL:
+          case ID_PC:
+          case ID_CF:
+          case ID_WS:
+          case ID_LP:
+            is_standard_id = true;
             break;
+          case ID_WM:
+          case ID_SCR:
+            /* Those are ignored here. */
+            /* Note: while Screens should be manageable here, deleting a screen used by a workspace
+             * will cause crashes when trying to use that workspace, so for now let's play minimal,
+             * safe change. */
+            break;
+        }
+        if (idcode == ID_NLA) {
+          /* Fake one, not an actual ID type... */
+          is_standard_id = true;
+        }
+
+        if (is_standard_id) {
+          if (*idlevel == 0) {
+            *idlevel = idcode;
+          }
+          else if (*idlevel != idcode) {
+            *idlevel = -1;
+          }
+          if (ELEM(*datalevel, TSE_VIEW_COLLECTION_BASE, TSE_SCENE_COLLECTION_BASE)) {
+            *datalevel = 0;
+          }
         }
       }
     }