diff --git a/app/pdb/selection-cmds.c b/app/pdb/selection-cmds.c index a65d8e68b3..aef87e4386 100644 --- a/app/pdb/selection-cmds.c +++ b/app/pdb/selection-cmds.c @@ -222,8 +222,8 @@ selection_float_invoker (GimpProcedure *procedure, for (i = 0; i < num_drawables; i++) { if (! gimp_pdb_item_is_attached (GIMP_ITEM (drawables[i]), NULL, - GIMP_PDB_ITEM_CONTENT, error) || - gimp_pdb_item_is_group (GIMP_ITEM (drawables[i]), error) || + GIMP_PDB_ITEM_CONTENT, error) || + ! gimp_pdb_item_is_not_group (GIMP_ITEM (drawables[i]), error) || (image && image != gimp_item_get_image (GIMP_ITEM (drawables[i])))) { success = FALSE; diff --git a/libgimp/tests/meson.build b/libgimp/tests/meson.build index 227e1b1d81..681b98d21a 100644 --- a/libgimp/tests/meson.build +++ b/libgimp/tests/meson.build @@ -8,6 +8,7 @@ endif tests = [ 'palette', + 'selection-float' ] # Unit testing environment is based on gimp_run_env with additional environment diff --git a/libgimp/tests/test-selection-float.c b/libgimp/tests/test-selection-float.c new file mode 100644 index 0000000000..7dc18fa096 --- /dev/null +++ b/libgimp/tests/test-selection-float.c @@ -0,0 +1,75 @@ + +static GimpValueArray * +gimp_c_test_run (GimpProcedure *procedure, + GimpRunMode run_mode, + GimpImage *image, + gint n_drawables, + GimpDrawable **drawables, + GimpProcedureConfig *config, + gpointer run_data) +{ + GimpImage *img; + GimpDrawable *layer1; + GimpDrawable *layer2; + GimpDrawable *group1; + GimpLayer *float_layer; + + /* Setup */ + + GIMP_TEST_START("gimp_image_new()") + img = gimp_image_new (32, 32, GIMP_RGB); + GIMP_TEST_END(GIMP_IS_IMAGE (img)) + + layer1 = GIMP_DRAWABLE (gimp_layer_new (img, "layer1", 20, 10, + GIMP_RGBA_IMAGE, 100.0, GIMP_LAYER_MODE_NORMAL)); + layer2 = GIMP_DRAWABLE (gimp_layer_new (img, "layer2", 10, 20, + GIMP_RGBA_IMAGE, 100.0, GIMP_LAYER_MODE_NORMAL)); + group1 = GIMP_DRAWABLE (gimp_layer_group_new (img)); + + GIMP_TEST_START("insert layer") + GIMP_TEST_END(gimp_image_insert_layer (img, GIMP_LAYER (layer1), NULL, 0)) + + GIMP_TEST_START("insert group layer") + GIMP_TEST_END(gimp_image_insert_layer (img, GIMP_LAYER (group1), NULL, -1)) + + GIMP_TEST_START("insert layer inside group") + GIMP_TEST_END(gimp_image_insert_layer (img, GIMP_LAYER (layer2), + GIMP_LAYER (group1), -1)) + + + /* Floating selection tests */ + + /* 1. Fail with no selection */ + GIMP_TEST_START("Gimp.Selection.float - no selection") + GIMP_TEST_END(gimp_selection_float (img, 1, &layer1, 10, 10) == NULL) + + /* 2. Fail on a group layer */ + GIMP_TEST_START("Gimp.Selection.float - group layer") + GIMP_TEST_END(gimp_selection_float (img, 1, &group1, 10, 10) == NULL) + + /* 3. Succeed on a normal layer */ + gimp_image_select_rectangle (img, GIMP_CHANNEL_OP_REPLACE, 5, 5, 20, 20); + + GIMP_TEST_START("gimp_selection_float - normal layer") + float_layer = gimp_selection_float (img, 1, &layer1, 10, 10); + GIMP_TEST_END(GIMP_IS_LAYER (float_layer)) + + GIMP_TEST_START("gimp_floating_sel_remove") + GIMP_TEST_END(gimp_floating_sel_remove (float_layer) == TRUE); + + /* 4. Succeed on a layer inside a group */ + gimp_image_select_rectangle (img, GIMP_CHANNEL_OP_REPLACE, 5, 5, 20, 20); + + GIMP_TEST_START("gimp_selection_float - layer inside group") + float_layer = gimp_selection_float (img, 1, &layer2, 10, 10); + GIMP_TEST_END(GIMP_IS_LAYER (float_layer)) + + GIMP_TEST_START("gimp_floating_sel_remove") + GIMP_TEST_END(gimp_floating_sel_remove (float_layer) == TRUE); + + + /* Teardown */ + gimp_image_delete (img); + + GIMP_TEST_RETURN +} diff --git a/libgimp/tests/test-selection-float.py b/libgimp/tests/test-selection-float.py new file mode 100644 index 0000000000..d6df5db265 --- /dev/null +++ b/libgimp/tests/test-selection-float.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +image = Gimp.Image.new(32,32,Gimp.ImageBaseType.RGB) +gimp_assert('Gimp.Image.new', image is not None) + +layer1 = Gimp.Layer.new(image, "layer1", 20, 10, + Gimp.ImageType.RGBA_IMAGE, 100.0, + Gimp.LayerMode.NORMAL) +image.insert_layer(layer1,None,0) + +group1 = Gimp.Layer.group_new(image) +image.insert_layer(group1,None,-1) + +layer2 = Gimp.Layer.new(image, "layer2", 10, 20, + Gimp.ImageType.RGBA_IMAGE, 100.0, + Gimp.LayerMode.NORMAL) + +gimp_assert('insert layer inside group', image.insert_layer(layer2,group1,-1) == True) + +# Make floating selection + +# 1. Fail with no selection +gimp_assert('Gimp.Selection.float - no selection', + Gimp.Selection.float(image,[layer1],10,10) is None) + +# 2. Fail on a group layer +gimp_assert('Gimp.Selection.float - group layer', + Gimp.Selection.float(image,[group1],10,10) is None) + +# Create a selection +image.select_rectangle(Gimp.ChannelOps.REPLACE, 5, 5, 20, 20) + +# 3. Succeed on a normal layer +gimp_assert('take selected layers: layer1', + image.take_selected_layers([layer1]) is True) +float1 = Gimp.Selection.float(image,[layer1],10,10) +gimp_assert('Gimp.Selection.float - normal layer', + float1 is not None) +gimp_assert('Remove float1 layer from image', + Gimp.floating_sel_remove(float1) is True) + +# Create a selection +image.select_rectangle(Gimp.ChannelOps.REPLACE, 5, 5, 20, 20) + +# 4. Succeed on a layer inside a group +gimp_assert('take selected layers: layer2', + image.take_selected_layers([layer2]) is True) +sel_drawables = image.get_selected_drawables() +gimp_assert('selected drawables', sel_drawables is not None) +float2 = Gimp.Selection.float(image,sel_drawables,10,10) +gimp_assert('Gimp.Selection.float - layer inside group', float2 is not None) +gimp_assert('Remove float2 layer from image', + Gimp.floating_sel_remove(float2) is True) diff --git a/pdb/groups/selection.pdb b/pdb/groups/selection.pdb index 6a6917410e..71d26255fb 100644 --- a/pdb/groups/selection.pdb +++ b/pdb/groups/selection.pdb @@ -213,8 +213,8 @@ HELP for (i = 0; i < num_drawables; i++) { if (! gimp_pdb_item_is_attached (GIMP_ITEM (drawables[i]), NULL, - GIMP_PDB_ITEM_CONTENT, error) || - gimp_pdb_item_is_group (GIMP_ITEM (drawables[i]), error) || + GIMP_PDB_ITEM_CONTENT, error) || + ! gimp_pdb_item_is_not_group (GIMP_ITEM (drawables[i]), error) || (image && image != gimp_item_get_image (GIMP_ITEM (drawables[i])))) { success = FALSE;