diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-01-26 17:18:16 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-01-26 17:18:16 +0300 |
commit | 2761799c649e728f7ed219f57faa78210c1291ca (patch) | |
tree | 8fcc4bcaae82b42731ba751ef2990d9123e86cb6 | |
parent | 307c10486de9fe264838b898931cae9db92f6ee9 (diff) |
Possible fix for issue #2 in [#25664] Remove Pack does not work in Texture panel
- There were 2 pack menu's, merged into 1.
- Don't attempt to unpack into // if the blend file isn't saved, would use the CWD instead.
-rw-r--r-- | source/blender/editors/include/ED_util.h | 3 | ||||
-rw-r--r-- | source/blender/editors/sound/sound_ops.c | 85 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 112 | ||||
-rw-r--r-- | source/blender/editors/util/ed_util.c | 98 |
4 files changed, 132 insertions, 166 deletions
diff --git a/source/blender/editors/include/ED_util.h b/source/blender/editors/include/ED_util.h index 626ca4bd1e8..1cbf1d0e998 100644 --- a/source/blender/editors/include/ED_util.h +++ b/source/blender/editors/include/ED_util.h @@ -78,5 +78,8 @@ void undo_editmode_step (struct bContext *C, int step); void apply_keyb_grid(int shift, int ctrl, float *val, float fac1, float fac2, float fac3, int invert); int GetButStringLength(const char *str); +/* where else to go ? */ +void unpack_menu(struct bContext *C, const char *opname, const char *id_name, const char *abs_name, const char *folder, struct PackedFile *pf); + #endif /* ED_UTIL_H */ diff --git a/source/blender/editors/sound/sound_ops.c b/source/blender/editors/sound/sound_ops.c index cd6c7e4305d..004fb33f0dd 100644 --- a/source/blender/editors/sound/sound_ops.c +++ b/source/blender/editors/sound/sound_ops.c @@ -29,6 +29,7 @@ #include <string.h> #include <stdlib.h> #include <stdio.h> +#include <stddef.h> #include "MEM_guardedalloc.h" @@ -44,6 +45,7 @@ #include "BKE_context.h" #include "BKE_global.h" +#include "BKE_main.h" #include "BKE_report.h" #include "BKE_packedFile.h" #include "BKE_sound.h" @@ -59,6 +61,8 @@ #include "AUD_C-API.h" +#include "ED_util.h" + #include "sound_intern.h" /******************** open sound operator ********************/ @@ -202,72 +206,17 @@ void SOUND_OT_pack(wmOperatorType *ot) /********************* unpack operator *********************/ -// XXX this function is in image_ops.c too, exactly the same, should be moved to a generally accessible position -static void unpack_menu(bContext *C, const char *opname, const char *abs_name, const char *folder, PackedFile *pf) -{ - uiPopupMenu *pup; - uiLayout *layout; - char line[FILE_MAX + 100]; - char local_name[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX]; - - 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); - - uiItemEnumO(layout, opname, "Remove Pack", 0, "method", PF_REMOVE); - - if(strcmp(abs_name, local_name)) { - switch(checkPackedFile(local_name, pf)) { - case PF_NOFILE: - sprintf(line, "Create %s", local_name); - uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_LOCAL); - break; - case PF_EQUAL: - sprintf(line, "Use %s (identical)", local_name); - uiItemEnumO(layout, opname, line, 0, "method", PF_USE_LOCAL); - break; - case PF_DIFFERS: - sprintf(line, "Use %s (differs)", local_name); - uiItemEnumO(layout, opname, line, 0, "method", PF_USE_LOCAL); - sprintf(line, "Overwrite %s", local_name); - uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_LOCAL); - break; - } - } - - switch(checkPackedFile(abs_name, pf)) { - case PF_NOFILE: - sprintf(line, "Create %s", abs_name); - uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_ORIGINAL); - break; - case PF_EQUAL: - sprintf(line, "Use %s (identical)", abs_name); - uiItemEnumO(layout, opname, line, 0, "method", PF_USE_ORIGINAL); - break; - case PF_DIFFERS: - sprintf(line, "Use %s (differs)", local_name); - uiItemEnumO(layout, opname, line, 0, "method", PF_USE_ORIGINAL); - sprintf(line, "Overwrite %s", local_name); - uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_ORIGINAL); - break; - } - - uiPupMenuEnd(C, pup); -} - -static int unpack_exec(bContext *C, wmOperator *op) +static int sound_unpack_exec(bContext *C, wmOperator *op) { int method= RNA_enum_get(op->ptr, "method"); - Editing* ed = CTX_data_scene(C)->ed; bSound* sound; - if(!ed || !ed->act_seq || ed->act_seq->type != SEQ_SOUND) - return OPERATOR_CANCELLED; - - sound = ed->act_seq->sound; + /* find the suppplied image by name */ + if (RNA_property_is_set(op->ptr, "id")) { + char sndname[22]; + RNA_string_get(op->ptr, "id", sndname); + sound = BLI_findstring(&CTX_data_main(C)->sound, sndname, offsetof(ID, name) + 2); + } if(!sound || !sound->packedfile) return OPERATOR_CANCELLED; @@ -280,11 +229,14 @@ static int unpack_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -static int unpack_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) +static int sound_unpack_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) { Editing* ed = CTX_data_scene(C)->ed; bSound* sound; + if(RNA_property_is_set(op->ptr, "id")) + return sound_unpack_exec(C, op); + if(!ed || !ed->act_seq || ed->act_seq->type != SEQ_SOUND) return OPERATOR_CANCELLED; @@ -296,7 +248,7 @@ 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, "SOUND_OT_unpack", sound->name, "audio", sound->packedfile); + unpack_menu(C, "SOUND_OT_unpack", sound->id.name+2, sound->name, "audio", sound->packedfile); return OPERATOR_FINISHED; } @@ -309,8 +261,8 @@ void SOUND_OT_unpack(wmOperatorType *ot) ot->idname= "SOUND_OT_unpack"; /* api callbacks */ - ot->exec= unpack_exec; - ot->invoke= unpack_invoke; + ot->exec= sound_unpack_exec; + ot->invoke= sound_unpack_invoke; ot->poll= sound_poll; /* flags */ @@ -318,6 +270,7 @@ void SOUND_OT_unpack(wmOperatorType *ot) /* properties */ RNA_def_enum(ot->srna, "method", unpack_method_items, PF_USE_LOCAL, "Method", "How to unpack."); + RNA_def_string(ot->srna, "id", "", 21, "Sound Name", "Sound datablock name to unpack."); /* XXX, weark!, will fail with library, name collisions */ } /* ******************************************************* */ 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 ********************/ diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index f7a4966821a..081bda60ba2 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -27,18 +27,23 @@ */ #include <stdlib.h> +#include <string.h> #include <math.h> #include "MEM_guardedalloc.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" +#include "DNA_packedFile_types.h" #include "BLI_blenlib.h" #include "BLI_editVert.h" #include "BKE_context.h" +#include "BKE_global.h" #include "BKE_main.h" +#include "BKE_utildefines.h" +#include "BKE_packedFile.h" #include "ED_armature.h" #include "ED_mesh.h" @@ -48,6 +53,11 @@ #include "UI_interface.h" +#include "WM_types.h" +#include "RNA_access.h" + + + /* ********* general editor util funcs, not BKE stuff please! ********* */ void ED_editors_init(bContext *C) @@ -161,3 +171,91 @@ int GetButStringLength(const char *str) return rt + 15; } + +void unpack_menu(bContext *C, const char *opname, const char *id_name, const char *abs_name, const char *folder, struct PackedFile *pf) +{ + PointerRNA props_ptr; + uiPopupMenu *pup; + uiLayout *layout; + char line[FILE_MAXDIR + FILE_MAXFILE + 100]; + + 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, "id", id_name); + + if(G.relbase_valid) { + char local_name[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX]; + + BLI_strncpy(local_name, abs_name, sizeof(local_name)); + BLI_splitdirstring(local_name, fi); + sprintf(local_name, "//%s/%s", folder, fi); + if(strcmp(abs_name, local_name)!=0) { + 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, "id", id_name); + + 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, "id", id_name); + + 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, "id", 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, "id", id_name); + 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, "id", id_name); + 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, "id", id_name); + break; + case PF_DIFFERS: + sprintf(line, "Use %s (differs)", 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, "id", id_name); + + sprintf(line, "Overwrite %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, "id", id_name); + break; + } + + uiPupMenuEnd(C, pup); +} |