code cleanup: favor braces when blocks have mixed brace use.
[blender.git] / source / blender / editors / interface / interface_templates.c
index 70a3672..9cc45f5 100644 (file)
 #include "DNA_dynamicpaint_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_object_types.h"
+#include "DNA_object_force.h"
 
 #include "BLI_utildefines.h"
 #include "BLI_string.h"
 #include "BLI_ghash.h"
 #include "BLI_rect.h"
+#include "BLI_math.h"
+#include "BLI_listbase.h"
 
 #include "BLF_api.h"
 #include "BLF_translation.h"
 #include "BKE_animsys.h"
 #include "BKE_colortools.h"
 #include "BKE_context.h"
+#include "BKE_depsgraph.h"
+#include "BKE_displist.h"
 #include "BKE_dynamicpaint.h"
 #include "BKE_global.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
-#include "BKE_object.h"
 #include "BKE_material.h"
-#include "BKE_texture.h"
+#include "BKE_modifier.h"
+#include "BKE_object.h"
+#include "BKE_packedFile.h"
+#include "BKE_particle.h"
 #include "BKE_report.h"
-#include "BKE_displist.h"
 #include "BKE_sca.h"
 #include "BKE_scene.h"
 #include "BKE_screen.h"
+#include "BKE_texture.h"
 
 #include "ED_screen.h"
 #include "ED_object.h"
 #include "ED_render.h"
+#include "ED_util.h"
 
 #include "RNA_access.h"
 #include "RNA_enum_types.h"
@@ -273,7 +281,9 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
                                if (id->flag & LIB_FAKEUSER) id_us_plus(id);
                                else id_us_min(id);
                        }
