diff options
author | Ton Roosendaal <ton@blender.org> | 2013-01-27 18:28:45 +0400 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2013-01-27 18:28:45 +0400 |
commit | 1a97efb1ba27a1aaf452da8ef65c27ad6f739fa0 (patch) | |
tree | 7610e0d05be04a055a4a9f1fd0548b816efec53a /source/blender/editors | |
parent | f0339c642d6116e4d7800330db060601da84b9f5 (diff) |
Very old todo: Packed file UI
- The "ID" buttons (for browse images, for example) now show a Pack icon, for packed
Images. Using this button allows unpack.
- Pack and unpack operations now give a Info report on what happened.
- Not restored yet: option to set "AutoPack".
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 14 | ||||
-rw-r--r-- | source/blender/editors/space_info/info_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_info/info_ops.c | 74 | ||||
-rw-r--r-- | source/blender/editors/space_info/space_info.c | 1 |
4 files changed, 89 insertions, 1 deletions
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 3385d334b71..742c7bd402a 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -58,6 +58,7 @@ #include "BKE_material.h" #include "BKE_modifier.h" #include "BKE_object.h" +#include "BKE_packedFile.h" #include "BKE_particle.h" #include "BKE_report.h" #include "BKE_sca.h" @@ -536,7 +537,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_UGLYPACKAGE, 0, 0, UI_UNIT_X, UI_UNIT_Y, "Packed File"); + 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) { diff --git a/source/blender/editors/space_info/info_intern.h b/source/blender/editors/space_info/info_intern.h index 62e9a3a7f73..b5426fe15e1 100644 --- a/source/blender/editors/space_info/info_intern.h +++ b/source/blender/editors/space_info/info_intern.h @@ -39,6 +39,7 @@ struct ReportList; void FILE_OT_pack_all(struct wmOperatorType *ot); void FILE_OT_unpack_all(struct wmOperatorType *ot); +void FILE_OT_unpack_item(struct wmOperatorType *ot); void FILE_OT_pack_libraries(struct wmOperatorType *ot); void FILE_OT_unpack_libraries(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_info/info_ops.c b/source/blender/editors/space_info/info_ops.c index 104349e172a..663d136fdf2 100644 --- a/source/blender/editors/space_info/info_ops.c +++ b/source/blender/editors/space_info/info_ops.c @@ -46,9 +46,11 @@ #include "BKE_context.h" #include "BKE_global.h" #include "BKE_image.h" +#include "BKE_library.h" #include "BKE_main.h" #include "BKE_packedFile.h" #include "BKE_report.h" +#include "BKE_screen.h" #include "WM_api.h" @@ -249,6 +251,78 @@ void FILE_OT_unpack_all(wmOperatorType *ot) RNA_def_enum(ot->srna, "method", unpack_all_method_items, PF_USE_LOCAL, "Method", "How to unpack"); } +/********************* unpack single item operator *********************/ + +static const EnumPropertyItem unpack_item_method_items[] = { + {PF_USE_LOCAL, "USE_LOCAL", 0, "Use file from current directory (create when necessary)", ""}, + {PF_WRITE_LOCAL, "WRITE_LOCAL", 0, "Write file to current directory (overwrite existing file)", ""}, + {PF_USE_ORIGINAL, "USE_ORIGINAL", 0, "Use file in original location (create when necessary)", ""}, + {PF_WRITE_ORIGINAL, "WRITE_ORIGINAL", 0, "Write file to original location (overwrite existing file)", ""}, + /* {PF_ASK, "ASK", 0, "Ask for each file", ""}, */ + {0, NULL, 0, NULL, NULL}}; + + +static int unpack_item_exec(bContext *C, wmOperator *op) +{ + Main *bmain = CTX_data_main(C); + ID *id; + char idname[BKE_ST_MAXNAME]; + int type = RNA_int_get(op->ptr, "id_type"); + int method = RNA_enum_get(op->ptr, "method"); + + RNA_string_get(op->ptr, "id_name", idname); + id = BKE_libblock_find_name(type, idname); + + if (id == NULL) { + BKE_report(op->reports, RPT_WARNING, "No packed file"); + return OPERATOR_CANCELLED; + } + + if (method != PF_KEEP) + BKE_unpack_id(bmain, id, op->reports, method); /* XXX PF_ASK can't work here */ + + G.fileflags &= ~G_AUTOPACK; + + return OPERATOR_FINISHED; +} + +static int unpack_item_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) +{ + uiPopupMenu *pup; + uiLayout *layout; + + pup = uiPupMenuBegin(C, "Unpack", ICON_NONE); + layout = uiPupMenuLayout(pup); + + uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT); + uiItemsFullEnumO(layout, op->type->idname, "method", op->ptr->data, WM_OP_EXEC_REGION_WIN, 0); + + uiPupMenuEnd(C, pup); + + return OPERATOR_CANCELLED; +} + +void FILE_OT_unpack_item(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Unpack Item"; + ot->idname = "FILE_OT_unpack_item"; + ot->description = "Unpack this file to an external file"; + + /* api callbacks */ + ot->exec = unpack_item_exec; + ot->invoke = unpack_item_invoke; + + /* flags */ + ot->flag = OPTYPE_UNDO; + + /* properties */ + RNA_def_enum(ot->srna, "method", unpack_item_method_items, PF_USE_LOCAL, "Method", "How to unpack"); + RNA_def_string(ot->srna, "id_name", "", BKE_ST_MAXNAME, "ID name", "Name of ID block to unpack"); + RNA_def_int(ot->srna, "id_type", 0, 0, INT_MAX, "ID Type", "Identifier type of ID block", 0, INT_MAX); +} + + /********************* make paths relative operator *********************/ static int make_paths_relative_exec(bContext *C, wmOperator *op) diff --git a/source/blender/editors/space_info/space_info.c b/source/blender/editors/space_info/space_info.c index 60b04f7b029..1577ac338e7 100644 --- a/source/blender/editors/space_info/space_info.c +++ b/source/blender/editors/space_info/space_info.c @@ -180,6 +180,7 @@ static void info_operatortypes(void) WM_operatortype_append(FILE_OT_pack_all); WM_operatortype_append(FILE_OT_pack_libraries); WM_operatortype_append(FILE_OT_unpack_all); + WM_operatortype_append(FILE_OT_unpack_item); WM_operatortype_append(FILE_OT_unpack_libraries); WM_operatortype_append(FILE_OT_make_paths_relative); |