Option not to select with un-hide
[blender.git] / source / blender / editors / gpencil / gpencil_data.c
index 2aa6d30c1144a60531b5a6db4c0e5baa91b3b131..5bd5c9c74b96b98727c5ef1f53a0482f1798a6c0 100644 (file)
@@ -42,6 +42,7 @@
 #include "BLI_utildefines.h"
 #include "BLI_ghash.h"
 #include "BLI_math.h"
+#include "BLI_string_utils.h"
 
 #include "BLT_translation.h"
 
@@ -75,9 +76,6 @@
 
 #include "gpencil_intern.h"
 
-/* maximum sizes of gp-session buffer */
-#define GP_STROKE_BUFFER_MAX    5000
-
 /* ************************************************ */
 /* Datablock Operators */
 
@@ -87,7 +85,8 @@
 static int gp_data_add_exec(bContext *C, wmOperator *op)
 {
        bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
-       
+       ToolSettings *ts = CTX_data_tool_settings(C);
+
        if (gpd_ptr == NULL) {
                BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go");
                return OPERATOR_CANCELLED;
@@ -98,6 +97,15 @@ static int gp_data_add_exec(bContext *C, wmOperator *op)
                
                id_us_min(&gpd->id);
                *gpd_ptr = BKE_gpencil_data_addnew(DATA_("GPencil"));
+
+               /* if not exist brushes, create a new set */
+               if (ts) {
+                       if (BLI_listbase_is_empty(&ts->gp_brushes)) {
+                               /* create new brushes */
+                               BKE_gpencil_brush_init_presets(ts);
+                       }
+               }
+
        }
        
        /* notifiers */
@@ -111,7 +119,7 @@ void GPENCIL_OT_data_add(wmOperatorType *ot)
        /* identifiers */
        ot->name = "Grease Pencil Add New";
        ot->idname = "GPENCIL_OT_data_add";
-       ot->description = "Add new Grease Pencil datablock";
+       ot->description = "Add new Grease Pencil data-block";
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        /* callbacks */
@@ -159,7 +167,7 @@ void GPENCIL_OT_data_unlink(wmOperatorType *ot)
        /* identifiers */
        ot->name = "Grease Pencil Unlink";
        ot->idname = "GPENCIL_OT_data_unlink";
-       ot->description = "Unlink active Grease Pencil datablock";
+       ot->description = "Unlink active Grease Pencil data-block";
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        /* callbacks */
@@ -177,7 +185,8 @@ void GPENCIL_OT_data_unlink(wmOperatorType *ot)
 static int gp_layer_add_exec(bContext *C, wmOperator *op)
 {
        bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
-       
+       ToolSettings *ts = CTX_data_tool_settings(C);
+
        /* if there's no existing Grease-Pencil data there, add some */
        if (gpd_ptr == NULL) {
                BKE_report(op->reports, RPT_ERROR, "Nowhere for grease pencil data to go");
@@ -186,6 +195,14 @@ static int gp_layer_add_exec(bContext *C, wmOperator *op)
        if (*gpd_ptr == NULL)
                *gpd_ptr = BKE_gpencil_data_addnew(DATA_("GPencil"));
        
+       /* if not exist brushes, create a new set */
+       if (ts) {
+               if (BLI_listbase_is_empty(&ts->gp_brushes)) {
+                       /* create new brushes */
+                       BKE_gpencil_brush_init_presets(ts);
+               }
+       }
+
        /* add new layer now */
        BKE_gpencil_layer_addnew(*gpd_ptr, DATA_("GP_Layer"), true);
        
@@ -200,7 +217,7 @@ void GPENCIL_OT_layer_add(wmOperatorType *ot)
        /* identifiers */
        ot->name = "Add New Layer";
        ot->idname = "GPENCIL_OT_layer_add";
-       ot->description = "Add new Grease Pencil layer for the active Grease Pencil datablock";
+       ot->description = "Add new Grease Pencil layer for the active Grease Pencil data-block";
        
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
@@ -275,27 +292,17 @@ static int gp_layer_move_exec(bContext *C, wmOperator *op)
        if (ELEM(NULL, gpd, gpl))
                return OPERATOR_CANCELLED;
        
-       /* up or down? */
-       if (direction == GP_LAYER_MOVE_UP) {
-               /* up */
-               BLI_remlink(&gpd->layers, gpl);
-               BLI_insertlinkbefore(&gpd->layers, gpl->prev, gpl);
+       BLI_assert(ELEM(direction, -1, 0, 1)); /* we use value below */
+       if (BLI_listbase_link_move(&gpd->layers, gpl, direction)) {
+               WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
        }
-       else {
-               /* down */
-               BLI_remlink(&gpd->layers, gpl);
-               BLI_insertlinkafter(&gpd->layers, gpl->next, gpl);
-       }
-       
-       /* notifiers */
-       WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
        
        return OPERATOR_FINISHED;
 }
 
 void GPENCIL_OT_layer_move(wmOperatorType *ot)
 {
-       static EnumPropertyItem slot_move[] = {
+       static const EnumPropertyItem slot_move[] = {
                {GP_LAYER_MOVE_UP, "UP", 0, "Up", ""},
                {GP_LAYER_MOVE_DOWN, "DOWN", 0, "Down", ""},
                {0, NULL, 0, NULL, NULL}
@@ -416,18 +423,59 @@ static int gp_reveal_poll(bContext *C)
        return ED_gpencil_data_get_active(C) != NULL;
 }
 
-static int gp_reveal_exec(bContext *C, wmOperator *UNUSED(op))
+static void gp_reveal_select_frame(bContext *C, bGPDframe *frame, bool select)
+{
+       bGPDstroke *gps;
+       for (gps = frame->strokes.first; gps; gps = gps->next) {
+
+               /* only deselect strokes that are valid in this view */
+               if (ED_gpencil_stroke_can_use(C, gps)) {
+
+                       /* (de)select points */
+                       int i;
+                       bGPDspoint *pt;
+                       for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+                               SET_FLAG_FROM_TEST(pt->flag, select, GP_SPOINT_SELECT);
+                       }
+
+                       /* (de)select stroke */
+                       SET_FLAG_FROM_TEST(gps->flag, select, GP_STROKE_SELECT);
+               }
+       }
+}
+
+static int gp_reveal_exec(bContext *C, wmOperator *op)
 {
        bGPdata *gpd = ED_gpencil_data_get_active(C);
        bGPDlayer *gpl;
-       
+       const bool select = RNA_boolean_get(op->ptr, "select");
+
        /* sanity checks */
        if (gpd == NULL)
                return OPERATOR_CANCELLED;
        
-       /* make all layers visible */
        for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
-               gpl->flag &= ~GP_LAYER_HIDE;
+
+               if (gpl->flag & GP_LAYER_HIDE) {
+                       gpl->flag &= ~GP_LAYER_HIDE;
+
+                       /* select or deselect if requested, only on hidden layers */
+                       if (gpd->flag & GP_DATA_STROKE_EDITMODE) {
+                               if (select) {
+                                       /* select all strokes on active frame only (same as select all operator) */
+                                       if (gpl->actframe) {
+                                               gp_reveal_select_frame(C, gpl->actframe, true);
+                                       }
+                               }
+                               else {
+                                       /* deselect strokes on all frames (same as deselect all operator) */
+                                       bGPDframe *gpf;
+                                       for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+                                               gp_reveal_select_frame(C, gpf, false);
+                                       }
+                               }
+                       }
+               }
        }
        
        /* notifiers */
@@ -449,6 +497,9 @@ void GPENCIL_OT_reveal(wmOperatorType *ot)
        
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+       /* props */
+       RNA_def_boolean(ot->srna, "select", true, "Select", "");
 }
 
 /* ***************** Lock/Unlock All Layers ************************ */
@@ -764,14 +815,12 @@ static int gp_stroke_arrange_exec(bContext *C, wmOperator *op)
                        /* some stroke is already at front*/
                        if ((direction == GP_STROKE_MOVE_TOP) || (direction == GP_STROKE_MOVE_UP)) {
                                if (gps == gpf->strokes.last) {
-                                       BKE_report(op->reports, RPT_ERROR, "Some selected stroke is already on top");
                                        return OPERATOR_CANCELLED;
                                }
                        }
                        /* some stroke is already at botom */
                        if ((direction == GP_STROKE_MOVE_BOTTOM) || (direction == GP_STROKE_MOVE_DOWN)) {
                                if (gps == gpf->strokes.first) {
-                                       BKE_report(op->reports, RPT_ERROR, "Some selected stroke is already on bottom");
                                        return OPERATOR_CANCELLED;
                                }
                        }
@@ -787,23 +836,21 @@ static int gp_stroke_arrange_exec(bContext *C, wmOperator *op)
                        for (LinkData *link = selected.first; link; link = link->next) {
                                gps = link->data;
                                BLI_remlink(&gpf->strokes, gps);
-                               BLI_insertlinkafter(&gpf->strokes, gpf->strokes.last, gps);
+                               BLI_addtail(&gpf->strokes, gps);
                        }
                        break;
                /* Bring Forward */
                case GP_STROKE_MOVE_UP:
                        for (LinkData *link = selected.last; link; link = link->prev) {
                                gps = link->data;
-                               BLI_remlink(&gpf->strokes, gps);
-                               BLI_insertlinkafter(&gpf->strokes, gps->next, gps);
+                               BLI_listbase_link_move(&gpf->strokes, gps, 1);
                        }
                        break;
-                       /* Send Backward */
+               /* Send Backward */
                case GP_STROKE_MOVE_DOWN:
                        for (LinkData *link = selected.first; link; link = link->next) {
                                gps = link->data;
-                               BLI_remlink(&gpf->strokes, gps);
-                               BLI_insertlinkbefore(&gpf->strokes, gps->prev, gps);
+                               BLI_listbase_link_move(&gpf->strokes, gps, -1);
                        }
                        break;
                /* Send to Back */
@@ -811,13 +858,15 @@ static int gp_stroke_arrange_exec(bContext *C, wmOperator *op)
                        for (LinkData *link = selected.last; link; link = link->prev) {
                                gps = link->data;
                                BLI_remlink(&gpf->strokes, gps);
-                               BLI_insertlinkbefore(&gpf->strokes, gpf->strokes.first, gps);
+                               BLI_addhead(&gpf->strokes, gps);
                        }
                        break;
                default:
                        BLI_assert(0);
                        break;
        }
+       BLI_freelistN(&selected);
+
        /* notifiers */
        WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
 
@@ -826,7 +875,7 @@ static int gp_stroke_arrange_exec(bContext *C, wmOperator *op)
 
 void GPENCIL_OT_stroke_arrange(wmOperatorType *ot)
 {
-       static EnumPropertyItem slot_move[] = {
+       static const EnumPropertyItem slot_move[] = {
                {GP_STROKE_MOVE_UP, "UP", 0, "Bring Forward", ""},
                {GP_STROKE_MOVE_DOWN, "DOWN", 0, "Send Backward", ""},
                {GP_STROKE_MOVE_TOP, "TOP", 0, "Bring to Front", ""},
@@ -882,9 +931,9 @@ static int gp_stroke_change_color_exec(bContext *C, wmOperator *UNUSED(op))
                                                continue;
 
                                        /* asign new color (only if different) */
-                                       if (STREQ(gps->colorname, color->info) == false) {
+                                       if ((STREQ(gps->colorname, color->info) == false) || (gps->palcolor != color)) {
                                                BLI_strncpy(gps->colorname, color->info, sizeof(gps->colorname));
-                                               gps->flag |= GP_STROKE_RECALC_COLOR;
+                                               gps->palcolor = color;
                                        }
                                }
                        }
@@ -965,431 +1014,6 @@ void GPENCIL_OT_stroke_lock_color(wmOperatorType *ot)
        ot->poll = gp_active_layer_poll;
 }
 
-/* ******************* Apply layer thickness change to Strokes ************************** */
-
-static int gp_stroke_apply_thickness_exec(bContext *C, wmOperator *UNUSED(op))
-{
-       bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd);
-
-       /* sanity checks */
-       if (ELEM(NULL, gpd, gpl, gpl->frames.first))
-               return OPERATOR_CANCELLED;
-
-       /* loop all strokes */
-       for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
-               for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
-                       /* Apply thickness */
-                       gps->thickness = gps->thickness + gpl->thickness;
-               }
-       }
-       /* clear value */
-       gpl->thickness = 0.0f;
-
-       /* notifiers */
-       WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
-
-       return OPERATOR_FINISHED;
-}
-
-void GPENCIL_OT_stroke_apply_thickness(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name = "Apply Stroke Thickness";
-       ot->idname = "GPENCIL_OT_stroke_apply_thickness";
-       ot->description = "Apply the thickness change of the layer to its strokes";
-
-       /* api callbacks */
-       ot->exec = gp_stroke_apply_thickness_exec;
-       ot->poll = gp_active_layer_poll;
-}
-
-/* ******************* Close Strokes ************************** */
-
-enum {
-       GP_STROKE_CYCLIC_CLOSE = 1,
-       GP_STROKE_CYCLIC_OPEN = 2,
-       GP_STROKE_CYCLIC_TOGGLE = 3
-};
-
-static int gp_stroke_cyclical_set_exec(bContext *C, wmOperator *op)
-{
-       bGPdata *gpd = ED_gpencil_data_get_active(C);
-       const int type = RNA_enum_get(op->ptr, "type");
-
-       /* sanity checks */
-       if (ELEM(NULL, gpd))
-               return OPERATOR_CANCELLED;
-
-       /* loop all selected strokes */
-       CTX_DATA_BEGIN(C, bGPDlayer *, gpl, editable_gpencil_layers)
-       {
-               for (bGPDstroke *gps = gpl->actframe->strokes.last; gps; gps = gps->prev) {
-                       bGPDpalettecolor *palcolor = gps->palcolor;
-
-                       /* skip strokes that are not selected or invalid for current view */
-                       if (((gps->flag & GP_STROKE_SELECT) == 0) || ED_gpencil_stroke_can_use(C, gps) == false)
-                               continue;
-                       /* skip hidden or locked colors */
-                       if (!palcolor || (palcolor->flag & PC_COLOR_HIDE) || (palcolor->flag & PC_COLOR_LOCKED))
-                               continue;
-
-                       switch (type) {
-                               case GP_STROKE_CYCLIC_CLOSE:
-                                       /* Close all (enable) */
-                                       gps->flag |= GP_STROKE_CYCLIC;
-                                       break;
-                               case GP_STROKE_CYCLIC_OPEN:
-                                       /* Open all (disable) */
-                                       gps->flag &= ~GP_STROKE_CYCLIC;
-                                       break;
-                               case GP_STROKE_CYCLIC_TOGGLE:
-                                       /* Just toggle flag... */
-                                       gps->flag ^= GP_STROKE_CYCLIC;
-                                       break;
-                               default:
-                                       BLI_assert(0);
-                                       break;
-                       }
-               }
-       }
-       CTX_DATA_END;
-
-       /* notifiers */
-       WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
-
-       return OPERATOR_FINISHED;
-}
-
-/**
- * Similar to #CURVE_OT_cyclic_toggle or #MASK_OT_cyclic_toggle, but with
- * option to force opened/closed strokes instead of just toggle behavior.
- */
-void GPENCIL_OT_stroke_cyclical_set(wmOperatorType *ot)
-{
-       static EnumPropertyItem cyclic_type[] = {
-               {GP_STROKE_CYCLIC_CLOSE, "CLOSE", 0, "Close all", ""},
-               {GP_STROKE_CYCLIC_OPEN, "OPEN", 0, "Open all", ""},
-               {GP_STROKE_CYCLIC_TOGGLE, "TOGGLE", 0, "Toggle", ""},
-               {0, NULL, 0, NULL, NULL}
-       };
-
-       /* identifiers */
-       ot->name = "Set Cyclical State";
-       ot->idname = "GPENCIL_OT_stroke_cyclical_set";
-       ot->description = "Close or open the selected stroke adding an edge from last to first point";
-
-       /* api callbacks */
-       ot->exec = gp_stroke_cyclical_set_exec;
-       ot->poll = gp_active_layer_poll;
-
-       /* flags */
-       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
-       ot->prop = RNA_def_enum(ot->srna, "type", cyclic_type, GP_STROKE_CYCLIC_TOGGLE, "Type", "");
-}
-
-/* ******************* Stroke join ************************** */
-
-/* Helper: flip stroke */
-static void gpencil_flip_stroke(bGPDstroke *gps)
-{
-       bGPDspoint pt, *point, *point2;
-       int end = gps->totpoints - 1;
-
-       for (int i = 0; i < gps->totpoints / 2; i++) {
-               /* save first point */
-               point = &gps->points[i];
-               pt.x = point->x;
-               pt.y = point->y;
-               pt.z = point->z;
-               pt.flag = point->flag;
-               pt.pressure = point->pressure;
-               pt.strength = point->strength;
-               pt.time = point->time;
-
-               /* replace first point with last point */
-               point2 = &gps->points[end];
-               point->x = point2->x;
-               point->y = point2->y;
-               point->z = point2->z;
-               point->flag = point2->flag;
-               point->pressure = point2->pressure;
-               point->strength = point2->strength;
-               point->time = point2->time;
-
-               /* replace last point with first saved before */
-               point = &gps->points[end];
-               point->x = pt.x;
-               point->y = pt.y;
-               point->z = pt.z;
-               point->flag = pt.flag;
-               point->pressure = pt.pressure;
-               point->strength = pt.strength;
-               point->time = pt.time;
-
-               end--;
-       }
-}
-
-/* Helper: copy point between strokes */
-static void gpencil_stroke_copy_point(bGPDstroke *gps, bGPDspoint *point, float delta[3],
-                                      float pressure, float strength, float deltatime)
-{
-       bGPDspoint *newpoint;
-
-       gps->points = MEM_reallocN(gps->points, sizeof(bGPDspoint) * (gps->totpoints + 1));
-       gps->totpoints++;
-
-       newpoint = &gps->points[gps->totpoints - 1];
-       newpoint->x = point->x * delta[0];
-       newpoint->y = point->y * delta[1];
-       newpoint->z = point->z * delta[2];
-       newpoint->flag = point->flag;
-       newpoint->pressure = pressure;
-       newpoint->strength = strength;
-       newpoint->time = point->time + deltatime;
-}
-
-/* Helper: join two strokes using the shortest distance (reorder stroke if necessary ) */
-static void gpencil_stroke_join_strokes(bGPDstroke *gps_a, bGPDstroke *gps_b, const bool leave_gaps)
-{
-       bGPDspoint point, *pt;
-       int i;
-       float delta[3] = {1.0f, 1.0f, 1.0f};
-       float deltatime = 0.0f;
-
-       /* sanity checks */
-       if (ELEM(NULL, gps_a, gps_b))
-               return;
-
-       if ((gps_a->totpoints == 0) || (gps_b->totpoints == 0))
-               return;
-
-       /* define start and end points of each stroke */
-       float sa[3], sb[3], ea[3], eb[3];
-       pt = &gps_a->points[0];
-       copy_v3_v3(sa, &pt->x);
-
-       pt = &gps_a->points[gps_a->totpoints - 1];
-       copy_v3_v3(ea, &pt->x);
-
-       pt = &gps_b->points[0];
-       copy_v3_v3(sb, &pt->x);
-       
-       pt = &gps_b->points[gps_b->totpoints - 1];
-       copy_v3_v3(eb, &pt->x);
-       
-       /* review if need flip stroke B */
-       float ea_sb = len_squared_v3v3(ea, sb);
-       float ea_eb = len_squared_v3v3(ea, eb);
-       /* flip if distance to end point is shorter */
-       if (ea_eb < ea_sb) {
-               gpencil_flip_stroke(gps_b);
-       }
-
-       /* don't visibly link the first and last points? */
-       if (leave_gaps) {
-               /* 1st: add one tail point to start invisible area */
-               point = gps_a->points[gps_a->totpoints - 1];
-               deltatime = point.time;
-               gpencil_stroke_copy_point(gps_a, &point, delta, 0.0f, 0.0f, 0.0f);
-
-               /* 2nd: add one head point to finish invisible area */
-               point = gps_b->points[0];
-               gpencil_stroke_copy_point(gps_a, &point, delta, 0.0f, 0.0f, deltatime);
-       }
-       
-       /* 3rd: add all points */
-       for (i = 0, pt = gps_b->points; i < gps_b->totpoints && pt; i++, pt++) {
-               /* check if still room in buffer */
-               if (gps_a->totpoints <= GP_STROKE_BUFFER_MAX - 2) {
-                       gpencil_stroke_copy_point(gps_a, pt, delta, pt->pressure, pt->strength, deltatime);
-               }
-       }
-}
-
-static int gp_stroke_join_exec(bContext *C, wmOperator *op)
-{
-       bGPdata *gpd = ED_gpencil_data_get_active(C);
-       bGPDlayer *activegpl = BKE_gpencil_layer_getactive(gpd);
-       bGPDstroke *gps, *gpsn;
-       bGPDpalette *palette = BKE_gpencil_palette_getactive(gpd);
-       bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_getactive(palette);
-
-       bGPDframe *gpf_a = NULL;
-       bGPDstroke *stroke_a = NULL;
-       bGPDstroke *stroke_b = NULL;
-       bGPDstroke *new_stroke = NULL;
-
-       const int type = RNA_enum_get(op->ptr, "type");
-       const bool leave_gaps = RNA_boolean_get(op->ptr, "leave_gaps");
-
-       /* sanity checks */
-       if (ELEM(NULL, gpd))
-               return OPERATOR_CANCELLED;
-
-       if (activegpl->flag & GP_LAYER_LOCKED)
-               return OPERATOR_CANCELLED;
-
-       BLI_assert(ELEM(type, GP_STROKE_JOIN, GP_STROKE_JOINCOPY));
-
-
-       /* read all selected strokes */
-       bool first = false;
-       CTX_DATA_BEGIN(C, bGPDlayer *, gpl, editable_gpencil_layers)
-       {
-               bGPDframe *gpf = gpl->actframe;
-               for (gps = gpf->strokes.first; gps; gps = gpsn) {
-                       gpsn = gps->next;
-                       if (gps->flag & GP_STROKE_SELECT) {
-                               /* skip strokes that are invalid for current view */
-                               if (ED_gpencil_stroke_can_use(C, gps) == false) {
-                                       continue;
-                               }
-                               /* check if the color is editable */
-                               if (ED_gpencil_stroke_color_use(gpl, gps) == false) {
-                                       continue;
-                               }
-                               /* to join strokes, cyclic must be disabled */
-                               gps->flag &= ~GP_STROKE_CYCLIC;
-                               /* saves first frame and stroke */
-                               if (!first) {
-                                       first = true;
-                                       gpf_a = gpf;
-                                       stroke_a = gps;
-                               }
-                               else {
-                                       stroke_b = gps;
-                                       /* create a new stroke if was not created before (only created if something to join) */
-                                       if (new_stroke == NULL) {
-                                               new_stroke = MEM_dupallocN(stroke_a);
-                                               new_stroke->points = MEM_dupallocN(stroke_a->points);
-                                               new_stroke->triangles = NULL;
-                                               new_stroke->tot_triangles = 0;
-                                               new_stroke->flag |= GP_STROKE_RECALC_CACHES;
-                                               /* if new, set current color */
-                                               if (type == GP_STROKE_JOINCOPY) {
-                                                       new_stroke->palcolor = palcolor;
-                                                       BLI_strncpy(new_stroke->colorname, palcolor->info, sizeof(new_stroke->colorname));
-                                                       new_stroke->flag |= GP_STROKE_RECALC_COLOR;
-                                               }
-                                       }
-                                       /* join new_stroke and stroke B. New stroke will contain all the previous data */
-                                       gpencil_stroke_join_strokes(new_stroke, stroke_b, leave_gaps);
-
-                                       /* if join only, delete old strokes */
-                                       if (type == GP_STROKE_JOIN) {
-                                               if (stroke_a) {
-                                                       BLI_insertlinkbefore(&gpf_a->strokes, stroke_a, new_stroke);
-                                                       BLI_remlink(&gpf->strokes, stroke_a);
-                                                       BKE_gpencil_free_stroke(stroke_a);
-                                                       stroke_a = NULL;
-                                               }
-                                               if (stroke_b) {
-                                                       BLI_remlink(&gpf->strokes, stroke_b);
-                                                       BKE_gpencil_free_stroke(stroke_b);
-                                                       stroke_b = NULL;
-                                               }
-                                       }
-                               }
-                       }
-               }
-       }
-       CTX_DATA_END;
-       /* add new stroke if was not added before */
-       if (type == GP_STROKE_JOINCOPY) {
-               if (new_stroke) {
-                       /* Add a new frame if needed */
-                       if (activegpl->actframe == NULL)
-                               activegpl->actframe = BKE_gpencil_frame_addnew(activegpl, gpf_a->framenum);
-
-                       BLI_addtail(&activegpl->actframe->strokes, new_stroke);
-               }
-       }
-
-       /* notifiers */
-       WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
-
-       return OPERATOR_FINISHED;
-}
-
-void GPENCIL_OT_stroke_join(wmOperatorType *ot)
-{
-       static EnumPropertyItem join_type[] = {
-               {GP_STROKE_JOIN, "JOIN", 0, "Join", ""},
-               {GP_STROKE_JOINCOPY, "JOINCOPY", 0, "Join and Copy", ""},
-               {0, NULL, 0, NULL, NULL}
-       };
-
-       /* identifiers */
-       ot->name = "Join Strokes";
-       ot->idname = "GPENCIL_OT_stroke_join";
-       ot->description = "Join selected strokes (optionally as new stroke)";
-
-       /* api callbacks */
-       ot->exec = gp_stroke_join_exec;
-       ot->poll = gp_active_layer_poll;
-
-       /* flags */
-       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
-       ot->prop = RNA_def_enum(ot->srna, "type", join_type, GP_STROKE_JOIN, "Type", "");
-       RNA_def_boolean(ot->srna, "leave_gaps", false, "Leave Gaps", "Leave gaps between joined strokes instead of linking them");
-}
-
-/* ******************* Stroke flip ************************** */
-
-static int gp_stroke_flip_exec(bContext *C, wmOperator *UNUSED(op))
-{
-       bGPdata *gpd = ED_gpencil_data_get_active(C);
-
-       /* sanity checks */
-       if (ELEM(NULL, gpd))
-               return OPERATOR_CANCELLED;
-
-       /* read all selected strokes */
-       CTX_DATA_BEGIN(C, bGPDlayer *, gpl, editable_gpencil_layers)
-       {
-               bGPDframe *gpf = gpl->actframe;
-               for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
-                       if (gps->flag & GP_STROKE_SELECT) {
-                               /* skip strokes that are invalid for current view */
-                               if (ED_gpencil_stroke_can_use(C, gps) == false) {
-                                       continue;
-                               }
-                               /* check if the color is editable */
-                               if (ED_gpencil_stroke_color_use(gpl, gps) == false) {
-                                       continue;
-                               }
-                               /* flip stroke */
-                               gpencil_flip_stroke(gps);
-                       }
-               }
-       }
-       CTX_DATA_END;
-
-       /* notifiers */
-       WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
-
-       return OPERATOR_FINISHED;
-}
-
-void GPENCIL_OT_stroke_flip(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name = "Flip Stroke";
-       ot->idname = "GPENCIL_OT_stroke_flip";
-       ot->description = "Change direction of the points of the selected strokes";
-
-       /* api callbacks */
-       ot->exec = gp_stroke_flip_exec;
-       ot->poll = gp_active_layer_poll;
-
-       /* flags */
-       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
 /* ************************************************ */
 /* Drawing Brushes Operators */
 
@@ -1419,7 +1043,7 @@ void GPENCIL_OT_brush_add(wmOperatorType *ot)
        /* identifiers */
        ot->name = "Add Brush";
        ot->idname = "GPENCIL_OT_brush_add";
-       ot->description = "Add new Grease Pencil drawing brush for the active Grease Pencil datablock";
+       ot->description = "Add new Grease Pencil drawing brush for the active Grease Pencil data-block";
 
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
@@ -1585,7 +1209,7 @@ static int gp_brush_move_exec(bContext *C, wmOperator *op)
 
 void GPENCIL_OT_brush_move(wmOperatorType *ot)
 {
-       static EnumPropertyItem slot_move[] = {
+       static const EnumPropertyItem slot_move[] = {
                {GP_BRUSH_MOVE_UP, "UP", 0, "Up", ""},
                {GP_BRUSH_MOVE_DOWN, "DOWN", 0, "Down", ""},
                {0, NULL, 0, NULL, NULL }
@@ -1777,7 +1401,7 @@ void GPENCIL_OT_palette_add(wmOperatorType *ot)
        /* identifiers */
        ot->name = "Add Palette";
        ot->idname = "GPENCIL_OT_palette_add";
-       ot->description = "Add new Grease Pencil palette for the active Grease Pencil datablock";
+       ot->description = "Add new Grease Pencil palette for the active Grease Pencil data-block";
 
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
@@ -1994,7 +1618,7 @@ void GPENCIL_OT_palettecolor_add(wmOperatorType *ot)
        /* identifiers */
        ot->name = "Add Palette Color";
        ot->idname = "GPENCIL_OT_palettecolor_add";
-       ot->description = "Add new Grease Pencil palette color for the active Grease Pencil datablock";
+       ot->description = "Add new Grease Pencil palette color for the active Grease Pencil data-block";
 
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
@@ -2342,7 +1966,7 @@ static int gp_palettecolor_move_exec(bContext *C, wmOperator *op)
 
 void GPENCIL_OT_palettecolor_move(wmOperatorType *ot)
 {
-       static EnumPropertyItem slot_move[] = {
+       static const EnumPropertyItem slot_move[] = {
                {GP_COLOR_MOVE_UP, "UP", 0, "Up", ""},
                {GP_COLOR_MOVE_DOWN, "DOWN", 0, "Down", ""},
                {0, NULL, 0, NULL, NULL}