Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-08-13 14:21:11 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-08-13 14:21:11 +0400
commita8d1c893e8cea727d24f0bd8c64732fadcbcbcf2 (patch)
tree7ece26514060f98da5e9b900ab1a534daf7928e9 /source/blender/makesrna/intern/rna_ID.c
parent4d5c64372ada6f8dbfd8d89d4bcd515eadbb32d4 (diff)
make materials.pop() and more like pythons list.pop
- allow negative index values. - error when invalid index value are passed in. - remove last item if no index argument is given. also change behavior to remove the material slot, it was only clearning by default but the list length remained the same.
Diffstat (limited to 'source/blender/makesrna/intern/rna_ID.c')
-rw-r--r--source/blender/makesrna/intern/rna_ID.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index 0489f85a37f..76337da3261 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -353,9 +353,26 @@ static void rna_IDMaterials_append_id(ID *id, Material *ma)
WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, id);
}
-static Material *rna_IDMaterials_pop_id(ID *id, int index_i, int remove_material_slot)
+static Material *rna_IDMaterials_pop_id(ID *id, ReportList *reports, int index_i, int remove_material_slot)
{
- Material *ma = material_pop_id(id, index_i, remove_material_slot);
+ Material *ma;
+ short *totcol = give_totcolp_id(id);
+ const short totcol_orig = *totcol;
+ if (index_i < 0) {
+ index_i += (*totcol);
+ }
+
+ if ((index_i < 0) || (index_i >= (*totcol))) {
+ BKE_report(reports, RPT_ERROR, "Index out of range");
+ return NULL;
+ }
+
+ ma = material_pop_id(id, index_i, remove_material_slot);
+
+ if (*totcol == totcol_orig) {
+ BKE_report(reports, RPT_ERROR, "No material to removed");
+ return NULL;
+ }
DAG_id_tag_update(id, OB_RECALC_DATA);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, id);
@@ -476,9 +493,9 @@ static void rna_def_ID_materials(BlenderRNA *brna)
RNA_def_property_flag(parm, PROP_REQUIRED);
func = RNA_def_function(srna, "pop", "rna_IDMaterials_pop_id");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
RNA_def_function_ui_description(func, "Remove a material from the data block");
- parm = RNA_def_int(func, "index", 0, 0, MAXMAT, "", "Index of material to remove", 0, MAXMAT);
- RNA_def_property_flag(parm, PROP_REQUIRED);
+ parm = RNA_def_int(func, "index", -1, -MAXMAT, MAXMAT, "", "Index of material to remove", 0, MAXMAT);
RNA_def_boolean(func, "update_data", 0, "", "Update data by re-adjusting the material slots assigned");
parm = RNA_def_pointer(func, "material", "Material", "", "Material to remove");
RNA_def_function_return(func, parm);