fix [#26685] Cannot exit from "edit mode"
authorCampbell Barton <ideasman42@gmail.com>
Wed, 30 Mar 2011 15:28:38 +0000 (15:28 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 30 Mar 2011 15:28:38 +0000 (15:28 +0000)
this does not fix the underlying problem that once in this state you cant exit editmode, only that the layer key bindings dont let the state come about.

Looked into fixing properly but its not so simple since currently object mode operators all use "active_object" which is supposed not to be set when in a hidden layer.

source/blender/editors/space_view3d/view3d_header.c

index 3b6b7257c9c91e9ea4245c3f4ffca427a157077b..246ed853cc8b049cafef2ffd0bdaf606070a128c 100644 (file)
@@ -147,6 +147,21 @@ static void handle_view3d_lock(bContext *C)
 - uiTemplateLayers in interface/ code for buttons
 - ED_view3d_scene_layer_set for RNA
  */
+static void view3d_layers_editmode_ensure(Scene *scene, View3D *v3d)
+{
+       /* sanity check - when in editmode disallow switching the editmode layer off since its confusing
+        * an alternative would be to always draw the editmode object. */
+       if(scene->obedit && (scene->obedit->lay & v3d->lay)==0) {
+               int bit;
+               for(bit=0; bit<32; bit++) {
+                       if(scene->obedit->lay & (1<<bit)) {
+                               v3d->lay |= 1<<bit;
+                               break;
+                       }
+               }
+       }
+}
+
 static int view3d_layers_exec(bContext *C, wmOperator *op)
 {
        Scene *scene= CTX_data_scene(C);
@@ -166,7 +181,10 @@ static int view3d_layers_exec(bContext *C, wmOperator *op)
                if (toggle && v3d->lay == ((1<<20)-1)) {
                        /* return to active layer only */
                        v3d->lay = v3d->layact;
-               } else {
+
+                       view3d_layers_editmode_ensure(scene, v3d);
+               }
+               else {
                        v3d->lay |= (1<<20)-1;
                }               
        }
@@ -181,19 +199,10 @@ static int view3d_layers_exec(bContext *C, wmOperator *op)
                                v3d->lay |= (1<<nr);
                } else {
                        v3d->lay = (1<<nr);
-
-                       /* sanity check - when in editmode disallow switching the editmode layer off since its confusing
-                        * an alternative would be to always draw the editmode object. */
-                       if(scene->obedit && (scene->obedit->lay & v3d->lay)==0) {
-                               for(bit=0; bit<32; bit++) {
-                                       if(scene->obedit->lay & (1<<bit)) {
-                                               v3d->lay |= 1<<bit;
-                                               break;
-                                       }
-                               }
-                       }
                }
-               
+
+               view3d_layers_editmode_ensure(scene, v3d);
+
                /* set active layer, ensure to always have one */
                if(v3d->lay & (1<<nr))
                   v3d->layact= 1<<nr;