-                       else return;
+                       else {
+                               return;
+                       }
                        break;
                case UI_ID_LOCAL:
                        if (id) {
@@ -504,7 +514,8 @@ static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, Str
                                                 BLF_I18NCONTEXT_ID_CAMERA,
                                                 BLF_I18NCONTEXT_ID_WORLD,
                                                 BLF_I18NCONTEXT_ID_SCREEN,
-                                                BLF_I18NCONTEXT_ID_TEXT);
+                                                BLF_I18NCONTEXT_ID_TEXT,
+               );
                BLF_I18N_MSGID_MULTI_CTXT("New", BLF_I18NCONTEXT_ID_SPEAKER,
                                                 BLF_I18NCONTEXT_ID_SOUND,
                                                 BLF_I18NCONTEXT_ID_ARMATURE,
@@ -512,7 +523,8 @@ static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, Str
                                                 BLF_I18NCONTEXT_ID_NODETREE,
                                                 BLF_I18NCONTEXT_ID_BRUSH,
                                                 BLF_I18NCONTEXT_ID_PARTICLESETTINGS,
-                                                BLF_I18NCONTEXT_ID_GPENCIL);
+                                                BLF_I18NCONTEXT_ID_GPENCIL,
+               );
                
                if (newop) {
                        but = uiDefIconTextButO(block, BUT, newop, WM_OP_INVOKE_DEFAULT, ICON_ZOOMIN,
@@ -529,7 +541,18 @@ static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, Str
                        uiButSetFlag(but, UI_BUT_DISABLED);
        }
 
-       if (flag & UI_ID_OPEN) {
+       /* Due to space limit in UI - skip the "open" icon for packed data, and allow to unpack.
+          Only for images, sound and fonts */
+       if (id && BKE_pack_check(id)) {
+               but = uiDefIconButO(block, BUT, "FILE_OT_unpack_item", WM_OP_INVOKE_REGION_WIN, ICON_PACKAGE, 0, 0,
+                                   UI_UNIT_X, UI_UNIT_Y, TIP_("Packed File, click to unpack"));
+               uiButGetOperatorPtrRNA(but);
+               
+               RNA_string_set(but->opptr, "id_name", id->name + 2);
+               RNA_int_set(but->opptr, "id_type", GS(id->name));
+               
+       }
+       else if (flag & UI_ID_OPEN) {
                int w = id ? UI_UNIT_X : (flag & UI_ID_ADD_NEW) ? UI_UNIT_X * 3 : UI_UNIT_X * 6;
                
                if (openop) {
@@ -670,7 +693,7 @@ void uiTemplateAnyID(uiLayout *layout, PointerRNA *ptr, const char *propname, co
                        uiItemL(row, text, ICON_NONE);
        }
        else
-               uiItemL(row, "ID-Block:", ICON_NONE);
+               uiItemL(row, IFACE_("ID-Block:"), ICON_NONE);
        
        /* ID-Type Selector - just have a menu of icons */
        /* FIXME: the icon-only setting doesn't work when we supply a blank name */
@@ -714,22 +737,7 @@ void uiTemplatePathBuilder(uiLayout *layout, PointerRNA *ptr, const char *propna
 
 /************************ Modifier Template *************************/
 
-#define ERROR_LIBDATA_MESSAGE "Can't edit external libdata"
-
-#include <string.h>
-
-#include "DNA_object_force.h"
-
-#include "BKE_depsgraph.h"
-#include "BKE_modifier.h"
-#include "BKE_particle.h"
-
-#include "ED_util.h"
-
-#include "BLI_math.h"
-#include "BLI_listbase.h"
-
-#include "ED_object.h"
+#define ERROR_LIBDATA_MESSAGE IFACE_("Can't edit external libdata")
 
 static void modifiers_setOnCage(bContext *C, void *ob_v, void *md_v)
 {
@@ -829,8 +837,8 @@ static uiLayout *draw_modifier(uiLayout *layout, Scene *scene, Object *ob,
                block = uiLayoutGetBlock(row);
                /* VIRTUAL MODIFIER */
                /* XXX this is not used now, since these cannot be accessed via RNA */
-               BLI_snprintf(str, sizeof(str), "%s parent deform", md->name);
-               uiDefBut(block, LABEL, 0, str, 0, 0, 185, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, "Modifier name"); 
+               BLI_snprintf(str, sizeof(str), IFACE_("%s parent deform"), md->name);
+               uiDefBut(block, LABEL, 0, str, 0, 0, 185, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Modifier name"));
                
                but = uiDefBut(block, BUT, 0, IFACE_("Make Real"), 0, 0, 80, 16, NULL, 0.0, 0.0, 0.0, 0.0,
                               TIP_("Convert virtual modifier to a real modifier"));
@@ -937,18 +945,22 @@ static uiLayout *draw_modifier(uiLayout *layout, Scene *scene, Object *ob,
                                
                                if (!(ob->mode & OB_MODE_PARTICLE_EDIT) && psys->pathcache) {
                                        if (ELEM(psys->part->ren_as, PART_DRAW_GR, PART_DRAW_OB))
-                                               uiItemO(row, "Convert", ICON_NONE, "OBJECT_OT_duplicates_make_real");
+                                               uiItemO(row, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Convert"), ICON_NONE,
+                                                       "OBJECT_OT_duplicates_make_real");
                                        else if (psys->part->ren_as == PART_DRAW_PATH)
-                                               uiItemO(row, "Convert", ICON_NONE, "OBJECT_OT_modifier_convert");
+                                               uiItemO(row, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Convert"), ICON_NONE,
+                                                       "OBJECT_OT_modifier_convert");
                                }
                        }
                        else {
                                uiLayoutSetOperatorContext(row, WM_OP_INVOKE_DEFAULT);
-                               uiItemEnumO(row, "OBJECT_OT_modifier_apply", IFACE_("Apply"), 0, "apply_as", MODIFIER_APPLY_DATA);
+                               uiItemEnumO(row, "OBJECT_OT_modifier_apply", CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Apply"),
+                                           0, "apply_as", MODIFIER_APPLY_DATA);
                                
                                if (modifier_isSameTopology(md) && !modifier_isNonGeometrical(md)) {
-                                       uiItemEnumO(row, "OBJECT_OT_modifier_apply", IFACE_("Apply as Shape Key"), 0,
-                                                   "apply_as", MODIFIER_APPLY_SHAPE);
+                                       uiItemEnumO(row, "OBJECT_OT_modifier_apply",
+                                                   CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Apply as Shape Key"),
+                                                   0, "apply_as", MODIFIER_APPLY_SHAPE);
                                }
                        }
                        
@@ -958,7 +970,8 @@ static uiLayout *draw_modifier(uiLayout *layout, Scene *scene, Object *ob,
                        if (!ELEM5(md->type, eModifierType_Fluidsim, eModifierType_Softbody, eModifierType_ParticleSystem,
                                   eModifierType_Cloth, eModifierType_Smoke))
                        {
-                               uiItemO(row, IFACE_("Copy"), ICON_NONE, "OBJECT_OT_modifier_copy");
+                               uiItemO(row, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Copy"), ICON_NONE,
+                                       "OBJECT_OT_modifier_copy");
                        }
                }
                
@@ -1037,9 +1050,8 @@ static void do_constraint_panels(bContext *C, void *ob_pt, int event)
                case B_CONSTRAINT_CHANGETARGET:
                {
                        Main *bmain = CTX_data_main(C);
-                       Scene *scene = CTX_data_scene(C);
                        if (ob->pose) ob->pose->flag |= POSE_RECALC;  /* checks & sorts pose channels */
-                       DAG_scene_sort(bmain, scene);
+                       DAG_relations_tag_update(bmain);
                        break;
                }
 #endif
@@ -1080,10 +1092,10 @@ static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con)
        cti = BKE_constraint_get_typeinfo(con);
        if (cti == NULL) {
                /* exception for 'Null' constraint - it doesn't have constraint typeinfo! */
-               BLI_strncpy(typestr, (con->type == CONSTRAINT_TYPE_NULL) ? "Null" : "Unknown", sizeof(typestr));
+               BLI_strncpy(typestr, (con->type == CONSTRAINT_TYPE_NULL) ? IFACE_("Null") : IFACE_("Unknown"), sizeof(typestr));
        }
        else
-               BLI_strncpy(typestr, cti->name, sizeof(typestr));
+               BLI_strncpy(typestr, IFACE_(cti->name), sizeof(typestr));
                
        /* determine whether constraint is proxy protected or not */
        if (BKE_proxylocked_constraints_owner(ob, pchan))
@@ -1188,7 +1200,7 @@ static uiLayout *draw_constraint(uiLayout *layout, Object *ob, bConstraint *con)
 
        /* Set but-locks for protected settings (magic numbers are used here!) */
        if (proxy_protected)
-               uiBlockSetButLock(block, 1, "Cannot edit Proxy-Protected Constraint");
+               uiBlockSetButLock(block, 1, IFACE_("Cannot edit Proxy-Protected Constraint"));
 
        /* Draw constraint data */
        if ((con->flag & CONSTRAINT_EXPAND) == 0) {
@@ -1472,7 +1484,7 @@ static void colorband_buttons_large(uiLayout *layout, uiBlock *block, ColorBand
                RNA_pointer_create(cb->ptr.id.data, &RNA_ColorRampElement, cbd, &ptr);
                row = uiLayoutRow(layout, FALSE);
 
-               uiItemR(row, &ptr, "position", 0, "Pos", ICON_NONE);
+               uiItemR(row, &ptr, "position", 0, IFACE_("Pos"), ICON_NONE);
                bt = block->buttons.last;
                uiButSetFunc(bt, colorband_update_cb, bt, coba);
 
@@ -1570,7 +1582,8 @@ static uiBlock *icon_view_menu(bContext *C, ARegion *ar, void *arg_litem)
        /* arg_litem is malloced, can be freed by parent button */
        cb = *((RNAUpdateCb *)arg_litem);
        
-       icon = RNA_property_enum_get(&cb.ptr, cb.prop);
+       /* unused */
+       // icon = RNA_property_enum_get(&cb.ptr, cb.prop);
        
        block = uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
        uiBlockSetFlag(block, UI_BLOCK_LOOP | UI_BLOCK_REDRAW);
@@ -1581,11 +1594,12 @@ static uiBlock *icon_view_menu(bContext *C, ARegion *ar, void *arg_litem)
        for (a = 0; item[a].identifier; a++) {
                int x, y;
                
-               x = (a % 8) * UI_UNIT_X * 6;
-               y = (a / 8) * UI_UNIT_X * 6;
+               /* XXX hardcoded size to 5 x unit */
+               x = (a % 8) * UI_UNIT_X * 5;
+               y = (a / 8) * UI_UNIT_X * 5;
                
                icon = item[a].icon;
-               but = uiDefIconButR_prop(block, ROW, 0, icon, x, y, UI_UNIT_X * 6, UI_UNIT_Y * 6, &cb.ptr, cb.prop, -1, 0, icon, -1, -1, NULL);
+               but = uiDefIconButR_prop(block, ROW, 0, icon, x, y, UI_UNIT_X * 5, UI_UNIT_Y * 5, &cb.ptr, cb.prop, -1, 0, icon, -1, -1, NULL);
                uiButSetFlag(but, UI_HAS_ICON | UI_ICON_PREVIEW);
        }
 
@@ -1606,7 +1620,7 @@ void uiTemplateIconView(uiLayout *layout, PointerRNA *ptr, const char *propname)
        RNAUpdateCb *cb;
        uiBlock *block;
        uiBut *but;
-       rctf rect;
+//     rctf rect;  /* UNUSED */
        int icon;
        
        if (!prop || RNA_property_type(prop) != PROP_ENUM)
@@ -1618,8 +1632,8 @@ void uiTemplateIconView(uiLayout *layout, PointerRNA *ptr, const char *propname)
        cb->ptr = *ptr;
        cb->prop = prop;
        
-       rect.xmin = 0; rect.xmax = 10.0f * UI_UNIT_X;
-       rect.ymin = 0; rect.ymax = 10.0f * UI_UNIT_X;
+//     rect.xmin = 0; rect.xmax = 10.0f * UI_UNIT_X;
+//     rect.ymin = 0; rect.ymax = 10.0f * UI_UNIT_X;
        
        block = uiLayoutAbsoluteBlock(layout);
 
@@ -1667,7 +1681,7 @@ void uiTemplateHistogram(uiLayout *layout, PointerRNA *ptr, const char *propname
 
        hist = (Histogram *)cptr.data;
 
-       hist->height = (hist->height <= UI_UNIT_Y) ? UI_UNIT_Y : hist->height;
+       hist->height = (hist->height <= 20) ? 20 : hist->height;
 
        bt = uiDefBut(block, HISTOGRAM, 0, "", rect.xmin, rect.ymin, BLI_rctf_size_x(&rect), UI_DPI_FAC * hist->height,
                      hist, 0, 0, 0, 0, "");
@@ -1706,7 +1720,7 @@ void uiTemplateWaveform(uiLayout *layout, PointerRNA *ptr, const char *propname)
        
        block = uiLayoutAbsoluteBlock(layout);
        
-       scopes->wavefrm_height = (scopes->wavefrm_height <= UI_UNIT_Y) ? UI_UNIT_Y : scopes->wavefrm_height;
+       scopes->wavefrm_height = (scopes->wavefrm_height <= 20) ? 20 : scopes->wavefrm_height;
 
        bt = uiDefBut(block, WAVEFORM, 0, "", rect.xmin, rect.ymin, BLI_rctf_size_x(&rect), UI_DPI_FAC * scopes->wavefrm_height,
                      scopes, 0, 0, 0, 0, "");
@@ -1744,7 +1758,7 @@ void uiTemplateVectorscope(uiLayout *layout, PointerRNA *ptr, const char *propna
        
        block = uiLayoutAbsoluteBlock(layout);
 
-       scopes->vecscope_height = (scopes->vecscope_height <= UI_UNIT_Y) ? UI_UNIT_Y : scopes->vecscope_height;
+       scopes->vecscope_height = (scopes->vecscope_height <= 20) ? 20 : scopes->vecscope_height;
        
        bt = uiDefBut(block, VECTORSCOPE, 0, "", rect.xmin, rect.ymin, BLI_rctf_size_x(&rect),
                      UI_DPI_FAC * scopes->vecscope_height, scopes, 0, 0, 0, 0, "");
@@ -1841,7 +1855,7 @@ static uiBlock *curvemap_clipping_func(bContext *C, ARegion *ar, void *cumap_v)
        /* use this for a fake extra empy space around the buttons */
        uiDefBut(block, LABEL, 0, "",           -4, 16, width + 8, 6 * UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
 
-       bt = uiDefButBitI(block, TOG, CUMA_DO_CLIP, 1, "Use Clipping",
+       bt = uiDefButBitI(block, TOG, CUMA_DO_CLIP, 1, IFACE_("Use Clipping"),
                          0, 5 * UI_UNIT_Y, width, UI_UNIT_Y, &cumap->flag, 0.0, 0.0, 10, 0, "");
        uiButSetFunc(bt, curvemap_buttons_setclip, cumap, NULL);
 
@@ -2471,6 +2485,13 @@ void uiTemplateList(uiLayout *layout, bContext *C, const char *listtype_name, co
        int min, max;
 
        /* validate arguments */
+       /* Forbid default UI_UL_DEFAULT_CLASS_NAME list class without a custom list_id! */
+       if (!strcmp(UI_UL_DEFAULT_CLASS_NAME, listtype_name) && !(list_id && list_id[0])) {
+               RNA_warning("template_list using default '%s' UIList class must provide a custom list_id",
+                           UI_UL_DEFAULT_CLASS_NAME);
+               return;
+       }
+
        block = uiLayoutGetBlock(layout);
 
        if (!active_dataptr->data) {
@@ -2566,7 +2587,8 @@ void uiTemplateList(uiLayout *layout, bContext *C, const char *listtype_name, co
 
                /* if list length changes and active is out of view, scroll to it */
                if ((ui_list->list_last_len != len) &&
-                   (activei < ui_list->list_scroll || activei >= ui_list->list_scroll + items)) {
+                   (activei < ui_list->list_scroll || activei >= ui_list->list_scroll + items))
+               {
                        ui_list->list_scroll = activei;
                }
 
@@ -2698,7 +2720,7 @@ static void operator_search_cb(const bContext *C, void *UNUSED(arg), const char
 {
        GHashIterator *iter = WM_operatortype_iter();
 
-       for (; !BLI_ghashIterator_isDone(iter); BLI_ghashIterator_step(iter)) {
+       for (; BLI_ghashIterator_notDone(iter); BLI_ghashIterator_step(iter)) {
                wmOperatorType *ot = BLI_ghashIterator_getValue(iter);
 
                if ((ot->flag & OPTYPE_INTERNAL) && (G.debug & G_DEBUG_WM) == 0)
@@ -2994,7 +3016,7 @@ void uiTemplateColorspaceSettings(uiLayout *layout, PointerRNA *ptr, const char
 
        colorspace_settings_ptr = RNA_property_pointer_get(ptr, prop);
 
-       uiItemL(layout, "Input Color Space:", ICON_NONE);
+       uiItemL(layout, IFACE_("Input Color Space:"), ICON_NONE);
        uiItemR(layout, &colorspace_settings_ptr, "name", 0, "", ICON_NONE);
 }