diff options
Diffstat (limited to 'source/blender/editors/space_image/image_ops.c')
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 112 |
1 files changed, 12 insertions, 100 deletions
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index cd54a899f35..f5675ebfbe8 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -65,6 +65,7 @@ #include "ED_screen.h" #include "ED_space_api.h" #include "ED_uvedit.h" +#include "ED_util.h" #include "UI_interface.h" #include "UI_resources.h" @@ -1429,104 +1430,15 @@ void IMAGE_OT_pack(wmOperatorType *ot) /********************* unpack operator *********************/ -static void unpack_menu(bContext *C, const char *opname, Image *ima, const char *folder, PackedFile *pf) -{ - PointerRNA props_ptr; - uiPopupMenu *pup; - uiLayout *layout; - char line[FILE_MAXDIR + FILE_MAXFILE + 100]; - char local_name[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX]; - char *abs_name = ima->name; - - strcpy(local_name, abs_name); - BLI_splitdirstring(local_name, fi); - sprintf(local_name, "//%s/%s", folder, fi); - - pup= uiPupMenuBegin(C, "Unpack file", ICON_NULL); - layout= uiPupMenuLayout(pup); - - sprintf(line, "Remove Pack"); - props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS); - RNA_enum_set(&props_ptr, "method", PF_REMOVE); - RNA_string_set(&props_ptr, "image", ima->id.name+2); - - if(strcmp(abs_name, local_name)) { - switch(checkPackedFile(local_name, pf)) { - case PF_NOFILE: - sprintf(line, "Create %s", local_name); - props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS); - RNA_enum_set(&props_ptr, "method", PF_WRITE_LOCAL); - RNA_string_set(&props_ptr, "image", ima->id.name+2); - - break; - case PF_EQUAL: - sprintf(line, "Use %s (identical)", local_name); - //uiItemEnumO(layout, opname, line, 0, "method", PF_USE_LOCAL); - props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS); - RNA_enum_set(&props_ptr, "method", PF_USE_LOCAL); - RNA_string_set(&props_ptr, "image", ima->id.name+2); - - break; - case PF_DIFFERS: - sprintf(line, "Use %s (differs)", local_name); - //uiItemEnumO(layout, opname, line, 0, "method", PF_USE_LOCAL); - props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS); - RNA_enum_set(&props_ptr, "method", PF_USE_LOCAL); - RNA_string_set(&props_ptr, "image", ima->id.name); - - sprintf(line, "Overwrite %s", local_name); - //uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_LOCAL); - props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS); - RNA_enum_set(&props_ptr, "method", PF_WRITE_LOCAL); - RNA_string_set(&props_ptr, "image", ima->id.name+2); - - - break; - } - } - - switch(checkPackedFile(abs_name, pf)) { - case PF_NOFILE: - sprintf(line, "Create %s", abs_name); - //uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_ORIGINAL); - props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS); - RNA_enum_set(&props_ptr, "method", PF_WRITE_ORIGINAL); - RNA_string_set(&props_ptr, "image", ima->id.name+2); - break; - case PF_EQUAL: - sprintf(line, "Use %s (identical)", abs_name); - //uiItemEnumO(layout, opname, line, 0, "method", PF_USE_ORIGINAL); - props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS); - RNA_enum_set(&props_ptr, "method", PF_USE_ORIGINAL); - RNA_string_set(&props_ptr, "image", ima->id.name+2); - break; - case PF_DIFFERS: - sprintf(line, "Use %s (differs)", local_name); - //uiItemEnumO(layout, opname, line, 0, "method", PF_USE_ORIGINAL); - props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS); - RNA_enum_set(&props_ptr, "method", PF_USE_ORIGINAL); - RNA_string_set(&props_ptr, "image", ima->id.name+2); - - sprintf(line, "Overwrite %s", local_name); - //uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_ORIGINAL); - props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS); - RNA_enum_set(&props_ptr, "method", PF_WRITE_ORIGINAL); - RNA_string_set(&props_ptr, "image", ima->id.name+2); - break; - } - - uiPupMenuEnd(C, pup); -} - -static int unpack_exec(bContext *C, wmOperator *op) +static int image_unpack_exec(bContext *C, wmOperator *op) { Image *ima= CTX_data_edit_image(C); int method= RNA_enum_get(op->ptr, "method"); /* find the suppplied image by name */ - if (RNA_property_is_set(op->ptr, "image")) { + if (RNA_property_is_set(op->ptr, "id")) { char imaname[22]; - RNA_string_get(op->ptr, "image", imaname); + RNA_string_get(op->ptr, "id", imaname); ima = BLI_findstring(&CTX_data_main(C)->image, imaname, offsetof(ID, name) + 2); if (!ima) ima = CTX_data_edit_image(C); } @@ -1549,12 +1461,12 @@ static int unpack_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static int unpack_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) +static int image_unpack_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) { Image *ima= CTX_data_edit_image(C); - if(RNA_property_is_set(op->ptr, "image")) - return unpack_exec(C, op); + if(RNA_property_is_set(op->ptr, "id")) + return image_unpack_exec(C, op); if(!ima || !ima->packedfile) return OPERATOR_CANCELLED; @@ -1566,8 +1478,8 @@ static int unpack_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) if(G.fileflags & G_AUTOPACK) BKE_report(op->reports, RPT_WARNING, "AutoPack is enabled, so image will be packed again on file save."); - - unpack_menu(C, "IMAGE_OT_unpack", ima, "textures", ima->packedfile); + + unpack_menu(C, "IMAGE_OT_unpack", ima->id.name+2, ima->name, "textures", ima->packedfile); return OPERATOR_FINISHED; } @@ -1580,15 +1492,15 @@ void IMAGE_OT_unpack(wmOperatorType *ot) ot->idname= "IMAGE_OT_unpack"; /* api callbacks */ - ot->exec= unpack_exec; - ot->invoke= unpack_invoke; + ot->exec= image_unpack_exec; + ot->invoke= image_unpack_invoke; /* flags */ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; /* properties */ RNA_def_enum(ot->srna, "method", unpack_method_items, PF_USE_LOCAL, "Method", "How to unpack."); - RNA_def_string(ot->srna, "image", "", 21, "Image Name", "Image datablock name to unpack."); + RNA_def_string(ot->srna, "id", "", 21, "Image Name", "Image datablock name to unpack."); /* XXX, weark!, will fail with library, name collisions */ } /******************** sample image operator ********************/ |