GP: Move to new layer did not work with autolock
authorAntonioya <blendergit@gmail.com>
Tue, 12 Feb 2019 17:14:36 +0000 (18:14 +0100)
committerAntonioya <blendergit@gmail.com>
Tue, 12 Feb 2019 17:15:00 +0000 (18:15 +0100)
When the autolock layer option was enabled, the move to new layer operator was not working as expected.

source/blender/editors/gpencil/gpencil_edit.c

index 580480a..cee259e 100644 (file)
@@ -1186,12 +1186,18 @@ static int gp_move_to_layer_exec(bContext *C, wmOperator *op)
        bGPDlayer *target_layer = NULL;
        ListBase strokes = {NULL, NULL};
        int layer_num = RNA_enum_get(op->ptr, "layer");
+       const bool use_autolock = (bool)(gpd->flag & GP_DATA_AUTOLOCK_LAYERS);
 
        if (GPENCIL_MULTIEDIT_SESSIONS_ON(gpd)) {
                BKE_report(op->reports, RPT_ERROR, "Operator not supported in multiframe edition");
                return OPERATOR_CANCELLED;
        }
 
+       /* if autolock enabled, disabled now */
+       if (use_autolock) {
+               gpd->flag &= ~GP_DATA_AUTOLOCK_LAYERS;
+       }
+
        /* Get layer or create new one */
        if (layer_num == -1) {
                /* Create layer */
@@ -1202,6 +1208,10 @@ static int gp_move_to_layer_exec(bContext *C, wmOperator *op)
                target_layer = BLI_findlink(&gpd->layers, layer_num);
 
                if (target_layer == NULL) {
+                       /* back autolock status */
+                       if (use_autolock) {
+                               gpd->flag |= GP_DATA_AUTOLOCK_LAYERS;
+                       }
                        BKE_reportf(op->reports, RPT_ERROR, "There is no layer number %d", layer_num);
                        return OPERATOR_CANCELLED;
                }
@@ -1234,6 +1244,11 @@ static int gp_move_to_layer_exec(bContext *C, wmOperator *op)
                                BLI_addtail(&strokes, gps);
                        }
                }
+
+               /* if new layer and autolock, lock old layer */
+               if ((layer_num == -1) && (use_autolock)) {
+                       gpl->flag |= GP_LAYER_LOCKED;
+               }
        }
        CTX_DATA_END;
 
@@ -1245,6 +1260,11 @@ static int gp_move_to_layer_exec(bContext *C, wmOperator *op)
                BLI_assert((strokes.first == strokes.last) && (strokes.first == NULL));
        }
 
+       /* back autolock status */
+       if (use_autolock) {
+               gpd->flag |= GP_DATA_AUTOLOCK_LAYERS;
+       }
+
        /* updates */
        DEG_id_tag_update(&gpd->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);